kern_sig.c (7b8d5e4865433d266be2782c5f188883c1a8b0eb) kern_sig.c (33f19bee6fe93bbebb203968a7e7c4277218c8e1)
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.

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

3057 register struct ucred *cred = td->td_ucred;
3058 struct flock lf;
3059 struct nameidata nd;
3060 struct vattr vattr;
3061 int error, error1, flags, locked;
3062 struct mount *mp;
3063 char *name; /* name of corefile */
3064 off_t limit;
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.

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

3057 register struct ucred *cred = td->td_ucred;
3058 struct flock lf;
3059 struct nameidata nd;
3060 struct vattr vattr;
3061 int error, error1, flags, locked;
3062 struct mount *mp;
3063 char *name; /* name of corefile */
3064 off_t limit;
3065 int vfslocked;
3065
3066 PROC_LOCK_ASSERT(p, MA_OWNED);
3067 MPASS((p->p_flag & P_HADTHREADS) == 0 || p->p_singlethread == td);
3068 _STOPEVENT(p, S_CORE, 0);
3069
3070 if (((sugid_coredump == 0) && p->p_flag & P_SUGID) || do_coredump == 0) {
3071 PROC_UNLOCK(p);
3072 return (EFAULT);

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

3080 * a corefile is truncated instead of not being created,
3081 * if it is larger than the limit.
3082 */
3083 limit = (off_t)lim_cur(p, RLIMIT_CORE);
3084 PROC_UNLOCK(p);
3085 if (limit == 0)
3086 return (EFBIG);
3087
3066
3067 PROC_LOCK_ASSERT(p, MA_OWNED);
3068 MPASS((p->p_flag & P_HADTHREADS) == 0 || p->p_singlethread == td);
3069 _STOPEVENT(p, S_CORE, 0);
3070
3071 if (((sugid_coredump == 0) && p->p_flag & P_SUGID) || do_coredump == 0) {
3072 PROC_UNLOCK(p);
3073 return (EFAULT);

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

3081 * a corefile is truncated instead of not being created,
3082 * if it is larger than the limit.
3083 */
3084 limit = (off_t)lim_cur(p, RLIMIT_CORE);
3085 PROC_UNLOCK(p);
3086 if (limit == 0)
3087 return (EFBIG);
3088
3088 mtx_lock(&Giant);
3089restart:
3090 name = expand_name(p->p_comm, td->td_ucred->cr_uid, p->p_pid);
3089restart:
3090 name = expand_name(p->p_comm, td->td_ucred->cr_uid, p->p_pid);
3091 if (name == NULL) {
3092 mtx_unlock(&Giant);
3091 if (name == NULL)
3093 return (EINVAL);
3092 return (EINVAL);
3094 }
3095 NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE, name, td); /* XXXKSE */
3093 NDINIT(&nd, LOOKUP, NOFOLLOW | MPSAFE, UIO_SYSSPACE, name, td);
3096 flags = O_CREAT | FWRITE | O_NOFOLLOW;
3097 error = vn_open(&nd, &flags, S_IRUSR | S_IWUSR, -1);
3098 free(name, M_TEMP);
3094 flags = O_CREAT | FWRITE | O_NOFOLLOW;
3095 error = vn_open(&nd, &flags, S_IRUSR | S_IWUSR, -1);
3096 free(name, M_TEMP);
3099 if (error) {
3100 mtx_unlock(&Giant);
3097 if (error)
3101 return (error);
3098 return (error);
3102 }
3099 vfslocked = NDHASGIANT(&nd);
3103 NDFREE(&nd, NDF_ONLY_PNBUF);
3104 vp = nd.ni_vp;
3105
3106 /* Don't dump to non-regular files or files with links. */
3107 if (vp->v_type != VREG ||
3108 VOP_GETATTR(vp, &vattr, cred, td) || vattr.va_nlink != 1) {
3109 VOP_UNLOCK(vp, 0, td);
3110 error = EFAULT;
3100 NDFREE(&nd, NDF_ONLY_PNBUF);
3101 vp = nd.ni_vp;
3102
3103 /* Don't dump to non-regular files or files with links. */
3104 if (vp->v_type != VREG ||
3105 VOP_GETATTR(vp, &vattr, cred, td) || vattr.va_nlink != 1) {
3106 VOP_UNLOCK(vp, 0, td);
3107 error = EFAULT;
3111 goto out;
3108 goto close;
3112 }
3113
3114 VOP_UNLOCK(vp, 0, td);
3115 lf.l_whence = SEEK_SET;
3116 lf.l_start = 0;
3117 lf.l_len = 0;
3118 lf.l_type = F_WRLCK;
3119 locked = (VOP_ADVLOCK(vp, (caddr_t)p, F_SETLK, &lf, F_FLOCK) == 0);
3120
3121 if (vn_start_write(vp, &mp, V_NOWAIT) != 0) {
3122 lf.l_type = F_UNLCK;
3123 if (locked)
3124 VOP_ADVLOCK(vp, (caddr_t)p, F_UNLCK, &lf, F_FLOCK);
3125 if ((error = vn_close(vp, FWRITE, cred, td)) != 0)
3109 }
3110
3111 VOP_UNLOCK(vp, 0, td);
3112 lf.l_whence = SEEK_SET;
3113 lf.l_start = 0;
3114 lf.l_len = 0;
3115 lf.l_type = F_WRLCK;
3116 locked = (VOP_ADVLOCK(vp, (caddr_t)p, F_SETLK, &lf, F_FLOCK) == 0);
3117
3118 if (vn_start_write(vp, &mp, V_NOWAIT) != 0) {
3119 lf.l_type = F_UNLCK;
3120 if (locked)
3121 VOP_ADVLOCK(vp, (caddr_t)p, F_UNLCK, &lf, F_FLOCK);
3122 if ((error = vn_close(vp, FWRITE, cred, td)) != 0)
3126 return (error);
3123 goto out;
3127 if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0)
3124 if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0)
3128 return (error);
3125 goto out;
3126 VFS_UNLOCK_GIANT(vfslocked);
3129 goto restart;
3130 }
3131
3132 VATTR_NULL(&vattr);
3133 vattr.va_size = 0;
3134 if (set_core_nodump_flag)
3135 vattr.va_flags = UF_NODUMP;
3136 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);

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

