Index: sys/kern/kern_sig.c =================================================================== --- sys/kern/kern_sig.c +++ sys/kern/kern_sig.c @@ -3214,11 +3214,7 @@ 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 @@ -3310,18 +3306,19 @@ /* * 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; @@ -3329,9 +3326,13 @@ 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, @@ -3401,12 +3402,14 @@ 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++) { @@ -3427,8 +3430,14 @@ 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); @@ -3468,7 +3477,8 @@ 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 "