kern_sig.c (fa1e92b687fa55aae3b9aff3cddc806ddd49cc4b) kern_sig.c (aa14e9b7c9d90c2db81e29b3c68bcee6129b8b4c)
1/*-
2 * Copyright (c) 1982, 1986, 1989, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 24 unchanged lines hidden (view full) ---

33 *
34 * @(#)kern_sig.c 8.7 (Berkeley) 4/18/94
35 */
36
37#include <sys/cdefs.h>
38__FBSDID("$FreeBSD$");
39
40#include "opt_compat.h"
1/*-
2 * Copyright (c) 1982, 1986, 1989, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 24 unchanged lines hidden (view full) ---

33 *
34 * @(#)kern_sig.c 8.7 (Berkeley) 4/18/94
35 */
36
37#include <sys/cdefs.h>
38__FBSDID("$FreeBSD$");
39
40#include "opt_compat.h"
41#include "opt_gzio.h"
41#include "opt_ktrace.h"
42#include "opt_ktrace.h"
42#include "opt_core.h"
43
44#include <sys/param.h>
45#include <sys/ctype.h>
46#include <sys/systm.h>
47#include <sys/signalvar.h>
48#include <sys/vnode.h>
49#include <sys/acct.h>
50#include <sys/bus.h>

--- 3019 unchanged lines hidden (view full) ---

3070 if (new_val < 0)
3071 new_val = 0;
3072 num_cores = new_val;
3073 return (0);
3074}
3075SYSCTL_PROC(_debug, OID_AUTO, ncores, CTLTYPE_INT|CTLFLAG_RW,
3076 0, sizeof(int), sysctl_debug_num_cores_check, "I", "");
3077
43
44#include <sys/param.h>
45#include <sys/ctype.h>
46#include <sys/systm.h>
47#include <sys/signalvar.h>
48#include <sys/vnode.h>
49#include <sys/acct.h>
50#include <sys/bus.h>

--- 3019 unchanged lines hidden (view full) ---

3070 if (new_val < 0)
3071 new_val = 0;
3072 num_cores = new_val;
3073 return (0);
3074}
3075SYSCTL_PROC(_debug, OID_AUTO, ncores, CTLTYPE_INT|CTLFLAG_RW,
3076 0, sizeof(int), sysctl_debug_num_cores_check, "I", "");
3077
3078#if defined(COMPRESS_USER_CORES)
3079int compress_user_cores = 1;
3080SYSCTL_INT(_kern, OID_AUTO, compress_user_cores, CTLFLAG_RW,
3078#define GZ_SUFFIX ".gz"
3079
3080#ifdef GZIO
3081static int compress_user_cores = 1;
3082SYSCTL_INT(_kern, OID_AUTO, compress_user_cores, CTLFLAG_RWTUN,
3081 &compress_user_cores, 0, "Compression of user corefiles");
3082
3083 &compress_user_cores, 0, "Compression of user corefiles");
3084
3083int compress_user_cores_gzlevel = -1; /* default level */
3084SYSCTL_INT(_kern, OID_AUTO, compress_user_cores_gzlevel, CTLFLAG_RW,
3085 &compress_user_cores_gzlevel, -1, "Corefile gzip compression level");
3086
3087#define GZ_SUFFIX ".gz"
3088#define GZ_SUFFIX_LEN 3
3085int compress_user_cores_gzlevel = 6;
3086SYSCTL_INT(_kern, OID_AUTO, compress_user_cores_gzlevel, CTLFLAG_RWTUN,
3087 &compress_user_cores_gzlevel, 0, "Corefile gzip compression level");
3088#else
3089static int compress_user_cores = 0;
3089#endif
3090
3091static char corefilename[MAXPATHLEN] = {"%N.core"};
3092SYSCTL_STRING(_kern, OID_AUTO, corefile, CTLFLAG_RWTUN, corefilename,
3093 sizeof(corefilename), "Process corefile name format string");
3094
3095/*
3096 * corefile_open(comm, uid, pid, td, compress, vpp, namep)

--- 60 unchanged lines hidden (view full) ---

3157 }
3158 break;
3159 default:
3160 sbuf_putc(&sb, format[i]);
3161 break;
3162 }
3163 }
3164 free(hostname, M_TEMP);
3090#endif
3091
3092static char corefilename[MAXPATHLEN] = {"%N.core"};
3093SYSCTL_STRING(_kern, OID_AUTO, corefile, CTLFLAG_RWTUN, corefilename,
3094 sizeof(corefilename), "Process corefile name format string");
3095
3096/*
3097 * corefile_open(comm, uid, pid, td, compress, vpp, namep)

--- 60 unchanged lines hidden (view full) ---

3158 }
3159 break;
3160 default:
3161 sbuf_putc(&sb, format[i]);
3162 break;
3163 }
3164 }
3165 free(hostname, M_TEMP);
3165#ifdef COMPRESS_USER_CORES
3166 if (compress)
3167 sbuf_printf(&sb, GZ_SUFFIX);
3166 if (compress)
3167 sbuf_printf(&sb, GZ_SUFFIX);
3168#endif
3169 if (sbuf_error(&sb) != 0) {
3170 log(LOG_ERR, "pid %ld (%s), uid (%lu): corename is too "
3171 "long\n", (long)pid, comm, (u_long)uid);
3172 sbuf_delete(&sb);
3173 free(name, M_TEMP);
3174 return (ENOMEM);
3175 }
3176 sbuf_finish(&sb);

--- 78 unchanged lines hidden (view full) ---

3255 struct ucred *cred = td->td_ucred;
3256 struct vnode *vp;
3257 struct flock lf;
3258 struct vattr vattr;
3259 int error, error1, locked;
3260 char *name; /* name of corefile */
3261 void *rl_cookie;
3262 off_t limit;
3168 if (sbuf_error(&sb) != 0) {
3169 log(LOG_ERR, "pid %ld (%s), uid (%lu): corename is too "
3170 "long\n", (long)pid, comm, (u_long)uid);
3171 sbuf_delete(&sb);
3172 free(name, M_TEMP);
3173 return (ENOMEM);
3174 }
3175 sbuf_finish(&sb);

