Skip to contentSkip to conversation

PID of multi-threaded core's file name is wrong in 2.5.59

PATCH MAEDA Naoaki 4 participants 8 messages Jan 25, 2003 – Jan 28, 2003

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi,

I found sometimes pid of muitl-threaded core's file name shows wrong number in 2.5.59 with NPTL-0.17. Problem is, pid of core file name comes from currnet->pid, but I think it should be current->tgid.

Following patch fixes this problem.

MAEDA Naoaki

fs/exec.c +2 -2
diff -Naur linux-2.5.59/fs/exec.c linux-2.5.59-corepidfix/fs/exec.c
@@ -1166,7 +1166,7 @@
 			case 'p':
 				pid_in_pattern = 1;
 				rc = snprintf(out_ptr, out_end - out_ptr,
-					      "%d", current->pid);
+					      "%d", current->tgid);
 				if (rc > out_end - out_ptr)
 					goto out;
 				out_ptr += rc;
@@ -1238,7 +1238,7 @@
 	if (!pid_in_pattern
             && (core_uses_pid || atomic_read(&current->mm->mm_users) != 1)) {
 		rc = snprintf(out_ptr, out_end - out_ptr,
-			      ".%d", current->pid);
+			      ".%d", current->tgid);
 		if (rc > out_end - out_ptr)
 			goto out;
 		out_ptr += rc;
#1 lore raw
Quoted 5 lines · MAEDA Naoaki

Hi,

I found sometimes pid of muitl-threaded core's file name shows wrong number in 2.5.59 with NPTL-0.17. Problem is, pid of core file name comes from currnet->pid, but I think it should be current->tgid.

The value needs to be unique so that you can dump multiple threads at the same time and not have one overwrite another. You might want to add the tgid as another format type to the core name formatting so users can select the behaviour you desire however ?

#2 lore raw
Quoted 11 lines · Alan Cox
Quoted 5 lines · MAEDA Naoaki

Hi,

I found sometimes pid of muitl-threaded core's file name shows wrong number in 2.5.59 with NPTL-0.17. Problem is, pid of core file name comes from currnet->pid, but I think it should be current->tgid.

The value needs to be unique so that you can dump multiple threads at the same time and not have one overwrite another. You might want to add the tgid as another format type to the core name formatting so users can select the behaviour you desire however ?

I think this isn't an issue; multi-threaded core dumps are done by the core_waiter synchronization, so all other threads will have exited before the first thread to crash actually writes out its core.

Signature · 2 lines
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer
#3 lore raw
Quoted 3 lines · Daniel Jacobowitz

I think this isn't an issue; multi-threaded core dumps are done by the core_waiter synchronization, so all other threads will have exited before the first thread to crash actually writes out its core.

I think the problem is the filenames need to not overwrite each other - not actual synchronization in the kernel (which, as you point out, is correct).

If we name the coredumps based on ->tgid, then all threads will dump to the same file. If we use ->pid, each thread will use its unique PID as its filename.

Robert Love

#4 lore raw
Quoted 6 lines · Robert Love
Quoted 3 lines · Daniel Jacobowitz

I think this isn't an issue; multi-threaded core dumps are done by the core_waiter synchronization, so all other threads will have exited before the first thread to crash actually writes out its core.

Quoted 7 lines

I think the problem is the filenames need to not overwrite each other - not actual synchronization in the kernel (which, as you point out, is correct).

If we name the coredumps based on ->tgid, then all threads will dump to the same file. If we use ->pid, each thread will use its unique PID as its filename.

That wasn't my point. All of the other threads have already terminated without dumping core at tis point; I don't think it's possible for two threads of a CLONE_THREAD application to both dump core. See fs/exec.c:coredump_wait.

Also, once one thread gets into do_coredump it clears mm->dumpable; nothing else will dump core from that MM anyway.

I think using ->tgid is a good idea.

Signature · 2 lines
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer
#5 lore raw
Quoted 7 lines · Daniel Jacobowitz

That wasn't my point. All of the other threads have already terminated without dumping core at tis point; I don't think it's possible for two threads of a CLONE_THREAD application to both dump core. See fs/exec.c:coredump_wait.

Also, once one thread gets into do_coredump it clears mm->dumpable; nothing else will dump core from that MM anyway.

Are you telling me only one thread per thread group can coredump, period? So if two of them segfault (say concurrently on two different processors) only one will win the race to dump and the others will simply exit?

If so, I did not know that. You are right, then.

Quoted 1 line

I think using ->tgid is a good idea.

I think it is, too - even if what I said is true - as a format option.

Anyhow, I stand corrected.

Robert Love

#6 lore raw
Quoted 7 lines · Robert Love
Quoted 5 lines · Daniel Jacobowitz

That wasn't my point. All of the other threads have already terminated without dumping core at tis point; I don't think it's possible for two threads of a CLONE_THREAD application to both dump core. See fs/exec.c:coredump_wait.

Quoted 7 lines
Quoted 2 lines

Also, once one thread gets into do_coredump it clears mm->dumpable; nothing else will dump core from that MM anyway.

Are you telling me only one thread per thread group can coredump, period? So if two of them segfault (say concurrently on two different processors) only one will win the race to dump and the others will simply exit?

That's right. The dump will include all the threads anyway, now.

Signature · 2 lines
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer
#7 lore raw
Quoted 6 lines · Daniel Jacobowitz
Quoted 4 lines

Are you telling me only one thread per thread group can coredump, period? So if two of them segfault (say concurrently on two different processors) only one will win the race to dump and the others will simply exit?

That's right. The dump will include all the threads anyway, now.

In which case using tgid is probably the right thing.