Subject: kern/4099: Gather coredumps in one place
To: None <gnats-bugs@gnats.netbsd.org>
From: Heiko W.Rupp <hwr@pilhuhn.de>
List: netbsd-bugs
Date: 09/08/1997 12:16:39
>Number:         4099
>Category:       kern
>Synopsis:       Gather cores in one place
>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  8 03:20:02 1997
>Last-Modified:
>Originator:     Heiko W.Rupp
>Organization:
Heiko W.Rupp        Gerwigstr.5        D-76131  Karlsruhe    +49 721 9661524
>Release:        1.1
>Environment:
	
System: NetBSD snert.pilhuhn.de 1.1 NetBSD 1.1 (SNERT+PPP) #11: Thu Jan 30 11:00:49 MET 1997 hwr@snert.pilhuhn.de:/usr/src/sys/arch/i386/compile/SNERT+PPP i386


>Description:

Normally core dumps are floating around in the enitre file system.
Each night a find needs to go over all disks to find them.

It would be nice to have them at one place only.

>How-To-Repeat:

Every one knows how to produce core dumps.

>Fix:

Something like:


*** kern_sig.c,1	Wed Aug 13 12:07:52 1997
--- kern_sig.c	Wed Aug 13 12:18:38 1997
***************
*** 1029,1034 ****
--- 1029,1037 ----
   * Dump core, into a file named "progname.core", unless the process was
   * setuid/setgid.
   */
+ 
+ #define COREDUMPDIRECTORY "/var/coredump"
+ #define CODDIRSIZ sizeof(COREDUMPDIRECTORY)-1
  int
  coredump(p)
  	register struct proc *p;
***************
*** 1040,1046 ****
  	struct nameidata nd;
  	struct vattr vattr;
  	int error, error1;
! 	char name[MAXCOMLEN+6];		/* progname.core */
  	struct core core;
  
  	if (pcred->p_svuid != pcred->p_ruid || pcred->p_svgid != pcred->p_rgid)
--- 1043,1049 ----
  	struct nameidata nd;
  	struct vattr vattr;
  	int error, error1;
! 	char name[MAXCOMLEN+6+CODDIRSIZ];	/* /path/progname.pid */
  	struct core core;
  
  	if (pcred->p_svuid != pcred->p_ruid || pcred->p_svgid != pcred->p_rgid)
***************
*** 1048,1057 ****
  	if (USPACE + ctob(vm->vm_dsize + vm->vm_ssize) >=
  	    p->p_rlimit[RLIMIT_CORE].rlim_cur)
  		return (EFAULT);
! 	sprintf(name, "%s.core", p->p_comm);
  	NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, name, p);
! 	if (error = vn_open(&nd, O_CREAT | FWRITE, S_IRUSR | S_IWUSR))
! 		return (error);
  	vp = nd.ni_vp;
  
  	/* Don't dump to non-regular files or files with links. */
--- 1051,1065 ----
  	if (USPACE + ctob(vm->vm_dsize + vm->vm_ssize) >=
  	    p->p_rlimit[RLIMIT_CORE].rlim_cur)
  		return (EFAULT);
! 	sprintf(name, "%s/%s.%d",COREDUMPDIRECTORY,p->p_comm,p->p_pid);
  	NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, name, p);
! 	if (error = vn_open(&nd, O_CREAT | FWRITE, S_IRUSR | S_IWUSR)) {
! 		/* try the classical way */
! 		sprintf(name, "%s.core", p->p_comm);
! 		NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, name, p);
! 		if (error = vn_open(&nd, O_CREAT | FWRITE, S_IRUSR | S_IWUSR))
! 			return (error);
! 	}
  	vp = nd.ni_vp;
  
  	/* Don't dump to non-regular files or files with links. */
>Audit-Trail:
>Unformatted: