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

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

31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)kern_sig.c 8.7 (Berkeley) 4/18/94
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.

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

31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)kern_sig.c 8.7 (Berkeley) 4/18/94
39 * $FreeBSD: head/sys/kern/kern_sig.c 50477 1999-08-28 01:08:13Z peter $
39 * $FreeBSD: head/sys/kern/kern_sig.c 50717 1999-09-01 00:29:56Z julian $
40 */
41
42#include "opt_compat.h"
43#include "opt_ktrace.h"
44
45#define SIGPROP /* include signal properties table */
46#include <sys/param.h>
47#include <sys/kernel.h>

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

66#include <machine/cpu.h>
67#ifdef SMP
68#include <machine/smp.h>
69#endif
70
71static int killpg1 __P((struct proc *cp, int signum, int pgid, int all));
72static void setsigvec __P((struct proc *p, int signum, struct sigaction *sa));
73static void stop __P((struct proc *));
40 */
41
42#include "opt_compat.h"
43#include "opt_ktrace.h"
44
45#define SIGPROP /* include signal properties table */
46#include <sys/param.h>
47#include <sys/kernel.h>

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

66#include <machine/cpu.h>
67#ifdef SMP
68#include <machine/smp.h>
69#endif
70
71static int killpg1 __P((struct proc *cp, int signum, int pgid, int all));
72static void setsigvec __P((struct proc *p, int signum, struct sigaction *sa));
73static void stop __P((struct proc *));
74static char *expand_name __P((const char *, uid_t, int));
75static int coredump __P((struct proc *));
74
75static int kern_logsigexit = 1;
76SYSCTL_INT(_kern, KERN_LOGSIGEXIT, logsigexit, CTLFLAG_RW,
77 &kern_logsigexit, 0,
78 "Log processes quitting on abnormal signals to syslog(3)");
79
80/*
81 * Can process p, with pcred pc, send the signal signum to process q?

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

1250 if (sigprop[signum] & SA_CORE) {
1251 p->p_sig = signum;
1252 /*
1253 * Log signals which would cause core dumps
1254 * (Log as LOG_INFO to appease those who don't want
1255 * these messages.)
1256 * XXX : Todo, as well as euid, write out ruid too
1257 */
76
77static int kern_logsigexit = 1;
78SYSCTL_INT(_kern, KERN_LOGSIGEXIT, logsigexit, CTLFLAG_RW,
79 &kern_logsigexit, 0,
80 "Log processes quitting on abnormal signals to syslog(3)");
81
82/*
83 * Can process p, with pcred pc, send the signal signum to process q?

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

1252 if (sigprop[signum] & SA_CORE) {
1253 p->p_sig = signum;
1254 /*
1255 * Log signals which would cause core dumps
1256 * (Log as LOG_INFO to appease those who don't want
1257 * these messages.)
1258 * XXX : Todo, as well as euid, write out ruid too
1259 */
1258 if (p->p_sysent->sv_coredump != NULL &&
1259 (*p->p_sysent->sv_coredump)(p) == 0)
1260 if (coredump(p) == 0)
1260 signum |= WCOREFLAG;
1261 if (kern_logsigexit)
1262 log(LOG_INFO,
1263 "pid %d (%s), uid %d: exited on signal %d%s\n",
1264 p->p_pid, p->p_comm,
1265 p->p_cred && p->p_ucred ? p->p_ucred->cr_uid : -1,
1266 signum &~ WCOREFLAG,
1267 signum & WCOREFLAG ? " (core dumped)" : "");

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

1281 * %N name of process ("name")
1282 * %P process id (pid)
1283 * %U user id (uid)
1284 * For example, "%N.core" is the default; they can be disabled completely
1285 * by using "/dev/null", or all core files can be stored in "/cores/%U/%N-%P".
1286 * This is controlled by the sysctl variable kern.corefile (see above).
1287 */
1288
1261 signum |= WCOREFLAG;
1262 if (kern_logsigexit)
1263 log(LOG_INFO,
1264 "pid %d (%s), uid %d: exited on signal %d%s\n",
1265 p->p_pid, p->p_comm,
1266 p->p_cred && p->p_ucred ? p->p_ucred->cr_uid : -1,
1267 signum &~ WCOREFLAG,
1268 signum & WCOREFLAG ? " (core dumped)" : "");

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

1282 * %N name of process ("name")
1283 * %P process id (pid)
1284 * %U user id (uid)
1285 * For example, "%N.core" is the default; they can be disabled completely
1286 * by using "/dev/null", or all core files can be stored in "/cores/%U/%N-%P".
1287 * This is controlled by the sysctl variable kern.corefile (see above).
1288 */
1289
1289char *
1290static char *
1290expand_name(name, uid, pid)
1291const char *name; uid_t uid; pid_t pid; {
1292 char *temp;
1293 char buf[11]; /* Buffer for pid/uid -- max 4B */
1294 int i, n;
1295 char *format = corefilename;
1296 size_t namelen;
1297

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

1348 temp[n++] = format[i];
1349 }
1350 }
1351 temp[n] = '\0';
1352 return temp;
1353}
1354
1355/*
1291expand_name(name, uid, pid)
1292const char *name; uid_t uid; pid_t pid; {
1293 char *temp;
1294 char buf[11]; /* Buffer for pid/uid -- max 4B */
1295 int i, n;
1296 char *format = corefilename;
1297 size_t namelen;
1298

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

1349 temp[n++] = format[i];
1350 }
1351 }
1352 temp[n] = '\0';
1353 return temp;
1354}
1355
1356/*
1357 * Dump a process' core. The main routine does some
1358 * policy checking, and creates the name of the coredump;
1359 * then it passes on a vnode and a size limit to the process-specific
1360 * coredump routine if there is one; if there _is not_ one, it returns
1361 * ENOSYS; otherwise it returns the error from the process-specific routine.
1362 */
1363
1364static int
1365coredump(p)
1366 register struct proc *p;
1367{
1368 register struct vnode *vp;
1369 register struct ucred *cred = p->p_cred->pc_ucred;
1370 struct nameidata nd;
1371 struct vattr vattr;
1372 int error, error1;
1373 char *name; /* name of corefile */
1374 off_t limit;
1375
1376 STOPEVENT(p, S_CORE, 0);
1377
1378 if ((sugid_coredump == 0) && p->p_flag & P_SUGID)
1379 return (EFAULT);
1380
1381 /*
1382 * Note that this layout means that limit checking is done
1383 * AFTER the corefile name is created. This could happen
1384 * other ways as well, so I'm not too worried about it, but
1385 * it is potentially confusing.
1386 */
1387 name = expand_name(p->p_comm, p->p_ucred->cr_uid, p->p_pid);
1388 NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE, name, p);
1389 error = vn_open(&nd, O_CREAT | FWRITE | O_NOFOLLOW, S_IRUSR | S_IWUSR);
1390 free(name, M_TEMP);
1391 if (error)
1392 return (error);
1393 vp = nd.ni_vp;
1394
1395 /* Don't dump to non-regular files or files with links. */
1396 if (vp->v_type != VREG ||
1397 VOP_GETATTR(vp, &vattr, cred, p) || vattr.va_nlink != 1) {
1398 error = EFAULT;
1399 goto out;
1400 }
1401 VATTR_NULL(&vattr);
1402 vattr.va_size = 0;
1403 VOP_LEASE(vp, p, cred, LEASE_WRITE);
1404 VOP_SETATTR(vp, &vattr, cred, p);
1405 p->p_acflag |= ACORE;
1406
1407 limit = p->p_rlimit[RLIMIT_CORE].rlim_cur;
1408
1409 error = p->p_sysent->sv_coredump ?
1410 p->p_sysent->sv_coredump(p, vp, limit) :
1411 ENOSYS;
1412
1413out:
1414 VOP_UNLOCK(vp, 0, p);
1415 error1 = vn_close(vp, FWRITE, cred, p);
1416 if (error == 0)
1417 error = error1;
1418 return (error);
1419}
1420
1421/*
1356 * Nonexistent system call-- signal process (may want to handle it).
1357 * Flag error in case process won't see signal immediately (blocked or ignored).
1358 */
1359#ifndef _SYS_SYSPROTO_H_
1360struct nosys_args {
1361 int dummy;
1362};
1363#endif

--- 37 unchanged lines hidden ---
1422 * Nonexistent system call-- signal process (may want to handle it).
1423 * Flag error in case process won't see signal immediately (blocked or ignored).
1424 */
1425#ifndef _SYS_SYSPROTO_H_
1426struct nosys_args {
1427 int dummy;
1428};
1429#endif

--- 37 unchanged lines hidden ---