Deleted Added
full compact
kern_sig.c (172916) kern_sig.c (172995)
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.

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

30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * @(#)kern_sig.c 8.7 (Berkeley) 4/18/94
35 */
36
37#include <sys/cdefs.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.

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

30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * @(#)kern_sig.c 8.7 (Berkeley) 4/18/94
35 */
36
37#include <sys/cdefs.h>
38__FBSDID("$FreeBSD: head/sys/kern/kern_sig.c 172916 2007-10-24 00:14:19Z csjp $");
38__FBSDID("$FreeBSD: head/sys/kern/kern_sig.c 172995 2007-10-26 01:23:07Z csjp $");
39
40#include "opt_compat.h"
41#include "opt_ktrace.h"
42
43#include <sys/param.h>
44#include <sys/systm.h>
45#include <sys/signalvar.h>
46#include <sys/vnode.h>

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

3053 char *name; /* name of corefile */
3054 off_t limit;
3055 int vfslocked;
3056
3057 PROC_LOCK_ASSERT(p, MA_OWNED);
3058 MPASS((p->p_flag & P_HADTHREADS) == 0 || p->p_singlethread == td);
3059 _STOPEVENT(p, S_CORE, 0);
3060
39
40#include "opt_compat.h"
41#include "opt_ktrace.h"
42
43#include <sys/param.h>
44#include <sys/systm.h>
45#include <sys/signalvar.h>
46#include <sys/vnode.h>

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

3053 char *name; /* name of corefile */
3054 off_t limit;
3055 int vfslocked;
3056
3057 PROC_LOCK_ASSERT(p, MA_OWNED);
3058 MPASS((p->p_flag & P_HADTHREADS) == 0 || p->p_singlethread == td);
3059 _STOPEVENT(p, S_CORE, 0);
3060
3061 name = expand_name(p->p_comm, td->td_ucred->cr_uid, p->p_pid);
3062 if (name == NULL) {
3063#ifdef AUDIT
3064 audit_proc_coredump(td, NULL, EINVAL);
3065#endif
3066 return (EINVAL);
3067 }
3061 if (((sugid_coredump == 0) && p->p_flag & P_SUGID) || do_coredump == 0) {
3062 PROC_UNLOCK(p);
3068 if (((sugid_coredump == 0) && p->p_flag & P_SUGID) || do_coredump == 0) {
3069 PROC_UNLOCK(p);
3070#ifdef AUDIT
3071 audit_proc_coredump(td, name, EFAULT);
3072#endif
3073 free(name, M_TEMP);
3063 return (EFAULT);
3064 }
3065
3066 /*
3067 * Note that the bulk of limit checking is done after
3068 * the corefile is created. The exception is if the limit
3069 * for corefiles is 0, in which case we don't bother
3070 * creating the corefile at all. This layout means that
3071 * a corefile is truncated instead of not being created,
3072 * if it is larger than the limit.
3073 */
3074 limit = (off_t)lim_cur(p, RLIMIT_CORE);
3075 PROC_UNLOCK(p);
3074 return (EFAULT);
3075 }
3076
3077 /*
3078 * Note that the bulk of limit checking is done after
3079 * the corefile is created. The exception is if the limit
3080 * for corefiles is 0, in which case we don't bother
3081 * creating the corefile at all. This layout means that
3082 * a corefile is truncated instead of not being created,
3083 * if it is larger than the limit.
3084 */
3085 limit = (off_t)lim_cur(p, RLIMIT_CORE);
3086 PROC_UNLOCK(p);
3076 if (limit == 0)
3087 if (limit == 0) {
3088#ifdef AUDIT
3089 audit_proc_coredump(td, name, EFBIG);
3090#endif
3091 free(name, M_TEMP);
3077 return (EFBIG);
3092 return (EFBIG);
3093 }
3078
3079restart:
3094
3095restart:
3080 name = expand_name(p->p_comm, td->td_ucred->cr_uid, p->p_pid);
3081 if (name == NULL)
3082 return (EINVAL);
3083 NDINIT(&nd, LOOKUP, NOFOLLOW | MPSAFE, UIO_SYSSPACE, name, td);
3084 flags = O_CREAT | FWRITE | O_NOFOLLOW;
3085 error = vn_open(&nd, &flags, S_IRUSR | S_IWUSR, NULL);
3096 NDINIT(&nd, LOOKUP, NOFOLLOW | MPSAFE, UIO_SYSSPACE, name, td);
3097 flags = O_CREAT | FWRITE | O_NOFOLLOW;
3098 error = vn_open(&nd, &flags, S_IRUSR | S_IWUSR, NULL);
3086 free(name, M_TEMP);
3087 if (error)
3099 if (error) {
3100#ifdef AUDIT
3101 audit_proc_coredump(td, name, error);
3102#endif
3103 free(name, M_TEMP);
3088 return (error);
3104 return (error);
3105 }
3089 vfslocked = NDHASGIANT(&nd);
3090 NDFREE(&nd, NDF_ONLY_PNBUF);
3091 vp = nd.ni_vp;
3092
3093 /* Don't dump to non-regular files or files with links. */
3094 if (vp->v_type != VREG ||
3095 VOP_GETATTR(vp, &vattr, cred, td) || vattr.va_nlink != 1) {
3096 VOP_UNLOCK(vp, 0, td);

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

3138 lf.l_type = F_UNLCK;
3139 VOP_ADVLOCK(vp, (caddr_t)p, F_UNLCK, &lf, F_FLOCK);
3140 }
3141close:
3142 error1 = vn_close(vp, FWRITE, cred, td);
3143 if (error == 0)
3144 error = error1;
3145out:
3106 vfslocked = NDHASGIANT(&nd);
3107 NDFREE(&nd, NDF_ONLY_PNBUF);
3108 vp = nd.ni_vp;
3109
3110 /* Don't dump to non-regular files or files with links. */
3111 if (vp->v_type != VREG ||
3112 VOP_GETATTR(vp, &vattr, cred, td) || vattr.va_nlink != 1) {
3113 VOP_UNLOCK(vp, 0, td);

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

3155 lf.l_type = F_UNLCK;
3156 VOP_ADVLOCK(vp, (caddr_t)p, F_UNLCK, &lf, F_FLOCK);
3157 }
3158close:
3159 error1 = vn_close(vp, FWRITE, cred, td);
3160 if (error == 0)
3161 error = error1;
3162out:
3163#ifdef AUDIT
3164 audit_proc_coredump(td, name, error);
3165#endif
3166 free(name, M_TEMP);
3146 VFS_UNLOCK_GIANT(vfslocked);
3147 return (error);
3148}
3149
3150/*
3151 * Nonexistent system call-- signal process (may want to handle it). Flag
3152 * error in case process won't see signal immediately (blocked or ignored).
3153 */

--- 150 unchanged lines hidden ---
3167 VFS_UNLOCK_GIANT(vfslocked);
3168 return (error);
3169}
3170
3171/*
3172 * Nonexistent system call-- signal process (may want to handle it). Flag
3173 * error in case process won't see signal immediately (blocked or ignored).
3174 */

--- 150 unchanged lines hidden ---