Subject: kern/4137: coredump logging feature
To: None <gnats-bugs@gnats.netbsd.org>
From: None <tsarna@endicor.com>
List: netbsd-bugs
Date: 09/22/1997 13:14:37
>Number:         4137
>Category:       kern
>Synopsis:       coredump logging feature
>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 Sep 22 16:20:01 1997
>Last-Modified:
>Originator:     Ty Sarna
>Organization:
	Endicor Technologies, Inc., San Antonio, Texas
>Release:        NetBSD-1.2G-970901
>Environment:
System: NetBSD iocane.endicor.com 1.2G-970901 NetBSD 1.2G-970901 (IOCANE) #12: Mon Sep 22 12:45:51 CDT 1997 tsarna@iocane.endicor.com:/usr/src/sys/arch/i386/compile/IOCANE i386

>Description:
	As mentioned on (tech-kern? current-users? I forget...),
	I think it'd be nice to optionally have log messages generated
	when coredumps are created.
>How-To-Repeat:
	See above.
>Fix:
	The patch below implements logging of core dumps, minus the full
	path name that would be nice. A sysctl, kern.coredump_logpri,
	sets the priority level (0-8, 0-7 being the levels defined in
	<sys/syslog.h>, 8 being to disable logging).

	Though this would be more useful if the core dump's full
	pathname could be logged, it still has some value in allowing
	immediate notification of programs dieing, rather that waiting
	for /etc/daily to run or until things start to break because
	some daemon has died, and then trying to figure out what
	happened.

	While doing this, I noticed that there is a function killproc()
	in kern_sig.c that seems not to be used anywhere at all.
	Someone should look at this and decide if it needs to be GC'd

*** sys/sysctl.h.orig	Mon Sep 22 10:54:07 1997
--- sys/sysctl.h	Mon Sep 22 11:07:37 1997
***************
*** 140,146 ****
  #define KERN_AUTONICEVAL	28	/* int: auto nice value */
  #define	KERN_RTC_OFFSET		29	/* int: offset of rtc from gmt */
  #define	KERN_ROOT_DEVICE	30	/* string: root device */
! #define	KERN_MAXID		31	/* number of valid kern ids */
  
  #define CTL_KERN_NAMES { \
  	{ 0, 0 }, \
--- 140,147 ----
  #define KERN_AUTONICEVAL	28	/* int: auto nice value */
  #define	KERN_RTC_OFFSET		29	/* int: offset of rtc from gmt */
  #define	KERN_ROOT_DEVICE	30	/* string: root device */
! #define KERN_COREDUMP_LOGPRI	31	/* int: coredump logging priority */
! #define	KERN_MAXID		32	/* number of valid kern ids */
  
  #define CTL_KERN_NAMES { \
  	{ 0, 0 }, \
***************
*** 174,179 ****
--- 175,181 ----
  	{ "autoniceval", CTLTYPE_INT }, \
  	{ "rtc_offset", CTLTYPE_INT }, \
  	{ "root_device", CTLTYPE_STRING }, \
+ 	{ "coredump_logpri", CTLTYPE_INT }, \
  }
  
  /*
*** sys/syslog.h.orig	Mon Sep 22 11:10:37 1997
--- sys/syslog.h	Mon Sep 22 11:11:07 1997
***************
*** 148,153 ****
--- 148,154 ----
  
  #ifdef _KERNEL
  #define	LOG_PRINTF	-1	/* pseudo-priority to indicate use of printf */
+ #define	LOG_NONE	8	/* pseudo-priority to indicate no logging */
  #endif
  
  /*
*** sys/systm.h.orig	Mon Sep 22 11:13:07 1997
--- sys/systm.h	Mon Sep 22 11:13:29 1997
***************
*** 85,90 ****
--- 85,92 ----
  extern int autonicetime;        /* time (in seconds) before autoniceval */
  extern int autoniceval;         /* proc priority after autonicetime */
  
+ extern int coredump_logpri;     /* syslog priority for logging coredumps */
+ 
  extern int nblkdev;		/* number of entries in bdevsw */
  extern int nchrdev;		/* number of entries in cdevsw */
  extern int nswdev;		/* number of swap devices */
*** kern/kern_sysctl.c.orig	Sat Jun  7 13:47:15 1997
--- kern/kern_sysctl.c	Mon Sep 22 12:18:37 1997
***************
*** 57,62 ****
--- 57,63 ----
  #include <sys/device.h>
  #include <vm/vm.h>
  #include <sys/sysctl.h>
+ #include <sys/syslog.h>
  
  #include <sys/mount.h>
  #include <sys/syscallargs.h>
***************
*** 310,315 ****
--- 311,324 ----
  	case KERN_ROOT_DEVICE:
  		return (sysctl_rdstring(oldp, oldlenp, newp,
  		    root_device->dv_xname));
+ 	case KERN_COREDUMP_LOGPRI:
+ 		error = sysctl_int(oldp, oldlenp, newp, newlen,
+ 		    &coredump_logpri);
+ 		if (coredump_logpri < LOG_EMERG)
+ 			coredump_logpri = LOG_EMERG;
+ 		if (coredump_logpri > LOG_NONE)
+ 			coredump_logpri = LOG_NONE;
+ 		return (error);
  	default:
  		return (EOPNOTSUPP);
  	}
*** kern/kern_sig.c.orig	Mon Sep 22 11:14:07 1997
--- kern/kern_sig.c	Mon Sep 22 11:43:37 1997
***************
*** 1018,1023 ****
--- 1018,1025 ----
  	/* NOTREACHED */
  }
  
+ int coredump_logpri = LOG_NONE;
+ 
  /*
   * Dump core, into a file named "progname.core", unless the process was
   * setuid/setgid.
***************
*** 1127,1132 ****
--- 1129,1144 ----
  	error1 = vn_close(vp, FWRITE, cred, p);
  	if (error == 0)
  		error = error1;
+ 
+ 	/*
+ 	* XXX it would be nice to list a full pathname to the
+ 	* core dump here, but there's currently no readymade
+ 	* function to get a name from a vp by walking up the tree.
+ 	*/
+ 	if (coredump_logpri < LOG_NONE)
+ 		log(coredump_logpri, "pid %d (uid=%d, gid=%d) dumped %s",
+ 		    p->p_pid, p->p_cred->p_ruid, p->p_cred->p_rgid, name);
+         
  	return (error);
  }
  
>Audit-Trail:
>Unformatted: