BUG? task->nsproxy == NULL after main calls pthread_exit

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

 



After the main thread in a multi-threaded program calls pthread_exit()
while other threads are still running, attempting to open files in /proc
(like /proc/mounts) fails because get_proc_task(inode)->nsproxy == NULL
(see fs/proc/base.c::mounts_open).  I tested kernel 2.6.12 + glibc 2.3.5
and kernel 2.6.23 + glibc 2.6.1 with the same results.  Here is a
program to illustrate:

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>

static void *thread_func(void *x)
{
   for (;;)
      {
      int fd;

      fd = open("/proc/mounts", O_RDONLY);
      if (fd == -1)
         {
         perror("open /proc/mounts");
         abort();
         }
      close(fd);

      printf("/proc/mounts still accessible\n");

      sleep(1);
      }

   return NULL;
}

int main(int argc, char *argv[])
{
   pthread_t thr;
   pthread_attr_t thread_attr;

   pthread_attr_init(&thread_attr);
   pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);
   pthread_create(&thr, &thread_attr, &thread_func, NULL);
   sleep(5);
   printf("main thread calling pthread_exit...\n");
   pthread_exit(NULL);

   return 0;
}

Compile with "-D_REENTRANT -lpthread".  Output:

/proc/mounts still accessible
/proc/mounts still accessible
/proc/mounts still accessible
/proc/mounts still accessible
/proc/mounts still accessible
main thread calling pthread_exit...
open /proc/mounts: Invalid argument
Aborted

If it is valid for main() to call pthread_exit() while leaving other
threads running, then this is a bug.  If it is not valid, then this
problem can be ignored, but let me know if that is the case.  AFAIK,
everything else seems to work in this situation; problems opening files
in /proc being the only exception that I have encountered so far.

Thanks,
Tony Battersby

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux