summaryrefslogtreecommitdiffstats
path: root/src/fastd.c
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2015-01-14 22:29:30 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2015-01-14 22:29:30 +0100
commit6b9c59efc9db4aa710d7c243d566973006020d42 (patch)
treef8da5b18b935f603b72eb37898f57a9df19369e1 /src/fastd.c
parentba3afc50b3819694f009adc6db5a966f524242f6 (diff)
downloadfastd-6b9c59efc9db4aa710d7c243d566973006020d42.tar
fastd-6b9c59efc9db4aa710d7c243d566973006020d42.zip
Refactor handling of platforms without user/group settings (Android)
Diffstat (limited to 'src/fastd.c')
-rw-r--r--src/fastd.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/fastd.c b/src/fastd.c
index 5a71b6a..f05b43e 100644
--- a/src/fastd.c
+++ b/src/fastd.c
@@ -256,6 +256,8 @@ static inline void write_pid(void) {
return;
}
#endif
+
+#ifdef USE_USER
uid_t uid = geteuid();
gid_t gid = getegid();
@@ -265,28 +267,32 @@ static inline void write_pid(void) {
if (seteuid(conf.uid) < 0)
pr_debug_errno("seteuid");
}
+#endif
FILE *f = fopen(conf.pid_file, "w");
- if (f == NULL) {
- pr_error_errno("can't write PID file: fopen");
- goto end;
- }
+ if (f) {
+ if (fprintf(f, "%u", (unsigned)getpid()) < 0)
+ pr_error_errno("can't write PID file: fprintf");
- if (fprintf(f, "%u", (unsigned)getpid()) < 0)
- pr_error_errno("can't write PID file: fprintf");
+ if (fclose(f) < 0)
+ pr_warn_errno("fclose");
- if (fclose(f) < 0)
- pr_warn_errno("fclose");
+ }
+ else {
+ pr_error_errno("can't write PID file: fopen");
+ }
- end:
+#ifdef USE_USER
if (seteuid(uid) < 0)
pr_debug_errno("seteuid");
if (setegid(gid) < 0)
pr_debug_errno("setegid");
+#endif
}
/** Switches to the configured user */
static void set_user(void) {
+#ifdef USE_USER
if (conf.user || conf.group) {
if (setgid(conf.gid) < 0)
exit_errno("setgid");
@@ -296,10 +302,12 @@ static void set_user(void) {
pr_info("changed to UID %i, GID %i", (int)conf.uid, (int)conf.gid);
}
+#endif
}
/** Sets the configured user's supplementary groups */
static void set_groups(void) {
+#ifdef USE_USER
if (conf.groups) {
if (setgroups(conf.n_groups, conf.groups) < 0) {
if (errno != EPERM)
@@ -312,6 +320,7 @@ static void set_groups(void) {
pr_debug_errno("setgroups");
}
}
+#endif
}
/** Switches the user and drops all capabilities */