3145 p->p_sysent->sv_coredump(td, vp, limit) :
3146 ENOSYS;
3147
3148 if (locked) {
3149 lf.l_type = F_UNLCK;
3150 VOP_ADVLOCK(vp, (caddr_t)p, F_UNLCK, &lf, F_FLOCK);
3151 }
3152 vn_finished_write(mp);
3127 goto restart;
3128 }
3129
3130 VATTR_NULL(&vattr);
3131 vattr.va_size = 0;
3132 if (set_core_nodump_flag)
3133 vattr.va_flags = UF_NODUMP;
3134 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);

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

3143 p->p_sysent->sv_coredump(td, vp, limit) :
3144 ENOSYS;
3145
3146 if (locked) {
3147 lf.l_type = F_UNLCK;
3148 VOP_ADVLOCK(vp, (caddr_t)p, F_UNLCK, &lf, F_FLOCK);
3149 }
3150 vn_finished_write(mp);
3153out:
3151close:
3154 error1 = vn_close(vp, FWRITE, cred, td);
3152 error1 = vn_close(vp, FWRITE, cred, td);
3155 mtx_unlock(&Giant);
3156 if (error == 0)
3157 error = error1;
3153 if (error == 0)
3154 error = error1;
3155out:
3156 VFS_UNLOCK_GIANT(vfslocked);
3158 return (error);
3159}
3160
3161/*
3162 * Nonexistent system call-- signal process (may want to handle it).
3163 * Flag error in case process won't see signal immediately (blocked or ignored).
3164 */
3165#ifndef _SYS_SYSPROTO_H_

--- 152 unchanged lines hidden ---
3157 return (error);
3158}
3159
3160/*
3161 * Nonexistent system call-- signal process (may want to handle it).
3162 * Flag error in case process won't see signal immediately (blocked or ignored).
3163 */
3164#ifndef _SYS_SYSPROTO_H_

--- 152 unchanged lines hidden ---