aboutsummaryrefslogtreecommitdiff
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
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.
-rw-r--r--configure.ac46
m---------grecs0
-rw-r--r--src/Makefile.am10
-rw-r--r--src/cmdline.opt4
-rw-r--r--src/comp.c3
-rw-r--r--src/ctl.c176
-rw-r--r--src/diag.c2
-rw-r--r--src/pies.c85
-rw-r--r--src/pies.h13
-rw-r--r--src/progman.c15
-rw-r--r--src/sysvinit.c62
11 files changed, 250 insertions, 166 deletions
diff --git a/configure.ac b/configure.ac
index ae3a9c7..3a23a1a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -125,6 +125,30 @@ AC_ARG_ENABLE([inetd],
125 no) ;; 125 no) ;;
126 esac]) 126 esac])
127 127
128sysvinit_status=maybe
129AC_ARG_ENABLE([sysvinit],
130 AC_HELP_STRING([--enable-sysvinit],
131 [compile the SystemV init support]),
132 [sysvinit_status=$enableval])
133
134if test $sysvinit_status = "maybe"; then
135 AC_TRY_COMPILE([#ifdef HAVE_UTMPX_H
136# include <utmpx.h>
137#else
138# include <utmp.h>
139#endif
140],
141[int x = RUN_LVL;],
142[sysvinit_status=yes],
143[sysvinit_status=no])
144fi
145
146test $sysvinit_status = "no"
147PIES_SYSVINIT_ENABLED=$?
148AC_DEFINE_UNQUOTED([PIES_SYSVINIT_ENABLED],[$PIES_SYSVINIT_ENABLED],
149 [whether SystemV init support is compiled])
150AM_CONDITIONAL([PIES_COND_SYSVINIT],[test $sysvinit_status = "yes"])
151
128AH_BOTTOM([ 152AH_BOTTOM([
129# ifndef ATTRIBUTE_NORETURN 153# ifndef ATTRIBUTE_NORETURN
130# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) 154# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
@@ -147,6 +171,28 @@ AC_CONFIG_TESTDIR(tests)
147AC_CONFIG_FILES([tests/Makefile tests/atlocal]) 171AC_CONFIG_FILES([tests/Makefile tests/atlocal])
148AM_MISSING_PROG([AUTOM4TE], [autom4te]) 172AM_MISSING_PROG([AUTOM4TE], [autom4te])
149 173
174AC_CONFIG_COMMANDS([status],[
175cat <<EOF
176Configuration summary:
177
178URL of the control API ............................. $control_url
179PAM support ........................................ $status_pam
180SystemV initialization support ..................... $sysvinit_status
181EOF
182if test $sysvinit_status = "yes"; then
183 cat <<EOF
184URL of the SystemV init ............................ $sysvinit_control_url
185Emergency shell .................................... $emergency_shell
186EOF
187fi
188],
189[sysvinit_status=$sysvinit_status
190control_url=`echo "$DEFAULT_PIES_CONTROL_URL" | sed 's/\\\$/\\\\\$/g'`
191sysvinit_control_url=$DEFAULT_INIT_CONTROL_URL
192emergency_shell=$EMERGENCY_SHELL
193status_pam=$status_pam
194])
195
150AC_CONFIG_FILES([Makefile 196AC_CONFIG_FILES([Makefile
151 gnu/Makefile 197 gnu/Makefile
152 lib/Makefile 198 lib/Makefile
diff --git a/grecs b/grecs
Subproject 12304127b52650588877f00b0c4b32dae083e85 Subproject ee35adccec058a5a8cc62f5030b9a925168236d
diff --git a/src/Makefile.am b/src/Makefile.am
index 16f8a75..925da88 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -30,11 +30,15 @@ pies_SOURCES = \
30 pies.c\ 30 pies.c\
31 progman.c\ 31 progman.c\
32 socket.c\ 32 socket.c\
33 sysdep.c\
34 sysvinit.c\
35 utmp.c\
36 userprivs.c 33 userprivs.c
37 34
35if PIES_COND_SYSVINIT
36pies_SOURCES += \
37 sysvinit.c\
38 sysdep.c\
39 utmp.c
40endif
41
38noinst_HEADERS = \ 42noinst_HEADERS = \
39 acl.h\ 43 acl.h\
40 cmdline.h\ 44 cmdline.h\
diff --git a/src/cmdline.opt b/src/cmdline.opt
index d2aaf6d..d9d90e1 100644
--- a/src/cmdline.opt
+++ b/src/cmdline.opt
@@ -118,12 +118,14 @@ BEGIN
118 lint_mode = 1; 118 lint_mode = 1;
119END 119END
120 120
121CPP(#if PIES_SYSVINIT_ENABLED)
121OPTION(telinit,T,, 122OPTION(telinit,T,,
122 [<telinit command: run "pies -T --help" for help>]) 123 [<telinit command: run "pies -T --help" for help>])
123BEGIN 124BEGIN
124 log_to_stderr_only = 1; 125 log_to_stderr_only = 1;
125 exit (telinit (argc - (optind - 1), argv + (optind - 1))); 126 exit (telinit (argc - (optind - 1), argv + (optind - 1)));
126END 127END
128CPP(#endif)
127 129
128GROUP(Preprocessor) 130GROUP(Preprocessor)
129 131
@@ -220,7 +222,7 @@ parse_options (int *pargc, char ***pargv)
220 char **argv = *pargv; 222 char **argv = *pargv;
221 int index; 223 int index;
222 224
223 if (init_process) 225 if (SYSVINIT_ACTIVE)
224 { 226 {
225 sysvinit_parse_argv (argc, argv); 227 sysvinit_parse_argv (argc, argv);
226 index = argc; 228 index = argc;
diff --git a/src/comp.c b/src/comp.c
index 6eeeeed..7b2b373 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -674,6 +674,9 @@ component_verify (struct component *comp, grecs_locus_t *locus)
674 return 1; 674 return 1;
675 } 675 }
676 default: 676 default:
677 if (PIES_SYSVINIT_ENABLED && comp->mode >= pies_mark_sysvinit)
678 COMPERR (grecs_error,
679 "%s", _("SystemV init support is not compiled in"));
677 /* FIXME: more checks perhaps */ 680 /* FIXME: more checks perhaps */
678 break; 681 break;
679 } 682 }
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