pstree: Avoid double getpid() call

Submitted by Radostin Stoyanov on Oct. 28, 2018, 11:06 a.m.

Details

Message ID 20181028110601.7493-1-rstoyanov1@gmail.com
State New
Series "pstree: Avoid double getpid() call"
Headers show

Commit Message

Radostin Stoyanov Oct. 28, 2018, 11:06 a.m.
Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
---
 criu/pstree.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/pstree.c b/criu/pstree.c
index 928fe2d1..ba9ff993 100644
--- a/criu/pstree.c
+++ b/criu/pstree.c
@@ -335,8 +335,9 @@  err:
 
 static int prepare_pstree_for_shell_job(void)
 {
-	pid_t current_sid = getsid(getpid());
-	pid_t current_gid = getpgid(getpid());
+	pid_t current_pid = getpid();
+	pid_t current_sid = getsid(current_pid);
+	pid_t current_gid = getpgid(current_pid);
 
 	struct pstree_item *pi;
 

Comments

Dmitry Safonov Oct. 28, 2018, 7:26 p.m.
On 10/28/18 11:06 AM, Radostin Stoyanov wrote:
> Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
> ---
>   criu/pstree.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/criu/pstree.c b/criu/pstree.c
> index 928fe2d1..ba9ff993 100644
> --- a/criu/pstree.c
> +++ b/criu/pstree.c
> @@ -335,8 +335,9 @@ err:
>   
>   static int prepare_pstree_for_shell_job(void)
>   {
> -	pid_t current_sid = getsid(getpid());
> -	pid_t current_gid = getpgid(getpid());
> +	pid_t current_pid = getpid();
> +	pid_t current_sid = getsid(current_pid);
> +	pid_t current_gid = getpgid(current_pid);

I like it. Can you add pid_t as a parameter and eliminate another call 
in prepare_pstree_ids()?
Radostin Stoyanov Oct. 28, 2018, 8:42 p.m.
On 28/10/2018 19:26, Dmitry Safonov wrote:
> On 10/28/18 11:06 AM, Radostin Stoyanov wrote:
>> Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
>> ---
>>   criu/pstree.c | 5 +++--
>>   1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/criu/pstree.c b/criu/pstree.c
>> index 928fe2d1..ba9ff993 100644
>> --- a/criu/pstree.c
>> +++ b/criu/pstree.c
>> @@ -335,8 +335,9 @@ err:
>>     static int prepare_pstree_for_shell_job(void)
>>   {
>> -    pid_t current_sid = getsid(getpid());
>> -    pid_t current_gid = getpgid(getpid());
>> +    pid_t current_pid = getpid();
>> +    pid_t current_sid = getsid(current_pid);
>> +    pid_t current_gid = getpgid(current_pid);
>
> I like it. Can you add pid_t as a parameter and eliminate another call
> in prepare_pstree_ids()?
>
Thanks Dima, I will resend the patch.

Radostin