summaryrefslogtreecommitdiff
path: root/usr/src/cmd/svc/startd
diff options
context:
space:
mode:
authorAndy Fiddaman <omnios@citrus-it.co.uk>2021-10-29 14:25:17 +0000
committerAndy Fiddaman <omnios@citrus-it.co.uk>2021-11-23 18:12:15 +0000
commita28480febf31f0e61debac062a55216a98a05a92 (patch)
treea6f43a36f9f9e7de8d8743949815e17b7012b08f /usr/src/cmd/svc/startd
parentb0de25cb23668fa4535078d18a0618eee442c000 (diff)
downloadillumos-joyent-a28480febf31f0e61debac062a55216a98a05a92.tar.gz
14208 zoneadmd should not inherit zoneadm's environment
Reviewed by: Robert Mustacchi <rm+illumos@fingolfin.org> Reviewed by: Gergő Mihály Doma <domag02@gmail.com> Reviewed by: Toomas Soome <tsoome@me.com> Reviewed by: Jason King <jason.brian.king@gmail.com> Approved by: Dan McDonald <danmcd@joyent.com>
Diffstat (limited to 'usr/src/cmd/svc/startd')
-rw-r--r--usr/src/cmd/svc/startd/Makefile18
-rw-r--r--usr/src/cmd/svc/startd/env.c116
2 files changed, 38 insertions, 96 deletions
diff --git a/usr/src/cmd/svc/startd/Makefile b/usr/src/cmd/svc/startd/Makefile
index bfd2ad2a15..962b20dc39 100644
--- a/usr/src/cmd/svc/startd/Makefile
+++ b/usr/src/cmd/svc/startd/Makefile
@@ -23,6 +23,7 @@
# Copyright 2012 Milan Jurik. All rights reserved.
# Copyright 2016 Toomas Soome <tsoome@me.com>
# Copyright (c) 2018, Joyent, Inc.
+# Copyright 2021 OmniOS Community Edition (OmniOSce) Association.
#
PROG = svc.startd
@@ -49,10 +50,12 @@ OBJS = \
ALLOBJS = $(OBJS) \
proc.o \
+ definit.o \
manifest_hash.o
SRCS = $(OBJS:%.o=%.c) \
proc.c \
+ $(SRC)/common/definit/definit.c \
../common/manifest_hash.c
POFILES = $(OBJS:%.o=%.po) \
@@ -64,7 +67,7 @@ include ../../Makefile.ctf
$(NOT_RELEASE_BUILD)CPPFLAGS += -DDEBUG
CFLAGS += $(CCVERBOSE)
-CPPFLAGS += -I. -I../common
+CPPFLAGS += -I. -I../common -I$(SRC)/common/definit
CERRWARN += -_gcc=-Wno-parentheses
CERRWARN += -_gcc=-Wno-unused-label
@@ -82,8 +85,9 @@ proc.o := CPPFLAGS += -D_REENTRANT
$(COMPILE.c) $(OUTPUT_OPTION) $<
$(POST_PROCESS_O)
-%.ln: ../common/%.c
- $(LINT.c) $(OUTPUT_OPTION) -c $<
+%.o: $(SRC)/common/definit/%.c
+ $(COMPILE.c) $(OUTPUT_OPTION) $<
+ $(POST_PROCESS_O)
LDLIBS += \
-lcontract \
@@ -110,12 +114,6 @@ LDFLAGS += -R/lib/fm
FILEMODE = 0555
-# lint doesn't like the unused _umem_*_init()
-# And lint thinks uadmin() is undefined.
-lint_SRCS := LINTFLAGS += -U_FILE_OFFSET_BITS -xerroff=E_NAME_DEF_NOT_USED2 -u
-lint_SRCS := CPPFLAGS += \
- -I. -I../common -D_REENTRANT -D_FILE_OFFSET_BITS=64
-
.KEEP_STATE:
.PARALLEL: $(ALLOBJS)
@@ -134,6 +132,4 @@ install: all $(ROOTLIBSVCBINPROG)
clean:
$(RM) $(ALLOBJS)
-lint: lint_SRCS
-
include ../../Makefile.targ
diff --git a/usr/src/cmd/svc/startd/env.c b/usr/src/cmd/svc/startd/env.c
index 1e54124cd6..9ef61dac15 100644
--- a/usr/src/cmd/svc/startd/env.c
+++ b/usr/src/cmd/svc/startd/env.c
@@ -21,9 +21,11 @@
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
+ * Copyright 2021 OmniOS Community Edition (OmniOSce) Association.
*/
#include <assert.h>
+#include <definit.h>
#include <libuutil.h>
#include <stdio.h>
#include <stdlib.h>
@@ -42,8 +44,6 @@
#define MAXCMDL 512
#define DEF_PATH "PATH=/usr/sbin:/usr/bin"
-static char *ENVFILE = "/etc/default/init"; /* Default env. */
-
static char **glob_envp; /* Array of environment strings */
static int glob_env_n; /* Number of environment slots allocated. */
@@ -57,12 +57,9 @@ static char zonename[ZONENAME_MAX];
void
init_env()
{
- int i;
- char line[MAXCMDL];
- FILE *fp;
- int inquotes, length, wslength;
- char *tokp, *cp1, *cp2;
- char **newp;
+ void *dstate;
+ const char *tokp;
+ int i;
glob_env_n = 16;
glob_envp = startd_alloc(sizeof (*glob_envp) * glob_env_n);
@@ -70,103 +67,52 @@ init_env()
glob_envp[0] = startd_alloc((unsigned)(strlen(DEF_PATH)+2));
(void) strcpy(glob_envp[0], DEF_PATH);
- if ((fp = fopen(ENVFILE, "r")) == NULL) {
+ if (definit_open(DEFINIT_DEFAULT_FILE, &dstate) != 0) {
uu_warn("Cannot open %s. Environment not initialized.\n",
- ENVFILE);
+ DEFINIT_DEFAULT_FILE);
glob_envp[1] = NULL;
return;
}
i = 1;
+ while ((tokp = definit_token(dstate)) != NULL) {
+ size_t length = strlen(tokp);
- while (fgets(line, MAXCMDL - 1, fp) != NULL) {
/*
- * Toss newline
+ * init already started us with this umask, and we
+ * handled it in startd.c, so just skip it.
*/
- length = strlen(line);
- if (line[length - 1] == '\n')
- line[length - 1] = '\0';
-
- /*
- * Ignore blank or comment lines.
- */
- if (line[0] == '#' || line[0] == '\0' ||
- (wslength = strspn(line, " \t\n")) == strlen(line) ||
- strchr(line, '#') == line + wslength)
+ if (strncmp(tokp, "CMASK=", 6) == 0 ||
+ strncmp(tokp, "SMF_", 4) == 0) {
continue;
-
- /*
- * First make a pass through the line and change
- * any non-quoted semi-colons to blanks so they
- * will be treated as token separators below.
- */
- inquotes = 0;
- for (cp1 = line; *cp1 != '\0'; cp1++) {
- if (*cp1 == '"') {
- if (inquotes == 0)
- inquotes = 1;
- else
- inquotes = 0;
- } else if (*cp1 == ';') {
- if (inquotes == 0)
- *cp1 = ' ';
- }
}
+ glob_envp[i] = startd_alloc((unsigned)(length + 1));
+ (void) strcpy(glob_envp[i], tokp);
+
/*
- * Tokens within the line are separated by blanks
- * and tabs. For each token in the line which
- * contains a '=' we strip out any quotes and then
- * stick the token in the environment array.
+ * Double the environment size whenever it is
+ * full.
*/
- if ((tokp = strtok(line, " \t")) == NULL)
- continue;
-
- do {
- cp1 = strchr(tokp, '=');
- if (cp1 == NULL || cp1 == tokp)
- continue;
- length = strlen(tokp);
- while ((cp1 = strpbrk(tokp, "\"\'")) != NULL) {
- for (cp2 = cp1; cp2 < &tokp[length]; cp2++)
- *cp2 = *(cp2 + 1);
- length--;
- }
-
- /*
- * init already started us with this umask, and we
- * handled it in startd.c, so just skip it.
- */
- if (strncmp(tokp, "CMASK=", 6) == 0 ||
- strncmp(tokp, "SMF_", 4) == 0)
- continue;
-
- glob_envp[i] = startd_alloc((unsigned)(length + 1));
- (void) strcpy(glob_envp[i], tokp);
-
- /*
- * Double the environment size whenever it is
- * full.
- */
- if (++i == glob_env_n) {
- glob_env_n *= 2;
- newp = startd_alloc(sizeof (*glob_envp) *
- glob_env_n);
- (void) memcpy(newp, glob_envp,
- sizeof (*glob_envp) * glob_env_n / 2);
- startd_free(glob_envp,
- sizeof (*glob_envp) * glob_env_n / 2);
- glob_envp = newp;
- }
- } while ((tokp = strtok(NULL, " \t")) != NULL);
+ if (++i == glob_env_n) {
+ char **newp;
+
+ glob_env_n *= 2;
+ newp = startd_alloc(sizeof (*glob_envp) * glob_env_n);
+ (void) memcpy(newp, glob_envp,
+ sizeof (*glob_envp) * glob_env_n / 2);
+ startd_free(glob_envp,
+ sizeof (*glob_envp) * glob_env_n / 2);
+ glob_envp = newp;
+ }
}
- startd_fclose(fp);
-
/* Append a null pointer to the environment array to mark its end. */
glob_envp[i] = NULL;
+ definit_close(dstate);
+
/*
* Get the zonename once; it is used to set SMF_ZONENAME for methods.
*/