Lines 35-44
Link Here
|
35 |
*/ |
35 |
*/ |
36 |
|
36 |
|
37 |
#include "sysinstall.h" |
37 |
#include "sysinstall.h" |
38 |
#include <sys/signal.h> |
|
|
39 |
#include <sys/fcntl.h> |
38 |
#include <sys/fcntl.h> |
|
|
39 |
#include <sys/resource.h> |
40 |
#include <sys/time.h> |
40 |
#include <sys/time.h> |
41 |
#include <sys/resource.h> |
41 |
#include <err.h> |
|
|
42 |
#include <signal.h> |
42 |
|
43 |
|
43 |
const char *StartName; /* Initial contents of argv[0] */ |
44 |
const char *StartName; /* Initial contents of argv[0] */ |
44 |
const char *ProgName = "sysinstall"; |
45 |
const char *ProgName = "sysinstall"; |
Lines 57-64
Link Here
|
57 |
char titlestr[80], *arch, *osrel, *ostype; |
58 |
char titlestr[80], *arch, *osrel, *ostype; |
58 |
struct rlimit rlim; |
59 |
struct rlimit rlim; |
59 |
char *arg; |
60 |
char *arg; |
60 |
int i; |
61 |
int exit_status, i; |
61 |
int optionArgs = 0; |
62 |
int optionArgs = 0; |
|
|
63 |
pid_t rv, sysinstall_proper; |
62 |
|
64 |
|
63 |
/* Record name to be able to restart */ |
65 |
/* Record name to be able to restart */ |
64 |
StartName = argv[0]; |
66 |
StartName = argv[0]; |
Lines 88-95
Link Here
|
88 |
} |
90 |
} |
89 |
|
91 |
|
90 |
if (getpid() == 1) |
92 |
if (getpid() == 1) |
91 |
RunningAsInit = TRUE; |
93 |
RunningAsInit = TRUE; |
92 |
|
94 |
|
|
|
95 |
/* We don't work too well when running as non-root anymore */ |
96 |
if (geteuid() != 0) { |
97 |
fprintf(stderr, "Error: This utility should only be run as root.\n"); |
98 |
return 1; |
99 |
} |
100 |
|
101 |
/* |
102 |
* To simplify things dealing with cleanup as sysinstall is reentrant |
103 |
* (sadly), it's just easier to fork a new process once we know that |
104 |
* we're root and running as init. |
105 |
* |
106 |
* Please do not move this logic. |
107 |
*/ |
108 |
do { |
109 |
|
110 |
/* Reset the process group just in case. */ |
111 |
setpgid(0, getpid()); |
112 |
|
113 |
sysinstall_proper = fork(); |
114 |
|
115 |
switch (sysinstall_proper) { |
116 |
case -1: |
117 |
err(1, "fork failed"); |
118 |
case 0: |
119 |
break; |
120 |
default: |
121 |
|
122 |
/* Let the child take the heat. */ |
123 |
signal(SIGINT, SIG_IGN); |
124 |
setpgrp(0, sysinstall_proper); |
125 |
|
126 |
do { |
127 |
rv = waitpid(sysinstall_proper, &exit_status, 0); |
128 |
if (errno == EINTR) |
129 |
/* Be kind to the CPU */ |
130 |
sleep(1); |
131 |
} while (rv == -1 && errno == EINTR); |
132 |
|
133 |
if (rv == -1) { |
134 |
/* |
135 |
* Just in case (see ECHILD/SA_NOCLDWAIT error under wait(2). |
136 |
* errant sysinstall processes => bad. |
137 |
*/ |
138 |
kill(9, sysinstall_proper); |
139 |
err(1, "waiting for sysinstall proper failed"); |
140 |
} else if (exit_status != 0) { |
141 |
/* For developer debug. */ |
142 |
#if 0 |
143 |
if (WIFSIGNALED(exit_status)) { |
144 |
errx(1, "sysinstall proper signaled with signal = %d", |
145 |
WTERMSIG(exit_status)); |
146 |
} else if (WIFEXITED(exit_status)) { |
147 |
errx(1, "sysinstall proper exited with exit code = %d", |
148 |
WEXITSTATUS(exit_status)); |
149 |
} |
150 |
#endif |
151 |
exit(1); |
152 |
} else |
153 |
/* All's good! */ |
154 |
exit(0); |
155 |
break; |
156 |
} |
157 |
|
158 |
} while (sysinstall_proper != 0); |
159 |
|
93 |
/* Catch fatal signals and complain about them if running as init */ |
160 |
/* Catch fatal signals and complain about them if running as init */ |
94 |
if (RunningAsInit) { |
161 |
if (RunningAsInit) { |
95 |
signal(SIGBUS, screech); |
162 |
signal(SIGBUS, screech); |
Lines 97-108
Link Here
|
97 |
} |
164 |
} |
98 |
signal(SIGPIPE, SIG_IGN); |
165 |
signal(SIGPIPE, SIG_IGN); |
99 |
|
166 |
|
100 |
/* We don't work too well when running as non-root anymore */ |
|
|
101 |
if (geteuid() != 0) { |
102 |
fprintf(stderr, "Error: This utility should only be run as root.\n"); |
103 |
return 1; |
104 |
} |
105 |
|
106 |
/* |
167 |
/* |
107 |
* Given what it does sysinstall (and stuff sysinstall runs like |
168 |
* Given what it does sysinstall (and stuff sysinstall runs like |
108 |
* pkg_add) shouldn't be subject to process limits. Better to just |
169 |
* pkg_add) shouldn't be subject to process limits. Better to just |