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
@@ -918,14 +918,17 @@ static void res_instance (struct ctlio *, enum http_method, char const *,
918 struct json_value *); 918 struct json_value *);
919static void res_programs (struct ctlio *, enum http_method, char const *, 919static void res_programs (struct ctlio *, enum http_method, char const *,
920 struct json_value *); 920 struct json_value *);
921static void res_conf (struct ctlio *, enum http_method, char const *,
922 struct json_value *);
923
924#if PIES_SYSVINIT_ENABLED
921static void res_runlevel (struct ctlio *, enum http_method, char const *, 925static void res_runlevel (struct ctlio *, enum http_method, char const *,
922 struct json_value *); 926 struct json_value *);
923static void res_environ (struct ctlio *, enum http_method, char const *, 927static void res_environ (struct ctlio *, enum http_method, char const *,
924 struct json_value *); 928 struct json_value *);
925static void res_conf (struct ctlio *, enum http_method, char const *,
926 struct json_value *);
927
928static int pred_sysvinit (void); 929static int pred_sysvinit (void);
930#endif
931
929 932
930struct ctlio_resource 933struct ctlio_resource
931{ 934{
@@ -943,8 +946,10 @@ static struct ctlio_resource restab[] = {
943 { S(/conf), CTL_ADMIN_STATE, NULL, res_conf }, 946 { S(/conf), CTL_ADMIN_STATE, NULL, res_conf },
944 { S(/programs), CTL_ADMIN_STATE|CTL_USER_STATE, NULL, 947 { S(/programs), CTL_ADMIN_STATE|CTL_USER_STATE, NULL,
945 res_programs }, 948 res_programs },
949#if PIES_SYSVINIT_ENABLED
946 { S(/runlevel), CTL_ADMIN_STATE, pred_sysvinit, res_runlevel }, 950 { S(/runlevel), CTL_ADMIN_STATE, pred_sysvinit, res_runlevel },
947 { S(/environ), CTL_ADMIN_STATE, pred_sysvinit, res_environ }, 951 { S(/environ), CTL_ADMIN_STATE, pred_sysvinit, res_environ },
952#endif
948 { NULL } 953 { NULL }
949#undef S 954#undef S
950}; 955};
@@ -2117,6 +2122,7 @@ res_programs (struct ctlio *io, enum http_method meth,
2117 res_programs_select (io, meth, uri, json); 2122 res_programs_select (io, meth, uri, json);
2118} 2123}
2119 2124
2125#if PIES_SYSVINIT_ENABLED
2120static int 2126static int
2121pred_sysvinit (void) 2127pred_sysvinit (void)
2122{ 2128{
@@ -2164,6 +2170,89 @@ res_runlevel (struct ctlio *io, enum http_method meth,
2164 ctlio_reply (io, 405, NULL); 2170 ctlio_reply (io, 405, NULL);
2165} 2171}
2166 2172
2173/* GET /environ - List entire environment
2174 * ["RUNLEVEL=3", "CONSOLE=/dev/tty", ...]
2175 * GET /environ/NAME - Get value of variable NAME
2176 * { "status":"OK", "value":"..." }
2177 * { "status":"ER", "error_message":"..." }
2178 * DELETE /environ/NAME - Unset variable
2179 * { "status":"OK" }
2180 * { "status":"ER", "error_message":"..." }
2181 * PUT /environ/NAME=VALUE - Set variable
2182 * { "status":"OK" }
2183 * { "status":"ER", "error_message":"..." }
2184 */
2185static void
2186env_reply (struct ctlio *io, int ok, int rc)
2187{
2188 switch (rc)
2189 {
2190 case 0:
2191 io->code = ok;
2192 io->output.reply = json_reply_create ();
2193 json_object_set_string (io->output.reply, "status", "OK");
2194 break;
2195
2196 case 1:
2197 ctlio_reply (io, 403, NULL);
2198 break;
2199
2200 case -1:
2201 ctlio_reply (io, 404, NULL);
2202 }
2203}
2204
2205static void
2206res_environ (struct ctlio *io, enum http_method meth,
2207 char const *uri, struct json_value *json)
2208{
2209 if (meth == METH_GET)
2210 {
2211 if (uri && uri[1])
2212 {
2213 char *value;
2214
2215 if (sysvinit_envlocate (uri + 1, &value) == -1)
2216 ctlio_reply (io, 404, NULL);
2217 else
2218 {
2219 env_reply (io, 200, 0);
2220 json_object_set_string (io->output.reply, "value", "%s", value);
2221 }
2222 }
2223 else
2224 {
2225 size_t i;
2226
2227 io->output.reply = json_new_array ();
2228 io->code = 200;
2229 for (i = 0; sysvinit_environ_hint[i]; i++)
2230 {
2231 json_array_append (io->output.reply,
2232 json_new_string (sysvinit_environ_hint[i]));
2233 }
2234 }
2235 }
2236 else if (meth == METH_DELETE)
2237 {
2238 if (!(uri && uri[0]))
2239 ctlio_reply (io, 400, NULL);
2240 else
2241 env_reply (io, 200, sysvinit_envupdate (uri + 1));
2242 }
2243 else if (meth == METH_PUT)
2244 {
2245 if (!(uri && uri[0]))
2246 ctlio_reply (io, 400, NULL);
2247 else
2248 env_reply (io, 201, sysvinit_envupdate (uri + 1));
2249 }
2250 else
2251 ctlio_reply (io, 405, NULL);
2252
2253}
2254#endif
2255
2167/* GET /conf/runtime - List configuration 2256/* GET /conf/runtime - List configuration
2168 * PUT /conf/runtime - Reload configuration 2257 * PUT /conf/runtime - Reload configuration
2169 * POST /conf/runtime - Post new configuration 2258 * POST /conf/runtime - Post new configuration
@@ -2408,84 +2497,3 @@ res_conf (struct ctlio *io, enum http_method meth,
2408 ctlio_reply (io, 404, NULL); 2497 ctlio_reply (io, 404, NULL);
2409} 2498}
2410 2499
2411/* GET /environ - List entire environment
2412 * ["RUNLEVEL=3", "CONSOLE=/dev/tty", ...]
2413 * GET /environ/NAME - Get value of variable NAME
2414 * { "status":"OK", "value":"..." }
2415 * { "status":"ER", "error_message":"..." }
2416 * DELETE /environ/NAME - Unset variable
2417 * { "status":"OK" }
2418 * { "status":"ER", "error_message":"..." }
2419 * PUT /environ/NAME=VALUE - Set variable
2420 * { "status":"OK" }
2421 * { "status":"ER", "error_message":"..." }
2422 */
2423static void
2424env_reply (struct ctlio *io, int ok, int rc)
2425{
2426 switch (rc)
2427 {
2428 case 0:
2429 io->code = ok;
2430 io->output.reply = json_reply_create ();
2431 json_object_set_string (io->output.reply, "status", "OK");
2432 break;
2433
2434 case 1:
2435 ctlio_reply (io, 403, NULL);
2436 break;
2437
2438 case -1:
2439 ctlio_reply (io, 404, NULL);
2440 }
2441}
2442
2443static void
2444res_environ (struct ctlio *io, enum http_method meth,
2445 char const *uri, struct json_value *json)
2446{
2447 if (meth == METH_GET)
2448 {
2449 if (uri && uri[1])
2450 {
2451 char *value;
2452
2453 if (sysvinit_envlocate (uri + 1, &value) == -1)
2454 ctlio_reply (io, 404, NULL);
2455 else
2456 {
2457 env_reply (io, 200, 0);
2458 json_object_set_string (io->output.reply, "value", "%s", value);
2459 }
2460 }
2461 else
2462 {
2463 size_t i;
2464
2465 io->output.reply = json_new_array ();
2466 io->code = 200;
2467 for (i = 0; sysvinit_environ_hint[i]; i++)
2468 {
2469 json_array_append (io->output.reply,
2470 json_new_string (sysvinit_environ_hint[i]));
2471 }
2472 }
2473 }
2474 else if (meth == METH_DELETE)
2475 {
2476 if (!(uri && uri[0]))
2477 ctlio_reply (io, 400, NULL);
2478 else
2479 env_reply (io, 200, sysvinit_envupdate (uri + 1));
2480 }
2481 else if (meth == METH_PUT)
2482 {
2483 if (!(uri && uri[0]))
2484 ctlio_reply (io, 400, NULL);
2485 else
2486 env_reply (io, 201, sysvinit_envupdate (uri + 1));
2487 }
2488 else
2489 ctlio_reply (io, 405, NULL);
2490
2491}

Return to:

Send suggestions and report system problems to the System administrator.