Reformat setuid-ing code in startup_child()

New code does the same as old one, but is more readable (I hope).

* strace.c (startup_child): Reformat setuid-ing code.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
This commit is contained in:
Denys Vlasenko 2011-09-01 10:27:42 +02:00
parent 2e968c0bb7
commit ab034fbf09

View File

@ -652,7 +652,7 @@ startup_child(char **argv)
kill(pid, SIGSTOP); kill(pid, SIGSTOP);
} }
if (username != NULL || geteuid() == 0) { if (username != NULL) {
uid_t run_euid = run_uid; uid_t run_euid = run_uid;
gid_t run_egid = run_gid; gid_t run_egid = run_gid;
@ -660,12 +660,10 @@ startup_child(char **argv)
run_euid = statbuf.st_uid; run_euid = statbuf.st_uid;
if (statbuf.st_mode & S_ISGID) if (statbuf.st_mode & S_ISGID)
run_egid = statbuf.st_gid; run_egid = statbuf.st_gid;
/* /*
* It is important to set groups before we * It is important to set groups before we
* lose privileges on setuid. * lose privileges on setuid.
*/ */
if (username != NULL) {
if (initgroups(username, run_gid) < 0) { if (initgroups(username, run_gid) < 0) {
perror_msg_and_die("initgroups"); perror_msg_and_die("initgroups");
} }
@ -676,8 +674,7 @@ startup_child(char **argv)
perror_msg_and_die("setreuid"); perror_msg_and_die("setreuid");
} }
} }
} else if (geteuid() != 0)
else
setreuid(run_uid, run_uid); setreuid(run_uid, run_uid);
if (!daemonized_tracer) { if (!daemonized_tracer) {