aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ctl.c22
-rw-r--r--src/pies.c17
-rw-r--r--src/pies.h3
-rw-r--r--src/piesctl.c108
4 files changed, 125 insertions, 25 deletions
diff --git a/src/ctl.c b/src/ctl.c
index cdb9b6c..8845390 100644
--- a/src/ctl.c
+++ b/src/ctl.c
@@ -1296,27 +1296,43 @@ static void
idfmt_pid (struct ctlio *io, char const *name, void *ptr)
{
json_object_set_number (io->output.reply, name, getpid ());
}
static void
+idfmt_argv (struct ctlio *io, char const *name, void *ptr)
+{
+ struct json_value *ar = json_new_array ();
+ size_t i;
+
+ for (i = 0; i < pies_master_argc; i++)
+ json_array_append (ar, json_new_string (pies_master_argv[i]));
+ json_object_set (io->output.reply, name, ar);
+}
+
+static void
+idfmt_binary (struct ctlio *io, char const *name, void *ptr)
+{
+ json_object_set_string (io->output.reply, name, "%s", pies_master_argv[0]);
+}
+
+static void
res_instance (struct ctlio *io, enum http_method meth,
char const *uri, struct json_value *req)
{
static struct idparam {
char *name;
void (*fmt) (struct ctlio *, char const *, void *);
void *data;
} idparam[] = {
{ "package", idfmt_string, PACKAGE_NAME },
{ "version", idfmt_string, PACKAGE_VERSION },
-#if HAVE_DECL_PROGRAM_INVOCATION_NAME
- { "binary", idfmt_string_ptr, &program_invocation_name },
-#endif
+ { "binary", idfmt_binary, NULL },
{ "PID", idfmt_pid, NULL },
{ "instance", idfmt_string_ptr, &instance },
+ { "argv", idfmt_argv, NULL },
{ NULL }
};
struct idparam *p;
io->output.reply = json_reply_create ();
if (uri)
diff --git a/src/pies.c b/src/pies.c
index f069552..875684a 100644
--- a/src/pies.c
+++ b/src/pies.c
@@ -2127,12 +2127,15 @@ set_state_file_names (const char *base)
if (!pidfile)
pidfile = mkfilename (statedir, base, ".pid");
if (!qotdfile)
qotdfile = mkfilename (statedir, base, ".qotd");
}
+size_t pies_master_argc;
+char **pies_master_argv;
+
int
main (int argc, char **argv)
{
int index;
pid_t pid;
extern char **environ;
@@ -2143,12 +2146,15 @@ main (int argc, char **argv)
#ifdef ENABLE_NLS
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
#endif
mf_proctitle_init (argc, argv, environ);
+
+ pies_master_argc = argc;
+ pies_master_argv = argv;
set_quoting_style (NULL, shell_quoting_style);
init_process = getpid () == 1;
#ifdef INIT_EMU
# warning "pies compiled with init emulation code"
@@ -2389,14 +2395,21 @@ main (int argc, char **argv)
action = ACTION_CONT;
}
else if (!children_cleanup)
pies_pause ();
switch (action)
{
- case ACTION_STOP:
case ACTION_RESTART:
+ if (argv[0][0] != '/' || init_process)
+ {
+ logmsg (LOG_INFO, _("restart command ignored"));
+ action = ACTION_CONT;
+ }
+ break;
+
+ case ACTION_STOP:
if (init_process)
{
debug (1, ("ignoring stop/restart"));
action = ACTION_CONT;
}
break;
@@ -2433,13 +2446,13 @@ main (int argc, char **argv)
}
while (init_process || action == ACTION_CONT);
progman_stop ();
remove_pidfile (pidfile);
- if (action == ACTION_RESTART && argv[0][0] == '/')
+ if (action == ACTION_RESTART)
{
int minfd = DIAG_OUTPUT (DIAG_TO_STDERR) ? 2 : 0;
int i;
for (i = getmaxfd (); i > minfd; i--)
close (i);
diff --git a/src/pies.h b/src/pies.h
index 7c5e6d7..f69c512 100644
--- a/src/pies.h
+++ b/src/pies.h
@@ -287,12 +287,15 @@ extern char *qotdfile;
extern int init_process;
extern char *console_device;
extern int initdefault;
extern int dfl_level;
+extern size_t pies_master_argc;
+extern char **pies_master_argv;
+
enum config_syntax
{
CONF_PIES,
CONF_META1,
CONF_INETD,
CONF_INITTAB
diff --git a/src/piesctl.c b/src/piesctl.c
index a9555a1..fcc346a 100644
--- a/src/piesctl.c
+++ b/src/piesctl.c
@@ -1555,55 +1555,123 @@ com_restart (struct shttp_connection *conn, int argc, char **argv)
conn->req.content_length = strlen (conn->req.content);
shttp_process (conn, METH_POST, "/programs/select");
shttp_print_response_status (conn);
return 0;
}
+static void
+id_fmt_string (struct json_value *val)
+{
+ fputs (val->v.s, stdout);
+}
+
+static void
+id_fmt_pid (struct json_value *val)
+{
+ printf ("%.0f", val->v.n);
+}
+
+static void
+id_fmt_argv (struct json_value *val)
+{
+ size_t i, n;
+ char const *delim = NULL;
+
+ n = json_array_size (val);
+ for (i = 0; i < n; i++)
+ {
+ struct json_value *elt;
+ if (json_array_get (val, i, &elt) == 0 && elt->type == json_string)
+ {
+ if (delim)
+ fputs (delim, stdout);
+ fputs (elt->v.s, stdout);
+ delim = " ";
+ }
+ }
+}
+
+struct id_fmt
+{
+ char *name;
+ enum json_value_type type;
+ void (*format) (struct json_value *);
+};
+
+static struct id_fmt id_fmt[] = {
+ { "package", json_string, id_fmt_string },
+ { "version", json_string, id_fmt_string },
+ { "instance", json_string, id_fmt_string },
+ { "binary", json_string, id_fmt_string },
+ { "argv", json_arr, id_fmt_argv },
+ { "PID", json_number, id_fmt_pid },
+ { NULL }
+};
+
+static struct id_fmt *
+find_id_fmt (char const *name)
+{
+ struct id_fmt *p;
+
+ for (p = id_fmt; p->name; p++)
+ if (strcmp (p->name, name) == 0)
+ return p;
+ return NULL;
+}
+
static int
com_id (struct shttp_connection *conn, int argc, char **argv)
{
struct json_value *v;
-
+ struct id_fmt *fmt;
+
if (argc == 1)
{
- size_t i;
- static char *keywords[] = {
- "package",
- "version",
- "instance",
- "binary",
- };
-
shttp_io_init (&conn->req);
shttp_process (conn, METH_GET, "/instance");
-
- for (i = 0; i < sizeof (keywords)/ sizeof (keywords[0]); i++)
- {
- v = shttp_getval (conn, keywords[i], json_string);
- if (v)
- printf ("%s: %s\n", keywords[i], v->v.s);
- }
- v = shttp_getval (conn, "PID", json_number);
- if (v)
- printf ("PID: %.0f\n", v->v.n);
+ if (!dump)
+ for (fmt = id_fmt; fmt->name; fmt++)
+ {
+ v = shttp_getval (conn, fmt->name, fmt->type);
+ if (v)
+ {
+ printf ("%s: ", fmt->name);
+ fmt->format (v);
+ putchar ('\n');
+ }
+ }
}
else
{
char *buf = NULL;
size_t size = 0;
size_t i;
for (i = 1; i < argc; i++)
{
grecs_asprintf (&buf, &size, "/instance/%s", argv[i]);
shttp_io_init (&conn->req);
shttp_process (conn, METH_GET, buf);
- if (json_object_get (conn->result, argv[i], &v) == 0)
+ if (dump)
+ continue;
+ fmt = find_id_fmt (argv[i]);
+ if (fmt)
+ {
+ v = shttp_getval (conn, fmt->name, fmt->type);
+ if (v)
+ {
+ printf ("%s: ", fmt->name);
+ fmt->format (v);
+ putchar ('\n');
+ }
+ }
+ else if (json_object_get (conn->result, argv[i], &v) == 0)
{
printf ("%s: ", argv[i]);
print_json (stdout, v);
+ putchar ('\n');
}
}
}
return 0;
}

Return to:

Send suggestions and report system problems to the System administrator.