summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2006-07-20 13:24:04 +0000
committerPierre Ossman <ossman@cendio.se>2006-07-20 13:24:04 +0000
commitf3d49244731498c009b5c1991cb7242a8e9914ae (patch)
tree3f553318dc0c91533eadeda80a16b572e96b6bc3
parent57d8a315ea3c3e4e19e19fe1d293ca941d6229d5 (diff)
Centralise check if we're running as root.
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1120 fefdeb5f-60dc-0310-8127-8f9354f1896f
-rw-r--r--src/daemon/main.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/daemon/main.c b/src/daemon/main.c
index 3f489981..14c16ab2 100644
--- a/src/daemon/main.c
+++ b/src/daemon/main.c
@@ -314,7 +314,7 @@ int main(int argc, char *argv[]) {
char *s;
int r, retval = 1, d = 0;
int daemon_pipe[2] = { -1, -1 };
- int suid_root;
+ int suid_root, real_root;
int valid_pid_file = 0;
#ifdef HAVE_GETUID
@@ -331,13 +331,15 @@ int main(int argc, char *argv[]) {
pa_limit_caps();
#ifdef HAVE_GETUID
- suid_root = getuid() != 0 && geteuid() == 0;
+ real_root = getuid() == 0;
+ suid_root = !real_root && geteuid() == 0;
if (suid_root && (pa_own_uid_in_group(PA_REALTIME_GROUP, &gid) <= 0 || gid >= 1000)) {
pa_log_warn(__FILE__": WARNING: called SUID root, but not in group '"PA_REALTIME_GROUP"'.");
pa_drop_root();
}
#else
+ real_root = 0;
suid_root = 0;
#endif
@@ -434,10 +436,10 @@ int main(int argc, char *argv[]) {
assert(conf->cmd == PA_CMD_DAEMON);
}
- if (getuid() == 0 && !conf->system_instance) {
+ if (real_root && !conf->system_instance) {
pa_log(__FILE__": This program is not intended to be run as root (unless --system is specified).");
goto finish;
- } else if (getuid() != 0 && conf->system_instance) {
+ } else if (!real_root && conf->system_instance) {
pa_log(__FILE__": Root priviliges required.");
goto finish;
}