public inbox for linux-man@vger.kernel.org
 help / color / mirror / Atom feed
From: Alejandro Colomar <alx@kernel.org>
To: Sargun Dhillon <sargun@sargun.me>
Cc: linux-man@vger.kernel.org
Subject: Re: [PATCH] clone.2: Fix the erroneous statement about CLONE_NEWPID
Date: Sat, 12 Aug 2023 19:51:43 +0200	[thread overview]
Message-ID: <923b82cd-9bfe-44bd-1d8b-26fa35799d64@kernel.org> (raw)
In-Reply-To: <69c6a263-3578-2d1e-23c0-6a8e9c35602f@kernel.org>


[-- Attachment #1.1: Type: text/plain, Size: 3266 bytes --]

On 2023-08-12 19:48, Alejandro Colomar wrote:
> Hello Sargun,
> 
> On 2023-08-10 04:26, Sargun Dhillon wrote:
>> It appears like the documentation is based on out of date information in
>> regards to using CLONE_NEWPID and CLONE_PARENT together.
>>
>> For example, in this test program, one can see that it works:
>>
>> static pid_t sys_clone3(struct clone_args *args)
>> {
>> 	fflush(stdout);
>> 	fflush(stderr);
>> 	return syscall(__NR_clone3, args, sizeof(*args));
>> }
>>
>> int main() {
>> 	struct clone_args args = {
>> 		.flags = CLONE_PARENT | CLONE_NEWPID,
>> 	};
>> 	int ret;
>>
>> 	printf("The main program is running with pid: %d, and ppid: %d\n", getpid(), getppid());
>> 	ret = sys_clone3(&args);
>> 	assert(ret != -1);
>> 	if (ret == 0) {
>> 		printf("This is the child, running with pid: %d, and ppid: %d\n", getpid(), getppid());
>> 		_exit(0);
> 
> Do we really need _exit(3)?  Why not exit(3)?  There are no atexit(3)
> or on_exit(3) handlers registered, so the only difference I expect is
> the flushing of stdio(3) streams, which _exit(3) doesn't perform but
> exit(3) does.  So exit(3) seems more appropriate, isn't it?
> 
>> 	}
>>
>> 	return 0;
>> }
> 
> Thanks for the example program!  It helps a lot with the review.  :)
> 
>>
>> This test program (successfully) outputs:
>> The main program is running with pid: 648411, and ppid: 648397
>> This is the child, running with pid: 1, and ppid: 0

Does this depend on any recent kernel version?  In my system,
the assertion fails.


$ cat clone.c 
#include <assert.h>
#include <linux/sched.h>
#include <sched.h>
#include <stdio.h>
#include <sys/syscall.h>
#include <unistd.h>

static pid_t
sys_clone3(struct clone_args *args)
{
	fflush(stdout);
	fflush(stderr);
	return syscall(SYS_clone3, args, sizeof(*args));
}

int
main(void)
{
	int                ret;
	struct clone_args  args = { .flags = CLONE_PARENT | CLONE_NEWPID, };

	printf("main program:  pid: %d, and ppid: %d\n", getpid(), getppid());
	ret = sys_clone3(&args);
	assert(ret != -1);
	if (ret == 0) {
		printf("This is the child, running with pid: %d, and ppid: %d\n", getpid(), getppid());
		_exit(0);
	}

	return 0;
}

$ cc -Wall -Wextra clone.c 
$ ./a.out 
main program:  pid: 18783, and ppid: 18703
a.out: clone.c:24: main: Assertion `ret != -1' failed.
Aborted


>>
>> Signed-off-by: Sargun Dhillon <sargun@sargun.me>
>> ---
>>  man2/clone.2 | 4 +---
>>  1 file changed, 1 insertion(+), 3 deletions(-)
>>
>> diff --git a/man2/clone.2 b/man2/clone.2
>> index 4c5b4ac6b..96ad24b95 100644
>> --- a/man2/clone.2
>> +++ b/man2/clone.2
>> @@ -736,9 +736,7 @@ Only a privileged process
>>  can employ
>>  .BR CLONE_NEWPID .
>>  This flag can't be specified in conjunction with
>> -.B CLONE_THREAD
>> -or
>> -.BR CLONE_PARENT .
>> +.B CLONE_THREAD.
> 
> You'll need BR here, and the space before the period; otherwise,
> the period will be in bold, which we don't want (as it's not part
> of the identifier).
> 
> Thanks,
> Alex
> 
>>  .TP
>>  .B CLONE_NEWUSER
>>  (This flag first became meaningful for
> 

-- 
<http://www.alejandro-colomar.es/>
GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2023-08-12 17:51 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-10  2:26 [PATCH] clone.2: Fix the erroneous statement about CLONE_NEWPID Sargun Dhillon
2023-08-12 17:48 ` Alejandro Colomar
2023-08-12 17:51   ` Alejandro Colomar [this message]
2023-08-12 19:05     ` John Watts
2023-08-13  0:57       ` Sargun Dhillon
2023-08-13 13:17         ` [PATCH v2] clone.2: Fix outdated " Alejandro Colomar
2023-08-13 13:35           ` Serge E. Hallyn
2023-08-13 13:40             ` Alejandro Colomar
2023-08-13 13:53               ` Serge E. Hallyn
2023-08-13 13:55 ` [PATCH v3] clone.2: Fix erroneous statement about CLONE_NEWPID|CLONE_PARENT Alejandro Colomar
2023-08-13 14:03   ` Alejandro Colomar
2023-08-13 14:36   ` Serge E. Hallyn
2023-08-13 14:37     ` Alejandro Colomar
2023-08-13 14:40       ` Alejandro Colomar
2023-08-13 14:14 ` [PATCH v4] " Alejandro Colomar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=923b82cd-9bfe-44bd-1d8b-26fa35799d64@kernel.org \
    --to=alx@kernel.org \
    --cc=linux-man@vger.kernel.org \
    --cc=sargun@sargun.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox