diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2016-02-18 22:51:58 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2016-02-18 22:51:58 +0200 |
commit | 51a797445a4bfc34ad1ae7ea91e12486d823abda (patch) | |
tree | 673d6ca84811f66f4a179b3d98864d2e30bab252 | |
parent | 0a55965bcc28928ae17ca39e3b8e35adf11ea09c (diff) | |
download | pies-51a797445a4bfc34ad1ae7ea91e12486d823abda.tar.gz pies-51a797445a4bfc34ad1ae7ea91e12486d823abda.tar.bz2 |
Preserve the order of progs when adding new ones.
* src/progman.c (link_prog): Take a pointer to the reference prog
as the second argument. Link the first argument after that reference
prog, or at the head of the list if the reference is NULL.
(register_prog0): Make sure progs are linked exactly in the same order
as the corresponding components.
(prog_create_socket): Process only progs with status == status_listener
(progman_start): Do the right thing depending on the prog type.
-rw-r--r-- | src/progman.c | 102 |
1 files changed, 73 insertions, 29 deletions
diff --git a/src/progman.c b/src/progman.c index 2c38b63..da5a970 100644 --- a/src/progman.c +++ b/src/progman.c @@ -121,13 +121,13 @@ prog_tag (struct prog const *prog) void -link_prog (struct prog *pp, int prepend) +link_prog (struct prog *prog, struct prog *ref) { - if (prepend) + if (!ref) { + prog->prev = NULL; + prog->next = proghead; if (proghead) - proghead->prev = pp; - pp->prev = NULL; - pp->next = proghead; - proghead = pp; - if (!progtail) - progtail = pp; + proghead->prev = prog; + else + progtail = prog; + proghead = prog; } @@ -135,9 +135,13 @@ link_prog (struct prog *pp, int prepend) { - pp->next = NULL; - pp->prev = progtail; - if (progtail) - progtail->next = pp; + struct prog *x; + + prog->prev = ref; + prog->next = ref->next; + + if ((x = ref->next)) + x->prev = prog; else - proghead = pp; - progtail = pp; + progtail = prog; + + ref->next = prog; } @@ -219,3 +223,3 @@ register_redir (int type, struct prog *master) pp->v.r.master = master; - link_prog (pp, 1); + link_prog (pp, NULL); component_ref_incr (master->v.p.comp); @@ -239,2 +243,38 @@ update_redir (int type, struct prog *master, pid_t pid) +/* Given the component COMP find the element of the program list + after which to link in the new prog associated with that COMP. + The progs in the resulting list must be arranged exactly in the + same order as the corresponding components. Points to note: + 1. If comp->prog is already present, follow progs in its next + chain until the last one that points to the same COMP is found. + 2. Otherwise, if that component is not the first one, step back + to the previous component and do the same for its comp->prog chain. + 3. Return the prog found. +*/ +static struct prog * +find_prog_ref (struct component *comp) +{ + struct prog *prog; + + if (!comp->prog) + { + comp = comp->prev; + if (!comp) + return NULL; /* FIXME: Skip redirectors? */ + } + + if (comp->prog) + { + for (prog = comp->prog; + prog->next + && IS_COMPONENT (prog->next) + && prog->next->v.p.comp == comp; + prog = prog->next) + ; + } + else + prog = NULL; + return prog; +} + static struct prog * @@ -263,4 +303,4 @@ register_prog0 (struct component *comp) comp->redir[RETR_OUT].type = redir_null; - - link_prog (newp, 0); + + link_prog (newp, find_prog_ref (comp)); component_ref_incr (comp); @@ -283,3 +323,3 @@ register_command (char *tag, char *command, pid_t pid) newp->v.c.command = command; - link_prog (newp, 0); + link_prog (newp, progtail); } @@ -1407,7 +1447,6 @@ prog_create_socket (struct prog *prog, void *data) { - if (IS_COMPONENT (prog)) + if (IS_COMPONENT (prog) && prog->v.p.status == status_listener) { struct component *comp = prog->v.p.comp; - if (comp->mode == pies_comp_inetd && !ISCF_TCPMUX (comp->flags) - && prog->v.p.socket == -1) + if (!ISCF_TCPMUX (comp->flags) && prog->v.p.socket == -1) { @@ -1488,4 +1527,15 @@ progman_start () { - if (prog->v.p.comp->mode == pies_comp_inetd) + switch (prog->v.p.status) { + case status_stopped: + case status_sleeping: + prog_start (prog); + break; + + case status_running: + case status_stopping: + case status_finished: + break; + + case status_listener: if (!prog->v.p.active) @@ -1493,10 +1543,4 @@ progman_start () else - { - prog->v.p.status = status_listener; - enable_socket (prog->v.p.socket); - } + enable_socket (prog->v.p.socket); } - else if (prog->v.p.status == status_stopped - || prog->v.p.status == status_sleeping) - prog_start (prog); } |