It's better for users if programs don't do "significant" things too easily, and
should be especially conservative when called without any arguments whatsoever.
So far systemd would would try to launch itself as a user manager and fail on
some cgroup permission stuff. systemd --user is run execlusively from user@.service
and there we call it with --user. Calls to the binary without any arguments as
non-pid1 are almost always a mistake.
https://github.com/systemd/systemd/issues/18419#issuecomment-
779422571
};
int c, r;
+ bool user_arg_seen = false;
assert(argc >= 1);
assert(argv);
case ARG_USER:
arg_system = false;
+ user_arg_seen = true;
break;
case ARG_TEST:
}
if (optind < argc && getpid_cached() != 1)
- /* Hmm, when we aren't run as init system
- * let's complain about excess arguments */
+ /* Hmm, when we aren't run as init system let's complain about excess arguments */
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Excess arguments.");
+
+ if (arg_action == ACTION_RUN && !arg_system && !user_arg_seen)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
- "Excess arguments.");
+ "Explicit --user argument required to run as user manager.");
return 0;
}