diff options
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/pies.c | 22 | ||||
-rw-r--r-- | src/pies.h | 13 | ||||
-rw-r--r-- | src/progman.c | 58 | ||||
-rw-r--r-- | src/sysvinit.c | 172 |
5 files changed, 226 insertions, 40 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 44e0a8d..0fca105 100644 --- a/src/Makefile.am +++ b/src/Makefile.am | |||
@@ -30,6 +30,7 @@ pies_SOURCES = \ | |||
30 | pies.c\ | 30 | pies.c\ |
31 | progman.c\ | 31 | progman.c\ |
32 | socket.c\ | 32 | socket.c\ |
33 | sysvinit.c\ | ||
33 | url.c\ | 34 | url.c\ |
34 | userprivs.c | 35 | userprivs.c |
35 | 36 | ||
@@ -39,8 +39,6 @@ enum pies_command { | |||
39 | }; | 39 | }; |
40 | 40 | ||
41 | enum pies_command command; | 41 | enum pies_command command; |
42 | int initdefault; /* Default runlevel */ | ||
43 | int dfl_level; | ||
44 | char *statedir = DEFAULT_STATE_DIR; | 42 | char *statedir = DEFAULT_STATE_DIR; |
45 | char *instance; | 43 | char *instance; |
46 | char *pidfile; | 44 | char *pidfile; |
@@ -834,6 +832,17 @@ static struct tokendef modetab[] = { | |||
834 | {"nostartaccept", pies_comp_inetd}, | 832 | {"nostartaccept", pies_comp_inetd}, |
835 | {"pass-fd", pies_comp_pass_fd}, | 833 | {"pass-fd", pies_comp_pass_fd}, |
836 | {"pass", pies_comp_pass_fd}, | 834 | {"pass", pies_comp_pass_fd}, |
835 | {"boot", pies_comp_boot}, | ||
836 | {"bootwait", pies_comp_boot}, | ||
837 | {"powerfail", pies_comp_powerfail}, | ||
838 | {"powerwait", pies_comp_powerwait}, | ||
839 | {"powerokwait", pies_comp_powerokwait}, | ||
840 | {"ctrlaltdel", pies_comp_ctrlaltdel}, | ||
841 | {"ondemand", pies_comp_ondemand}, | ||
842 | {"sysinit", pies_comp_sysinit}, | ||
843 | {"powerfailnow", pies_comp_powerfailnow}, | ||
844 | {"kbrequest", pies_comp_kbrequest}, | ||
845 | |||
837 | {NULL} | 846 | {NULL} |
838 | }; | 847 | }; |
839 | 848 | ||
@@ -2132,15 +2141,6 @@ set_console_dev () | |||
2132 | console_device = "/dev/null"; | 2141 | console_device = "/dev/null"; |
2133 | } | 2142 | } |
2134 | 2143 | ||
2135 | static void | ||
2136 | inittrans () | ||
2137 | { | ||
2138 | if (progman_running_p ()) | ||
2139 | /* Noting to do if there are processes left in the previous runlevel */ | ||
2140 | return; | ||
2141 | |||
2142 | } | ||
2143 | |||
2144 | int | 2144 | int |
2145 | main (int argc, char **argv) | 2145 | main (int argc, char **argv) |
2146 | { | 2146 | { |
@@ -145,10 +145,10 @@ enum pies_comp_mode | |||
145 | /* | 145 | /* |
146 | ** Init-style components | 146 | ** Init-style components |
147 | */ | 147 | */ |
148 | 148 | pies_mark_sysvinit, | |
149 | /* Start the process when the specified runlevel is entered and wait | 149 | /* Start the process when the specified runlevel is entered and wait |
150 | for its termination */ | 150 | for its termination */ |
151 | pies_comp_wait, | 151 | pies_comp_wait = pies_mark_sysvinit, |
152 | /* Execute the component once, when the specified runlevel is entered */ | 152 | /* Execute the component once, when the specified runlevel is entered */ |
153 | pies_comp_once, | 153 | pies_comp_once, |
154 | /* Execute the component during system boot. Ignore runlevel settings. */ | 154 | /* Execute the component during system boot. Ignore runlevel settings. */ |
@@ -183,6 +183,8 @@ enum pies_comp_mode | |||
183 | pies_comp_respawn = pies_comp_exec, | 183 | pies_comp_respawn = pies_comp_exec, |
184 | }; | 184 | }; |
185 | 185 | ||
186 | #define is_sysvinit(m) ((m)>=pies_mark_sysvinit) | ||
187 | |||
186 | #define CF_DISABLED 0x001 /* The componenet is disabled */ | 188 | #define CF_DISABLED 0x001 /* The componenet is disabled */ |
187 | #define CF_PRECIOUS 0x002 /* The component is precious (should not | 189 | #define CF_PRECIOUS 0x002 /* The component is precious (should not |
188 | be disabled) */ | 190 | be disabled) */ |
@@ -274,6 +276,7 @@ extern char *qotdfile; | |||
274 | extern int init_process; | 276 | extern int init_process; |
275 | extern char *console_device; | 277 | extern char *console_device; |
276 | extern int initdefault; | 278 | extern int initdefault; |
279 | extern int dfl_level; | ||
277 | 280 | ||
278 | void register_prog (struct component *comp); | 281 | void register_prog (struct component *comp); |
279 | int progman_running_p (void); | 282 | int progman_running_p (void); |
@@ -445,5 +448,11 @@ struct inetd_builtin | |||
445 | }; | 448 | }; |
446 | 449 | ||
447 | struct inetd_builtin *inetd_builtin_lookup (const char *service, int socktype); | 450 | struct inetd_builtin *inetd_builtin_lookup (const char *service, int socktype); |
451 | |||
452 | /* sysvinit.c */ | ||
453 | int runlevel_match (struct component *comp); | ||
454 | void inittrans (void); | ||
455 | int is_comp_wait (struct component *comp); | ||
456 | |||
448 | 457 | ||
449 | 458 | ||
diff --git a/src/progman.c b/src/progman.c index 639c22f..e25219a 100644 --- a/src/progman.c +++ b/src/progman.c | |||
@@ -409,8 +409,11 @@ progman_running_p () | |||
409 | struct prog *prog; | 409 | struct prog *prog; |
410 | 410 | ||
411 | for (prog = proghead; prog; prog = prog->next) | 411 | for (prog = proghead; prog; prog = prog->next) |
412 | if (prog->pid > 0) | 412 | { |
413 | return 1; | 413 | if (IS_COMPONENT (prog) && is_comp_wait (prog->v.p.comp) && |
414 | prog->pid > 0) | ||
415 | return 1; | ||
416 | } | ||
414 | return 0; | 417 | return 0; |
415 | } | 418 | } |
416 | 419 | ||
@@ -1181,6 +1184,14 @@ prog_start (struct prog *prog) | |||
1181 | 1184 | ||
1182 | if (prog->pid > 0 || !IS_COMPONENT (prog)) | 1185 | if (prog->pid > 0 || !IS_COMPONENT (prog)) |
1183 | return; | 1186 | return; |
1187 | |||
1188 | if (is_sysvinit (prog->v.p.comp->mode) && !init_process && | ||
1189 | prog->v.p.status != status_disabled) | ||
1190 | { | ||
1191 | logmsg (LOG_NOTICE, "disabling sysvinit component %s", prog->tag); | ||
1192 | prog->v.p.status = status_disabled; | ||
1193 | return; | ||
1194 | } | ||
1184 | 1195 | ||
1185 | /* This call returns 1 in two cases: Either prog is marked as disabled, | 1196 | /* This call returns 1 in two cases: Either prog is marked as disabled, |
1186 | in which case there's nothing more to do, or one or more of its | 1197 | in which case there's nothing more to do, or one or more of its |
@@ -1256,9 +1267,17 @@ prog_start (struct prog *prog) | |||
1256 | prog_start_prologue (prog); | 1267 | prog_start_prologue (prog); |
1257 | switch (prog->v.p.comp->mode) | 1268 | switch (prog->v.p.comp->mode) |
1258 | { | 1269 | { |
1259 | case pies_comp_pass_fd: | 1270 | case pies_comp_accept: |
1260 | case pies_comp_exec: | 1271 | case pies_comp_inetd: |
1261 | case pies_comp_once: | 1272 | prog_sockenv (prog); |
1273 | |||
1274 | dup2 (prog->v.p.socket, 0); | ||
1275 | dup2 (prog->v.p.socket, 1); | ||
1276 | close (prog->v.p.socket); | ||
1277 | prog->v.p.socket = -1; | ||
1278 | break; | ||
1279 | |||
1280 | default: | ||
1262 | if (init_process) | 1281 | if (init_process) |
1263 | { | 1282 | { |
1264 | int fd = console_open (O_RDWR|O_NOCTTY); | 1283 | int fd = console_open (O_RDWR|O_NOCTTY); |
@@ -1288,16 +1307,6 @@ prog_start (struct prog *prog) | |||
1288 | } | 1307 | } |
1289 | } | 1308 | } |
1290 | break; | 1309 | break; |
1291 | |||
1292 | case pies_comp_accept: | ||
1293 | case pies_comp_inetd: | ||
1294 | prog_sockenv (prog); | ||
1295 | |||
1296 | dup2 (prog->v.p.socket, 0); | ||
1297 | dup2 (prog->v.p.socket, 1); | ||
1298 | close (prog->v.p.socket); | ||
1299 | prog->v.p.socket = -1; | ||
1300 | break; | ||
1301 | } | 1310 | } |
1302 | 1311 | ||
1303 | if (!init_process) | 1312 | if (!init_process) |
@@ -1346,8 +1355,9 @@ prog_start (struct prog *prog) | |||
1346 | { | 1355 | { |
1347 | disable_socket (prog->v.p.socket); | 1356 | disable_socket (prog->v.p.socket); |
1348 | } | 1357 | } |
1349 | else if (prog->v.p.comp->mode != pies_comp_exec && | 1358 | else if (prog->v.p.comp->mode == pies_comp_accept || |
1350 | prog->v.p.comp->mode != pies_comp_once) | 1359 | prog->v.p.comp->mode == pies_comp_inetd || |
1360 | prog->v.p.comp->mode == pies_comp_pass_fd) | ||
1351 | close (prog->v.p.socket); | 1361 | close (prog->v.p.socket); |
1352 | prog->pid = pid; | 1362 | prog->pid = pid; |
1353 | prog->v.p.status = status_enabled; | 1363 | prog->v.p.status = status_enabled; |
@@ -1760,14 +1770,6 @@ progman_recompute_alarm () | |||
1760 | 1770 | ||
1761 | 1771 | ||
1762 | 1772 | ||
1763 | static int | ||
1764 | runlevel_match (struct prog *prog) | ||
1765 | { | ||
1766 | if (!initdefault || !prog->v.p.comp->runlevels) | ||
1767 | return 1; | ||
1768 | return !!strchr (prog->v.p.comp->runlevels, initdefault); | ||
1769 | } | ||
1770 | |||
1771 | void | 1773 | void |
1772 | progman_start () | 1774 | progman_start () |
1773 | { | 1775 | { |
@@ -1781,7 +1783,7 @@ progman_start () | |||
1781 | if (prog->v.p.comp->mode == pies_comp_inetd) | 1783 | if (prog->v.p.comp->mode == pies_comp_inetd) |
1782 | { | 1784 | { |
1783 | if ((prog->v.p.comp->flags & CF_DISABLED) | 1785 | if ((prog->v.p.comp->flags & CF_DISABLED) |
1784 | || !runlevel_match (prog)) | 1786 | || !runlevel_match (prog->v.p.comp)) |
1785 | disable_socket (prog->v.p.socket); | 1787 | disable_socket (prog->v.p.socket); |
1786 | else | 1788 | else |
1787 | { | 1789 | { |
@@ -1790,7 +1792,7 @@ progman_start () | |||
1790 | } | 1792 | } |
1791 | } | 1793 | } |
1792 | else if ((prog->v.p.status == status_enabled && prog->pid == 0 | 1794 | else if ((prog->v.p.status == status_enabled && prog->pid == 0 |
1793 | && runlevel_match (prog)) | 1795 | && runlevel_match (prog->v.p.comp)) |
1794 | || prog->v.p.status == status_sleeping) | 1796 | || prog->v.p.status == status_sleeping) |
1795 | prog_start (prog); | 1797 | prog_start (prog); |
1796 | } | 1798 | } |
@@ -1872,6 +1874,8 @@ prog_start_prerequisites (struct prog *prog) | |||
1872 | int i; |