summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-12-29 14:18:19 +0100
committerMax Kellermann <max@duempel.org>2013-12-29 14:18:19 +0100
commit92a4bf4441b239e44067ab4f5785fec27d651b22 (patch)
tree9e9a61ff136013175cd5f73e81b9be86f913a014 /src
parent5465647c2e2ac71b932f1268a83a00b36fdada82 (diff)
parentd7f80eab68b5cb0d2aa90e67fa2bb04b1bbef975 (diff)
Merge branch 'v0.18.x'
Diffstat (limited to 'src')
-rw-r--r--src/Daemon.cxx19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/Daemon.cxx b/src/Daemon.cxx
index 6fc0f2d7c..0a4eea841 100644
--- a/src/Daemon.cxx
+++ b/src/Daemon.cxx
@@ -47,7 +47,7 @@ static char *user_name;
static uid_t user_uid = (uid_t)-1;
/** the Unix group id which MPD runs as */
-static gid_t user_gid = (pid_t)-1;
+static gid_t user_gid = (gid_t)-1;
/** the absolute path of the pidfile */
static AllocatedPath pidfile = AllocatedPath::Null();
@@ -101,18 +101,21 @@ daemonize_set_user(void)
return;
/* set gid */
- if (user_gid != (gid_t)-1 && user_gid != getgid()) {
- if (setgid(user_gid) == -1) {
- FormatFatalSystemError("Failed to set group %d",
- (int)user_gid);
- }
+ if (user_gid != (gid_t)-1 && user_gid != getgid() &&
+ setgid(user_gid) == -1) {
+ FormatFatalSystemError("Failed to set group %d",
+ (int)user_gid);
}
#ifdef _BSD_SOURCE
- /* init suplementary groups
+ /* init supplementary groups
* (must be done before we change our uid)
*/
- if (!had_group && initgroups(user_name, user_gid) == -1) {
+ if (!had_group &&
+ /* no need to set the new user's supplementary groups if
+ we are already this user */
+ user_uid != getuid() &&
+ initgroups(user_name, user_gid) == -1) {
FormatFatalSystemError("Failed to set supplementary groups "
"of user \"%s\"",
user_name);