aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2009-10-26 21:57:44 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2009-10-26 21:57:44 +0200
commit7e662d44f8c64be0533d2a4548b7ecdda45a2019 (patch)
tree0ae69f1a7c445257b5fe0b651ad45e3049736aa8
parent4769e173a6630c464c633198c3ac97da3500905a (diff)
downloadpies-7e662d44f8c64be0533d2a4548b7ecdda45a2019.tar.gz
pies-7e662d44f8c64be0533d2a4548b7ecdda45a2019.tar.bz2
Rearrange structures prog and component.
* config_array_to_argv (config_array_to_argv): Take four arguments. Return argc in the memory location pointed to by the 4th one (unless NULL). All callers updated. (_cb_command): Fill both comp->argv and comp->argc. (component_keywords): Pass pointer to struct component to _cb_command. * src/pies.h (struct component): New member `argc'. * src/progman.c (struct prog): Move idx to v.p; change its type to unsigned. Remove v.p.argc. All uses updated. (numprog): Rename to numcomp; change type to unsigned. (prog_lookup_by_idx): Check only elements of type TYPE_COMPONENT.
-rw-r--r--src/pies.c19
-rw-r--r--src/pies.h1
-rw-r--r--src/progman.c48
3 files changed, 32 insertions, 36 deletions
diff --git a/src/pies.c b/src/pies.c
index a79ceae..b46dedf 100644
--- a/src/pies.c
+++ b/src/pies.c
@@ -426,7 +426,7 @@ return_code_section_parser (enum grecs_callback_command cmd,
}
static char **
-config_array_to_argv (grecs_value_t *val, grecs_locus_t *locus)
+config_array_to_argv (grecs_value_t *val, grecs_locus_t *locus, size_t *pargc)
{
int i, j;
int argc;
@@ -441,6 +441,8 @@ config_array_to_argv (grecs_value_t *val, grecs_locus_t *locus)
argv[j++] = xstrdup (val->v.arg.v[i].v.string);
}
argv[j] = NULL;
+ if (pargc)
+ *pargc = argc;
return argv;
}
@@ -449,8 +451,7 @@ _cb_command (enum grecs_callback_command cmd,
grecs_locus_t * locus,
void *varptr, grecs_value_t * value, void *cb_data)
{
- int argc;
- char **argv, ***pargv = varptr;
+ struct component *comp = varptr;
struct wordsplit ws;
switch (value->type)
@@ -461,20 +462,18 @@ _cb_command (enum grecs_callback_command cmd,
grecs_error (locus, 0, "wordsplit: %s", strerror (errno));
return 1;
}
- argc = ws.ws_wordc;
- argv = ws.ws_wordv;
- ws.ws_wordv = NULL;
+ comp->argc = ws.ws_wordc;
+ comp->argv = ws.ws_wordv;
break;
case GRECS_TYPE_ARRAY:
- argv = config_array_to_argv (value, locus);
+ comp->argv = config_array_to_argv (value, locus, &comp->argc);
break;
case GRECS_TYPE_LIST:
grecs_error (locus, 0, _("unexpected list"));
return 1;
}
- *pargv = argv;
return 0;
}
@@ -524,7 +523,7 @@ _cb_env (enum grecs_callback_command cmd,
break;
case GRECS_TYPE_ARRAY:
- argv = config_array_to_argv (value, locus);
+ argv = config_array_to_argv (value, locus, NULL);
break;
case GRECS_TYPE_LIST:
@@ -777,7 +776,7 @@ struct grecs_keyword component_keywords[] = {
{"command",
NULL,
N_("Command line."),
- grecs_type_string, NULL, offsetof (struct component, argv),
+ grecs_type_string, NULL, 0,
_cb_command,
},
{"prerequisites",
diff --git a/src/pies.h b/src/pies.h
index 014bd81..08a9c4f 100644
--- a/src/pies.h
+++ b/src/pies.h
@@ -141,6 +141,7 @@ struct component
enum pies_comp_mode mode;
char *tag; /* Entry tag (for diagnostics purposes) */
char *program; /* Program name */
+ size_t argc; /* Number of command line arguments */
char **argv; /* Program command line */
char **env; /* Program environment */
char *dir; /* Working directory */
diff --git a/src/progman.c b/src/progman.c
index c864966..456b5ff 100644
--- a/src/progman.c
+++ b/src/progman.c
@@ -40,7 +40,6 @@ struct prog
enum prog_type type;
pid_t pid; /* PID */
char *tag; /* Entry tag (for diagnostics purposes) */
- int idx; /* Numeric identifier */
char **prereq;
int facility;
union
@@ -48,11 +47,11 @@ struct prog
struct
{
struct component *comp;
- int argc; /* Number of elements in comp->argv */
+ unsigned idx; /* Numeric identifier */
int socket;
struct prog *redir[2]; /* Pointers to redirectors */
- time_t timestamp; /* Time of last startup */
- size_t count; /* Number of failed starts since timestamp */
+ time_t timestamp; /* Time of last startup */
+ size_t count; /* Number of failed starts since timestamp */
enum prog_status status; /* Current component status */
} p;
@@ -70,7 +69,7 @@ struct prog
#define IS_COMPONENT(p) ((p)->type == TYPE_COMPONENT)
-static int numprog;
+static unsigned numcomp;
static struct prog *proghead, *progtail;
static pies_depmap_t depmap;
static int recompute_alarm;
@@ -122,7 +121,7 @@ prog_lookup_by_idx (unsigned idx)
{
struct prog *prog;
for (prog = proghead; prog; prog = prog->next)
- if (prog->idx == idx)
+ if (IS_COMPONENT (prog) && prog->v.p.idx == idx)
break;
return prog;
}
@@ -225,7 +224,6 @@ register_redir (int type, struct prog *master)
pstr += strlen (pp->tag) + 1;
free (tag);
pp->v.r.master = master;
- pp->idx = -1; /* Retranslators are not indexed */
pp->prereq = (char**)pstr;
pp->prereq[0] = master->tag;
pp->prereq[1] = NULL;
@@ -249,21 +247,17 @@ update_redir (int type, struct prog *master, pid_t pid)
}
static struct prog *
-register_prog0 (struct component *comp, int index)
+register_prog0 (struct component *comp, unsigned index)
{
struct prog *newp;
- int i;
newp = xzalloc (sizeof (*newp));
newp->type = TYPE_COMPONENT;
newp->tag = comp->tag;
newp->pid = 0;
- newp->idx = index;
newp->facility = comp->facility;
newp->v.p.comp = comp;
- for (i = 0; comp->argv[i]; i++)
- ;
- newp->v.p.argc = i;
+ newp->v.p.idx = index;
newp->v.p.socket = -1;
if (comp->disabled)
newp->v.p.status = status_disabled;
@@ -280,7 +274,7 @@ register_prog0 (struct component *comp, int index)
void
register_prog (struct component *comp)
{
- register_prog0 (comp, numprog++);
+ register_prog0 (comp, numcomp++);
}
void
@@ -729,10 +723,12 @@ prog_start (struct prog *prog)
if (debug_level >= 1)
{
int i;
+ struct component *comp = prog->v.p.comp;
+
logmsg_printf (LOG_DEBUG, "executing");
- for (i = 0; i < prog->v.p.argc; i++)
+ for (i = 0; i < comp->argc; i++)
logmsg_printf (LOG_DEBUG, " %s",
- quotearg (prog->v.p.comp->argv[i]));
+ quotearg (comp->argv[i]));
logmsg_printf (LOG_DEBUG, "\n");
}
@@ -951,7 +947,7 @@ print_dep (struct prog *prog)
unsigned n;
logmsg_printf (LOG_NOTICE, "%s -> ", prog->tag);
- for (n = depmap_first (depmap, depmap_col, prog->idx, &pos);
+ for (n = depmap_first (depmap, depmap_col, prog->v.p.idx, &pos);
n != (unsigned)-1;
n = depmap_next (depmap, pos))
{
@@ -984,18 +980,18 @@ progman_dump_depmap ()
printf ("%s:\n", _("Dependency map"));
printf (" ");
- for (i = 0; i < numprog; i++)
+ for (i = 0; i < numcomp; i++)
printf (" %2d", i);
printf ("\n");
- for (i = 0; i < numprog; i++)
+ for (i = 0; i < numcomp; i++)
{
printf ("%2d ", i);
- for (j = 0; j < numprog; j++)
+ for (j = 0; j < numcomp; j++)
printf (" %c ", depmap_isset (depmap, i, j) ? 'X' : ' ');
printf ("\n");
}
printf ("\n%s:\n", _("Legend"));
- for (i = 0; i < numprog; i++)
+ for (i = 0; i < numcomp; i++)
{
prog = prog_lookup_by_idx (i);
if (prog)
@@ -1013,7 +1009,7 @@ progman_build_depmap ()
fixup_prerequisites ();
rebuild_prerequisites ();
- depmap = depmap_alloc (numprog);
+ depmap = depmap_alloc (numcomp);
for (prog = proghead; prog; prog = prog->next)
if (prog->prereq)
{
@@ -1029,12 +1025,12 @@ progman_build_depmap ()
rc++;
}
else
- depmap_set (depmap, prog->idx, dep->idx);
+ depmap_set (depmap, prog->v.p.idx, dep->v.p.idx);
}
}
dp = depmap_copy (depmap);
depmap_tc (dp);
- for (i = 0; i < numprog; i++)
+ for (i = 0; i < numcomp; i++)
if (depmap_isset (dp, i, i))
{
prog = prog_lookup_by_idx (i);
@@ -1252,7 +1248,7 @@ prog_stop_dependents (struct prog *prog)
int warned = 0;
prog_stop_redirectors (prog);
- for (n = depmap_first (depmap, depmap_row, prog->idx, &pos);
+ for (n = depmap_first (depmap, depmap_row, prog->v.p.idx, &pos);
n != (unsigned)-1;
n = depmap_next (depmap, pos))
{
@@ -1865,7 +1861,7 @@ progman_dump_stats (const char *filename)
fprintf (fp, _("[listener]"));
else
fprintf (fp, _("[not running]"));
- for (i = 0; i < prog->v.p.argc; i++)
+ for (i = 0; i < prog->v.p.comp->argc; i++)
fprintf (fp, " %s", quotearg (prog->v.p.comp->argv[i]));
fputc ('\n', fp);
break;

Return to:

Send suggestions and report system problems to the System administrator.