Re: [PATCH] setsid: don't fork

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Nov 14, 2013 at 02:23:13PM -0500, Phillip Susi wrote:
> 2.24 added a switch to setsid to wait for the child to exit
> and return its exit status.  I believe this was the wrong way
> to fix the underlying bug since the behavior of the program
> still differs depending on whether it is run as the group leader
> or not, and requires a switch to get the correct behavior.

Yep, it was our goal to not change the default behaviour that exists
for years.

> Instead of this --wait switch, just make sure the parent
> process is the one that execs the new program rather than
> the child process.

>  		case 0:
>  			/* child */
> +			sleep(5);

 pause() ?

>  			break;
>  		default:
>  			/* parent */
> -			if (!status)
> -				return EXIT_SUCCESS;
> -			if (wait(&status) != pid)
> -				err(EXIT_FAILURE, "wait");
> -			if (WIFEXITED(status))
> -				return WEXITSTATUS(status);
> -			err(status, _("child %d did not exit normally"), pid);
> +			if (setpgid(pid, 0) == -1)
> +				err(EXIT_FAILURE, _("setpgid failed"));
> +			if (setpgid(0, pid) == -1)
> +				err(EXIT_FAILURE, _("setpgid failed"));
> +
>  		}
>  	}
>  	if (setsid() < 0)
>  		/* cannot happen */
>  		err(EXIT_FAILURE, _("setsid failed"));
> -
> +	if (pid)
> +		kill(pid, SIGTERM);

It does not seem too elegant :-) If you really want to change the
default behaviour than it would be better to make --wait default
and exec() in child, then you don't need setpgid(), kill() and
sleep/pause() at all.

    Karel

-- 
 Karel Zak  <kzak@xxxxxxxxxx>
 http://karelzak.blogspot.com
--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux