Bug 6312 - core_uses_pid=0 not always honored
Summary: core_uses_pid=0 not always honored
Status: REJECTED WILL_NOT_FIX
Alias: None
Product: Other
Classification: Unclassified
Component: Other (show other bugs)
Hardware: i386 Linux
: P2 normal
Assignee: other_other
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-03-30 15:10 UTC by David M. Lee
Modified: 2007-01-31 01:03 UTC (History)
1 user (show)

See Also:
Kernel Version: 2.6.15.2
Subsystem:
Regression: ---
Bisected commit-id:


Attachments
Suggested fix (1.67 KB, patch)
2006-03-30 15:13 UTC, David M. Lee
Details | Diff

Description David M. Lee 2006-03-30 15:10:07 UTC
Distribution:
Vanilla kernel

Hardware Environment:
x86_64

Software Environment:
?

Problem Description:
If an application is multi-threaded, the linux kernel will append the pid 
number to the core file, even if echo 0 > /proc/sys/kernel/core_uses_pid.

From looking at fs/exec.c, this looks intentional.

Steps to reproduce:
Set core_uses_pid to 0 and core_pattern to core.  Compile the following 
program (stolen from Bug 5826).  kill -SEGV it.  The core file will have the 
pid number appended to it.

For those who like to copy/paste:

cat <<EOF > threader.c
 #include <pthread.h>
 static void* thread_sleep(void* x) { while (1) sleep(30); }
 int main(int c, char** v) {
     const static int tcount = 5;
     pthread_t thr[tcount];
     int i;
     for (i=0; i<tcount; ++i)
         pthread_create(&thr[i], NULL, thread_sleep, NULL);
     while (1)
         sleep(30);
     return 0;
 }
EOF

gcc threader.c -o threader -l pthread
echo 0 > /proc/sys/kernel/core_uses_pid
echo core > /proc/sys/kernel/core_pattern
ulimit -c 5000
./threader &
sleep 1
rm -f core*
kill -SEGV %1
ls core*
Comment 1 David M. Lee 2006-03-30 15:13:37 UTC
Created attachment 7726 [details]
Suggested fix

The easiest fix would be to remove the phrase
'atomic_read(&current->mm->mm_users) != 1'; then the kernel will behave as it
is documented.

If this is undesireable, then the attached patch could also work.  This adds
'%q' as a core-pattern option, which simulates pid_in_pattern.	The patch
updates the documentation as well.
Comment 2 Andrew Morton 2006-03-30 15:26:23 UTC
bugme-daemon@bugzilla.kernel.org wrote:
>
> http://bugzilla.kernel.org/show_bug.cgi?id=6312
> 
>            Summary: core_uses_pid=0 not always honored
>     Kernel Version: 2.6.15.2
>             Status: NEW
>           Severity: normal
>              Owner: other_other@kernel-bugs.osdl.org
>          Submitter: dmlee@crossroads.com
> 
> 
> Distribution:
> Vanilla kernel
> 
> Hardware Environment:
> x86_64
> 
> Software Environment:
> ?
> 
> Problem Description:
> If an application is multi-threaded, the linux kernel will append the pid 
> number to the core file, even if echo 0 > /proc/sys/kernel/core_uses_pid.
> 
> >From looking at fs/exec.c, this looks intentional.
> 
> Steps to reproduce:
> Set core_uses_pid to 0 and core_pattern to core.  Compile the following 
> program (stolen from Bug 5826).  kill -SEGV it.  The core file will have the 
> pid number appended to it.
> 
> For those who like to copy/paste:
> 
> cat <<EOF > threader.c
>  #include <pthread.h>
>  static void* thread_sleep(void* x) { while (1) sleep(30); }
>  int main(int c, char** v) {
>      const static int tcount = 5;
>      pthread_t thr[tcount];
>      int i;
>      for (i=0; i<tcount; ++i)
>          pthread_create(&thr[i], NULL, thread_sleep, NULL);
>      while (1)
>          sleep(30);
>      return 0;
>  }
> EOF
> 
> gcc threader.c -o threader -l pthread
> echo 0 > /proc/sys/kernel/core_uses_pid
> echo core > /proc/sys/kernel/core_pattern
> ulimit -c 5000
> ./threader &
> sleep 1
> rm -f core*
> kill -SEGV %1
> ls core*
> 

Alan, was this intentional?

Thanks.

Comment 3 Alan 2006-03-31 02:32:27 UTC
On Iau, 2006-03-30 at 15:28 -0800, Andrew Morton wrote:
> > 
> > gcc threader.c -o threader -l pthread
> > echo 0 > /proc/sys/kernel/core_uses_pid
> > echo core > /proc/sys/kernel/core_pattern
> > ulimit -c 5000
> > ./threader &
> > sleep 1
> > rm -f core*
> > kill -SEGV %1
> > ls core*
> > 
> 
> Alan, was this intentional?

If I remember rightly it was the automatic behaviour for threaded core
dumps before I ever added the core_pattern stuff and it goes back a long
way. The alternative was that you got a mangled file where they all
dumped on top of each other.



Alan

Comment 4 David M. Lee 2006-03-31 10:53:29 UTC
Currently (at least with NPTL) a multi-threaded program core-dumps into a 
single file just fine.
Comment 5 Andrew Morton 2007-01-31 01:03:21 UTC
I think we'll leave things as-is.  Changing anything in this area will break
things for some people.

Note You need to log in before you can comment on or make changes to this bug.