aboutsummaryrefslogtreecommitdiff
path: root/src/ctl.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2019-06-24 12:56:24 +0300
committerSergey Poznyakoff <gray@gnu.org>2019-06-24 12:56:24 +0300
commit006bfbc5235c181783445d321ce7a7e3c6d8bd8a (patch)
treef483e0d30c3e801add01b372b24a342281b70b86 /src/ctl.c
parentcb90ca582a46ef9f0779837dc4c6fb00656e70c9 (diff)
downloadpies-006bfbc5235c181783445d321ce7a7e3c6d8bd8a.tar.gz
pies-006bfbc5235c181783445d321ce7a7e3c6d8bd8a.tar.bz2
Enable/disable SystemV init code at compile time
* configure.ac: New option --enable-sysvinit. Disable the init code if RUN_LVL is not available. (PIES_SYSVINIT_ENABLED): New configuration define. (PIES_COND_SYSVINIT): New condition Print configuration settings summary. * src/pies.h (is_sysvinit): Check for PIES_SYSVINIT_ENABLED. (SYSVINIT_ACTIVE): New macro. * grecs: Upgrade. * src/Makefile.am: Conditionally link sysvinit-related code. * src/cmdline.opt: Disable the --telinit option if sysvinit support is not available. (parse_options): Use SYSVINIT_ACTIVE in the conditional. * src/comp.c (component_verify): Check if component definition is allowed by the current state of the sysvinit support. * src/ctl.c: Disable the /runlevel entry point if sysvinit support is not compiled. * src/diag.c (stderr_open): Make sure sysvinit-related code is not compiled if the sysvinit support is not available. * src/pies.c (config_syntax_tab): Add entry for CONF_INITTAB only if sysvinit support is available. (_cb_initdefault,_cb_runlevels): Remove. Use cb_initdefault and cb_runlevels instead. (component_keywords): Disable runlevels without sysvinit support. (pies_keywords): Same for initdefault. Use SYSVINIT_ACTIVE to suppress compilation of sysvinit code without sysvinit support. * src/progman.c: Use SYSVINIT_ACTIVE to suppress compilation of sysvinit code without sysvinit support. * src/sysvinit.c (cb_initdefault,cb_runlevels): New functions.
Diffstat (limited to 'src/ctl.c')
-rw-r--r--src/ctl.c176
1 files changed, 92 insertions, 84 deletions
diff --git a/src/ctl.c b/src/ctl.c
index d9a8998..5609f19 100644
--- a/src/ctl.c
+++ b/src/ctl.c
@@ -920,2 +920,6 @@ static void res_programs (struct ctlio *, enum http_method, char const *,
struct json_value *);
+static void res_conf (struct ctlio *, enum http_method, char const *,
+ struct json_value *);
+
+#if PIES_SYSVINIT_ENABLED
static void res_runlevel (struct ctlio *, enum http_method, char const *,
@@ -924,6 +928,5 @@ static void res_environ (struct ctlio *, enum http_method, char const *,
struct json_value *);
-static void res_conf (struct ctlio *, enum http_method, char const *,
- struct json_value *);
-
static int pred_sysvinit (void);
+#endif
+
@@ -945,4 +948,6 @@ static struct ctlio_resource restab[] = {
res_programs },
+#if PIES_SYSVINIT_ENABLED
{ S(/runlevel), CTL_ADMIN_STATE, pred_sysvinit, res_runlevel },
{ S(/environ), CTL_ADMIN_STATE, pred_sysvinit, res_environ },
+#endif
{ NULL }
@@ -2119,2 +2124,3 @@ res_programs (struct ctlio *io, enum http_method meth,
+#if PIES_SYSVINIT_ENABLED
static int
@@ -2166,2 +2172,85 @@ res_runlevel (struct ctlio *io, enum http_method meth,
+/* GET /environ - List entire environment
+ * ["RUNLEVEL=3", "CONSOLE=/dev/tty", ...]
+ * GET /environ/NAME - Get value of variable NAME
+ * { "status":"OK", "value":"..." }
+ * { "status":"ER", "error_message":"..." }
+ * DELETE /environ/NAME - Unset variable
+ * { "status":"OK" }
+ * { "status":"ER", "error_message":"..." }
+ * PUT /environ/NAME=VALUE - Set variable
+ * { "status":"OK" }
+ * { "status":"ER", "error_message":"..." }
+ */
+static void
+env_reply (struct ctlio *io, int ok, int rc)
+{
+ switch (rc)
+ {
+ case 0:
+ io->code = ok;
+ io->output.reply = json_reply_create ();
+ json_object_set_string (io->output.reply, "status", "OK");
+ break;
+
+ case 1:
+ ctlio_reply (io, 403, NULL);
+ break;
+
+ case -1:
+ ctlio_reply (io, 404, NULL);
+ }
+}
+
+static void
+res_environ (struct ctlio *io, enum http_method meth,
+ char const *uri, struct json_value *json)
+{
+ if (meth == METH_GET)
+ {
+ if (uri && uri[1])
+ {
+ char *value;
+
+ if (sysvinit_envlocate (uri + 1, &value) == -1)
+ ctlio_reply (io, 404, NULL);
+ else
+ {
+ env_reply (io, 200, 0);
+ json_object_set_string (io->output.reply, "value", "%s", value);
+ }
+ }
+ else
+ {
+ size_t i;
+
+ io->output.reply = json_new_array ();
+ io->code = 200;
+ for (i = 0; sysvinit_environ_hint[i]; i++)
+ {
+ json_array_append (io->output.reply,
+ json_new_string (sysvinit_environ_hint[i]));
+ }
+ }
+ }
+ else if (meth == METH_DELETE)
+ {
+ if (!(uri && uri[0]))
+ ctlio_reply (io, 400, NULL);
+ else
+ env_reply (io, 200, sysvinit_envupdate (uri + 1));
+ }
+ else if (meth == METH_PUT)
+ {
+ if (!(uri && uri[0]))
+ ctlio_reply (io, 400, NULL);
+ else
+ env_reply (io, 201, sysvinit_envupdate (uri + 1));
+ }
+ else
+ ctlio_reply (io, 405, NULL);
+
+}
+#endif
+
/* GET /conf/runtime - List configuration
@@ -2410,82 +2499 @@ res_conf (struct ctlio *io, enum http_method meth,
-/* GET /environ - List entire environment
- * ["RUNLEVEL=3", "CONSOLE=/dev/tty", ...]
- * GET /environ/NAME - Get value of variable NAME
- * { "status":"OK", "value":"..." }
- * { "status":"ER", "error_message":"..." }
- * DELETE /environ/NAME - Unset variable
- * { "status":"OK" }
- * { "status":"ER", "error_message":"..." }
- * PUT /environ/NAME=VALUE - Set variable
- * { "status":"OK" }
- * { "status":"ER", "error_message":"..." }
- */
-static void
-env_reply (struct ctlio *io, int ok, int rc)
-{
- switch (rc)
- {
- case 0:
- io->code = ok;
- io->output.reply = json_reply_create ();
- json_object_set_string (io->output.reply, "status", "OK");
- break;
-
- case 1:
- ctlio_reply (io, 403, NULL);
- break;
-
- case -1:
- ctlio_reply (io, 404, NULL);
- }
-}
-
-static void
-res_environ (struct ctlio *io, enum http_method meth,
- char const *uri, struct json_value *json)
-{
- if (meth == METH_GET)
- {
- if (uri && uri[1])
- {
- char *value;
-
- if (sysvinit_envlocate (uri + 1, &value) == -1)
- ctlio_reply (io, 404, NULL);
- else
- {
- env_reply (io, 200, 0);
- json_object_set_string (io->output.reply, "value", "%s", value);
- }
- }
- else
- {
- size_t i;
-
- io->output.reply = json_new_array ();
- io->code = 200;
- for (i = 0; sysvinit_environ_hint[i]; i++)
- {
- json_array_append (io->output.reply,
- json_new_string (sysvinit_environ_hint[i]));
- }
- }
- }
- else if (meth == METH_DELETE)
- {
- if (!(uri && uri[0]))
- ctlio_reply (io, 400, NULL);
- else
- env_reply (io, 200, sysvinit_envupdate (uri + 1));
- }
- else if (meth == METH_PUT)
- {
- if (!(uri && uri[0]))
- ctlio_reply (io, 400, NULL);
- else
- env_reply (io, 201, sysvinit_envupdate (uri + 1));
- }
- else
- ctlio_reply (io, 405, NULL);
-
-}

Return to:

Send suggestions and report system problems to the System administrator.