From: Tony Battersby <tonyb@cybernetics.com>
To: linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk
Subject: BUG? task->nsproxy == NULL after main calls pthread_exit
Date: Wed, 31 Oct 2007 14:25:34 -0400 [thread overview]
Message-ID: <4728C89E.6040402@cybernetics.com> (raw)
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
reply other threads:[~2007-10-31 18:55 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=4728C89E.6040402@cybernetics.com \
--to=tonyb@cybernetics.com \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.