From owner-freebsd-current Thu Aug 27 08:04:57 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id IAA22471 for freebsd-current-outgoing; Thu, 27 Aug 1998 08:04:57 -0700 (PDT) (envelope-from owner-freebsd-current@FreeBSD.ORG) Received: from baerenklau.de.freebsd.org (baerenklau.de.freebsd.org [195.185.195.14]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id IAA22459 for ; Thu, 27 Aug 1998 08:04:53 -0700 (PDT) (envelope-from wosch@panke.de.freebsd.org) Received: (from uucp@localhost) by baerenklau.de.freebsd.org (8.8.8/8.8.8) with UUCP id RAA07884; Thu, 27 Aug 1998 17:03:45 +0200 (CEST) (envelope-from wosch@panke.de.freebsd.org) Received: (from wosch@localhost) by campa.panke.de (8.8.8/8.8.8) id QAA03183; Thu, 27 Aug 1998 16:09:53 +0200 (MET DST) (envelope-from wosch) Message-ID: <19980827160951.A3164@panke.de> Date: Thu, 27 Aug 1998 16:09:51 +0200 From: Wolfram Schneider 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 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> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.93.1i In-Reply-To: <199808262253.RAA03247@detlev.UUCP>; from Joel Ray Holveck on Wed, Aug 26, 1998 at 05:53:23PM -0500 Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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 #include +#include +#include +#include #include #include #include @@ -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 http://www.freebsd.org/~w/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message