summaryrefslogtreecommitdiffabout
path: root/src
authorSergey Poznyakoff <gray@gnu.org.ua>2016-02-23 16:04:52 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2016-02-23 16:04:52 (GMT)
commitdd2c48ddfc7f8bc62c565b43bbd42a3a2a87836d (patch) (side-by-side diff)
treec160c3d7af3a7709fb33224e8344caafe581fcc4 /src
parent6e73a7b0822d1fd506c75a662070f447bba94afb (diff)
downloadpies-dd2c48ddfc7f8bc62c565b43bbd42a3a2a87836d.tar.gz
pies-dd2c48ddfc7f8bc62c565b43bbd42a3a2a87836d.tar.bz2
Bugfixes
* lib/addrfmt.c: Include limits.h * src/ctl.c (fun_stop,fun_start): Ignore non-component progs. * src/pies.c (request_restart_components): Fix piesctl invocation. * src/pies.h (PIES_CHLD_RESCHEDULE_ALARM): New flag. (progman_wait_until): Remove. (progman_recompute_alarm): New proto. * src/progman.c (recompute_alarm): Remove. All uses raise PIES_CHLD_RESCHEDULE_ALARM instead. (progman_wake_sleeping): Handle status_stopping components independently on their activity flag. (prog_stop_all, progman_wait_until): Remove. (progman_stop): Rewrite using mark+sweep approach.
Diffstat (limited to 'src') (more/less context) (ignore whitespace changes)
-rw-r--r--src/ctl.c32
-rw-r--r--src/pies.c17
-rw-r--r--src/pies.h11
-rw-r--r--src/progman.c91
4 files changed, 67 insertions, 84 deletions
diff --git a/src/ctl.c b/src/ctl.c
index fd7bfdc..2d63933 100644
--- a/src/ctl.c
+++ b/src/ctl.c
@@ -1910,22 +1910,36 @@ fun_list (struct json_value *result, struct prog *prog)
static int
fun_stop (struct json_value *result, struct prog *prog)
{
- if (!prog->v.p.active)
- {
- json_object_set_string (result, "status", "ER");
- json_object_set_string (result, "error_message", "already stopped");
- return 1;
+ if (IS_COMPONENT (prog))
+ {
+ if (!prog->v.p.active)
+ {
+ json_object_set_string (result, "status", "ER");
+ json_object_set_string (result, "error_message", "already stopped");
+ return 1;
+ }
+
+ prog->v.p.active = 0;
+ progman_stop_component (&prog);
+ json_object_set_string (result, "status", "OK");
+ }
+ else
+ {
+ //FIXME progman_stop_component (&prog);
+ json_object_set_string (result, "status", "OK");
}
-
- prog->v.p.active = 0;
- progman_stop_component (&prog);
- json_object_set_string (result, "status", "OK");
return 0;
}
static int
fun_start (struct json_value *result, struct prog *prog)
{
+ if (!IS_COMPONENT (prog))
+ {
+ json_object_set_string (result, "status", "ER");
+ json_object_set_string (result, "error_message", "not a component");
+ return 1;
+ }
switch (prog->v.p.status)
{
case status_stopped:
diff --git a/src/pies.c b/src/pies.c
index 36b869a..c5b3649 100644
--- a/src/pies.c
+++ b/src/pies.c
@@ -1769,15 +1769,22 @@ int
request_restart_components (size_t cc, char **cv)
{
char **argv;
- size_t i;
+ size_t i, j;
- argv = grecs_calloc (cc + 4, sizeof (*argv));
+ argv = grecs_calloc (5 + 3 * cc - 1, sizeof (*argv));
argv[0] = "piesctl";
argv[1] = "--url";
argv[2] = (char*) pies_control_url ();
+ argv[3] = "restart";
+ j = 4;
for (i = 0; i < cc; i++)
- argv[3 + i] = cv[i];
- argv[3 + i] = NULL;
+ {
+ if (i > 0)
+ argv[j++] = "or";
+ argv[j++] = "component";
+ argv[j++] = cv[i];
+ }
+ argv[j] = NULL;
execvp (argv[0], argv);
logmsg (LOG_ERR, "can't run piesctl: %s", strerror (errno));
return EX_OSFILE;
@@ -2279,6 +2286,8 @@ main (int argc, char **argv)
}
if (action == ACTION_CONT)
{
+ if (children_op & PIES_CHLD_RESCHEDULE_ALARM)
+ progman_recompute_alarm ();
if (children_op & PIES_CHLD_GC)
progman_gc ();
if (children_op & PIES_CHLD_CLEANUP)
diff --git a/src/pies.h b/src/pies.h
index 3528e82..37eb4ba 100644
--- a/src/pies.h
+++ b/src/pies.h
@@ -320,10 +320,11 @@ void free_redirector (struct redirector *rp);
void pies_schedule_action (int act);
void free_action (struct action *act);
-#define PIES_CHLD_NONE 0
-#define PIES_CHLD_CLEANUP 0x01
-#define PIES_CHLD_WAKEUP 0x02
-#define PIES_CHLD_GC 0x04
+#define PIES_CHLD_NONE 0
+#define PIES_CHLD_CLEANUP 0x01
+#define PIES_CHLD_WAKEUP 0x02
+#define PIES_CHLD_GC 0x04
+#define PIES_CHLD_RESCHEDULE_ALARM 0x08
void pies_schedule_children (int op);
@@ -338,7 +339,6 @@ void progman_stop (void);
void progman_cleanup (int expect_term);
void progman_filter (int (*filter) (struct component *, void *data),
void *data);
-int progman_wait_until (int (*cond) (void *), void *data);
int progman_accept (int socket, void *data);
void progman_create_sockets (void);
@@ -348,6 +348,7 @@ struct component *progman_lookup_tcpmux (const char *service,
void progman_run_comp (struct component *comp, int fd,
union pies_sockaddr_storage *sa, socklen_t salen);
+void progman_recompute_alarm (void);
void fd_report (int fd, const char *msg);
diff --git a/src/progman.c b/src/progman.c
index 547f806..2d3a14c 100644
--- a/src/progman.c
+++ b/src/progman.c
@@ -18,7 +18,6 @@
#include "prog.h"
static struct prog *proghead, *progtail;
-static int recompute_alarm;
static struct grecs_symtab *conn_tab;
struct prog *
@@ -908,7 +907,7 @@ check_rate (struct prog *prog, unsigned testtime, size_t max_count)
{
prog->v.p.timestamp = now;
prog->v.p.status = status_sleeping;
- recompute_alarm = 1;
+ pies_schedule_children (PIES_CHLD_RESCHEDULE_ALARM);
return 1;
}
@@ -1471,7 +1470,6 @@ progman_recompute_alarm ()
time_t now = time (NULL);
time_t alarm_time = 0, x;
- recompute_alarm = 0;
debug (2, ("Recomputing alarm settings"));
for (prog = proghead; prog; prog = prog->next)
if (IS_COMPONENT (prog))
@@ -1508,7 +1506,6 @@ progman_start ()
/* Noting to do if there are processes left in the previous runlevel */
return;
- recompute_alarm = 0;
debug (1, ("starting components"));
for (prog = proghead; prog; prog = prog->next)
if (IS_COMPONENT (prog))
@@ -1549,7 +1546,7 @@ check_stopping (struct prog *prog, time_t now)
kill (prog->pid, SIGKILL);
}
else
- recompute_alarm = 1;
+ pies_schedule_children (PIES_CHLD_RESCHEDULE_ALARM);
}
void
@@ -1574,11 +1571,11 @@ progman_wake_sleeping (int onalrm)
}
for (prog = proghead; prog; prog = prog->next)
- if (IS_ACTIVE_COMPONENT (prog))
+ switch (prog->v.p.status)
{
- switch (prog->v.p.status)
+ case status_sleeping:
+ if (IS_ACTIVE_COMPONENT (prog))
{
- case status_sleeping:
if (now - prog->v.p.timestamp >= SLEEPTIME)
{
if (prog->v.p.comp->mode == pies_comp_inetd)
@@ -1597,23 +1594,22 @@ progman_wake_sleeping (int onalrm)
/* If there is no alarm pending, recompute next alarm.
This allows to cope with eventual clock inaccuracies. */
if (onalrm)
- recompute_alarm = 1;
- break;
+ pies_schedule_children (PIES_CHLD_RESCHEDULE_ALARM);
+ }
+ break;
- case status_stopping:
- check_stopping (prog, now);
- break;
+ case status_stopping:
+ check_stopping (prog, now);
+ break;
- case status_stopped:
- prog_start (prog);
- break;
+ case status_stopped:
+ if (IS_ACTIVE_COMPONENT (prog))
+ prog_start (prog);
+ break;
- default:
- break;
- }
+ default:
+ break;
}
- if (recompute_alarm)
- progman_recompute_alarm ();
}
static int
@@ -1725,7 +1721,7 @@ prog_stop (struct prog *prog, int sig)
{
prog->v.p.status = status_stopping;
prog->v.p.timestamp = time (NULL);
- recompute_alarm = 1;
+ pies_schedule_children (PIES_CHLD_RESCHEDULE_ALARM);
}
}
debug (1, ("stopping %s (%lu)", prog_tag (prog), (unsigned long) prog->pid));
@@ -1735,56 +1731,19 @@ prog_stop (struct prog *prog, int sig)
kill (prog->pid, sig);
}
-static void
-prog_stop_all (int sig)
-{
- struct prog *prog;
-
- debug (1, ("stopping all components (signal %d)", sig));
- for (prog = progtail; prog; prog = prog->prev)
- if (IS_COMPONENT (prog)
- && (prog->v.p.status == status_running
- || prog->v.p.status == status_stopping))
- prog_stop (prog, sig);
-}
-
-int
-progman_wait_until (int (*cond) (void *), void *data)
-{
- time_t start = time (NULL);
-
- do
- {
- progman_cleanup (1);
- if (cond && cond (data))
- return 0;
- sleep (1);
- }
- while (time (NULL) - start < shutdown_timeout);
- return 1;
-}
-
static int
-no_children_left (void *p)
+mark_for_stopping (struct prog *prog, void *data)
{
- struct prog *prog;
-
- for (prog = proghead; prog; prog = prog->next)
- if (prog->pid > 0)
- return 0;
-
- return 1;
+ if (IS_COMPONENT (prog))
+ prog->v.p.stop = 1;
+ return 0;
}
void
-progman_stop ()
+progman_stop (void)
{
- prog_stop_all (SIGTERM);
- if (progman_wait_until (no_children_left, NULL))
- {
- prog_stop_all (SIGKILL);
- progman_wait_until (no_children_left, NULL);
- }
+ progman_foreach (mark_for_stopping, NULL);
+ progman_gc ();
}
static void

Return to:

Send suggestions and report system problems to the System administrator.