From owner-svn-src-head@freebsd.org Sun Jul 15 17:10:13 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C02E310472CE; Sun, 15 Jul 2018 17:10:13 +0000 (UTC) (envelope-from oshogbo@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 6D8368F0D7; Sun, 15 Jul 2018 17:10:13 +0000 (UTC) (envelope-from oshogbo@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4AA9010C62; Sun, 15 Jul 2018 17:10:13 +0000 (UTC) (envelope-from oshogbo@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w6FHADkU079192; Sun, 15 Jul 2018 17:10:13 GMT (envelope-from oshogbo@FreeBSD.org) Received: (from oshogbo@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w6FHADmu079191; Sun, 15 Jul 2018 17:10:13 GMT (envelope-from oshogbo@FreeBSD.org) Message-Id: <201807151710.w6FHADmu079191@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: oshogbo set sender to oshogbo@FreeBSD.org using -f From: Mariusz Zaborski Date: Sun, 15 Jul 2018 17:10:13 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r336306 - head/sys/kern X-SVN-Group: head X-SVN-Commit-Author: oshogbo X-SVN-Commit-Paths: head/sys/kern X-SVN-Commit-Revision: 336306 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 Jul 2018 17:10:14 -0000 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 "