diff options
-rw-r--r-- | src/comp.c | 41 | ||||
-rw-r--r-- | src/ctl.c | 4 | ||||
-rw-r--r-- | src/piesctl.c | 4 | ||||
-rw-r--r-- | src/prog.h | 2 | ||||
-rw-r--r-- | src/progman.c | 19 |
5 files changed, 26 insertions, 44 deletions
@@ -15,29 +15,24 @@ along with GNU Pies. If not, see <http://www.gnu.org/licenses/>. */ #include "pies.h" #include "prog.h" #include <assert.h> struct complist { struct component *head; struct component *tail; }; -/* 0 on the first load, and 1 on all subsequent reloads. Tells the - component_config_commit whether we're starting from scratch or just - updating an already loaded configuration */ -static int loaded; - static struct complist comp_list[2]; static int cur; static struct component **comp_array; static size_t comp_count; static pies_depmap_t depmap; static inline int next_index (void) { return (cur + 1) % ARRAY_SIZE (comp_list); @@ -531,71 +526,55 @@ component_config_commit (void) /* nothing */; if (i == 0) { free (comp_array); comp_array = NULL; } else comp_array = grecs_realloc (comp_array, i * sizeof (comp_array[0])); comp_count = i; /* Rearrange components, registering entries for the new ones */ - for (comp = list->head, i = 0; comp; ) + for (comp = list->head, i = 0; comp; comp = comp->next, i++) { - struct component *next = comp->next; - if (loaded && comp->mode == pies_comp_startup) + match = complist_find_match (prev, comp); + if (match) { - /* Ignore startup components */ - component_unlink (comp); + component_merge (match, comp); + component_unlink (match); + match->listidx = cur; + component_link (match, comp->prev); component_free (comp); + comp = match; } - else - { - match = complist_find_match (prev, comp); - if (match) - { - component_merge (match, comp); - component_unlink (match); - match->listidx = cur; - component_link (match, comp->prev); - component_free (comp); - comp = match; - } - comp_array[i] = comp; - comp->arridx = i; - i++; - } - comp = next; + comp_array[i] = comp; + comp->arridx = i; } - /* Adjust comp_count */ - comp_count = i; /* Mark orphaned progs for termination */ list = &comp_list[prev]; if (list->head) { progman_foreach (mark_prog, NULL); pies_schedule_children (PIES_CHLD_GC); } /* Build dependency map */ component_build_depmap (); /* Register new progs */ for (comp = comp_list[cur].head; comp; comp = comp->next) if (!comp->prog) register_prog (comp); - - loaded = 1; } static int component_verify (struct component *comp, grecs_locus_t *locus) { int header = 0; int i; #define COMPERR(func, fmt, arg) \ do \ { \ if (!header) \ { \ @@ -1444,25 +1444,27 @@ auth_prog (struct prog *prog, struct ctlio *io) } static char * const pies_type_str[] = { [TYPE_COMPONENT] = "component", [TYPE_REDIRECTOR] = "redirector", [TYPE_COMMAND] = "command" }; static char * const pies_comp_mode_str[] = { [pies_comp_exec] = "exec", [pies_comp_accept] = "accept", [pies_comp_inetd] = "inetd", - [pies_comp_pass_fd] = "pass_fd", + [pies_comp_pass_fd] = "pass_fd", + [pies_comp_startup] = "startup", + [pies_comp_shutdown] = "shutdown", [pies_comp_wait] = "wait", [pies_comp_once] = "once", [pies_comp_boot] = "boot", [pies_comp_bootwait] = "bootwait", [pies_comp_powerfail] = "powerfail", [pies_comp_powerwait] = "powerwait", [pies_comp_powerokwait] = "powerokwait", [pies_comp_ctrlaltdel] = "ctrlaltdel", [pies_comp_ondemand] = "ondemand", [pies_comp_sysinit] = "sysinit", [pies_comp_powerfailnow] = "powerfailnow", [pies_comp_kbrequest] = "kbrequest" diff --git a/src/piesctl.c b/src/piesctl.c index f2e774b..0cd2736 100644 --- a/src/piesctl.c +++ b/src/piesctl.c @@ -1043,25 +1043,27 @@ shttp_getval (struct shttp_connection *conn, char const *name, } struct kwtrans { char const *name; int c; }; struct kwtrans mode_trans[] = { { "exec", 'C' }, { "accept", 'A' }, { "inetd", 'I' }, - { "pass_fd", 'P' }, + { "pass_fd", 'P' }, + { "startup", 'S' }, + { "shutdown", 'E' }, { "wait", 'W' }, { "once", 'c' }, { "boot", 'B' }, { "bootwait", 'w' }, { "powerfail", 'F' }, { "powerwait", 'f' }, { "powerokwait", 'o' }, { "ctrlaltdel", '3' }, { "ondemand", 'D' }, { "sysinit", 'i' }, { "powerfailnow", 'n' }, { "kbrequest", 'k' }, @@ -20,25 +20,25 @@ enum prog_type TYPE_REDIRECTOR, TYPE_COMMAND }; enum prog_status { status_stopped, /* Component is stopped. */ status_running, /* Component is running */ status_listener, /* Component is an inetd listener */ status_sleeping, /* Component is sleeping. An attempt to start it will be made at prog->v.p.timestamp + SLEEPTIME */ status_stopping, /* Component is being stopped */ - status_finished, /* A "once" component has finished */ + status_finished, /* A "once" or "startup" component has finished */ }; struct conn_class { const char *tag; union pies_sockaddr_storage sa_storage; size_t sa_len; size_t count; }; struct prog { diff --git a/src/progman.c b/src/progman.c index 5bc4eb3..a625885 100644 --- a/src/progman.c +++ b/src/progman.c @@ -315,39 +315,40 @@ register_command (char *tag, char *command, pid_t pid) newp->v.c.tag = grecs_strdup (tag); newp->v.c.command = command; link_prog (newp, progtail); } static inline int progman_startup_phase (void) { struct prog *prog; for (prog = proghead; prog; prog = prog->next) { - if (IS_COMPONENT (prog) && prog->v.p.comp->mode == pies_comp_startup) + if (IS_COMPONENT (prog) && prog->v.p.comp->mode == pies_comp_startup + && prog->v.p.status == status_running) return 1; } return 0; } int progman_waiting_p (void) { struct prog *prog; for (prog = proghead; prog; prog = prog->next) { if (IS_COMPONENT (prog) - && prog->pid > 0 + && prog->v.p.status == status_running && (prog->wait || prog->v.p.comp->mode == pies_comp_startup)) { debug (3, ("%s: waiting for %s (%lu)", __FUNCTION__, prog_tag (prog), (unsigned long) prog->pid)); return 1; } } return 0; } RETSIGTYPE @@ -2347,47 +2348,45 @@ progman_cleanup (int expect_term) if (listener->v.p.num_instances == 0 && !component_is_active (prog->v.p.comp)) destroy_prog (&listener); else { if (!expect_term) react (listener, status, pid); if (listener->v.p.comp->flags & CF_WAIT) enable_socket (listener->v.p.socket); } destroy_prog (&prog); } - else if (prog->v.p.comp->mode == pies_comp_startup) - { - debug (1, (_("removing startup component %s, pid=%lu"), - prog_tag (prog), (unsigned long)pid)); - destroy_prog (&prog); - if (!progman_startup_phase ()) - pies_schedule_children (PIES_CHLD_WAKEUP); - } else { if (prog->v.p.comp->mode >= pies_mark_sysvinit && prog->v.p.comp->mode != pies_comp_ondemand) { sysvinit_acct (SYSV_ACCT_PROC_STOP, "", prog_tag (prog), pid, ""); prog->v.p.status = status_finished; if (prog->wait) { pies_schedule_children (PIES_CHLD_WAKEUP); prog->wait = 0; } } + else if (prog->v.p.comp->mode == pies_comp_startup) + { + prog->v.p.status = status_finished; + if (!progman_startup_phase ()) + pies_schedule_children (PIES_CHLD_WAKEUP); + } else { if (is_sysvinit (prog->v.p.comp)) sysvinit_acct (SYSV_ACCT_PROC_STOP, "", prog_tag (prog), pid, ""); prog->v.p.status = status_stopped; prog_stop_dependents (prog); if (!expect_term) react (prog, status, pid); } |