aboutsummaryrefslogtreecommitdiff
path: root/src/sysvinit.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2016-02-25 16:17:36 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2016-02-25 16:17:36 +0200
commitc9abb69acae95a0136ee1b03dec8b08d9639005e (patch)
treefa5849647e6d9430289a71035630475a82f4cf54 /src/sysvinit.c
parent1ec50721c1aa5959009f0c74afc8b7796f4ffd20 (diff)
downloadpies-c9abb69acae95a0136ee1b03dec8b08d9639005e.tar.gz
pies-c9abb69acae95a0136ee1b03dec8b08d9639005e.tar.bz2
Implement "telinit environ" ctl command
* src/ctl.c: New endpoint "environ" * src/pies.h (sysvinit_envlocate) (sysvinit_envdelete) (sysvinit_envupdate): New protos. * src/piesctl.c: New subcommand "telinit environ". * src/sysvinit.c (sysvinit_envlocate) (sysvinit_envdelete) (sysvinit_envupdate): New functions. (sysvinit_begin): Create allocated copies of instance and pies_master_argv to avoid them being rewritten by calls to mf_proctitle_format
Diffstat (limited to 'src/sysvinit.c')
-rw-r--r--src/sysvinit.c90
1 files changed, 66 insertions, 24 deletions
diff --git a/src/sysvinit.c b/src/sysvinit.c
index 0b12b4a..695dc5c 100644
--- a/src/sysvinit.c
+++ b/src/sysvinit.c
@@ -389,12 +389,61 @@ envsetup (void)
}
}
}
+
+int
+sysvinit_envlocate (char const *name, char **value)
+{
+ int i, j;
+ char *var;
+
+ for (i = 0; (var = sysvinit_environ_hint[i]); i++)
+ {
+ for (j = 0; var[j] && name[j] == var[j]; j++)
+ ;
+ if (!name[j] && var[j] == '=')
+ {
+ if (value)
+ *value = var + j + 1;
+ return i;
+ }
+ }
+ return -1;
+}
+
+int
+sysvinit_envupdate (char const *var)
+{
+ int i, j;
+ size_t len;
+
+ len = strcspn (var, "=");
+ for (i = 0; i < NR_ENVHINT; i++)
+ {
+ char *s = sysvinit_environ_hint[i];
+ if (s)
+ {
+ for (j = 0; *s && j < len; j++, s++)
+ if (var[j] != *s) break;
+ if (*s != '=' || j != len)
+ continue;
+ if (i < ENVI_AVAIL)
+ return 1;
+ free (sysvinit_environ_hint[i]);
+ }
+
+ if (var[len] == '=')
+ sysvinit_environ_hint[i] = grecs_strdup (var);
+ else
+ while ((sysvinit_environ_hint[i] = sysvinit_environ_hint[i+1]))
+ ++i;
+ return 0;
+ }
+ return -1;
+}
static void
sysvinit_setenv (char const *data, int size)
{
- int i, j;
-
while (size)
{
char const *var = data;
@@ -403,28 +452,7 @@ sysvinit_setenv (char const *data, int size)
if (size < 0)
break;
data += len;
- if (strncmp (var, "INIT_", 5) != 0)
- continue;
- len = strcspn (var, "=");
- for (i = ENVI_AVAIL; i < NR_ENVHINT; i++)
- {
- char *s = sysvinit_environ_hint[i];
- if (s)
- {
- for (j = 0; *s && j < len; j++, s++)
- if (var[j] != *s) break;
- if (*s != '=' || j != len)
- continue;
- free (sysvinit_environ_hint[i]);
- }
-
- if (var[len] == '=')
- sysvinit_environ_hint[i] = grecs_strdup (var);
- else
- for (j = i + 1; j < NR_ENVHINT; j++, i++)
- sysvinit_environ_hint[i] = sysvinit_environ_hint[j];
- break;
- }
+ sysvinit_envupdate (var);
}
}
@@ -735,6 +763,19 @@ sysvinit_realloc (void *ptr, size_t size)
return p;
}
+static void
+save_argv (void)
+{
+ int i;
+ char **av;
+ instance = grecs_strdup (instance);
+ av = grecs_calloc (pies_master_argc + 1, sizeof (av[0]));
+ for (i = 0; i < pies_master_argc; i++)
+ av[i] = grecs_strdup (pies_master_argv[i]);
+ av[i] = NULL;
+ pies_master_argv = av;
+}
+
void
sysvinit_begin (void)
{
@@ -757,6 +798,7 @@ sysvinit_begin (void)
sysvinit_runlevel_setup (PIES_COMP_DEFAULT);
add_extra_sigv (sigv, ARRAY_SIZE (sigv));
sysvinit_sysdep_begin ();
+ save_argv ();
if (emergency)
start_shell (emergency_shell);
}

Return to:

Send suggestions and report system problems to the System administrator.