Commit 1be8269c authored by Radostin Stoyanov's avatar Radostin Stoyanov Committed by Andrei Vagin

Avoid unnecessary getpid() calls

getsid(0) and getpgid(0) will return session ID and PGID of
the calling process.
Signed-off-by: 's avatarRadostin Stoyanov <rstoyanov1@gmail.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@gmail.com>
parent 901f5d48
...@@ -1488,7 +1488,7 @@ static void restore_sid(void) ...@@ -1488,7 +1488,7 @@ static void restore_sid(void)
exit(1); exit(1);
} }
} else { } else {
sid = getsid(getpid()); sid = getsid(0);
if (sid != current->sid) { if (sid != current->sid) {
/* Skip the root task if it's not init */ /* Skip the root task if it's not init */
if (current == root_item && vpid(root_item) != INIT_PID) if (current == root_item && vpid(root_item) != INIT_PID)
...@@ -1593,7 +1593,7 @@ static int create_children_and_session(void) ...@@ -1593,7 +1593,7 @@ static int create_children_and_session(void)
if (!restore_before_setsid(child)) if (!restore_before_setsid(child))
continue; continue;
BUG_ON(child->born_sid != -1 && getsid(getpid()) != child->born_sid); BUG_ON(child->born_sid != -1 && getsid(0) != child->born_sid);
ret = fork_with_pid(child); ret = fork_with_pid(child);
if (ret < 0) if (ret < 0)
......
...@@ -90,7 +90,7 @@ static int fork_child(int i) ...@@ -90,7 +90,7 @@ static int fork_child(int i)
close(p[1]); close(p[1]);
wait(NULL); wait(NULL);
if (getsid(getpid()) != sid) { if (getsid(0) != sid) {
fail("The process %d (%x) has SID=%d (expected %d)", fail("The process %d (%x) has SID=%d (expected %d)",
pid, testcases[i].flags, sid, testcases[i].sid); pid, testcases[i].flags, sid, testcases[i].sid);
exit(1); exit(1);
...@@ -117,7 +117,7 @@ static int fork_child(int i) ...@@ -117,7 +117,7 @@ static int fork_child(int i)
close(p[1]); close(p[1]);
wait(NULL); wait(NULL);
if (getsid(getpid()) != sid) { if (getsid(0) != sid) {
fail("The process %d (%x) has SID=%d (expected %d)", fail("The process %d (%x) has SID=%d (expected %d)",
pid, testcases[i].flags, sid, testcases[i].sid); pid, testcases[i].flags, sid, testcases[i].sid);
exit(1); exit(1);
......
...@@ -102,14 +102,14 @@ static int child(const int c) ...@@ -102,14 +102,14 @@ static int child(const int c)
goto err; goto err;
if (t->pid == t->sid) { if (t->pid == t->sid) {
if (getpid() != getsid(getpid())) if (getpid() != getsid(0))
if (setsid() < 0) if (setsid() < 0)
goto err; goto err;
if (fork_children(t, 1)) if (fork_children(t, 1))
goto err; goto err;
} }
if (t->pid == t->pgid) { if (t->pid == t->pgid) {
if (getpid() != getpgid(getpid())) if (getpid() != getpgid(0))
if (setpgid(getpid(), getpid()) < 0) { if (setpgid(getpid(), getpid()) < 0) {
pr_perror("setpgid() failed"); pr_perror("setpgid() failed");
goto err; goto err;
...@@ -129,7 +129,7 @@ static int child(const int c) ...@@ -129,7 +129,7 @@ static int child(const int c)
break; break;
if (t->pgid != testcases[i].pid) if (t->pgid != testcases[i].pid)
continue; continue;
if (getpgid(getpid()) != testcases[i].master.pid) if (getpgid(0) != testcases[i].master.pid)
if (setpgid(getpid(), testcases[i].master.pid) < 0) { if (setpgid(getpid(), testcases[i].master.pid) < 0) {
pr_perror("setpgid() failed (%d) (%d)", c, i); pr_perror("setpgid() failed (%d) (%d)", c, i);
goto err; goto err;
...@@ -161,7 +161,7 @@ static int child(const int c) ...@@ -161,7 +161,7 @@ static int child(const int c)
/* Save the master copy */ /* Save the master copy */
t->master.ppid = getppid(); t->master.ppid = getppid();
t->master.sid = getsid(getpid()); t->master.sid = getsid(0);
futex_set_and_wake(&t->futex, c); futex_set_and_wake(&t->futex, c);
...@@ -169,8 +169,8 @@ static int child(const int c) ...@@ -169,8 +169,8 @@ static int child(const int c)
check("pid", t->master.pid, getpid()); check("pid", t->master.pid, getpid());
check("ppid", t->master.ppid, getppid()); check("ppid", t->master.ppid, getppid());
check("sid", t->master.sid, getsid(getpid())); check("sid", t->master.sid, getsid(0));
check("pgid", t->master.pgid, getpgid(getpid())); check("pgid", t->master.pgid, getpgid(0));
futex_set_and_wake(&t->futex, c); futex_set_and_wake(&t->futex, c);
......
...@@ -177,7 +177,7 @@ static void handle_command() ...@@ -177,7 +177,7 @@ static void handle_command()
} }
break; break;
case TEST_SETSID: case TEST_SETSID:
if (getsid(getpid()) == getpid()) if (getsid(0) == getpid())
break; break;
test_msg("%3d: setsid()\n", current); test_msg("%3d: setsid()\n", current);
if(setsid() == -1) { if(setsid() == -1) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment