Project

General

Profile

Bug #1047

ksh overwrites child core files

Added by Gordon Ross almost 9 years ago. Updated almost 9 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
-
Start date:
2011-05-18
Due date:
% Done:

0%

Estimated time:
Difficulty:
Medium
Tags:
needs-triage

Description

This script:

#!/bin/sh
find . -name '*.[ch]' -print | sort

Run with these environment settings:
LANG=en_US.UTF-8
LC_COLLATE=C

and run in this illumos directory:
$ cd $SRC/cmd/smbsrv

$ ~/bin/findch
Memory fault(coredump)
$ file core
core: ELF 32-bit LSB core file 80386 Version 1, from 'findch'
$ mdb core
08047858 libc_hwcap1.so.1`kill+0x15(fee07bb0, 0, a, fedb01c5)
08047938 libshell.so.1`sh_main+0x840(2, 8047998, 0, fee6e9f2, 4, 0)
08047968 main+0x4a(2, 8047998, 80479a4, 804798c)
0804798c _start+0x7d(2, 8047ab8, 8047ac0, 0, 8061210, 8047af9)

After using coreadm as follows:
coreadm -i core.%p
one can observe that the real reason for this core was
the child (sort) having dumped core, after which ksh
does a kill(2) of itself with the signal from the child.
[alanc reports this is 7008357]

The reason for the child core was
https://www.illumos.org/issues/1046

ksh should avoid making itself dump core here.

History

#1

Updated by Gordon Ross almost 9 years ago

  • Subject changed from ksh script (find|sort) core dump to ksh overwrites child core files

This appears to be in libshell : fault.c 630

    if(savxit&SH_EXITSIG)
        sig = savxit&SH_EXITMASK;
    if(sig)
    {
        /* generate fault termination code */
        signal(sig,SIG_DFL);
        sigrelease(sig);
        kill(getpid(),sig);
        pause();
    }

#2

Updated by Gordon Ross almost 9 years ago

ksh93 appears to have fixed this by doing an "rlimit core 0"
before sending itself the fatal signal from the child status.

--- a/usr/src/lib/libshell/common/sh/fault.c    Tue Apr 13 14:24:21 2010
+++ b/usr/src/lib/libshell/common/sh/fault.c    Wed Mar  9 22:04:01 2011
@@ -632,6 +645,17 @@
     if(sig)
     {
         /* generate fault termination code */
+        if(RLIMIT_CORE!=RLIMIT_UNKNOWN)
+        {
+#ifdef _lib_getrlimit
+            struct rlimit rlp;
+            getrlimit(RLIMIT_CORE,&rlp);
+            rlp.rlim_cur = 0;
+            setrlimit(RLIMIT_CORE,&rlp);
+#else
+            vlimit(RLIMIT_CORE,0);
+#endif
+        }
         signal(sig,SIG_DFL);
         sigrelease(sig);
         kill(getpid(),sig);

Also available in: Atom PDF