Lines 168-173
struct actions {
Link Here
|
168 |
{ "initdefault", INITDEFAULT }, |
168 |
{ "initdefault", INITDEFAULT }, |
169 |
{ "sysinit", SYSINIT }, |
169 |
{ "sysinit", SYSINIT }, |
170 |
{ "kbrequest", KBREQUEST }, |
170 |
{ "kbrequest", KBREQUEST }, |
|
|
171 |
{ "exec", EXEC }, |
171 |
{ NULL, 0 }, |
172 |
{ NULL, 0 }, |
172 |
}; |
173 |
}; |
173 |
|
174 |
|
Lines 924-930
void init_freeenv(char **e)
Link Here
|
924 |
* |
925 |
* |
925 |
*/ |
926 |
*/ |
926 |
static |
927 |
static |
927 |
pid_t spawn(CHILD *ch, int *res) |
928 |
pid_t spawn(CHILD *ch, int *res, int do_fork) |
928 |
{ |
929 |
{ |
929 |
char *args[16]; /* Argv array */ |
930 |
char *args[16]; /* Argv array */ |
930 |
char buf[136]; /* Line buffer */ |
931 |
char buf[136]; /* Line buffer */ |
Lines 933-939
pid_t spawn(CHILD *ch, int *res)
Link Here
|
933 |
time_t t; /* System time */ |
934 |
time_t t; /* System time */ |
934 |
int oldAlarm; /* Previous alarm value */ |
935 |
int oldAlarm; /* Previous alarm value */ |
935 |
char *proc = ch->process; /* Command line */ |
936 |
char *proc = ch->process; /* Command line */ |
936 |
pid_t pid, pgrp; /* child, console process group. */ |
937 |
pid_t pid = -1, pgrp; /* child, console process group. */ |
937 |
sigset_t nmask, omask; /* For blocking SIGCHLD */ |
938 |
sigset_t nmask, omask; /* For blocking SIGCHLD */ |
938 |
struct sigaction sa; |
939 |
struct sigaction sa; |
939 |
|
940 |
|
Lines 1033-1057
pid_t spawn(CHILD *ch, int *res)
Link Here
|
1033 |
/* |
1034 |
/* |
1034 |
* Block sigchild while forking. |
1035 |
* Block sigchild while forking. |
1035 |
*/ |
1036 |
*/ |
1036 |
sigemptyset(&nmask); |
1037 |
if (do_fork) { |
1037 |
sigaddset(&nmask, SIGCHLD); |
1038 |
sigemptyset(&nmask); |
1038 |
sigprocmask(SIG_BLOCK, &nmask, &omask); |
1039 |
sigaddset(&nmask, SIGCHLD); |
|
|
1040 |
sigprocmask(SIG_BLOCK, &nmask, &omask); |
1041 |
} |
1039 |
|
1042 |
|
1040 |
if ((pid = fork()) == 0) { |
1043 |
if ((!do_fork) || ((pid = fork()) == 0)) { |
1041 |
|
1044 |
|
1042 |
close(0); |
1045 |
if (do_fork) { |
1043 |
close(1); |
1046 |
close(0); |
1044 |
close(2); |
1047 |
close(1); |
1045 |
if (pipe_fd >= 0) close(pipe_fd); |
1048 |
close(2); |
|
|
1049 |
if (pipe_fd >= 0) close(pipe_fd); |
1046 |
|
1050 |
|
1047 |
sigprocmask(SIG_SETMASK, &omask, NULL); |
1051 |
sigprocmask(SIG_SETMASK, &omask, NULL); |
|
|
1052 |
} |
1048 |
|
1053 |
|
1049 |
/* |
1054 |
/* |
1050 |
* In sysinit, boot, bootwait or single user mode: |
1055 |
* In sysinit, boot, bootwait or single user mode: |
1051 |
* for any wait-type subprocess we _force_ the console |
1056 |
* for any wait-type subprocess we _force_ the console |
1052 |
* to be its controlling tty. |
1057 |
* to be its controlling tty. |
1053 |
*/ |
1058 |
*/ |
1054 |
if (strchr("*#sS", runlevel) && ch->flags & WAITING) { |
1059 |
if (strchr("*#sS", runlevel) && ch->flags & WAITING && do_fork) { |
1055 |
/* |
1060 |
/* |
1056 |
* We fork once extra. This is so that we can |
1061 |
* We fork once extra. This is so that we can |
1057 |
* wait and change the process group and session |
1062 |
* wait and change the process group and session |
Lines 1123-1130
pid_t spawn(CHILD *ch, int *res)
Link Here
|
1123 |
/* Set ioctl settings to default ones */ |
1128 |
/* Set ioctl settings to default ones */ |
1124 |
console_stty(); |
1129 |
console_stty(); |
1125 |
|
1130 |
|
1126 |
} else { |
1131 |
} else { |
1127 |
setsid(); |
1132 |
if (do_fork) { |
|
|
1133 |
setsid(); |
1134 |
} |
1128 |
if ((f = console_open(O_RDWR|O_NOCTTY)) < 0) { |
1135 |
if ((f = console_open(O_RDWR|O_NOCTTY)) < 0) { |
1129 |
initlog(L_VB, "open(%s): %s", console_dev, |
1136 |
initlog(L_VB, "open(%s): %s", console_dev, |
1130 |
strerror(errno)); |
1137 |
strerror(errno)); |
Lines 1150-1157
pid_t spawn(CHILD *ch, int *res)
Link Here
|
1150 |
* FIXME: that's for compatibility with *very* |
1157 |
* FIXME: that's for compatibility with *very* |
1151 |
* old getties - probably it can be taken out. |
1158 |
* old getties - probably it can be taken out. |
1152 |
*/ |
1159 |
*/ |
1153 |
if (ch->process[0] != '+') |
1160 |
if (do_fork) { |
1154 |
write_utmp_wtmp("", ch->id, getpid(), INIT_PROCESS, ""); |
1161 |
if (ch->process[0] != '+') |
|
|
1162 |
write_utmp_wtmp("", ch->id, getpid(), INIT_PROCESS, ""); |
1163 |
} |
1155 |
|
1164 |
|
1156 |
/* Reset all the signals, set up environment */ |
1165 |
/* Reset all the signals, set up environment */ |
1157 |
for(f = 1; f < NSIG; f++) SETSIG(sa, f, SIG_DFL, SA_RESTART); |
1166 |
for(f = 1; f < NSIG; f++) SETSIG(sa, f, SIG_DFL, SA_RESTART); |
Lines 1173-1188
pid_t spawn(CHILD *ch, int *res)
Link Here
|
1173 |
} |
1182 |
} |
1174 |
initlog(L_VB, "cannot execute \"%s\"", args[1]); |
1183 |
initlog(L_VB, "cannot execute \"%s\"", args[1]); |
1175 |
|
1184 |
|
1176 |
if (ch->process[0] != '+') |
1185 |
if (do_fork) { |
1177 |
write_utmp_wtmp("", ch->id, getpid(), DEAD_PROCESS, NULL); |
1186 |
if (ch->process[0] != '+') |
1178 |
exit(1); |
1187 |
write_utmp_wtmp("", ch->id, getpid(), DEAD_PROCESS, NULL); |
|
|
1188 |
exit(1); |
1189 |
} |
1190 |
else |
1191 |
{ |
1192 |
/* |
1193 |
* exec() failed, continue init process |
1194 |
* Make sure there are some fallback records after an exec record |
1195 |
*/ |
1196 |
|
1197 |
initlog(L_VB, "cannot execute \"%s\", continuing to next action", args[1]); |
1198 |
} |
1179 |
} |
1199 |
} |
|
|
1200 |
|
1180 |
*res = pid; |
1201 |
*res = pid; |
1181 |
sigprocmask(SIG_SETMASK, &omask, NULL); |
|
|
1182 |
|
1202 |
|
1183 |
INITDBG(L_VB, "Started id %s (pid %d)", ch->id, pid); |
1203 |
if (do_fork) { |
|
|
1204 |
sigprocmask(SIG_SETMASK, &omask, NULL); |
1184 |
|
1205 |
|
1185 |
if (pid == -1) { |
1206 |
INITDBG(L_VB, "Started id %s (pid %d)", ch->id, pid); |
|
|
1207 |
} |
1208 |
|
1209 |
if (do_fork && (pid == -1)) { |
1186 |
initlog(L_VB, "cannot fork, retry.."); |
1210 |
initlog(L_VB, "cannot fork, retry.."); |
1187 |
do_sleep(5); |
1211 |
do_sleep(5); |
1188 |
continue; |
1212 |
continue; |
Lines 1220-1227
void startup(CHILD *ch)
Link Here
|
1220 |
case ONDEMAND: |
1244 |
case ONDEMAND: |
1221 |
case RESPAWN: |
1245 |
case RESPAWN: |
1222 |
ch->flags |= RUNNING; |
1246 |
ch->flags |= RUNNING; |
1223 |
(void)spawn(ch, &(ch->pid)); |
1247 |
(void)spawn(ch, &(ch->pid), 1); |
1224 |
break; |
1248 |
break; |
|
|
1249 |
case EXEC: |
1250 |
(void)spawn(ch, &(ch->pid), 0); |
1251 |
break; |
1225 |
} |
1252 |
} |
1226 |
} |
1253 |
} |
1227 |
|
1254 |
|
Lines 2606-2612
void init_main(void)
Link Here
|
2606 |
if (emerg_shell) { |
2633 |
if (emerg_shell) { |
2607 |
pid_t rc; |
2634 |
pid_t rc; |
2608 |
SETSIG(sa, SIGCHLD, SIG_DFL, SA_RESTART); |
2635 |
SETSIG(sa, SIGCHLD, SIG_DFL, SA_RESTART); |
2609 |
if (spawn(&ch_emerg, &f) > 0) { |
2636 |
if (spawn(&ch_emerg, &f, 1) > 0) { |
2610 |
while((rc = wait(&st)) != f) |
2637 |
while((rc = wait(&st)) != f) |
2611 |
if (rc < 0 && errno == ECHILD) |
2638 |
if (rc < 0 && errno == ECHILD) |
2612 |
break; |
2639 |
break; |