Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern Allow PT_DUMPCORE to specify the core filename.



details:   https://anonhg.NetBSD.org/src/rev/e9d322c346b1
branches:  trunk
changeset: 572645:e9d322c346b1
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Jan 09 19:22:55 2005 +0000

description:
Allow PT_DUMPCORE to specify the core filename.

diffstat:

 sys/kern/kern_sig.c    |  20 ++++++++++----------
 sys/kern/sys_process.c |  24 +++++++++++++++++++++---
 2 files changed, 31 insertions(+), 13 deletions(-)

diffs (133 lines):

diff -r 023ed10d8c95 -r e9d322c346b1 sys/kern/kern_sig.c
--- a/sys/kern/kern_sig.c       Sun Jan 09 17:47:45 2005 +0000
+++ b/sys/kern/kern_sig.c       Sun Jan 09 19:22:55 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_sig.c,v 1.200 2005/01/06 19:26:41 mycroft Exp $   */
+/*     $NetBSD: kern_sig.c,v 1.201 2005/01/09 19:22:55 christos Exp $  */
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1991, 1993
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.200 2005/01/06 19:26:41 mycroft Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.201 2005/01/09 19:22:55 christos Exp $");
 
 #include "opt_ktrace.h"
 #include "opt_compat_sunos.h"
@@ -82,7 +82,7 @@
 #include <uvm/uvm_extern.h>
 
 static void    child_psignal(struct proc *, int);
-static int     build_corename(struct proc *, char [MAXPATHLEN]);
+static int     build_corename(struct proc *, char *, const char *, size_t);
 static void    ksiginfo_exithook(struct proc *, void *);
 static void    ksiginfo_put(struct proc *, const ksiginfo_t *);
 static ksiginfo_t *ksiginfo_get(struct proc *, int);
@@ -2010,7 +2010,7 @@
        p->p_acflag |= AXSIG;
        if (sigprop[signum] & SA_CORE) {
                p->p_sigctx.ps_signo = signum;
-               if ((error = coredump(l)) == 0)
+               if ((error = coredump(l, NULL)) == 0)
                        exitsig |= WCOREFLAG;
 
                if (kern_logsigexit) {
@@ -2037,7 +2037,7 @@
  * value of shortcorename), unless the process was setuid/setgid.
  */
 int
-coredump(struct lwp *l)
+coredump(struct lwp *l, const char *pattern)
 {
        struct vnode            *vp;
        struct proc             *p;
@@ -2079,8 +2079,9 @@
            (vp->v_mount->mnt_flag & MNT_NOCOREDUMP) != 0)
                return (EPERM);
 
-       error = build_corename(p, name);
-       if (error)
+       if (pattern == NULL)
+               pattern = p->p_limit->pl_corename;
+       if ((error = build_corename(p, name, pattern, sizeof(name))) != 0)
                return error;
 
        NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE, name, p);
@@ -2138,14 +2139,13 @@
 }
 
 static int
-build_corename(struct proc *p, char dst[MAXPATHLEN])
+build_corename(struct proc *p, char *dst, const char *src, size_t len)
 {
        const char      *s;
        char            *d, *end;
        int             i;
        
-       for (s = p->p_limit->pl_corename, d = dst, end = d + MAXPATHLEN;
-           *s != '\0'; s++) {
+       for (s = src, d = dst, end = d + len; *s != '\0'; s++) {
                if (*s == '%') {
                        switch (*(s + 1)) {
                        case 'n':
diff -r 023ed10d8c95 -r e9d322c346b1 sys/kern/sys_process.c
--- a/sys/kern/sys_process.c    Sun Jan 09 17:47:45 2005 +0000
+++ b/sys/kern/sys_process.c    Sun Jan 09 19:22:55 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sys_process.c,v 1.92 2004/09/17 14:11:25 skrll Exp $   */
+/*     $NetBSD: sys_process.c,v 1.93 2005/01/09 19:22:55 christos Exp $        */
 
 /*-
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -89,7 +89,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_process.c,v 1.92 2004/09/17 14:11:25 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_process.c,v 1.93 2005/01/09 19:22:55 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -99,6 +99,7 @@
 #include <sys/uio.h>
 #include <sys/user.h>
 #include <sys/ras.h>
+#include <sys/malloc.h>
 
 #include <sys/mount.h>
 #include <sys/sa.h>
@@ -136,6 +137,7 @@
        struct ptrace_io_desc piod;
        struct ptrace_lwpinfo pl;
        int s, error, write, tmp, size;
+       char *path;
 
        /* "A foolish consistency..." XXX */
        if (SCARG(uap, req) == PT_TRACE_ME)
@@ -350,7 +352,23 @@
                return (error);
 
        case  PT_DUMPCORE:
-               return coredump(lt);
+               if ((path = SCARG(uap, addr)) != NULL) {
+                       char *dst;
+                       int len = SCARG(uap, data);
+                       if (len >= MAXPATHLEN)
+                               return EINVAL;
+                       dst = malloc(len + 1, M_TEMP, M_WAITOK); 
+                       if ((error = copyin(path, dst, len)) != 0) {
+                               free(dst, M_TEMP);
+                               return error;
+                       }
+                       path[len] = '\0';
+                       path = dst;
+               }
+               error = coredump(lt, path);
+               if (path)
+                       free(path, M_TEMP);
+               return error;
 
 #ifdef PT_STEP
        case  PT_STEP:



Home | Main Index | Thread Index | Old Index