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)
exit(1);
}
} else {
sid = getsid(getpid());
sid = getsid(0);
if (sid != current->sid) {
/* Skip the root task if it's not init */
if (current == root_item && vpid(root_item) != INIT_PID)
......@@ -1593,7 +1593,7 @@ static int create_children_and_session(void)
if (!restore_before_setsid(child))
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);
if (ret < 0)
......
......@@ -90,7 +90,7 @@ static int fork_child(int i)
close(p[1]);
wait(NULL);
if (getsid(getpid()) != sid) {
if (getsid(0) != sid) {
fail("The process %d (%x) has SID=%d (expected %d)",
pid, testcases[i].flags, sid, testcases[i].sid);
exit(1);
......@@ -117,7 +117,7 @@ static int fork_child(int i)
close(p[1]);
wait(NULL);
if (getsid(getpid()) != sid) {
if (getsid(0) != sid) {
fail("The process %d (%x) has SID=%d (expected %d)",
pid, testcases[i].flags, sid, testcases[i].sid);
exit(1);
......
......@@ -102,14 +102,14 @@ static int child(const int c)
goto err;
if (t->pid == t->sid) {
if (getpid() != getsid(getpid()))
if (getpid() != getsid(0))
if (setsid() < 0)
goto err;
if (fork_children(t, 1))
goto err;
}
if (t->pid == t->pgid) {
if (getpid() != getpgid(getpid()))
if (getpid() != getpgid(0))
if (setpgid(getpid(), getpid()) < 0) {
pr_perror("setpgid() failed");
goto err;
......@@ -129,7 +129,7 @@ static int child(const int c)
break;
if (t->pgid != testcases[i].pid)
continue;
if (getpgid(getpid()) != testcases[i].master.pid)
if (getpgid(0) != testcases[i].master.pid)
if (setpgid(getpid(), testcases[i].master.pid) < 0) {
pr_perror("setpgid() failed (%d) (%d)", c, i);
goto err;
......@@ -161,7 +161,7 @@ static int child(const int c)
/* Save the master copy */
t->master.ppid = getppid();
t->master.sid = getsid(getpid());
t->master.sid = getsid(0);
futex_set_and_wake(&t->futex, c);
......@@ -169,8 +169,8 @@ static int child(const int c)
check("pid", t->master.pid, getpid());
check("ppid", t->master.ppid, getppid());
check("sid", t->master.sid, getsid(getpid()));
check("pgid", t->master.pgid, getpgid(getpid()));
check("sid", t->master.sid, getsid(0));
check("pgid", t->master.pgid, getpgid(0));
futex_set_and_wake(&t->futex, c);
......
......@@ -177,7 +177,7 @@ static void handle_command()
}
break;
case TEST_SETSID:
if (getsid(getpid()) == getpid())
if (getsid(0) == getpid())
break;
test_msg("%3d: setsid()\n", current);
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