summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorKylie McClain <kylie@somas.is>2020-09-24 13:24:41 -0400
committerKylie McClain <kylie@somas.is>2020-09-24 21:06:24 -0400
commitf8761c1626848fb98c72d55d19d391b99122778f (patch)
treef2ab7bf3ed09a4dcf8444e4f6d955fc658c5c7a5
parent0d040c32c8947f002d2b2db6fd3b55098e79ba87 (diff)
downloadcatsit-f8761c1626848fb98c72d55d19d391b99122778f.tar.gz
catsit-f8761c1626848fb98c72d55d19d391b99122778f.tar.xz
catsit-f8761c1626848fb98c72d55d19d391b99122778f.zip
Add option for allowing services to inherit the environment
-rw-r--r--catsitd.812
-rw-r--r--daemon.c3
-rw-r--r--daemon.h2
-rw-r--r--service.c19
4 files changed, 28 insertions, 8 deletions
diff --git a/catsitd.8 b/catsitd.8
index 9c5721e..fd4345e 100644
--- a/catsitd.8
+++ b/catsitd.8
@@ -8,7 +8,7 @@
.
.Sh SYNOPSIS
.Nm
-.Op Fl d
+.Op Fl Ed
.Op Fl C Ar path
.Op Fl c Ar control
.Op Fl f Ar config
@@ -101,6 +101,12 @@ If
is set,
the default group is the user's group.
.
+.It Fl i
+For each service, inherit the environment of
+.Nm
+.Ap s parent instead of resetting it (see
+.Sx ENVIRONMENT ) .
+.
.It Fl p Ar pidfile
Write the PID of the
.Nm
@@ -181,7 +187,9 @@ The current status of all services is logged.
.El
.
.Sh ENVIRONMENT
-Services are started
+Unless started with
+.Fl i ,
+services are started
with empty environments
apart from the following:
.Bl -tag -width Ds
diff --git a/daemon.c b/daemon.c
index 3ec244b..5ae9e7a 100644
--- a/daemon.c
+++ b/daemon.c
@@ -209,9 +209,10 @@ int main(int argc, char *argv[]) {
const char *userName = NULL;
const char *groupName = NULL;
- for (int opt; 0 < (opt = getopt(argc, argv, "C:c:df:g:p:r:s:t:u:"));) {
+ for (int opt; 0 < (opt = getopt(argc, argv, "C:Ec:df:g:ip:r:s:t:u:"));) {
switch (opt) {
break; case 'C': serviceDir = optarg;
+ break; case 'E': inheritEnvironment = true;
break; case 'c': fifoPath = optarg;
break; case 'd': daemonize = false;
break; case 'f': configPath = optarg;
diff --git a/daemon.h b/daemon.h
index eb26f48..671c625 100644
--- a/daemon.h
+++ b/daemon.h
@@ -155,3 +155,5 @@ static inline uint32_t setTest(const struct Set256 *set, byte x) {
extern struct Set256 stopExits;
extern struct timespec restartInterval;
extern struct timespec resetInterval;
+
+extern bool inheritEnvironment;
diff --git a/service.c b/service.c
index fea23ef..c20e5be 100644
--- a/service.c
+++ b/service.c
@@ -48,6 +48,8 @@ char *serviceEnviron[EnvironLen] = {
[PATH] = "PATH=" _PATH_DEFPATH,
};
+bool inheritEnvironment = false;
+
struct Prepend prepend;
struct Services services;
@@ -247,11 +249,18 @@ void serviceStart(struct Service *service) {
len += n;
if (len >= sizeof(command)) errx(ExitNoExec, "command truncated");
- execle(
- _PATH_BSHELL,
- _PATH_BSHELL, "-c", command, service->name, NULL,
- serviceEnviron
- );
+ if (inheritEnvironment) {
+ execl(
+ _PATH_BSHELL,
+ _PATH_BSHELL, "-c", command, service->name, NULL
+ );
+ } else {
+ execle(
+ _PATH_BSHELL,
+ _PATH_BSHELL, "-c", command, service->name, NULL,
+ serviceEnviron
+ );
+ }
err(ExitNoExec, "%s", _PATH_BSHELL);
}