Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 15 Jul 2018 17:10:13 +0000 (UTC)
From:      Mariusz Zaborski <oshogbo@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r336306 - head/sys/kern
Message-ID:  <201807151710.w6FHADmu079191@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: oshogbo
Date: Sun Jul 15 17:10:12 2018
New Revision: 336306
URL: https://svnweb.freebsd.org/changeset/base/336306

Log:
  Extend amount of possible coredumps from 10 to 100000 when using index format.
  The amount of digits in the name of corefile is assigned dynamically.
  
  Reviewed by:	kib
  Differential Revision:	https://reviews.freebsd.org/D16118

Modified:
  head/sys/kern/kern_sig.c

Modified: head/sys/kern/kern_sig.c
==============================================================================
--- head/sys/kern/kern_sig.c	Sun Jul 15 15:28:23 2018	(r336305)
+++ head/sys/kern/kern_sig.c	Sun Jul 15 17:10:12 2018	(r336306)
@@ -3214,11 +3214,7 @@ childproc_exited(struct proc *p)
 	sigparent(p, reason, status);
 }
 
-/*
- * We only have 1 character for the core count in the format
- * string, so the range will be 0-9
- */
-#define	MAX_NUM_CORE_FILES 10
+#define	MAX_NUM_CORE_FILES 100000
 #ifndef NUM_CORE_FILES
 #define	NUM_CORE_FILES 5
 #endif
@@ -3311,18 +3307,19 @@ vnode_close_locked(struct thread *td, struct vnode *vp
 /*
  * If the core format has a %I in it, then we need to check
  * for existing corefiles before defining a name.
- * To do this we iterate over 0..num_cores to find a
+ * To do this we iterate over 0..ncores to find a
  * non-existing core file name to use. If all core files are
  * already used we choose the oldest one.
  */
 static int
 corefile_open_last(struct thread *td, char *name, int indexpos,
-    struct vnode **vpp)
+    int indexlen, int ncores, struct vnode **vpp)
 {
 	struct vnode *oldvp, *nextvp, *vp;
 	struct vattr vattr;
 	struct nameidata nd;
 	int error, i, flags, oflags, cmode;
+	char ch;
 	struct timespec lasttime;
 
 	nextvp = oldvp = NULL;
@@ -3330,10 +3327,14 @@ corefile_open_last(struct thread *td, char *name, int 
 	oflags = VN_OPEN_NOAUDIT | VN_OPEN_NAMECACHE |
 	    (capmode_coredump ? VN_OPEN_NOCAPCHECK : 0);
 
-	for (i = 0; i < num_cores; i++) {
+	for (i = 0; i < ncores; i++) {
 		flags = O_CREAT | FWRITE | O_NOFOLLOW;
-		name[indexpos] = '0' + i;
 
+		ch = name[indexpos + indexlen];
+		(void)snprintf(name + indexpos, indexlen + 1, "%.*u", indexlen,
+		    i);
+		name[indexpos + indexlen] = ch;
+
 		NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE, name, td);
 		error = vn_open_cred(&nd, &flags, cmode, oflags, td->td_ucred,
 		    NULL);
@@ -3402,12 +3403,14 @@ corefile_open(const char *comm, uid_t uid, pid_t pid, 
 	struct nameidata nd;
 	const char *format;
 	char *hostname, *name;
-	int cmode, error, flags, i, indexpos, oflags;
+	int cmode, error, flags, i, indexpos, indexlen, oflags, ncores;
 
 	hostname = NULL;
 	format = corefilename;
 	name = malloc(MAXPATHLEN, M_TEMP, M_WAITOK | M_ZERO);
+	indexlen = 0;
 	indexpos = -1;
+	ncores = num_cores;
 	(void)sbuf_new(&sb, name, MAXPATHLEN, SBUF_FIXEDLEN);
 	sx_slock(&corefilename_lock);
 	for (i = 0; format[i] != '\0'; i++) {
@@ -3428,8 +3431,14 @@ corefile_open(const char *comm, uid_t uid, pid_t pid, 
 				sbuf_printf(&sb, "%s", hostname);
 				break;
 			case 'I':	/* autoincrementing index */
-				sbuf_printf(&sb, "0");
-				indexpos = sbuf_len(&sb) - 1;
+				if (indexpos != -1) {
+					sbuf_printf(&sb, "%%I");
+					break;
+				}
+
+				indexpos = sbuf_len(&sb);
+				sbuf_printf(&sb, "%u", ncores - 1);
+				indexlen = sbuf_len(&sb) - indexpos;
 				break;
 			case 'N':	/* process name */
 				sbuf_printf(&sb, "%s", comm);
@@ -3469,7 +3478,8 @@ corefile_open(const char *comm, uid_t uid, pid_t pid, 
 	sbuf_delete(&sb);
 
 	if (indexpos != -1) {
-		error = corefile_open_last(td, name, indexpos, vpp);
+		error = corefile_open_last(td, name, indexpos, indexlen, ncores,
+		    vpp);
 		if (error != 0) {
 			log(LOG_ERR,
 			    "pid %d (%s), uid (%u):  Path `%s' failed "



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201807151710.w6FHADmu079191>