gcore.c (125859) | gcore.c (199805) |
---|---|
1/*- 2 * Copyright (c) 1992, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 29 unchanged lines hidden (view full) --- 38#endif /* not lint */ 39 40#if 0 41#ifndef lint 42static char sccsid[] = "@(#)gcore.c 8.2 (Berkeley) 9/23/93"; 43#endif /* not lint */ 44#endif 45#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1992, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 29 unchanged lines hidden (view full) --- 38#endif /* not lint */ 39 40#if 0 41#ifndef lint 42static char sccsid[] = "@(#)gcore.c 8.2 (Berkeley) 9/23/93"; 43#endif /* not lint */ 44#endif 45#include <sys/cdefs.h> |
46__FBSDID("$FreeBSD: head/usr.bin/gcore/gcore.c 125859 2004-02-15 22:48:25Z dwmalone $"); | 46__FBSDID("$FreeBSD: head/usr.bin/gcore/gcore.c 199805 2009-11-25 15:23:14Z attilio $"); |
47 48/* 49 * Originally written by Eric Cooper in Fall 1981. 50 * Inspired by a version 6 program by Len Levin, 1978. 51 * Several pieces of code lifted from Bill Joy's 4BSD ps. 52 * Most recently, hacked beyond recognition for 4.4BSD by Steven McCanne, 53 * Lawrence Berkeley Laboratory. 54 * 55 * Portions of this software were developed by the Computer Systems 56 * Engineering group at Lawrence Berkeley Laboratory under DARPA 57 * contract BG 91-66 and contributed to Berkeley. 58 */ 59 60#include <sys/param.h> 61#include <sys/time.h> 62#include <sys/stat.h> 63#include <sys/linker_set.h> | 47 48/* 49 * Originally written by Eric Cooper in Fall 1981. 50 * Inspired by a version 6 program by Len Levin, 1978. 51 * Several pieces of code lifted from Bill Joy's 4BSD ps. 52 * Most recently, hacked beyond recognition for 4.4BSD by Steven McCanne, 53 * Lawrence Berkeley Laboratory. 54 * 55 * Portions of this software were developed by the Computer Systems 56 * Engineering group at Lawrence Berkeley Laboratory under DARPA 57 * contract BG 91-66 and contributed to Berkeley. 58 */ 59 60#include <sys/param.h> 61#include <sys/time.h> 62#include <sys/stat.h> 63#include <sys/linker_set.h> |
64#include <sys/sysctl.h> |
|
64 65#include <err.h> 66#include <fcntl.h> 67#include <signal.h> 68#include <stdio.h> 69#include <stdlib.h> 70#include <string.h> 71#include <unistd.h> --- 6 unchanged lines hidden (view full) --- 78 79static pid_t pid; 80 81SET_DECLARE(dumpset, struct dumpers); 82 83int 84main(int argc, char *argv[]) 85{ | 65 66#include <err.h> 67#include <fcntl.h> 68#include <signal.h> 69#include <stdio.h> 70#include <stdlib.h> 71#include <string.h> 72#include <unistd.h> --- 6 unchanged lines hidden (view full) --- 79 80static pid_t pid; 81 82SET_DECLARE(dumpset, struct dumpers); 83 84int 85main(int argc, char *argv[]) 86{ |
86 int ch, efd, fd, sflag; | 87 int ch, efd, fd, name[4], sflag; |
87 char *binfile, *corefile; | 88 char *binfile, *corefile; |
88 char fname[MAXPATHLEN]; | 89 char passpath[MAXPATHLEN], fname[MAXPATHLEN]; |
89 struct dumpers **d, *dumper; | 90 struct dumpers **d, *dumper; |
91 size_t len; |
|
90 91 sflag = 0; 92 corefile = NULL; 93 while ((ch = getopt(argc, argv, "c:s")) != -1) { 94 switch (ch) { 95 case 'c': 96 corefile = optarg; 97 break; --- 6 unchanged lines hidden (view full) --- 104 } 105 } 106 argv += optind; 107 argc -= optind; 108 /* XXX we should check that the pid argument is really a number */ 109 switch (argc) { 110 case 1: 111 pid = atoi(argv[0]); | 92 93 sflag = 0; 94 corefile = NULL; 95 while ((ch = getopt(argc, argv, "c:s")) != -1) { 96 switch (ch) { 97 case 'c': 98 corefile = optarg; 99 break; --- 6 unchanged lines hidden (view full) --- 106 } 107 } 108 argv += optind; 109 argc -= optind; 110 /* XXX we should check that the pid argument is really a number */ 111 switch (argc) { 112 case 1: 113 pid = atoi(argv[0]); |
112 asprintf(&binfile, "/proc/%d/file", pid); 113 if (binfile == NULL) 114 errx(1, "allocation failure"); | 114 name[0] = CTL_KERN; 115 name[1] = KERN_PROC; 116 name[2] = KERN_PROC_PATHNAME; 117 name[3] = pid; 118 len = sizeof(passpath); 119 if (sysctl(name, 4, passpath, &len, NULL, 0) == -1) 120 errx(1, "kern.proc.pathname failure"); 121 binfile = passpath; |
115 break; 116 case 2: 117 pid = atoi(argv[1]); 118 binfile = argv[0]; 119 break; 120 default: 121 usage(); 122 } --- 58 unchanged lines hidden --- | 122 break; 123 case 2: 124 pid = atoi(argv[1]); 125 binfile = argv[0]; 126 break; 127 default: 128 usage(); 129 } --- 58 unchanged lines hidden --- |