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
This commit is contained in:
parent
7d6f6a3532
commit
f1fe1e020f
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=336306
@ -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,9 +3327,13 @@ corefile_open_last(struct thread *td, char *name, int indexpos,
|
||||
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,
|
||||
@ -3402,12 +3403,14 @@ corefile_open(const char *comm, uid_t uid, pid_t pid, struct thread *td,
|
||||
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, struct thread *td,
|
||||
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, struct thread *td,
|
||||
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 "
|
||||
|
Loading…
Reference in New Issue
Block a user