Subject: kern/5191: Feature addition: Ability to dump core to "core"
To: None <gnats-bugs@gnats.netbsd.org>
From: None <nathanw@MIT.EDU>
List: netbsd-bugs
Date: 03/23/1998 22:55:52
>Number: 5191
>Category: kern
>Synopsis: A feature to allow dumping core to "core" instead of "prog.core"
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: kern-bug-people (Kernel Bug People)
>State: open
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Mon Mar 23 20:05:00 1998
>Last-Modified:
>Originator: Nathan J. Williams
>Organization:
Massachvsetts Institvte of Technology
>Release: NetBSD-current of 1998/3/22
>Environment:
System: NetBSD road-runner.mit.edu 1.3E NetBSD 1.3E (ROAD-RUNNER) #98: Mon Mar 23 22:12:16 EST 1998 nathanw@road-runner.mit.edu:/u1/usr/src/sys/arch/i386/compile/ROAD-RUNNER i386
>Description:
NetBSD, like other 4.4BSD derivitaves, dumps a program's core image
into a file named "progname.core" under various circumstances. At some sites
it may be prefereable for the core file to simply be named "core". There may
be non-NetBSD corefile expungers, or there may be a desire to have a
"core -> /somewhere/core" symlink work for all programs and across different
platforms, or the administrator may simply be of a traditional frame of mind.
NetBSD is not currently adjustable in this regard.
>How-To-Repeat:
>Fix:
I have implemented this feature by way of a kernel variable
"shortcorename", adjustable by the sysctl variable kern.shortcorefile
and by a "options SHORTCOREFILE" kernel configuration option.
This patch adds the variable, the option, and appropriate
documentation in sysctl(3), sysctl(8), options(4), and core(5). It also
adjusts /etc/daily to look for both foo.core and core, which is useful both
in the presence of this setting and when the partitions being searched are
exported to non-4.4BSD clients. It also fixes a minor bug in /etc/daily's
"Possible core dumps" display heuristic.
I'm not very attached to the name. The names "longcorename",
"44bsdcorefilename", "kern_44bsdcorefilename", "bsd44corefilename", and
"progdotcore" were considered but ultimately rejected.
*** sys/kern/kern_sig.c.orig Sun Mar 1 07:21:14 1998
--- sys/kern/kern_sig.c Mon Mar 23 21:34:51 1998
***************
*** 1043,1050 ****
}
/*
! * Dump core, into a file named "progname.core", unless the process was
! * setuid/setgid.
*/
int
coredump(p)
--- 1043,1050 ----
}
/*
! * Dump core, into a file named "progname.core" or "core" (depending on the
! * value of shortcorename), unless the process was setuid/setgid.
*/
int
coredump(p)
***************
*** 1058,1063 ****
--- 1058,1064 ----
int error, error1;
char name[MAXCOMLEN+6]; /* progname.core */
struct core core;
+ extern int shortcorename;
/*
* Make sure the process has not set-id, to prevent data leaks.
***************
*** 1081,1087 ****
if (p->p_fd->fd_cdir->v_mount->mnt_flag & MNT_NOCOREDUMP)
return (EPERM);
! sprintf(name, "%s.core", p->p_comm);
NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, name, p);
error = vn_open(&nd, O_CREAT | FWRITE, S_IRUSR | S_IWUSR);
if (error)
--- 1082,1091 ----
if (p->p_fd->fd_cdir->v_mount->mnt_flag & MNT_NOCOREDUMP)
return (EPERM);
! if (shortcorename)
! sprintf(name, "core");
! else
! sprintf(name, "%s.core", p->p_comm);
NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, name, p);
error = vn_open(&nd, O_CREAT | FWRITE, S_IRUSR | S_IWUSR);
if (error)
*** sys/kern/kern_sysctl.c.orig Sun Mar 1 07:21:16 1998
--- sys/kern/kern_sysctl.c Mon Mar 23 22:31:39 1998
***************
*** 212,217 ****
--- 212,222 ----
#else
int securelevel = 0;
#endif
+ #ifdef SHORTCORENAME
+ int shortcorename = 1;
+ #else
+ int shortcorename = 0;
+ #endif
/*
* kernel related system variables.
***************
*** 229,234 ****
--- 234,240 ----
int error, level, inthostid;
int old_autonicetime;
int old_vnodes;
+ int old_shortcorename;
extern char ostype[], osrelease[], version[];
/* all sysctl names at this level are terminal */
***************
*** 348,353 ****
--- 354,369 ----
return (ENXIO);
}
return (sysctl_rdint(oldp, oldlenp, newp, msgbufp->msg_bufs));
+ case KERN_SHORTCORENAME:
+ /* Only allow values of zero or one. */
+ old_shortcorename = shortcorename;
+ error = sysctl_int(oldp, oldlenp, newp, newlen,
+ &shortcorename);
+ if (shortcorename != 0 && shortcorename != 1) {
+ shortcorename = old_shortcorename;
+ return (EINVAL);
+ }
+ return (error);
default:
return (EOPNOTSUPP);
}
*** sys/sys/sysctl.h.orig Tue Mar 3 07:26:19 1998
--- sys/sys/sysctl.h Mon Mar 23 22:31:14 1998
***************
*** 141,147 ****
#define KERN_RTC_OFFSET 29 /* int: offset of rtc from gmt */
#define KERN_ROOT_DEVICE 30 /* string: root device */
#define KERN_MSGBUFSIZE 31 /* int: max # of chars in msg buffer */
! #define KERN_MAXID 32 /* number of valid kern ids */
#define CTL_KERN_NAMES { \
{ 0, 0 }, \
--- 141,148 ----
#define KERN_RTC_OFFSET 29 /* int: offset of rtc from gmt */
#define KERN_ROOT_DEVICE 30 /* string: root device */
#define KERN_MSGBUFSIZE 31 /* int: max # of chars in msg buffer */
! #define KERN_SHORTCORENAME 32 /* int: dump core as "core" */
! #define KERN_MAXID 33 /* number of valid kern ids */
#define CTL_KERN_NAMES { \
{ 0, 0 }, \
***************
*** 176,181 ****
--- 177,183 ----
{ "rtc_offset", CTLTYPE_INT }, \
{ "root_device", CTLTYPE_STRING }, \
{ "msgbufsize", CTLTYPE_INT }, \
+ { "shortcorename", CTLTYPE_INT }, \
}
/*
*** etc/daily.orig Mon Jan 26 07:43:53 1998
--- etc/daily Mon Mar 23 22:05:22 1998
***************
*** 77,88 ****
find / \( ! -fstype local -o -fstype rdonly -o -fstype fdesc \
-o -fstype kernfs -o -fstype procfs \) -a -prune -o \
-name 'lost+found' -a -prune -o \
! -name '*.core' -a -print > $TMP
# \( -name '[#,]*' -o -name '.#*' -o -name a.out \
# -o -name '*.CKP' -o -name '.emacs_[0-9]*' \) \
# -a -atime +3 -exec rm -f -- {} \; -a -print > $TMP
! egrep '\.core' $TMP > $TMP2
if [ -s $TMP2 ]; then
echo ""
echo "Possible core dumps:"
--- 77,88 ----
find / \( ! -fstype local -o -fstype rdonly -o -fstype fdesc \
-o -fstype kernfs -o -fstype procfs \) -a -prune -o \
-name 'lost+found' -a -prune -o \
! \( -name '*.core' -o -name 'core' \) -a -print > $TMP
# \( -name '[#,]*' -o -name '.#*' -o -name a.out \
# -o -name '*.CKP' -o -name '.emacs_[0-9]*' \) \
# -a -atime +3 -exec rm -f -- {} \; -a -print > $TMP
! egrep '\.core$|^core$' $TMP > $TMP2
if [ -s $TMP2 ]; then
echo ""
echo "Possible core dumps:"
*** usr.sbin/sysctl/sysctl.8.orig Fri Feb 6 08:07:50 1998
--- usr.sbin/sysctl/sysctl.8 Mon Mar 23 21:36:54 1998
***************
*** 133,138 ****
--- 133,139 ----
.It kern.boottime struct no
.It kern.autonicetime integer yes
.It kern.autoniceval integer yes
+ .It kern.shortcorename integer yes
.It vm.loadavg struct no
.It machdep.console_device dev_t no
.It net.inet.ip.forwarding integer yes
*** lib/libc/gen/sysctl.3.orig Fri Feb 6 07:41:35 1998
--- lib/libc/gen/sysctl.3 Mon Mar 23 22:34:15 1998
***************
*** 282,287 ****
--- 282,288 ----
.It KERN\_RAWPARTITION integer no
.It KERN\_SAVED\_IDS integer no
.It KERN\_SECURELVL integer raise only
+ .It KERN\_SHORTCORENAME integer yes
.It KERN\_VDISABLE integer no
.It KERN\_VERSION string no
.It KERN\_VNODE struct vnode no
***************
*** 424,429 ****
--- 425,441 ----
The system security level.
This level may be raised by processes with appropriate privilege.
It may only be lowered by process 1.
+ .It Li KERN_SHORTCORENAME
+ Whether core dumps are named
+ .Nm programname.core
+ (default, value 0) or
+ .Nm core
+ (value 1).
+ The default value can be changed to 1 with the kernel configuration option
+ .Cd options SHORTCORENAME
+ (see
+ .Xr options 4 ,
+ .Xr core 5 ).
.It Li KERN_VDISABLE
Returns the terminal character disabling value.
.It Li KERN_VERSION
*** share/man/man4/options.4.orig Thu Mar 19 07:18:26 1998
--- share/man/man4/options.4 Mon Mar 23 21:49:55 1998
***************
*** 697,702 ****
--- 697,714 ----
.Em CHILD_MAX
is not permitted, as this would result in a violation of the semantics of
.St -p1003.1-90 .
+ .It Cd options SHORTCORENAME
+ If set, process core dumps are named
+ .Nm core .
+ If not specified, they are named
+ .Nm programname.core
+ (the default in 4.4BSD). Note that this changes the value of the
+ .Em kern.shortcorename
+ sysctl variable which may be changed at run time. See
+ .Xr sysctl 8
+ and
+ .Xr sysctl 3
+ for details.
.El
.Ss Networking Options
.Bl -ohang
*** share/man/man5/core.5.orig Thu Jul 10 07:15:47 1997
--- share/man/man5/core.5 Mon Mar 23 21:52:35 1998
***************
*** 47,60 ****
to disk for later examination by one of the available debuggers.
(See
.Xr sigaction 2 . )
! This memory image is written to a file named
! .Nm programname.core
in the working directory;
provided the terminated process had write permission in the directory,
and provided the abnormality did not cause
a system crash.
(In this event, the decision to save the core file is arbitrary, see
.Xr savecore 8 . )
.Pp
The maximum size of a
.Nm programname.core
--- 47,69 ----
to disk for later examination by one of the available debuggers.
(See
.Xr sigaction 2 . )
! This memory image is written to a file
in the working directory;
provided the terminated process had write permission in the directory,
and provided the abnormality did not cause
a system crash.
(In this event, the decision to save the core file is arbitrary, see
.Xr savecore 8 . )
+ The file is normally named
+ .Nm programname.core ,
+ but is called
+ .Nm core
+ if the
+ kernel configuration option
+ .Cd options SHORTCORENAME
+ is defined or the sysctl variable
+ .Em kern.shortcorename
+ is set to 1.
.Pp
The maximum size of a
.Nm programname.core
>Audit-Trail:
>Unformatted: