aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2020-01-26 00:49:27 +0200
committerSergey Poznyakoff <gray@gnu.org>2020-01-26 00:49:27 +0200
commitdba0361eb509d3c9a633e05945378a204a4a0f4e (patch)
tree98c1d161f5ccb34b217d427d444fc835169492bd
parent1f1d9bb64c4c4e0a0127502f896db8f641a0748a (diff)
downloadjumper-dba0361eb509d3c9a633e05945378a204a4a0f4e.tar.gz
jumper-dba0361eb509d3c9a633e05945378a204a4a0f4e.tar.bz2
Fix program reload. Avoid rescanning the process list twice.
* src/config.c (cb_listen): Register new version of the listener first, and then decommission the existing one. This order is important to avoid dereferencing interface, if it hasn't changed. * src/jumper.c (main): Remove call to listener_proc_report * src/jumper.h (listener_proc_report): Change signature. * src/listener.c (listener_cmp): Compare command lines. (listener_proc_report): Rewrite. * src/progman.c (proc_stop): Remove global. (progman_cleanup): Call listener_proc_report here. (progman_decommission): Remove call to listener_proc_report. Display diagnostics (info and debug) only if some listeners are going to be decommissioned.
-rw-r--r--src/config.c2
-rw-r--r--src/jumper.c1
-rw-r--r--src/jumper.h2
-rw-r--r--src/listener.c27
-rw-r--r--src/progman.c16
5 files changed, 22 insertions, 26 deletions
diff --git a/src/config.c b/src/config.c
index e5cba1b..53d757d 100644
--- a/src/config.c
+++ b/src/config.c
@@ -711,9 +711,9 @@ cb_listen(enum grecs_callback_command cmd, grecs_node_t *node,
interface_ref(lp->iface);
listener_list_add(&clist, lp);
} else if (listener_cmp(p, lp)) {
- listener_decommission(p);
interface_ref(lp->iface);
listener_list_add(&clist, lp);
+ listener_decommission(p);
} else
listener_free(lp);
}
diff --git a/src/jumper.c b/src/jumper.c
index 922172a..16d6142 100644
--- a/src/jumper.c
+++ b/src/jumper.c
@@ -259,7 +259,6 @@ main(int argc, char **argv)
command = command_none;
}
- listener_proc_report();
rdset = fdset;
rc = select(maxfd + 1, &rdset, NULL, NULL,
progman_timeout(&tv));
diff --git a/src/jumper.h b/src/jumper.h
index 5aea623..448e8ef 100644
--- a/src/jumper.h
+++ b/src/jumper.h
@@ -236,7 +236,7 @@ int listener_cmp(listener_t *a, listener_t *b);
listener_t *listener_locate(uint32_t src, uint32_t dst);
listener_t *listener_find_id(const char *id);
void listener_print_status(listener_t *lp);
-void listener_proc_report(void);
+void listener_proc_report(listener_t *lp);
void listener_kill_redirector(listener_t *lp, int what);
void listener_start(listener_t *lp, char **kve);
int listener_run_action(listener_t *lp, int a);
diff --git a/src/listener.c b/src/listener.c
index d68897d..69f4b52 100644
--- a/src/listener.c
+++ b/src/listener.c
@@ -233,6 +233,11 @@ listener_cmp(listener_t *a, listener_t *b)
return 1;
}
+ if (strcmp(a->prog, b->prog)) {
+ debug(5, ("%s/%s: commands differ", a->id, b->id));
+ return 1;
+ }
+
if (ipv4_match_list_cmp(a->match_source, b->match_source)) {
debug(5, ("%s/%s: match-source lists differ", a->id, b->id));
return 1;
@@ -532,23 +537,13 @@ onexit_reaction(listener_t *lp)
}
void
-listener_proc_report()
+listener_proc_report(listener_t *lp)
{
- listener_t *lp;
-
- if (proc_stop == 0)
- return;
- proc_stop = 0;
-
- for (lp = llist.head; lp; lp = lp->next) {
- if (lp->status == stat_term) {
- listener_print_status(lp);
- if (lp->decommission)
- listener_run_action(lp, event_cleanup);
- else
- onexit_reaction(lp);
- }
- }
+ listener_print_status(lp);
+ if (lp->decommission)
+ listener_run_action(lp, event_cleanup);
+ else
+ onexit_reaction(lp);
}
void
diff --git a/src/progman.c b/src/progman.c
index ef5c73d..b9a0f5f 100644
--- a/src/progman.c
+++ b/src/progman.c
@@ -50,7 +50,6 @@ static struct process *ts_proc_list, *ts_proc_tail;
static struct process *proc_avail;
static unsigned proc_count; /* Total number of processes in proc_list */
-int proc_stop; /* Number of terminated processes */
static char *
@@ -289,7 +288,7 @@ progman_cleanup(void)
proc_kill(p->lp);
p->lp->progstat = status;
p->lp->status = stat_term;
- proc_stop++;
+ listener_proc_report(p->lp);
break;
case type_redirector:
@@ -338,7 +337,6 @@ progman_terminate(void)
for (p = proc_list; p; p = p->next)
kill(p->pid, SIGKILL);
}
- listener_proc_report();
sleep(1);
}
}
@@ -349,15 +347,20 @@ progman_decommission(void)
struct process *p;
time_t start;
size_t count = 0;
+ int info_shown = 0;
if (proc_count == 0)
return;
- diag(LOG_INFO, "terminating decommissioned processes");
-
- debug(1, ("sending running decommissioned processes the TERM signal"));
for (p = proc_list; p; p = p->next)
if (p->type != type_redirector && p->lp->decommission) {
+ if (!info_shown) {
+ diag(LOG_INFO,
+ "terminating decommissioned processes");
+ debug(1,
+ ("sending running decommissioned processes the TERM signal"));
+ info_shown = 1;
+ }
kill(p->pid, SIGTERM);
count++;
}
@@ -372,7 +375,6 @@ progman_decommission(void)
kill(p->pid, SIGKILL);
}
progman_cleanup();
- listener_proc_report();
sleep(1);
count = 0;
for (p = proc_list; p; p = p->next)

Return to:

Send suggestions and report system problems to the System administrator.