summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2017-12-12 22:16:34 +0100
committerGitHub <noreply@github.com>2017-12-12 22:16:34 +0100
commit4432ac91ee699ef70ae56ef60868ec7ef4ff83ac (patch)
treef89f67c8df7c5620a954caeb5607c1f8810fec1f /src/basic
parentbbaa8055acea0b5fe6816a21a7c1e2a43fcc7bee (diff)
parent0c63eb7138306c988a12e5366ba291700db7b03f (diff)
downloadsystemd-4432ac91ee699ef70ae56ef60868ec7ef4ff83ac.tar.gz
systemd-4432ac91ee699ef70ae56ef60868ec7ef4ff83ac.tar.bz2
systemd-4432ac91ee699ef70ae56ef60868ec7ef4ff83ac.zip
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
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/process-util.c9
-rw-r--r--src/basic/process-util.h2
-rw-r--r--src/basic/verbs.c8
-rw-r--r--src/basic/verbs.h10
4 files changed, 25 insertions, 4 deletions
diff --git a/src/basic/process-util.c b/src/basic/process-util.c
index b3d96cdb0f..5f001494f0 100644
--- a/src/basic/process-util.c
+++ b/src/basic/process-util.c
@@ -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",
diff --git a/src/basic/process-util.h b/src/basic/process-util.h
index d99fb3d6b8..39c194df0d 100644
--- a/src/basic/process-util.h
+++ b/src/basic/process-util.h
@@ -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);
diff --git a/src/basic/verbs.c b/src/basic/verbs.c
index cc1bd7e323..cb42e6dd08 100644
--- a/src/basic/verbs.c
+++ b/src/basic/verbs.c
@@ -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 {
diff --git a/src/basic/verbs.h b/src/basic/verbs.h
index ed62f4d07b..5f44a18f8e 100644
--- a/src/basic/verbs.h
+++ b/src/basic/verbs.h
@@ -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;