Skip to content

Commit 47cf8ff

Browse files
committed
manager: rework manager_clean_environment()
Let's rename it manager_sanitize_environment() which is a more precise name. Moreover, sort the environment implicitly inside it, as all our callers do that anyway afterwards and we can save some code this way. Also, update the list of env vars to drop, i.e. the env vars we manage ourselves and don't want user code to interfear with. Also sort this list to make it easier to update later on.
1 parent 24eccc3 commit 47cf8ff

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

src/core/manager.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -513,23 +513,31 @@ static int manager_setup_signals(Manager *m) {
513513
return 0;
514514
}
515515

516-
static void manager_clean_environment(Manager *m) {
516+
static void manager_sanitize_environment(Manager *m) {
517517
assert(m);
518518

519-
/* Let's remove some environment variables that we
520-
* need ourselves to communicate with our clients */
519+
/* Let's remove some environment variables that we need ourselves to communicate with our clients */
521520
strv_env_unset_many(
522521
m->environment,
523-
"NOTIFY_SOCKET",
522+
"EXIT_CODE",
523+
"EXIT_STATUS",
524+
"INVOCATION_ID",
525+
"JOURNAL_STREAM",
526+
"LISTEN_FDNAMES",
527+
"LISTEN_FDS",
528+
"LISTEN_PID",
524529
"MAINPID",
525530
"MANAGERPID",
526-
"LISTEN_PID",
527-
"LISTEN_FDS",
528-
"LISTEN_FDNAMES",
531+
"NOTIFY_SOCKET",
532+
"REMOTE_ADDR",
533+
"REMOTE_PORT",
534+
"SERVICE_RESULT",
529535
"WATCHDOG_PID",
530536
"WATCHDOG_USEC",
531-
"INVOCATION_ID",
532537
NULL);
538+
539+
/* Let's order the environment alphabetically, just to make it pretty */
540+
strv_sort(m->environment);
533541
}
534542

535543
static int manager_default_environment(Manager *m) {
@@ -556,8 +564,7 @@ static int manager_default_environment(Manager *m) {
556564
if (!m->environment)
557565
return -ENOMEM;
558566

559-
manager_clean_environment(m);
560-
strv_sort(m->environment);
567+
manager_sanitize_environment(m);
561568

562569
return 0;
563570
}
@@ -3308,8 +3315,7 @@ int manager_environment_add(Manager *m, char **minus, char **plus) {
33083315
strv_free(b);
33093316

33103317
m->environment = l;
3311-
manager_clean_environment(m);
3312-
strv_sort(m->environment);
3318+
manager_sanitize_environment(m);
33133319

33143320
return 0;
33153321
}

0 commit comments

Comments
 (0)