Merge pull request #7611 from poettering/bootspec-fixes
minor fixes to bootctl.c/bootspec.c to make sure the tool works cleanly on my system
This commit is contained in:
@@ -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[] = {
|
||||
[IOPRIO_CLASS_NONE] = "none",
|
||||
[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);
|
||||
|
||||
pid_t getpid_cached(void);
|
||||
|
||||
int must_be_root(void);
|
||||
|
||||
+7
-1
@@ -33,7 +33,7 @@ int dispatch_verb(int argc, char *argv[], const Verb verbs[], void *userdata) {
|
||||
const Verb *verb;
|
||||
const char *name;
|
||||
unsigned i;
|
||||
int left;
|
||||
int left, r;
|
||||
|
||||
assert(verbs);
|
||||
assert(verbs[0].dispatch);
|
||||
@@ -89,6 +89,12 @@ int dispatch_verb(int argc, char *argv[], const Verb verbs[], void *userdata) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (verb->flags & VERB_MUSTBEROOT) {
|
||||
r = must_be_root();
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
if (name)
|
||||
return verb->dispatch(left, argv + optind, userdata);
|
||||
else {
|
||||
|
||||
+7
-3
@@ -21,13 +21,17 @@
|
||||
***/
|
||||
|
||||
#define VERB_ANY ((unsigned) -1)
|
||||
#define VERB_DEFAULT 1U
|
||||
#define VERB_NOCHROOT 2U
|
||||
|
||||
typedef enum VerbFlags {
|
||||
VERB_DEFAULT = 1 << 0,
|
||||
VERB_NOCHROOT = 1 << 1,
|
||||
VERB_MUSTBEROOT = 1 << 2,
|
||||
} VerbFlags;
|
||||
|
||||
typedef struct {
|
||||
const char *verb;
|
||||
unsigned min_args, max_args;
|
||||
unsigned flags;
|
||||
VerbFlags flags;
|
||||
int (* const dispatch)(int argc, char *argv[], void *userdata);
|
||||
} Verb;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user