aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/comp.c2
-rw-r--r--src/ctl.c12
-rw-r--r--src/inetd-bi.c2
-rw-r--r--src/prog.h10
-rw-r--r--src/progman.c51
-rw-r--r--src/sysvinit.c18
6 files changed, 46 insertions, 49 deletions
diff --git a/src/comp.c b/src/comp.c
index 7babae7..41b77ce 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -366,13 +366,13 @@ prog_is_leftover (struct prog *prog)
/* If PROG is a leftover, mark it for termination */
static int
mark_prog (struct prog *prog, void *data)
{
if (prog_is_leftover (prog))
- prog->v.p.stop = 1;
+ prog->stop = 1;
return 0;
}
static int
list_str_cmp (const void *a, const void *b)
{
diff --git a/src/ctl.c b/src/ctl.c
index 21abf59..a7db410 100644
--- a/src/ctl.c
+++ b/src/ctl.c
@@ -1831,21 +1831,21 @@ selector (struct prog *prog, void *data)
the state of the master listener.
FIXME: Ideally all TCPMUXen must form a list attached to their master
listener. When this is fixed, this function will disappear. */
static int
prog_active (struct prog *prog)
{
- if (prog->v.p.active)
+ if (prog->active)
{
if (ISCF_TCPMUX (prog->v.p.comp->flags))
{
prog = progman_locate (prog->v.p.comp->tcpmux);
- return prog && prog->v.p.active;
+ return prog && prog->active;
}
}
- return prog->v.p.active;
+ return prog->active;
}
static struct json_value *
prog_serialize (struct json_value *ret, struct prog *prog)
{
struct json_value *v;
@@ -1909,20 +1909,20 @@ fun_list (struct json_value *result, struct prog *prog)
static int
fun_stop (struct json_value *result, struct prog *prog)
{
if (IS_COMPONENT (prog))
{
- if (!prog->v.p.active)
+ if (!prog->active)
{
json_object_set_string (result, "status", "ER");
json_object_set_string (result, "error_message", "already stopped");
return 1;
}
- prog->v.p.active = 0;
+ prog->active = 0;
progman_stop_component (&prog);
json_object_set_string (result, "status", "OK");
}
else
{
//FIXME progman_stop_component (&prog);
@@ -1969,13 +1969,13 @@ fun_start (struct json_value *result, struct prog *prog)
default:
json_object_set_string (result, "status", "ER");
json_object_set_string (result, "error_message", "already running");
return 1;
}
- prog->v.p.active = 1;
+ prog->active = 1;
return 0;
}
static int
fun_restart (struct json_value *result, struct prog *prog)
{
diff --git a/src/inetd-bi.c b/src/inetd-bi.c
index 2032123..61b6f55 100644
--- a/src/inetd-bi.c
+++ b/src/inetd-bi.c
@@ -302,13 +302,13 @@ fd_getline (int fd, char *buf, int len)
static int
tcpmux_help (struct component *comp, void *data)
{
int *pfd = data;
- if (ISCF_TCPMUX (comp->flags) && comp->prog && comp->prog->v.p.active)
+ if (ISCF_TCPMUX (comp->flags) && comp->prog && comp->prog->active)
{
fd_report (*pfd, comp->service);
fd_report (*pfd, "\r\n");
}
return 0;
}
diff --git a/src/prog.h b/src/prog.h
index 3358885..be072e1 100644
--- a/src/prog.h
+++ b/src/prog.h
@@ -42,21 +42,20 @@ struct conn_class
struct prog
{
struct prog *next, *prev;
enum prog_type type;
pid_t pid; /* PID */
- int facility;
+ int active :1; /* The prog is active */
+ int wait :1; /* Wait for this prog to terminate */
+ int stop :1; /* Stop this prog */
union
{
struct
{
struct component *comp;
- int active :1; /* The prog is active */
- int wait :1; /* Wait for this prog to terminate */
- int stop :1; /* Stop this prog */
int socket;
struct prog *redir[2]; /* Pointers to redirectors */
time_t timestamp; /* Time of last startup */
size_t failcount; /* Number of failed starts since timestamp */
enum prog_status status; /* Current component status */
/* If status == status_listener: */
@@ -81,14 +80,13 @@ struct prog
char *command;
} c;
} v;
};
#define IS_COMPONENT(p) ((p)->type == TYPE_COMPONENT)
-#define IS_ACTIVE_COMPONENT(prog) \
- (IS_COMPONENT(prog) && (prog)->v.p.active)
+#define IS_ACTIVE_COMPONENT(prog) (IS_COMPONENT(prog) && (prog)->active)
struct prog *progman_locate (const char *name);
int progman_foreach (int (*filter) (struct prog *, void *data), void *data);
void prog_stop (struct prog *prog, int sig);
void progman_stop_component (struct prog **prog);
diff --git a/src/progman.c b/src/progman.c
index 852a71c..9f5c466 100644
--- a/src/progman.c
+++ b/src/progman.c
@@ -71,13 +71,13 @@ struct component *
progman_lookup_tcpmux (const char *service, const char *master)
{
struct prog *prog;
for (prog = proghead; prog; prog = prog->next)
if (IS_COMPONENT (prog)
&& ISCF_TCPMUX (prog->v.p.comp->flags)
- && prog->v.p.active
+ && prog->active
&& prog->v.p.comp->service
&& strcasecmp (prog->v.p.comp->service, service) == 0
&& prog->v.p.comp->tcpmux
&& strcmp (prog->v.p.comp->tcpmux, master) == 0)
return prog->v.p.comp;
return NULL;
@@ -276,25 +276,24 @@ register_prog0 (struct component *comp)
{
struct prog *newp;
newp = grecs_zalloc (sizeof (*newp));
newp->type = TYPE_COMPONENT;
newp->pid = 0;
- 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;
+ newp->active = 0;
else
- newp->v.p.active = 1;
+ newp->active = 1;
if (comp->mode != pies_comp_exec)
comp->redir[RETR_OUT].type = redir_null;
link_prog (newp, find_prog_ref (comp));
component_ref_incr (comp);
@@ -322,13 +321,13 @@ int
progman_waiting_p (void)
{
struct prog *prog;
for (prog = proghead; prog; prog = prog->next)
{
- if (IS_COMPONENT (prog) && prog->v.p.wait && prog->pid > 0)
+ if (IS_COMPONENT (prog) && prog->wait && prog->pid > 0)
{
debug (3, ("%s: waiting for %s (%lu)",
__FUNCTION__, prog_tag (prog),
(unsigned long) prog->pid));
return 1;
}
@@ -437,13 +436,13 @@ open_redirector (struct prog *master, int stream)
signal_setup (redir_exit);
close (p[1]);
fp = fdopen (p[0], "r");
if (fp == NULL)
_exit (1);
- openlog (prog_tag (master), LOG_PID, master->facility);
+ openlog (prog_tag (master), LOG_PID, master->v.p.comp->facility);
prio = master->v.p.comp->redir[stream].v.prio;
while (getline (&buf, &size, fp) > 0)
syslog (prio, "%s", buf);
_exit (0);
case -1:
@@ -953,22 +952,22 @@ prog_open_socket (struct prog *prog)
prog->v.p.comp->socket_type,
prog->v.p.comp->privs.user,
prog->v.p.comp->umask);
if (prog->v.p.socket == -1)
{
prog->v.p.status = status_stopped;
- prog->v.p.active = 0;
+ prog->active = 0;
return 1;
}
if (listen (prog->v.p.socket, 8))
{
logmsg (LOG_ERR, "listen: %s", strerror (errno));
close (prog->v.p.socket);
prog->v.p.socket = -1;
prog->v.p.status = status_stopped;
- prog->v.p.active = 0;
+ prog->active = 0;
return 1;
}
return 0;
}
static void
@@ -1054,18 +1053,18 @@ prog_start (struct prog *prog)
return;
if (is_sysvinit (prog->v.p.comp))
{
if (!init_process)
{
- if (prog->v.p.active)
+ if (prog->active)
{
logmsg (LOG_NOTICE, "disabling sysvinit component %s",
prog_tag (prog));
prog->v.p.status = status_stopped;
- prog->v.p.active = 0;
+ prog->active = 0;
}
return;
}
}
/* This call returns 1 in two cases: Either prog is marked as disabled,
@@ -1520,13 +1519,13 @@ progman_start (void)
case status_running:
case status_stopping:
case status_finished:
break;
case status_listener:
- if (!prog->v.p.active)
+ if (!prog->active)
disable_socket (prog->v.p.socket);
else
enable_socket (prog->v.p.socket);
}
}
}
@@ -1556,15 +1555,15 @@ progman_wake_sleeping (int onalrm)
time_t now = time (NULL);
debug (1, (_("checking for components to start")));
for (prog = proghead; prog; prog = prog->next)
{
- if (IS_ACTIVE_COMPONENT (prog) && prog->v.p.wait)
+ if (IS_ACTIVE_COMPONENT (prog) && prog->wait)
{
- /* The following works on the assumption that prog->v.p.wait is
+ /* The following works on the assumption that prog->wait is
set when enabling the component and gets cleared right after
it has finished. */
if (prog->v.p.status != status_running)
prog_start (prog);
return;
}
@@ -1617,13 +1616,13 @@ prog_start_prerequisites (struct prog *prog)
{
int ret = 0;
pies_depmap_pos_t pos;
struct component *comp;
int warned = 0;
- if (!prog->v.p.active)
+ if (!prog->active)
return 1;
for (comp = component_depmap_first (depmap_col, prog->v.p.comp->arridx, &pos);
comp;
comp = component_depmap_next (pos))
{
struct prog *p;
@@ -1633,15 +1632,15 @@ prog_start_prerequisites (struct prog *prog)
if (!warned)
{
debug (1, ("starting prerequisites of %s", prog_tag (prog)));
warned = 1;
}
- if (!prog->v.p.active)
+ if (!prog->active)
{
- prog->v.p.active = 0;
+ prog->active = 0;
return 1;
}
p = comp->prog;
switch (p->v.p.status)
{
@@ -1732,13 +1731,13 @@ prog_stop (struct prog *prog, int sig)
}
static int
mark_for_stopping (struct prog *prog, void *data)
{
if (IS_COMPONENT (prog))
- prog->v.p.stop = 1;
+ prog->stop = 1;
return 0;
}
void
progman_stop (void)
{
@@ -2220,13 +2219,13 @@ react (struct prog *prog, int status, pid_t pid)
prog_start (prog);
break;
case action_disable:
logmsg (LOG_NOTICE, _("disabling component %s"),
prog_tag (prog));
- prog->v.p.active = 0;
+ prog->active = 0;
/* FIXME:
if (prog->v.p.comp->mode == pies_comp_inetd)
disable_socket (prog->v.p.socket);
*/
}
if (act->addr)
@@ -2259,13 +2258,13 @@ progman_cleanup (int expect_term)
}
prog->pid = 0;
switch (prog->type)
{
case TYPE_COMPONENT:
print_status (prog_tag (prog), pid, status, expect_term);
- prog->v.p.stop = 0;
+ prog->stop = 0;
if (prog->v.p.comp->mode == pies_comp_inetd)
{
struct prog *listener = prog->v.p.listener;
listener->v.p.num_instances--;
if (prog->v.p.cclass)
@@ -2299,16 +2298,16 @@ progman_cleanup (int expect_term)
&& 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->v.p.wait)
+ if (prog->wait)
{
pies_schedule_children (PIES_CHLD_WAKEUP);
- prog->v.p.wait = 0;
+ prog->wait = 0;
}
}
else
{
if (is_sysvinit (prog->v.p.comp))
sysvinit_acct (SYSV_ACCT_PROC_STOP, "",
@@ -2363,34 +2362,34 @@ progman_stop_component (struct prog **progptr)
break;
case status_listener:
prog_deactivate_listener (prog);
/* fall through */
case status_stopped:
- prog->v.p.stop = 0;
+ prog->stop = 0;
if (!component_is_active (prog->v.p.comp))
destroy_prog (progptr);
break;
case status_sleeping:
if (!component_is_active (prog->v.p.comp))
destroy_prog (progptr);
- else if (prog->v.p.stop)
- prog->v.p.stop = 0;
+ else if (prog->stop)
+ prog->stop = 0;
else
{
logmsg (LOG_INFO, _("waking up component %s"), prog_tag (prog));
prog->v.p.failcount = 0;
}
break;
case status_stopping:
break;
case status_finished:
- prog->v.p.stop = 0;
+ prog->stop = 0;
if (!component_is_active (prog->v.p.comp))
destroy_prog (progptr);
else
logmsg (LOG_INFO,
_("stopping component %s: component not started"),
prog_tag (prog));
@@ -2436,13 +2435,13 @@ prog_activate_listener (struct prog *prog)
/* Starting at PROG, find first program component marked for termination. */
static struct prog *
prog_to_stop (struct prog *prog)
{
for (; prog; prog = prog->next)
- if (IS_COMPONENT (prog) && prog->v.p.stop)
+ if (IS_COMPONENT (prog) && prog->stop)
break;
return prog;
}
#define DIAG_CON \
(init_process ? (DIAG_TO_STDERR|DIAG_REOPEN_LOG) : diag_output)
diff --git a/src/sysvinit.c b/src/sysvinit.c
index bbd97f3..0b12b4a 100644
--- a/src/sysvinit.c
+++ b/src/sysvinit.c
@@ -240,13 +240,13 @@ enablecomp (struct prog *prog, void *data)
case pies_comp_boot:
case pies_comp_bootwait:
return 0;
case pies_comp_ondemand:
/* Active flag persists: */
- return prog->v.p.active;
+ return prog->active;
case pies_comp_powerfail:
case pies_comp_powerwait:
case pies_comp_powerokwait:
case pies_comp_ctrlaltdel:
case pies_comp_powerfailnow:
@@ -279,24 +279,24 @@ runlevel_setup_prog (struct prog *prog, void *data)
{
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 || prog->v.p.active == rc)
+ if (rc < 0 || prog->active == rc)
return 0;
- prog->v.p.active = rc;
+ prog->active = rc;
if (rc)
- prog->v.p.wait = is_comp_wait (prog->v.p.comp);
+ prog->wait = is_comp_wait (prog->v.p.comp);
else if (prog->v.p.status != status_stopped
&& prog->v.p.status != status_finished)
- prog->v.p.stop = 1;
+ prog->stop = 1;
debug (2, ("%s: %s%s", prog_tag (prog),
- prog->v.p.active ?
+ prog->active ?
"enabled" : "disabled",
- prog->v.p.active && prog->v.p.wait ? " (wait)" : ""));
+ prog->active && prog->wait ? " (wait)" : ""));
}
return 0;
}
void
sysvinit_runlevel_setup (int mask)
@@ -313,13 +313,13 @@ demand_prog (struct prog *prog, void *data)
int *rl = data;
struct component *comp = prog->v.p.comp;
if (comp->mode == pies_comp_ondemand
&& comp->runlevels
&& strchr (comp->runlevels, *rl))
{
- prog->v.p.active = 1;
+ prog->active = 1;
debug (1, ("%s: %s", prog_tag (prog), "enabled"));
}
return 0;
}
static void
@@ -761,13 +761,13 @@ sysvinit_begin (void)
start_shell (emergency_shell);
}
#define IS_RUNNING_DISABLED_PROG(prog) \
(IS_COMPONENT (prog) \
&& prog->v.p.status == status_running \
- && !prog->v.p.active)
+ && !prog->active)
int
inittrans (void)
{
int n;
int newlevel = 0;

Return to:

Send suggestions and report system problems to the System administrator.