Re: [PATCH] Add setsid option to save child process id
Karel Zak <[email protected]>
| Newsgroups | org.kernel.vger.util-linux |
|---|---|
| Message-ID | <ez4oc4bocqcilq36ncfjusirdkmt6jkpfvaakrx5qcslzoqj6f@wxu57ze7zutk> |
Hi Marc,
On Sun, Jan 26, 2025 at 10:40:19AM GMT, Marc Aurèle La France wrote:
> Add an option to save the child's pid into a file.
we usually use Signed-off-by: line in the commit messages.
> @@ -105,6 +115,16 @@ int main(int argc, char **argv)
> break;
> default:
> /* parent */
> + if (pidpath) {
> + pidfile = fopen(pidpath, "w");
> + if (pidfile == NULL)
> + warn(_("cannot open pidfile %s"),
> + pidpath);
> + else {
> + fprintf(pidfile, "%d\n", pid);
> + fclose(pidfile);
> + }
> + }
> if (!status)
> return EXIT_SUCCESS;
> if (wait(&status) != pid)
What is the intended use-case for this feature?
I am unsure if this implementation is too simplistic. It seems that
the file is not deleted after the child process exits. Furthermore,
what would happen if we call multiple setsid instances with the same
pidfile? Would it be better to create the pidfile in the child process
after setsid() and ioctl(), in order to avoid creating the
pidfile in case of an error?
For reference, the code in misc-utils/uuidd.c uses a more advanced
method.
Karel
--
Karel Zak <[email protected]>
http://karelzak.blogspot.com