tree-wide: unify logging of "Must be root" message
Let's unify this in one call, generalizing must_be_root() from bootctl.c.
This commit is contained in:
parent
4fe2ba0e25
commit
fba868fa71
|
@ -1053,6 +1053,15 @@ pid_t getpid_cached(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int must_be_root(void) {
|
||||||
|
|
||||||
|
if (geteuid() == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
log_error("Need to be root.");
|
||||||
|
return -EPERM;
|
||||||
|
}
|
||||||
|
|
||||||
static const char *const ioprio_class_table[] = {
|
static const char *const ioprio_class_table[] = {
|
||||||
[IOPRIO_CLASS_NONE] = "none",
|
[IOPRIO_CLASS_NONE] = "none",
|
||||||
[IOPRIO_CLASS_RT] = "realtime",
|
[IOPRIO_CLASS_RT] = "realtime",
|
||||||
|
|
|
@ -138,3 +138,5 @@ static inline bool pid_is_valid(pid_t p) {
|
||||||
int ioprio_parse_priority(const char *s, int *ret);
|
int ioprio_parse_priority(const char *s, int *ret);
|
||||||
|
|
||||||
pid_t getpid_cached(void);
|
pid_t getpid_cached(void);
|
||||||
|
|
||||||
|
int must_be_root(void);
|
||||||
|
|
|
@ -925,15 +925,6 @@ static void read_loader_efi_var(const char *name, char **var) {
|
||||||
log_warning_errno(r, "Failed to read EFI variable %s: %m", name);
|
log_warning_errno(r, "Failed to read EFI variable %s: %m", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int must_be_root(void) {
|
|
||||||
|
|
||||||
if (geteuid() == 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
log_error("Need to be root.");
|
|
||||||
return -EPERM;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int verb_status(int argc, char *argv[], void *userdata) {
|
static int verb_status(int argc, char *argv[], void *userdata) {
|
||||||
|
|
||||||
sd_id128_t uuid = SD_ID128_NULL;
|
sd_id128_t uuid = SD_ID128_NULL;
|
||||||
|
|
|
@ -3783,11 +3783,10 @@ int main(int argc, char *argv[]) {
|
||||||
if (r <= 0)
|
if (r <= 0)
|
||||||
goto finish;
|
goto finish;
|
||||||
|
|
||||||
if (geteuid() != 0) {
|
r = must_be_root();
|
||||||
log_error("Need to be root.");
|
if (r < 0)
|
||||||
r = -EPERM;
|
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
|
||||||
r = determine_names();
|
r = determine_names();
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
goto finish;
|
goto finish;
|
||||||
|
|
|
@ -2074,10 +2074,9 @@ static int list_machines(int argc, char *argv[], void *userdata) {
|
||||||
sd_bus *bus;
|
sd_bus *bus;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (geteuid() != 0) {
|
r = must_be_root();
|
||||||
log_error("Must be root.");
|
if (r < 0)
|
||||||
return -EPERM;
|
return r;
|
||||||
}
|
|
||||||
|
|
||||||
r = acquire_bus(BUS_MANAGER, &bus);
|
r = acquire_bus(BUS_MANAGER, &bus);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
|
@ -3603,9 +3602,10 @@ static int start_special(int argc, char *argv[], void *userdata) {
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
if (arg_force >= 2 && geteuid() != 0) {
|
if (arg_force >= 2) {
|
||||||
log_error("Must be root.");
|
r = must_be_root();
|
||||||
return -EPERM;
|
if (r < 0)
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = prepare_firmware_setup();
|
r = prepare_firmware_setup();
|
||||||
|
@ -8638,7 +8638,7 @@ static int halt_main(void) {
|
||||||
|
|
||||||
if (geteuid() != 0) {
|
if (geteuid() != 0) {
|
||||||
if (arg_dry_run || arg_force > 0) {
|
if (arg_dry_run || arg_force > 0) {
|
||||||
log_error("Must be root.");
|
(void) must_be_root();
|
||||||
return -EPERM;
|
return -EPERM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,10 +63,8 @@ static int adm_control(struct udev *udev, int argc, char *argv[]) {
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (getuid() != 0) {
|
if (must_be_root() < 0)
|
||||||
log_error("root privileges required");
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
|
||||||
|
|
||||||
uctrl = udev_ctrl_new(udev);
|
uctrl = udev_ctrl_new(udev);
|
||||||
if (uctrl == NULL)
|
if (uctrl == NULL)
|
||||||
|
|
|
@ -1670,10 +1670,9 @@ int main(int argc, char *argv[]) {
|
||||||
log_set_max_level(LOG_DEBUG);
|
log_set_max_level(LOG_DEBUG);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getuid() != 0) {
|
r = must_be_root();
|
||||||
r = log_error_errno(EPERM, "root privileges required");
|
if (r < 0)
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
|
||||||
|
|
||||||
if (arg_children_max == 0) {
|
if (arg_children_max == 0) {
|
||||||
cpu_set_t cpu_set;
|
cpu_set_t cpu_set;
|
||||||
|
|
Loading…
Reference in a new issue