summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>2001-11-23 23:14:19 +0000
committerRoland McGrath <roland@gnu.org>2001-11-23 23:14:19 +0000
commitead7eb8d7f9de11f63c738ea72d802ebd219c361 (patch)
treed2017c0be92176358427e39db36e826721c13f44 /utils
parent9ac3344dfbe72fcb45a153f214c300d87631ced1 (diff)
2001-11-23 Roland McGrath <roland@frob.com>
* gcore.c: New file (previously ../exec/gcore.c). Update the code. * Makefile (targets): Add gcore.
Diffstat (limited to 'utils')
-rw-r--r--utils/Makefile6
-rw-r--r--utils/gcore.c104
2 files changed, 107 insertions, 3 deletions
diff --git a/utils/Makefile b/utils/Makefile
index e0d0bc16..cdd1dcdf 100644
--- a/utils/Makefile
+++ b/utils/Makefile
@@ -1,5 +1,5 @@
#
-# Copyright (C) 1994,95,96,97,98,99,2000 Free Software Foundation, Inc.
+# Copyright (C) 1994,95,96,97,98,99,2000,01 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
@@ -21,14 +21,14 @@ makemode := utilities
targets = shd ps settrans showtrans syncfs fsysopts \
storeinfo login w uptime ids loginpr sush vmstat portinfo \
devprobe vminfo addauth rmauth unsu setauth ftpcp ftpdir storecat \
- storeread ping msgport rpctrace mount
+ storeread ping msgport rpctrace mount gcore
special-targets = loginpr sush uptime
SRCS = shd.c ps.c settrans.c syncfs.c showtrans.c addauth.c rmauth.c \
fsysopts.c storeinfo.c login.c loginpr.sh sush.sh w.c \
uptime.sh psout.c ids.c vmstat.c portinfo.c devprobe.c vminfo.c \
parse.c frobauth.c frobauth-mod.c setauth.c pids.c nonsugid.c \
unsu.c ftpcp.c ftpdir.c storeread.c storecat.c ping.c msgport.c \
- rpctrace.c mount.c
+ rpctrace.c mount.c gcore.c
LCLHDRS = psout.h parse.h pids.h frobauth.h
OBJS = $(filter-out %.sh,$(SRCS:.c=.o))
diff --git a/utils/gcore.c b/utils/gcore.c
new file mode 100644
index 00000000..be9a4f2f
--- /dev/null
+++ b/utils/gcore.c
@@ -0,0 +1,104 @@
+/* `gcore' program for GNU Hurd: write a core dump from a running process.
+ Copyright (C) 1992,2001 Free Software Foundation, Inc.
+ Written by Roland McGrath.
+
+This file is part of the GNU Hurd.
+
+The GNU Hurd is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+The GNU Hurd is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with the GNU Hurd; see the file COPYING. If not, write to
+the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <hurd.h>
+#include <hurd/crash.h>
+#include <hurd/paths.h>
+#include <fcntl.h>
+#include <argp.h>
+#include <error.h>
+
+static const struct argp argp =
+{
+ NULL, NULL,
+ "PID...",
+ "Generate a core dump file from a running process"
+ "\vFor each PID, a core dump file \"core.PID\" is written."
+};
+
+int
+main (int argc, char **argv)
+{
+ int status = 0;
+ file_t crashserv;
+ int argi;
+
+ argp_parse (&argp, argc, argv, 0, &argi, 0);
+
+ crashserv = file_name_lookup (_SERVERS_CRASH, 0, 0);
+ if (crashserv == MACH_PORT_NULL)
+ error (1, errno, "cannot reach crash server: %s", _SERVERS_CRASH);
+
+ for (; argi < argc; ++argi)
+ {
+ char *end;
+ pid_t pid;
+ task_t task;
+
+ pid = strtol (argv[argi], &end, 10);
+ if (end == argv[argi] || *end != '\0')
+ {
+ error (0, 0, "cannot parse process ID: %s", argv[argi]);
+ status = 1;
+ continue;
+ }
+
+ task = pid2task ((pid_t) pid);
+ if (task == MACH_PORT_NULL)
+ {
+ error (0, errno, "pid2task: %d", pid);
+ status = 1;
+ }
+ else
+ {
+ file_t file;
+ char *name = 0;
+ asprintf (&name, "core.%d", pid);
+
+ file = file_name_lookup (name, O_WRONLY|O_CREAT,
+ 0600 &~ getumask ());
+ if (file == MACH_PORT_NULL)
+ {
+ error (0, errno, "cannot create %s", name);
+ status = 1;
+ }
+ else
+ {
+ error_t err = crash_dump_task (crashserv, task, file,
+ 0, 0, 0, 0, 0, 0,
+ MACH_PORT_NULL,
+ MACH_MSG_TYPE_COPY_SEND);
+ mach_port_deallocate (mach_task_self (), file);
+ if (err)
+ {
+ (void) remove (name);
+ error (0, err, "crash_dump_task on %d to %s", pid, name);
+ status = 1;
+ }
+ free (name);
+ }
+ }
+ mach_port_deallocate (mach_task_self (), task);
+ }
+
+ return status;
+}