Changeset View
Changeset View
Standalone View
Standalone View
head/sys/kern/kern_sig.c
Show All 32 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 "opt_core.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> | ||||
▲ Show 20 Lines • Show All 3,019 Lines • ▼ Show 20 Lines | sysctl_debug_num_cores_check (SYSCTL_HANDLER_ARGS) | ||||
if (new_val < 0) | if (new_val < 0) | ||||
new_val = 0; | new_val = 0; | ||||
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", ""); | ||||
#if defined(COMPRESS_USER_CORES) | #define GZ_SUFFIX ".gz" | ||||
int compress_user_cores = 1; | |||||
SYSCTL_INT(_kern, OID_AUTO, compress_user_cores, CTLFLAG_RW, | #ifdef GZIO | ||||
static int compress_user_cores = 1; | |||||
SYSCTL_INT(_kern, OID_AUTO, compress_user_cores, CTLFLAG_RWTUN, | |||||
&compress_user_cores, 0, "Compression of user corefiles"); | &compress_user_cores, 0, "Compression of user corefiles"); | ||||
int compress_user_cores_gzlevel = -1; /* default level */ | int compress_user_cores_gzlevel = 6; | ||||
SYSCTL_INT(_kern, OID_AUTO, compress_user_cores_gzlevel, CTLFLAG_RW, | SYSCTL_INT(_kern, OID_AUTO, compress_user_cores_gzlevel, CTLFLAG_RWTUN, | ||||
&compress_user_cores_gzlevel, -1, "Corefile gzip compression level"); | &compress_user_cores_gzlevel, 0, "Corefile gzip compression level"); | ||||
#else | |||||
#define GZ_SUFFIX ".gz" | static int compress_user_cores = 0; | ||||
#define GZ_SUFFIX_LEN 3 | |||||
#endif | #endif | ||||
static char corefilename[MAXPATHLEN] = {"%N.core"}; | static char corefilename[MAXPATHLEN] = {"%N.core"}; | ||||
SYSCTL_STRING(_kern, OID_AUTO, corefile, CTLFLAG_RWTUN, corefilename, | SYSCTL_STRING(_kern, OID_AUTO, corefile, CTLFLAG_RWTUN, corefilename, | ||||
sizeof(corefilename), "Process corefile name format string"); | sizeof(corefilename), "Process corefile name format string"); | ||||
/* | /* | ||||
* corefile_open(comm, uid, pid, td, compress, vpp, namep) | * corefile_open(comm, uid, pid, td, compress, vpp, namep) | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | case '%': /* Format character */ | ||||
} | } | ||||
break; | break; | ||||
default: | default: | ||||
sbuf_putc(&sb, format[i]); | sbuf_putc(&sb, format[i]); | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
free(hostname, M_TEMP); | free(hostname, M_TEMP); | ||||
#ifdef COMPRESS_USER_CORES | |||||
if (compress) | if (compress) | ||||
sbuf_printf(&sb, GZ_SUFFIX); | sbuf_printf(&sb, GZ_SUFFIX); | ||||
#endif | |||||
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); | ||||
} | } | ||||
sbuf_finish(&sb); | sbuf_finish(&sb); | ||||
▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | coredump(struct thread *td) | ||||
struct ucred *cred = td->td_ucred; | struct ucred *cred = td->td_ucred; | ||||
struct vnode *vp; | struct vnode *vp; | ||||
struct flock lf; | struct flock lf; | ||||
struct vattr vattr; | struct vattr vattr; | ||||
int error, error1, locked; | int error, error1, locked; | ||||
char *name; /* name of corefile */ | char *name; /* name of corefile */ | ||||
void *rl_cookie; | void *rl_cookie; | ||||
off_t limit; | off_t limit; | ||||
int compress; | |||||
char *data = NULL; | char *data = NULL; | ||||
char *fullpath, *freepath = NULL; | char *fullpath, *freepath = NULL; | ||||
size_t len; | size_t len; | ||||
static const char comm_name[] = "comm="; | static const char comm_name[] = "comm="; | ||||
static const char core_name[] = "core="; | static const char core_name[] = "core="; | ||||
#ifdef COMPRESS_USER_CORES | |||||
compress = compress_user_cores; | |||||
#else | |||||
compress = 0; | |||||
#endif | |||||
PROC_LOCK_ASSERT(p, MA_OWNED); | PROC_LOCK_ASSERT(p, MA_OWNED); | ||||
MPASS((p->p_flag & P_HADTHREADS) == 0 || p->p_singlethread == td); | MPASS((p->p_flag & P_HADTHREADS) == 0 || p->p_singlethread == td); | ||||
_STOPEVENT(p, S_CORE, 0); | _STOPEVENT(p, S_CORE, 0); | ||||
if (!do_coredump || (!sugid_coredump && (p->p_flag & P_SUGID) != 0) || | if (!do_coredump || (!sugid_coredump && (p->p_flag & P_SUGID) != 0) || | ||||
(p->p_flag2 & P2_NOTRACE) != 0) { | (p->p_flag2 & P2_NOTRACE) != 0) { | ||||
PROC_UNLOCK(p); | PROC_UNLOCK(p); | ||||
return (EFAULT); | return (EFAULT); | ||||
Show All 9 Lines | coredump(struct thread *td) | ||||
*/ | */ | ||||
limit = (off_t)lim_cur(p, RLIMIT_CORE); | limit = (off_t)lim_cur(p, RLIMIT_CORE); | ||||
if (limit == 0 || racct_get_available(p, RACCT_CORE) == 0) { | if (limit == 0 || racct_get_available(p, RACCT_CORE) == 0) { | ||||
PROC_UNLOCK(p); | PROC_UNLOCK(p); | ||||
return (EFBIG); | return (EFBIG); | ||||
} | } | ||||
PROC_UNLOCK(p); | PROC_UNLOCK(p); | ||||
error = corefile_open(p->p_comm, cred->cr_uid, p->p_pid, td, compress, | error = corefile_open(p->p_comm, cred->cr_uid, p->p_pid, td, | ||||
&vp, &name); | compress_user_cores, &vp, &name); | ||||
if (error != 0) | if (error != 0) | ||||
return (error); | return (error); | ||||
/* | /* | ||||
* Don't dump to non-regular files or files with links. | * Don't dump to non-regular files or files with links. | ||||
* Do not dump into system files. | * Do not dump into system files. | ||||
*/ | */ | ||||
if (vp->v_type != VREG || VOP_GETATTR(vp, &vattr, cred) != 0 || | if (vp->v_type != VREG || VOP_GETATTR(vp, &vattr, cred) != 0 || | ||||
Show All 22 Lines | coredump(struct thread *td) | ||||
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, | ||||
compress ? IMGACT_CORE_COMPRESS : 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 190 Lines • Show Last 20 Lines |