[Bug 215769] vfork() returns EINVAL after unshare(CLONE_NEWTIME)

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

 



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

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

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

--- Comment #13 from Коренберг Марк (socketpair@xxxxxxxxx) ---
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.



[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux 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