summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org>2016-02-16 05:15:42 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2016-02-16 05:15:42 (GMT)
commitbd8bd1640c72ceefd87b46a7a3d378c78c9081f5 (patch) (side-by-side diff)
tree8224d8dfd67ab70240744dfb2df4c3af9fd1f850
parent27366c475aa4955f296f169cf9acd33e36b9d7b3 (diff)
downloadpies-bd8bd1640c72ceefd87b46a7a3d378c78c9081f5.tar.gz
pies-bd8bd1640c72ceefd87b46a7a3d378c78c9081f5.tar.bz2
Associate program's activity flag with prog, instead of with component.
The CF_DISABLED flag is still retained to indicate that the component is disabled administratively. * src/prog.h (prog.v.p) <active>: New member. (IS_ACTIVE_COMPONENT): Use active flag. * src/comp.c (component_finish): Don't modify component flags. * src/ctl.c (prog_serialize): Replace attribute "disabled" with "active". (fun_stop): Set prog->v.p.active * src/pies.c (main): Use pies_master_argv to check whether program name is absolute. * src/piesctl.c (print_comp): Check "active" attribute. * src/progman.c (register_prog0): Set prog->v.p.active. (progman_create_sockets): Remove components if their socket cannot be opened. (progman_lookup_tcpmux, prog_open_socket) (prog_start, progman_start) (prog_start_prerequisites, react): Operate on prog->v.p.active to test/change prog's activity state. * src/sysvinit.c (enablecomp, runlevel_setup_prog): Operate on prog->v.p.active to test/change prog's activity state. (demand_prog, IS_RUNNING_DISABLED_PROG): Likewise.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--src/comp.c3
-rw-r--r--src/ctl.c9
-rw-r--r--src/pies.c2
-rw-r--r--src/piesctl.c6
-rw-r--r--src/prog.h5
-rw-r--r--src/progman.c72
-rw-r--r--src/sysvinit.c25
7 files changed, 63 insertions, 59 deletions
diff --git a/src/comp.c b/src/comp.c
index 83818c2..6a0e4ba 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -729,9 +729,6 @@ component_finish (struct component *comp, grecs_locus_t *locus)
comp->prereq = NULL;
}
}
-
- if (comp->mode == pies_comp_ondemand)
- comp->flags |= CF_DISABLED;
}
}
diff --git a/src/ctl.c b/src/ctl.c
index f4154f6..6e162e5 100644
--- a/src/ctl.c
+++ b/src/ctl.c
@@ -1829,8 +1829,7 @@ prog_serialize (struct json_value *ret, struct prog *prog)
FORMAT_IDX (ret, "mode", pies_comp_mode_str, prog->v.p.comp->mode);
FORMAT_IDX (ret, "status", pies_status_str, prog->v.p.status);
- json_object_set_bool (ret, "disabled",
- prog->v.p.comp->flags & CF_DISABLED);
+ json_object_set_bool (ret, "active", prog->v.p.active);
if (prog->pid)
json_object_set_number (ret, "PID", prog->pid);
@@ -1873,8 +1872,7 @@ fun_list (struct json_value *result, struct prog *prog)
static int
fun_stop (struct json_value *result, struct prog *prog)
{
- if (prog->v.p.comp->flags & CF_DISABLED
- && prog->v.p.status == status_stopped)
+ if (prog->v.p.active && prog->v.p.status == status_stopped)
{
json_object_set_string (result, "status", "ER");
@@ -1883,7 +1881,7 @@ fun_stop (struct json_value *result, struct prog *prog)
}
else
{
- prog->v.p.comp->flags |= CF_DISABLED;
+ prog->v.p.active = 0;
progman_stop_component (&prog);
json_object_set_string (result, "status", "OK");
}
@@ -1897,6 +1895,7 @@ fun_start (struct json_value *result, struct prog *prog)
{
case status_stopped:
prog->v.p.comp->flags &= ~CF_DISABLED;
+ prog->v.p.active = 1;
json_object_set_string (result, "status", "OK");
break;
diff --git a/src/pies.c b/src/pies.c
index 653a865..67aedd1 100644
--- a/src/pies.c
+++ b/src/pies.c
@@ -2158,7 +2158,7 @@ main (int argc, char **argv)
create_pidfile (pidfile);
}
- if (argv[0][0] != '/')
+ if (pies_master_argv[0][0] != '/')
logmsg (LOG_NOTICE,
_("not started as an absolute pathname; "
"restart will not work"));
diff --git a/src/piesctl.c b/src/piesctl.c
index 5f26aec..e2e0483 100644
--- a/src/piesctl.c
+++ b/src/piesctl.c
@@ -1163,10 +1163,8 @@ print_comp (FILE *fp, struct json_value *v, size_t n)
fbuf[fidx++] = kwtoc (p->v.s, mode_trans);
else
fbuf[fidx++] = '-';
- p = getval (v, "disabled", json_bool, 0);
+ p = getval (v, "active", json_bool, 0);
if (p && p->v.b)
- fbuf[fidx++] = '-';
- else
{
p = getval (v, "status", json_string, 0);
if (p)
@@ -1174,6 +1172,8 @@ print_comp (FILE *fp, struct json_value *v, size_t n)
else
fbuf[fidx++] = '-';
}
+ else
+ fbuf[fidx++] = '-';
}
else if (strcmp (type, "redirector") == 0)
{
diff --git a/src/prog.h b/src/prog.h
index 4658518..3b20979 100644
--- a/src/prog.h
+++ b/src/prog.h
@@ -51,7 +51,8 @@ struct prog
struct
{
struct component *comp;
- int wait;
+ int wait :1;
+ int active :1;
int socket;
struct prog *redir[2]; /* Pointers to redirectors */
time_t timestamp; /* Time of last startup */
@@ -82,7 +83,7 @@ struct prog
#define IS_COMPONENT(p) ((p)->type == TYPE_COMPONENT)
#define IS_ACTIVE_COMPONENT(prog) \
- (IS_COMPONENT(prog) && !((prog)->v.p.comp->flags & CF_DISABLED))
+ (IS_COMPONENT(prog) && (prog)->v.p.active)
struct prog *progman_locate (const char *name);
int progman_foreach (int (*filter) (struct prog *, void *data), void *data);
diff --git a/src/progman.c b/src/progman.c
index 1be7d27..d6929d6 100644
--- a/src/progman.c
+++ b/src/progman.c
@@ -111,7 +111,7 @@ progman_lookup_tcpmux (const char *service, const char *master)
for (prog = proghead; prog; prog = prog->next)
if (IS_COMPONENT (prog)
&& ISCF_TCPMUX (prog->v.p.comp->flags)
- && !(prog->v.p.comp->flags & CF_DISABLED)
+ && prog->v.p.active
&& prog->v.p.comp->service
&& strcasecmp (prog->v.p.comp->service, service) == 0
&& prog->v.p.comp->tcpmux
@@ -270,11 +270,17 @@ register_prog0 (struct component *comp)
newp->facility = comp->facility;
newp->v.p.comp = comp;
newp->v.p.socket = -1;
+
if (comp->mode == pies_comp_inetd)
newp->v.p.status = status_listener;
else
newp->v.p.status = status_stopped;
-
+
+ if ((comp->flags & CF_DISABLED) || comp->mode == pies_comp_ondemand)
+ newp->v.p.active = 0;
+ else
+ newp->v.p.active = 1;
+
if (comp->mode != pies_comp_exec)
comp->redir[RETR_OUT].type = redir_null;
@@ -939,7 +945,7 @@ prog_open_socket (struct prog *prog)
if (prog->v.p.socket == -1)
{
prog->v.p.status = status_stopped;
- prog->v.p.comp->flags |= CF_DISABLED;
+ prog->v.p.active = 0;
return 1;
}
if (listen (prog->v.p.socket, 8))
@@ -948,7 +954,7 @@ prog_open_socket (struct prog *prog)
close (prog->v.p.socket);
prog->v.p.socket = -1;
prog->v.p.status = status_stopped;
- prog->v.p.comp->flags |= CF_DISABLED;
+ prog->v.p.active = 0;
return 1;
}
return 0;
@@ -1041,12 +1047,12 @@ prog_start (struct prog *prog)
{
if (!init_process)
{
- if (!(prog->v.p.comp->flags & CF_DISABLED))
+ if (prog->v.p.active)
{
logmsg (LOG_NOTICE, "disabling sysvinit component %s",
prog_tag (prog));
prog->v.p.status = status_stopped;
- prog->v.p.comp->flags |= CF_DISABLED;
+ prog->v.p.active = 0;
}
return;
}
@@ -1418,34 +1424,36 @@ progman_accept (int socket, void *data)
return _prog_wait (p);
}
-void
-progman_create_sockets ()
+static int
+prog_create_socket (struct prog *prog, void *data)
{
- struct prog *prog;
-
- for (prog = proghead; prog; prog = prog->next)
+ if (IS_COMPONENT (prog))
{
- if (IS_COMPONENT (prog))
+ struct component *comp = prog->v.p.comp;
+ if (comp->mode == pies_comp_inetd && !ISCF_TCPMUX (comp->flags)
+ && prog->v.p.socket == -1)
{
- struct component *comp = prog->v.p.comp;
- if (comp->mode == pies_comp_inetd && !ISCF_TCPMUX (comp->flags)
- && prog->v.p.socket == -1)
+ int fd = create_socket (comp->socket_url,
+ comp->socket_type,
+ comp->privs.user, comp->umask);
+ if (fd == -1)
+ destroy_prog (&prog);
+ else if (register_program_socket (comp->socket_type, fd, prog))
{
- int fd = create_socket (comp->socket_url,
- comp->socket_type,
- comp->privs.user, comp->umask);
- if (fd == -1)
- prog->v.p.comp->flags |= CF_DISABLED;
- else if (register_program_socket (comp->socket_type, fd, prog))
- {
- close (fd);
- prog->v.p.comp->flags |= CF_DISABLED;
- }
- else
- prog->v.p.socket = fd;
+ close (fd);
+ destroy_prog (&prog);
}
+ else
+ prog->v.p.socket = fd;
}
}
+ return 0;
+}
+
+void
+progman_create_sockets ()
+{
+ progman_foreach (prog_create_socket, NULL);
}
@@ -1502,7 +1510,7 @@ progman_start ()
{
if (prog->v.p.comp->mode == pies_comp_inetd)
{
- if (prog->v.p.comp->flags & CF_DISABLED)
+ if (!prog->v.p.active)
disable_socket (prog->v.p.socket);
else
{
@@ -1606,7 +1614,7 @@ prog_start_prerequisites (struct prog *prog)
struct component *comp;
int warned = 0;
- if (prog->v.p.comp->flags & CF_DISABLED)
+ if (!prog->v.p.active)
return 1;
for (comp = component_depmap_first (depmap_col, prog->v.p.comp->arridx, &pos);
comp;
@@ -1622,9 +1630,9 @@ prog_start_prerequisites (struct prog *prog)
warned = 1;
}
- if (comp->flags & CF_DISABLED)
+ if (!prog->v.p.active)
{
- prog->v.p.comp->flags |= CF_DISABLED;
+ prog->v.p.active = 0;
return 1;
}
@@ -2246,7 +2254,7 @@ react (struct prog *prog, int status, pid_t pid)
case action_disable:
logmsg (LOG_NOTICE, _("disabling component %s"),
prog_tag (prog));
- prog->v.p.comp->flags |= CF_DISABLED;
+ prog->v.p.active = 0;
/* FIXME:
if (prog->v.p.comp->mode == pies_comp_inetd)
disable_socket (prog->v.p.socket);
diff --git a/src/sysvinit.c b/src/sysvinit.c
index 0370fcc..625fd7b 100644
--- a/src/sysvinit.c
+++ b/src/sysvinit.c
@@ -240,8 +240,8 @@ enablecomp (struct prog *prog, void *data)
return 0;
case pies_comp_ondemand:
- /* Disabled flag persists: */
- return !(prog->v.p.comp->flags & CF_DISABLED);
+ /* Active flag persists: */
+ return prog->v.p.active;
case pies_comp_powerfail:
case pies_comp_powerwait:
@@ -271,21 +271,20 @@ enablecomp (struct prog *prog, void *data)
static int
runlevel_setup_prog (struct prog *prog, void *data)
{
- if (IS_COMPONENT (prog) && is_sysvinit (prog->v.p.comp))
+ if (IS_COMPONENT (prog)
+ && !(prog->v.p.comp->flags & CF_DISABLED)
+ && is_sysvinit (prog->v.p.comp))
{
int rc = enablecomp (prog, data);
if (rc < 0)
return 0;
+ prog->v.p.active = rc;
if (rc)
- prog->v.p.comp->flags &= ~CF_DISABLED;
- else
- prog->v.p.comp->flags |= CF_DISABLED;
- prog->v.p.wait = is_comp_wait (prog->v.p.comp);
+ prog->v.p.wait = is_comp_wait (prog->v.p.comp);
debug (2, ("%s: %s%s", prog_tag (prog),
- prog->v.p.comp->flags & CF_DISABLED ?
- "disabled" : "enabled",
- !(prog->v.p.comp->flags & CF_DISABLED) && prog->v.p.wait
- ? " (wait)" : ""));
+ prog->v.p.active ?
+ "enabled" : "disabled",
+ prog->v.p.active && prog->v.p.wait ? " (wait)" : ""));
}
return 0;
}
@@ -307,7 +306,7 @@ demand_prog (struct prog *prog, void *data)
&& comp->runlevels
&& strchr (comp->runlevels, *rl))
{
- prog->v.p.comp->flags &= ~CF_DISABLED;
+ prog->v.p.active = 1;
debug (1, ("%s: %s", prog_tag (prog), "enabled"));
}
return 0;
@@ -757,7 +756,7 @@ sysvinit_begin ()
#define IS_RUNNING_DISABLED_PROG(prog) \
(IS_COMPONENT (prog) \
&& prog->v.p.status == status_running \
- && prog->v.p.comp->flags & CF_DISABLED) \
+ && !prog->v.p.active)
static int
cond_running_disabled (struct prog *prog, void *data)

Return to:

Send suggestions and report system problems to the System administrator.