public inbox for linux-man@vger.kernel.org
 help / color / mirror / Atom feed
From: bugzilla-daemon@kernel.org
To: linux-man@vger.kernel.org
Subject: [Bug 215769] vfork() returns EINVAL after unshare(CLONE_NEWTIME)
Date: Fri, 08 Apr 2022 11:36:20 +0000	[thread overview]
Message-ID: <bug-215769-11311-eOiTVTU2er@https.bugzilla.kernel.org/> (raw)
In-Reply-To: <bug-215769-11311@https.bugzilla.kernel.org/>

https://bugzilla.kernel.org/show_bug.cgi?id=215769

Коренберг Марк (socketpair@gmail.com) changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|man-pages                   |Other
            Version|unspecified                 |2.5
            Product|Documentation               |Other

--- Comment #13 from Коренберг Марк (socketpair@gmail.com) ---
Please help me to change Bugzilla fields in the issue. This is a kernel bug as
I think. Nothing should be changed in documentation.


And also, please stop discussing how to correctly use vfork() (regarding
modifying stack, glibc and so on). This issue is actually about vfork() +
CLONE_NEWTIME.

Regarding CLONE_VM. We have no problems for, say, PID namespace. Suppose we
have parent process with two threads. Let's second thread calls vfork() and is
stopped as expected. So children process is running and the first thread of
parent process too. They share VM, but getpid() will give different values in
them, right ?

If YES, I don't see any stoppers for doing the same for CLONE_NEWTIME.
If NO, this is a bug.

Actually, yes:

#define _GNU_SOURCE 1
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <syscall.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <err.h>
#include <pthread.h>

static void *showpid (void *restrict arg)
{
  (void) arg;
  for (int i = 0; i < 25; i++)
  {
    printf ("thr pid=%lu\n", (unsigned long) syscall (SYS_getpid));
    struct timespec ts = { 0, 100000000 };<---->// 0.1 sec
    nanosleep (&ts, NULL);
  }
  return NULL;
}

int main (void)
{
  pthread_t thr;
  if (pthread_create (&thr, NULL, showpid, NULL))
    abort ();

  if (unshare (CLONE_NEWPID) == -1)
    err (EXIT_FAILURE, "unshare(newpid)");

  sleep (1);<--><------><------>// allow the thread to work for 1 second

  pid_t p = vfork ();
  if (!p)
  {
    static char qwe[100];
    static struct timespec ts = { 1, 0 };
    syscall (SYS_write, 1, qwe, sprintf (qwe, "child: %lu\n", (unsigned long)
syscall (SYS_getpid)));
    syscall (SYS_clock_nanosleep, CLOCK_MONOTONIC, 0, &ts, NULL);
    syscall (SYS_write, 1, qwe, sprintf (qwe, "child sleep complete\n"));
    _exit (0);
  }
  if (p == -1)
    err (EXIT_FAILURE, "vfork");

  printf("Waiting for child\n");
  waitpid (p, NULL, 0);
  pthread_join (thr, NULL);
}

$ sudo ./a.out 
thr pid=46371
thr pid=46371
thr pid=46371
thr pid=46371
thr pid=46371
thr pid=46371
thr pid=46371
thr pid=46371
thr pid=46371
thr pid=46371
child: 1
thr pid=46371
thr pid=46371
thr pid=46371
thr pid=46371
thr pid=46371
thr pid=46371
thr pid=46371
thr pid=46371
thr pid=46371
thr pid=46371
child sleep complete
Waiting for child
thr pid=46371
thr pid=46371
thr pid=46371
thr pid=46371
thr pid=46371

-- 
You may reply to this email to add a comment.

You are receiving this mail because:
You are watching the assignee of the bug.

  parent reply	other threads:[~2022-04-08 11:36 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-29 11:02 [Bug 215769] New: man 2 vfork() does not document corner case when PID == 1 bugzilla-daemon
2022-03-30  0:48 ` [Bug 215769] " bugzilla-daemon
2022-03-30  1:00 ` bugzilla-daemon
2022-03-31  7:53 ` bugzilla-daemon
2022-03-31  8:12 ` bugzilla-daemon
2022-04-02 21:15 ` bugzilla-daemon
2022-04-04  8:05 ` bugzilla-daemon
2022-04-05 11:37 ` bugzilla-daemon
2022-04-05 19:27 ` bugzilla-daemon
2022-04-06  5:44 ` bugzilla-daemon
2022-04-06  8:46 ` bugzilla-daemon
2022-04-06 17:13 ` bugzilla-daemon
2022-04-06 19:22 ` bugzilla-daemon
2022-04-08 10:55 ` [Bug 215769] vfork() returns EINVAL after unshare(CLONE_NEWTIME) bugzilla-daemon
2022-04-08 11:36 ` bugzilla-daemon [this message]
2022-04-11 15:36 ` bugzilla-daemon
2022-05-09 10:23 ` bugzilla-daemon
2022-09-06  8:32 ` bugzilla-daemon
2022-10-08  0:25 ` bugzilla-daemon
2022-10-08 18:52 ` bugzilla-daemon

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=bug-215769-11311-eOiTVTU2er@https.bugzilla.kernel.org/ \
    --to=bugzilla-daemon@kernel.org \
    --cc=linux-man@vger.kernel.org \
    /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