--- 78 unchanged lines hidden (view full) ---

3254 struct ucred *cred = td->td_ucred;
3255 struct vnode *vp;
3256 struct flock lf;
3257 struct vattr vattr;
3258 int error, error1, locked;
3259 char *name; /* name of corefile */
3260 void *rl_cookie;
3261 off_t limit;
3263 int compress;
3264 char *data = NULL;
3265 char *fullpath, *freepath = NULL;
3266 size_t len;
3267 static const char comm_name[] = "comm=";
3268 static const char core_name[] = "core=";
3269
3262 char *data = NULL;
3263 char *fullpath, *freepath = NULL;
3264 size_t len;
3265 static const char comm_name[] = "comm=";
3266 static const char core_name[] = "core=";
3267
3270#ifdef COMPRESS_USER_CORES
3271 compress = compress_user_cores;
3272#else
3273 compress = 0;
3274#endif
3275 PROC_LOCK_ASSERT(p, MA_OWNED);
3276 MPASS((p->p_flag & P_HADTHREADS) == 0 || p->p_singlethread == td);
3277 _STOPEVENT(p, S_CORE, 0);
3278
3279 if (!do_coredump || (!sugid_coredump && (p->p_flag & P_SUGID) != 0) ||
3280 (p->p_flag2 & P2_NOTRACE) != 0) {
3281 PROC_UNLOCK(p);
3282 return (EFAULT);

--- 9 unchanged lines hidden (view full) ---

3292 */
3293 limit = (off_t)lim_cur(p, RLIMIT_CORE);
3294 if (limit == 0 || racct_get_available(p, RACCT_CORE) == 0) {
3295 PROC_UNLOCK(p);
3296 return (EFBIG);
3297 }
3298 PROC_UNLOCK(p);
3299
3268 PROC_LOCK_ASSERT(p, MA_OWNED);
3269 MPASS((p->p_flag & P_HADTHREADS) == 0 || p->p_singlethread == td);
3270 _STOPEVENT(p, S_CORE, 0);
3271
3272 if (!do_coredump || (!sugid_coredump && (p->p_flag & P_SUGID) != 0) ||
3273 (p->p_flag2 & P2_NOTRACE) != 0) {
3274 PROC_UNLOCK(p);
3275 return (EFAULT);

--- 9 unchanged lines hidden (view full) ---

3285 */
3286 limit = (off_t)lim_cur(p, RLIMIT_CORE);
3287 if (limit == 0 || racct_get_available(p, RACCT_CORE) == 0) {
3288 PROC_UNLOCK(p);
3289 return (EFBIG);
3290 }
3291 PROC_UNLOCK(p);
3292
3300 error = corefile_open(p->p_comm, cred->cr_uid, p->p_pid, td, compress,
3301 &vp, &name);
3293 error = corefile_open(p->p_comm, cred->cr_uid, p->p_pid, td,
3294 compress_user_cores, &vp, &name);
3302 if (error != 0)
3303 return (error);
3304
3305 /*
3306 * Don't dump to non-regular files or files with links.
3307 * Do not dump into system files.
3308 */
3309 if (vp->v_type != VREG || VOP_GETATTR(vp, &vattr, cred) != 0 ||

--- 22 unchanged lines hidden (view full) ---

3332 VOP_SETATTR(vp, &vattr, cred);
3333 VOP_UNLOCK(vp, 0);
3334 PROC_LOCK(p);
3335 p->p_acflag |= ACORE;
3336 PROC_UNLOCK(p);
3337
3338 if (p->p_sysent->sv_coredump != NULL) {
3339 error = p->p_sysent->sv_coredump(td, vp, limit,
3295 if (error != 0)
3296 return (error);
3297
3298 /*
3299 * Don't dump to non-regular files or files with links.
3300 * Do not dump into system files.
3301 */
3302 if (vp->v_type != VREG || VOP_GETATTR(vp, &vattr, cred) != 0 ||

--- 22 unchanged lines hidden (view full) ---

3325 VOP_SETATTR(vp, &vattr, cred);
3326 VOP_UNLOCK(vp, 0);
3327 PROC_LOCK(p);
3328 p->p_acflag |= ACORE;
3329 PROC_UNLOCK(p);
3330
3331 if (p->p_sysent->sv_coredump != NULL) {
3332 error = p->p_sysent->sv_coredump(td, vp, limit,
3340 compress ? IMGACT_CORE_COMPRESS : 0);
3333 compress_user_cores ? IMGACT_CORE_COMPRESS : 0);
3341 } else {
3342 error = ENOSYS;
3343 }
3344
3345 if (locked) {
3346 lf.l_type = F_UNLCK;
3347 VOP_ADVLOCK(vp, (caddr_t)p, F_UNLCK, &lf, F_FLOCK);
3348 }

--- 190 unchanged lines hidden ---
3334 } else {
3335 error = ENOSYS;
3336 }
3337
3338 if (locked) {
3339 lf.l_type = F_UNLCK;
3340 VOP_ADVLOCK(vp, (caddr_t)p, F_UNLCK, &lf, F_FLOCK);
3341 }

--- 190 unchanged lines hidden ---