}
static bool should_parse_proc_cmdline(void) {
- const char *e;
- pid_t p;
-
/* PID1 always reads the kernel command line. */
if (getpid_cached() == 1)
return true;
- /* If the process is directly executed by PID1 (e.g. ExecStart= or generator), systemd-importd,
- * or systemd-homed, then $SYSTEMD_EXEC_PID= is set, and read the command line. */
- e = getenv("SYSTEMD_EXEC_PID");
- if (!e)
- return false;
-
- if (streq(e, "*"))
- /* For testing. */
- return true;
-
- if (parse_pid(e, &p) < 0) {
- /* We know that systemd sets the variable correctly. Something else must have set it. */
- log_debug("Failed to parse \"$SYSTEMD_EXEC_PID=%s\". Ignoring.", e);
- return false;
- }
-
- return getpid_cached() == p;
+ /* Otherwise, parse the commandline if invoked directly by systemd. */
+ return invoked_by_systemd();
}
void log_parse_environment_variables(void) {
return strstr(last_path_component(argv[0]), token);
}
+bool invoked_by_systemd(void) {
+ int r;
+
+ /* If the process is directly executed by PID1 (e.g. ExecStart= or generator), systemd-importd,
+ * or systemd-homed, then $SYSTEMD_EXEC_PID= is set, and read the command line. */
+ const char *e = getenv("SYSTEMD_EXEC_PID");
+ if (!e)
+ return false;
+
+ if (streq(e, "*"))
+ /* For testing. */
+ return true;
+
+ pid_t p;
+ r = parse_pid(e, &p);
+ if (r < 0) {
+ /* We know that systemd sets the variable correctly. Something else must have set it. */
+ log_debug_errno(r, "Failed to parse \"SYSTEMD_EXEC_PID=%s\", ignoring: %m", e);
+ return false;
+ }
+
+ return getpid_cached() == p;
+}
+
_noreturn_ void freeze(void) {
log_close();
bool invoked_as(char *argv[], const char *token);
+bool invoked_by_systemd(void);
+
_noreturn_ void freeze(void);
bool argv_looks_like_help(int argc, char **argv);