summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcharnier <charnier@FreeBSD.org>1997-07-08 11:04:19 +0000
committercharnier <charnier@FreeBSD.org>1997-07-08 11:04:19 +0000
commit0b74b1044e108ab2d7b26b257d5ae8bea1acad6e (patch)
treece9ebd7fd0c4991e5bb37dbd7f183b99a60b5806
parent47dc77937cfa740b63f95820f027e412b270f1fa (diff)
downloadFreeBSD-src-0b74b1044e108ab2d7b26b257d5ae8bea1acad6e.zip
FreeBSD-src-0b74b1044e108ab2d7b26b257d5ae8bea1acad6e.tar.gz
Use err(3) instead of local redefinition.
-rw-r--r--usr.bin/gcore/aoutcore.c70
-rw-r--r--usr.bin/gcore/gcore.18
-rw-r--r--usr.bin/gcore/gcore.c70
-rw-r--r--usr.bin/gcore/md-nop.c4
-rw-r--r--usr.bin/gcore/md-sparc.c21
5 files changed, 64 insertions, 109 deletions
diff --git a/usr.bin/gcore/aoutcore.c b/usr.bin/gcore/aoutcore.c
index 7ecbe1c..a40feff 100644
--- a/usr.bin/gcore/aoutcore.c
+++ b/usr.bin/gcore/aoutcore.c
@@ -32,13 +32,17 @@
*/
#ifndef lint
-static char copyright[] =
+static const char copyright[] =
"@(#) Copyright (c) 1992, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
+#if 0
static char sccsid[] = "@(#)gcore.c 8.2 (Berkeley) 9/23/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* not lint */
/*
@@ -62,6 +66,7 @@ static char sccsid[] = "@(#)gcore.c 8.2 (Berkeley) 9/23/93";
#include <machine/vmparam.h>
#include <a.out.h>
+#include <err.h>
#include <fcntl.h>
#include <kvm.h>
#include <limits.h>
@@ -119,26 +124,26 @@ main(argc, argv)
kd = kvm_openfiles(0, 0, 0, O_RDONLY, errbuf);
if (kd == NULL)
- err(1, "%s", errbuf);
+ errx(1, "%s", errbuf);
uid = getuid();
pid = atoi(argv[1]);
ki = kvm_getprocs(kd, KERN_PROC_PID, pid, &cnt);
if (ki == NULL || cnt != 1)
- err(1, "%d: not found", pid);
+ errx(1, "%d: not found", pid);
p = &ki->kp_proc;
if (ki->kp_eproc.e_pcred.p_ruid != uid && uid != 0)
- err(1, "%d: not owner", pid);
+ errx(1, "%d: not owner", pid);
if (p->p_stat == SZOMB)
- err(1, "%d: zombie", pid);
+ errx(1, "%d: zombie", pid);
if (p->p_flag & P_WEXIT)
- err(0, "process exiting");
+ errx(1, "process exiting");
if (p->p_flag & P_SYSTEM) /* Swapper or pagedaemon. */
- err(1, "%d: system process");
+ errx(1, "%d: system process");
if (corefile == NULL) {
(void)snprintf(fname, sizeof(fname), "core.%d", pid);
@@ -146,26 +151,26 @@ main(argc, argv)
}
fd = open(corefile, O_RDWR|O_CREAT|O_TRUNC, DEFFILEMODE);
if (fd < 0)
- err(1, "%s: %s\n", corefile, strerror(errno));
+ err(1, "%s", corefile);
efd = open(argv[0], O_RDONLY, 0);
if (efd < 0)
- err(1, "%s: %s\n", argv[0], strerror(errno));
+ err(1, "%s", argv[0]);
cnt = read(efd, &exec, sizeof(exec));
if (cnt != sizeof(exec))
- err(1, "%s exec header: %s",
+ errx(1, "%s exec header: %s",
argv[0], cnt > 0 ? strerror(EIO) : strerror(errno));
data_offset = N_DATOFF(exec);
if (sflag && kill(pid, SIGSTOP) < 0)
- err(0, "%d: stop signal: %s", pid, strerror(errno));
+ err(1, "%d: stop signal", pid);
core(efd, fd, ki);
if (sflag && kill(pid, SIGCONT) < 0)
- err(0, "%d: continue signal: %s", pid, strerror(errno));
+ err(1, "%d: continue signal", pid);
(void)close(fd);
exit(0);
@@ -194,7 +199,7 @@ core(efd, fd, ki)
/* Read in user struct */
cnt = kvm_read(kd, (u_long)p->p_addr, &uarea, sizeof(uarea));
if (cnt != sizeof(uarea))
- err(1, "read user structure: %s",
+ errx(1, "read user structure: %s",
cnt > 0 ? strerror(EIO) : strerror(errno));
/*
@@ -206,7 +211,7 @@ core(efd, fd, ki)
/* Dump user area */
cnt = write(fd, &uarea, sizeof(uarea));
if (cnt != sizeof(uarea))
- err(1, "write user structure: %s",
+ errx(1, "write user structure: %s",
cnt > 0 ? strerror(EIO) : strerror(errno));
/* Dump data segment */
@@ -240,14 +245,13 @@ datadump(efd, fd, p, addr, npage)
cc = read(efd, buffer, sizeof(buffer));
if (cc != sizeof(buffer))
if (cc < 0)
- err(1, "read executable: %s",
- strerror(errno));
+ err(1, "read executable");
else /* Assume untouched bss page. */
bzero(buffer, sizeof(buffer));
}
cc = write(fd, buffer, PAGE_SIZE);
if (cc != PAGE_SIZE)
- err(1, "write data segment: %s",
+ errx(1, "write data segment: %s",
cc > 0 ? strerror(EIO) : strerror(errno));
addr += PAGE_SIZE;
}
@@ -270,7 +274,7 @@ userdump(fd, p, addr, npage)
bzero(buffer, PAGE_SIZE);
cc = write(fd, buffer, PAGE_SIZE);
if (cc != PAGE_SIZE)
- err(1, "write stack segment: %s",
+ errx(1, "write stack segment: %s",
cc > 0 ? strerror(EIO) : strerror(errno));
addr += PAGE_SIZE;
}
@@ -282,33 +286,3 @@ usage()
(void)fprintf(stderr, "usage: gcore [-s] [-c core] executable pid\n");
exit(1);
}
-
-#if __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
-
-void
-#if __STDC__
-err(int fatal, const char *fmt, ...)
-#else
-err(fatal, fmt, va_alist)
- int fatal;
- char *fmt;
- va_dcl
-#endif
-{
- va_list ap;
-#if __STDC__
- va_start(ap, fmt);
-#else
- va_start(ap);
-#endif
- (void)fprintf(stderr, "gcore: ");
- (void)vfprintf(stderr, fmt, ap);
- va_end(ap);
- (void)fprintf(stderr, "\n");
- exit(1);
- /* NOTREACHED */
-}
diff --git a/usr.bin/gcore/gcore.1 b/usr.bin/gcore/gcore.1
index ce8fc68..2e1d5f6 100644
--- a/usr.bin/gcore/gcore.1
+++ b/usr.bin/gcore/gcore.1
@@ -38,7 +38,7 @@
.Nm gcore
.Nd get core images of running process
.Sh SYNOPSIS
-.Nm gcore
+.Nm
.Op Fl s
.Op Fl c Ar core
.Ar exec pid
@@ -80,9 +80,11 @@ appeared in
.Bx 4.2 .
.Sh BUGS
Context switches or paging activity that occur while
-.Nm gcore
+.Nm
is running may cause the program to become confused.
-For best results, use -s to temporarily stop the target process.
+For best results, use
+.Fl s
+to temporarily stop the target process.
.Pp
.Nm Gcore
is not compatible with the original
diff --git a/usr.bin/gcore/gcore.c b/usr.bin/gcore/gcore.c
index 7ecbe1c..a40feff 100644
--- a/usr.bin/gcore/gcore.c
+++ b/usr.bin/gcore/gcore.c
@@ -32,13 +32,17 @@
*/
#ifndef lint
-static char copyright[] =
+static const char copyright[] =
"@(#) Copyright (c) 1992, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
+#if 0
static char sccsid[] = "@(#)gcore.c 8.2 (Berkeley) 9/23/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* not lint */
/*
@@ -62,6 +66,7 @@ static char sccsid[] = "@(#)gcore.c 8.2 (Berkeley) 9/23/93";
#include <machine/vmparam.h>
#include <a.out.h>
+#include <err.h>
#include <fcntl.h>
#include <kvm.h>
#include <limits.h>
@@ -119,26 +124,26 @@ main(argc, argv)
kd = kvm_openfiles(0, 0, 0, O_RDONLY, errbuf);
if (kd == NULL)
- err(1, "%s", errbuf);
+ errx(1, "%s", errbuf);
uid = getuid();
pid = atoi(argv[1]);
ki = kvm_getprocs(kd, KERN_PROC_PID, pid, &cnt);
if (ki == NULL || cnt != 1)
- err(1, "%d: not found", pid);
+ errx(1, "%d: not found", pid);
p = &ki->kp_proc;
if (ki->kp_eproc.e_pcred.p_ruid != uid && uid != 0)
- err(1, "%d: not owner", pid);
+ errx(1, "%d: not owner", pid);
if (p->p_stat == SZOMB)
- err(1, "%d: zombie", pid);
+ errx(1, "%d: zombie", pid);
if (p->p_flag & P_WEXIT)
- err(0, "process exiting");
+ errx(1, "process exiting");
if (p->p_flag & P_SYSTEM) /* Swapper or pagedaemon. */
- err(1, "%d: system process");
+ errx(1, "%d: system process");
if (corefile == NULL) {
(void)snprintf(fname, sizeof(fname), "core.%d", pid);
@@ -146,26 +151,26 @@ main(argc, argv)
}
fd = open(corefile, O_RDWR|O_CREAT|O_TRUNC, DEFFILEMODE);
if (fd < 0)
- err(1, "%s: %s\n", corefile, strerror(errno));
+ err(1, "%s", corefile);
efd = open(argv[0], O_RDONLY, 0);
if (efd < 0)
- err(1, "%s: %s\n", argv[0], strerror(errno));
+ err(1, "%s", argv[0]);
cnt = read(efd, &exec, sizeof(exec));
if (cnt != sizeof(exec))
- err(1, "%s exec header: %s",
+ errx(1, "%s exec header: %s",
argv[0], cnt > 0 ? strerror(EIO) : strerror(errno));
data_offset = N_DATOFF(exec);
if (sflag && kill(pid, SIGSTOP) < 0)
- err(0, "%d: stop signal: %s", pid, strerror(errno));
+ err(1, "%d: stop signal", pid);
core(efd, fd, ki);
if (sflag && kill(pid, SIGCONT) < 0)
- err(0, "%d: continue signal: %s", pid, strerror(errno));
+ err(1, "%d: continue signal", pid);
(void)close(fd);
exit(0);
@@ -194,7 +199,7 @@ core(efd, fd, ki)
/* Read in user struct */
cnt = kvm_read(kd, (u_long)p->p_addr, &uarea, sizeof(uarea));
if (cnt != sizeof(uarea))
- err(1, "read user structure: %s",
+ errx(1, "read user structure: %s",
cnt > 0 ? strerror(EIO) : strerror(errno));
/*
@@ -206,7 +211,7 @@ core(efd, fd, ki)
/* Dump user area */
cnt = write(fd, &uarea, sizeof(uarea));
if (cnt != sizeof(uarea))
- err(1, "write user structure: %s",
+ errx(1, "write user structure: %s",
cnt > 0 ? strerror(EIO) : strerror(errno));
/* Dump data segment */
@@ -240,14 +245,13 @@ datadump(efd, fd, p, addr, npage)
cc = read(efd, buffer, sizeof(buffer));
if (cc != sizeof(buffer))
if (cc < 0)
- err(1, "read executable: %s",
- strerror(errno));
+ err(1, "read executable");
else /* Assume untouched bss page. */
bzero(buffer, sizeof(buffer));
}
cc = write(fd, buffer, PAGE_SIZE);
if (cc != PAGE_SIZE)
- err(1, "write data segment: %s",
+ errx(1, "write data segment: %s",
cc > 0 ? strerror(EIO) : strerror(errno));
addr += PAGE_SIZE;
}
@@ -270,7 +274,7 @@ userdump(fd, p, addr, npage)
bzero(buffer, PAGE_SIZE);
cc = write(fd, buffer, PAGE_SIZE);
if (cc != PAGE_SIZE)
- err(1, "write stack segment: %s",
+ errx(1, "write stack segment: %s",
cc > 0 ? strerror(EIO) : strerror(errno));
addr += PAGE_SIZE;
}
@@ -282,33 +286,3 @@ usage()
(void)fprintf(stderr, "usage: gcore [-s] [-c core] executable pid\n");
exit(1);
}
-
-#if __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
-
-void
-#if __STDC__
-err(int fatal, const char *fmt, ...)
-#else
-err(fatal, fmt, va_alist)
- int fatal;
- char *fmt;
- va_dcl
-#endif
-{
- va_list ap;
-#if __STDC__
- va_start(ap, fmt);
-#else
- va_start(ap);
-#endif
- (void)fprintf(stderr, "gcore: ");
- (void)vfprintf(stderr, fmt, ap);
- va_end(ap);
- (void)fprintf(stderr, "\n");
- exit(1);
- /* NOTREACHED */
-}
diff --git a/usr.bin/gcore/md-nop.c b/usr.bin/gcore/md-nop.c
index 46e90c4..b7dcdc4 100644
--- a/usr.bin/gcore/md-nop.c
+++ b/usr.bin/gcore/md-nop.c
@@ -32,7 +32,11 @@
*/
#ifndef lint
+#if 0
static char sccsid[] = "@(#)md-nop.c 8.1 (Berkeley) 6/6/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* not lint */
#include <sys/param.h>
diff --git a/usr.bin/gcore/md-sparc.c b/usr.bin/gcore/md-sparc.c
index 5df8a57..1557fb5 100644
--- a/usr.bin/gcore/md-sparc.c
+++ b/usr.bin/gcore/md-sparc.c
@@ -48,6 +48,7 @@ static char sccsid[] = "@(#)md-sparc.c 8.1 (Berkeley) 6/6/93";
#include <sys/sysctl.h>
#include <machine/vmparam.h>
+#include <err.h>
#include <kvm.h>
#include <unistd.h>
#include <stdio.h>
@@ -101,10 +102,10 @@ md_core(kd, fd, ki)
/* XXX */
(void *)&tf, sizeof(tf));
if (cc < 0)
- err(1, "kvm_read: %s (reading kernel trapframe)",
+ errx(1, "kvm_read: %s (reading kernel trapframe)",
kvm_geterr(kd));
if (cc != sizeof(tf))
- err(1, "cannot read kernel trapframe");
+ errx(1, "cannot read kernel trapframe");
/*
* Write out the real trap frame.
@@ -112,7 +113,7 @@ md_core(kd, fd, ki)
off = offsetof(struct user, u_md);
off += offsetof(struct md_coredump, md_tf);
if (lseek(fd, off, SEEK_SET) == -1)
- err(1, "lseek: %s", strerror(errno));
+ err(1, "lseek");
(void)write(fd, &tf, sizeof(tf));
if (ki->kp_proc.p_md.md_fpstate != 0) {
@@ -124,21 +125,21 @@ md_core(kd, fd, ki)
cc = kvm_read(kd, (u_long)ki->kp_proc.p_md.md_fpstate,
(void *)&fs, sizeof(fs));
if (cc < 0)
- err(1, "kvm_read: %s (fpu state)", kvm_geterr(kd));
+ errx(1, "kvm_read: %s (fpu state)", kvm_geterr(kd));
if (cc != sizeof(fs))
- err(1, "cannot read fpu state");
+ errx(1, "cannot read fpu state");
(void)write(fd, (char *)&fs, sizeof(fs));
}
/*
* Read pcb.
*/
if (lseek(fd, (off_t)offsetof(struct user, u_pcb), SEEK_SET) == -1)
- err(1, "lseek: %s", strerror(errno));
+ err(1, "lseek");
cc = read(fd, (char *)&pcb, sizeof(pcb));
if (cc != sizeof(pcb)) {
if (cc < 0)
- err(1, "read: %s", strerror(errno));
- err(1, "couldn't read pcb from core file");
+ err(1, "read");
+ errx(1, "couldn't read pcb from core file");
}
/*
@@ -159,7 +160,7 @@ md_core(kd, fd, ki)
s = ssize - (USRSTACK - sp);
if (s < 0) {
if (s < -NBPG)
- err(1, "cannot copy pcb windows to stack");
+ errx(1, "cannot copy pcb windows to stack");
/*
* It's possible to be missing the bottomost
* page because a stack page hasn't been allocated
@@ -178,7 +179,7 @@ md_core(kd, fd, ki)
&ki->kp_eproc.e_vm, sizeof(ki->kp_eproc.e_vm));
}
if (lseek(fd, off + s, SEEK_SET) == -1)
- err(1, "cannot copy pcb windows to stack");
+ errx(1, "cannot copy pcb windows to stack");
(void)write(fd, rw, sizeof(*rw));
sp = rw->rw_in[6];
OpenPOWER on IntegriCloud