Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 27 Aug 1998 16:09:51 +0200
From:      Wolfram Schneider <wosch@panke.de.freebsd.org>
To:        joelh@gnu.org, thyerm@camtech.net.au
Cc:        wosch@panke.de.freebsd.org, current@FreeBSD.ORG
Subject:   Re: file segment sizes of a core dump
Message-ID:  <19980827160951.A3164@panke.de>
In-Reply-To: <199808262253.RAA03247@detlev.UUCP>; from Joel Ray Holveck on Wed, Aug 26, 1998 at 05:53:23PM -0500
References:  <199808231906.VAA04727@campa.panke.de> <35E18FF5.B7FADA7B@camtech.net.au> <19980824193728.B4111@panke.de> <199808251931.OAA00986@detlev.UUCP> <35E40C49.C673670C@camtech.net.au> <199808262253.RAA03247@detlev.UUCP>

next in thread | previous in thread | raw e-mail | index | archive | help
On 1998-08-26 17:53:23 -0500, Joel Ray Holveck wrote:
> I accept GIGO as a fact of life.  I would vote against needing the
> switch.  That's all I have to say on the topic.

I have now a version without the switch. size(1) checks now
a value of the user structure (number of groups). If
the values seems correct size(1) assume it is a core file.
  
Index: size.c
===================================================================
RCS file: /usr/cvs/src/usr.bin/size/size.c,v
retrieving revision 1.4
diff -u -r1.4 size.c
--- size.c	1998/07/06 21:01:32	1.4
+++ size.c	1998/08/27 12:43:08
@@ -47,6 +47,9 @@
 
 #include <sys/param.h>
 #include <sys/file.h>
+#include <sys/types.h>
+#include <sys/user.h>
+#include <sys/stat.h>
 #include <err.h>
 #include <a.out.h>
 #include <unistd.h>
@@ -66,7 +69,6 @@
 
 	while ((ch = getopt(argc, argv, "")) != -1)
 		switch(ch) {
-		case '?':
 		default:
 			usage();
 		}
@@ -90,29 +92,63 @@
 {
 	static int first = 1;
 	struct exec head;
+	struct user user;
+	struct stat stat;
 	u_long total;
 	int fd;
+	int coredump = 0;
 
 	if ((fd = open(name, O_RDONLY, 0)) < 0) {
 		warn("%s", name);
 		return (1);
 	}
-	if (read(fd, &head, sizeof(head)) != sizeof(head) || N_BADMAG(head)) {
-		(void)close(fd);
+	
+	if (read(fd, &head, sizeof(head)) != sizeof(head)) {
 		warnx("%s: not in a.out format", name);
+		(void)close(fd);
 		return (1);
 	}
+
+	/* if not a.out try coredump format */
+	if (N_BADMAG(head)) {
+		if (lseek(fd, (off_t)0, SEEK_SET) != -1 &&
+		    read(fd, &user, sizeof(user)) == sizeof(user) &&
+		    fstat(fd, &stat) != -1 &&
+		    stat.st_size >= 
+		         ptoa(UPAGES + user.u_dsize + user.u_ssize) &&
+		    user.u_kproc.kp_eproc.e_ucred.cr_ngroups <= NGROUPS_MAX &&
+		    user.u_kproc.kp_eproc.e_ucred.cr_ngroups > 0) {
+			coredump = 1;
+		} else {
+			warnx("%s: not in a.out or core format", name);
+			(void)close(fd);
+			return (1);
+		}
+	}
 	(void)close(fd);
 
 	if (first) {
 		first = 0;
 		(void)printf("text\tdata\tbss\tdec\thex\n");
+	}
+
+	if (!coredump) {
+		total = head.a_text + head.a_data + head.a_bss;
+		(void)printf("%lu\t%lu\t%lu\t%lu\t%lx", (u_long)head.a_text,
+		     (u_long)head.a_data, (u_long)head.a_bss, total, total);
+	} else {
+		total = ptoa(user.u_tsize) + ptoa(user.u_dsize) + 
+			ptoa(user.u_ssize);
+		(void)printf("%lu\t%lu\t%lu\t%lu\t%lx", 
+			     (u_long)ptoa(user.u_tsize), 
+			     (u_long)ptoa(user.u_dsize), 
+			     (u_long)ptoa(user.u_ssize), total, total);
 	}
-	total = head.a_text + head.a_data + head.a_bss;
-	(void)printf("%lu\t%lu\t%lu\t%lu\t%lx", (u_long)head.a_text,
-	    (u_long)head.a_data, (u_long)head.a_bss, total, total);
-	if (count > 1)
+
+	if (count > 1 || coredump)
 		(void)printf("\t%s", name);
+	if (coredump)
+		printf(" [coredump]");
 	(void)printf("\n");
 	return (0);
 }
-- 
Wolfram Schneider <wosch@freebsd.org> http://www.freebsd.org/~w/

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19980827160951.A3164>