Changeset View
Changeset View
Standalone View
Standalone View
head/sys/kern/kern_sig.c
Show All 34 Lines | |||||
* | * | ||||
* @(#)kern_sig.c 8.7 (Berkeley) 4/18/94 | * @(#)kern_sig.c 8.7 (Berkeley) 4/18/94 | ||||
*/ | */ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include "opt_compat.h" | #include "opt_compat.h" | ||||
#include "opt_gzio.h" | |||||
#include "opt_ktrace.h" | #include "opt_ktrace.h" | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/ctype.h> | #include <sys/ctype.h> | ||||
#include <sys/systm.h> | #include <sys/systm.h> | ||||
#include <sys/signalvar.h> | #include <sys/signalvar.h> | ||||
#include <sys/vnode.h> | #include <sys/vnode.h> | ||||
#include <sys/acct.h> | #include <sys/acct.h> | ||||
#include <sys/bus.h> | #include <sys/bus.h> | ||||
#include <sys/capsicum.h> | #include <sys/capsicum.h> | ||||
#include <sys/compressor.h> | |||||
#include <sys/condvar.h> | #include <sys/condvar.h> | ||||
#include <sys/event.h> | #include <sys/event.h> | ||||
#include <sys/fcntl.h> | #include <sys/fcntl.h> | ||||
#include <sys/imgact.h> | #include <sys/imgact.h> | ||||
#include <sys/kernel.h> | #include <sys/kernel.h> | ||||
#include <sys/ktr.h> | #include <sys/ktr.h> | ||||
#include <sys/ktrace.h> | #include <sys/ktrace.h> | ||||
#include <sys/lock.h> | #include <sys/lock.h> | ||||
▲ Show 20 Lines • Show All 3,188 Lines • ▼ Show 20 Lines | sysctl_debug_num_cores_check (SYSCTL_HANDLER_ARGS) | ||||
num_cores = new_val; | num_cores = new_val; | ||||
return (0); | return (0); | ||||
} | } | ||||
SYSCTL_PROC(_debug, OID_AUTO, ncores, CTLTYPE_INT|CTLFLAG_RW, | SYSCTL_PROC(_debug, OID_AUTO, ncores, CTLTYPE_INT|CTLFLAG_RW, | ||||
0, sizeof(int), sysctl_debug_num_cores_check, "I", ""); | 0, sizeof(int), sysctl_debug_num_cores_check, "I", ""); | ||||
#define GZ_SUFFIX ".gz" | #define GZ_SUFFIX ".gz" | ||||
#ifdef GZIO | int compress_user_cores = 0; | ||||
static int compress_user_cores = 1; | |||||
SYSCTL_INT(_kern, OID_AUTO, compress_user_cores, CTLFLAG_RWTUN, | |||||
&compress_user_cores, 0, "Compression of user corefiles"); | |||||
int compress_user_cores_gzlevel = 6; | static int | ||||
SYSCTL_INT(_kern, OID_AUTO, compress_user_cores_gzlevel, CTLFLAG_RWTUN, | sysctl_compress_user_cores(SYSCTL_HANDLER_ARGS) | ||||
&compress_user_cores_gzlevel, 0, "Corefile gzip compression level"); | { | ||||
#else | int error, val; | ||||
static int compress_user_cores = 0; | |||||
#endif | |||||
val = compress_user_cores; | |||||
error = sysctl_handle_int(oidp, &val, 0, req); | |||||
if (error != 0 || req->newptr == NULL) | |||||
return (error); | |||||
if (val != 0 && !compressor_avail(val)) | |||||
return (EINVAL); | |||||
compress_user_cores = val; | |||||
return (error); | |||||
} | |||||
SYSCTL_PROC(_kern, OID_AUTO, compress_user_cores, CTLTYPE_INT | CTLFLAG_RWTUN, | |||||
0, sizeof(int), sysctl_compress_user_cores, "I", | |||||
"Enable compression of user corefiles (" __XSTRING(COMPRESS_GZIP) " = gzip)"); | |||||
int compress_user_cores_level = 6; | |||||
SYSCTL_INT(_kern, OID_AUTO, compress_user_cores_level, CTLFLAG_RWTUN, | |||||
&compress_user_cores_level, 0, | |||||
"Corefile compression level"); | |||||
/* | /* | ||||
* Protect the access to corefilename[] by allproc_lock. | * Protect the access to corefilename[] by allproc_lock. | ||||
*/ | */ | ||||
#define corefilename_lock allproc_lock | #define corefilename_lock allproc_lock | ||||
static char corefilename[MAXPATHLEN] = {"%N.core"}; | static char corefilename[MAXPATHLEN] = {"%N.core"}; | ||||
TUNABLE_STR("kern.corefile", corefilename, sizeof(corefilename)); | TUNABLE_STR("kern.corefile", corefilename, sizeof(corefilename)); | ||||
▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | case '%': /* Format character */ | ||||
break; | break; | ||||
default: | default: | ||||
sbuf_putc(&sb, format[i]); | sbuf_putc(&sb, format[i]); | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
sx_sunlock(&corefilename_lock); | sx_sunlock(&corefilename_lock); | ||||
free(hostname, M_TEMP); | free(hostname, M_TEMP); | ||||
if (compress) | if (compress == COMPRESS_GZIP) | ||||
sbuf_printf(&sb, GZ_SUFFIX); | sbuf_printf(&sb, GZ_SUFFIX); | ||||
if (sbuf_error(&sb) != 0) { | if (sbuf_error(&sb) != 0) { | ||||
log(LOG_ERR, "pid %ld (%s), uid (%lu): corename is too " | log(LOG_ERR, "pid %ld (%s), uid (%lu): corename is too " | ||||
"long\n", (long)pid, comm, (u_long)uid); | "long\n", (long)pid, comm, (u_long)uid); | ||||
sbuf_delete(&sb); | sbuf_delete(&sb); | ||||
free(name, M_TEMP); | free(name, M_TEMP); | ||||
return (ENOMEM); | return (ENOMEM); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 149 Lines • ▼ Show 20 Lines | coredump(struct thread *td) | ||||
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); | vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); | ||||
VOP_SETATTR(vp, &vattr, cred); | VOP_SETATTR(vp, &vattr, cred); | ||||
VOP_UNLOCK(vp, 0); | VOP_UNLOCK(vp, 0); | ||||
PROC_LOCK(p); | PROC_LOCK(p); | ||||
p->p_acflag |= ACORE; | p->p_acflag |= ACORE; | ||||
PROC_UNLOCK(p); | PROC_UNLOCK(p); | ||||
if (p->p_sysent->sv_coredump != NULL) { | if (p->p_sysent->sv_coredump != NULL) { | ||||
error = p->p_sysent->sv_coredump(td, vp, limit, | error = p->p_sysent->sv_coredump(td, vp, limit, 0); | ||||
compress_user_cores ? IMGACT_CORE_COMPRESS : 0); | |||||
} else { | } else { | ||||
error = ENOSYS; | error = ENOSYS; | ||||
} | } | ||||
if (locked) { | if (locked) { | ||||
lf.l_type = F_UNLCK; | lf.l_type = F_UNLCK; | ||||
VOP_ADVLOCK(vp, (caddr_t)p, F_UNLCK, &lf, F_FLOCK); | VOP_ADVLOCK(vp, (caddr_t)p, F_UNLCK, &lf, F_FLOCK); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 196 Lines • Show Last 20 Lines |