From owner-freebsd-bugs Sat Dec 25 11:50:13 1999 Delivered-To: freebsd-bugs@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (Postfix) with ESMTP id C206D1510D for ; Sat, 25 Dec 1999 11:50:07 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.3/8.9.2) id LAA29725; Sat, 25 Dec 1999 11:50:06 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: from hunahpu.sics.se (hunahpu.sics.se [193.10.66.220]) by hub.freebsd.org (Postfix) with ESMTP id C1B6A14EB7 for ; Sat, 25 Dec 1999 11:40:48 -0800 (PST) (envelope-from root@hunahpu.sics.se) Received: (from root@localhost) by hunahpu.sics.se (8.9.3/8.9.3) id UAA00692; Sat, 25 Dec 1999 20:40:48 +0100 (CET) (envelope-from root) Message-Id: <199912251940.UAA00692@hunahpu.sics.se> Date: Sat, 25 Dec 1999 20:40:48 +0100 (CET) From: assar@sics.se To: FreeBSD-gnats-submit@freebsd.org Cc: assar@sics.se X-Send-Pr-Version: 3.2 Subject: kern/15690: savecore fails to work when it doesn't find the block-device Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org >Number: 15690 >Category: kern >Synopsis: savecore fails to work when it doesn't find the block-device >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sat Dec 25 11:50:00 PST 1999 >Closed-Date: >Last-Modified: >Originator: Assar Westerlund >Release: FreeBSD 4.0-19991225-CURRENT i386 >Organization: none >Environment: -current on i386 >Description: savecore tries to open the raw device with a fallback to the block device but this is done wrong and it ends up closing the block device that's used later. Dec 25 19:59:02 hunahpu savecore: /dev/rrad0s1b: No such file or directory; using block device but since we don't have any block devices anymore we might just remove that fallback. >How-To-Repeat: crash and run savecore >Fix: Index: savecore.c =================================================================== RCS file: /home/ncvs/src/sbin/savecore/savecore.c,v retrieving revision 1.28 diff -u -w -r1.28 savecore.c --- savecore.c 1999/12/21 07:41:07 1.28 +++ savecore.c 1999/12/25 19:36:31 @@ -134,7 +134,6 @@ void Lseek __P((int, off_t, int)); int Open __P((const char *, int rw)); int Read __P((int, void *, int)); -char *rawname __P((char *s)); void save_core __P((void)); void usage __P((void)); void Write __P((int, void *, int)); @@ -340,7 +339,7 @@ { register FILE *fp; register int bounds, ifd, nr, nw, ofd; - char *rawp, path[MAXPATHLEN]; + char path[MAXPATHLEN]; mode_t oumask; /* @@ -379,15 +378,8 @@ ofd = Create(path, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); (void)umask(oumask); - /* Open the raw device. */ - rawp = rawname(ddname); - if ((ifd = open(rawp, O_RDONLY)) == -1) { - syslog(LOG_WARNING, "%s: %m; using block device", rawp); - ifd = dumpfd; - } - /* Seek to the start of the core. */ - Lseek(ifd, (off_t)dumplo, L_SET); + Lseek(dumpfd, (off_t)dumplo, L_SET); /* Copy the core file. */ syslog(LOG_NOTICE, "writing %score to %s", @@ -395,13 +387,13 @@ for (; dumpsize > 0; dumpsize -= nr) { (void)printf("%6dK\r", dumpsize / 1024); (void)fflush(stdout); - nr = read(ifd, buf, MIN(dumpsize, sizeof(buf))); + nr = read(dumpfd, buf, MIN(dumpsize, sizeof(buf))); if (nr <= 0) { if (nr == 0) syslog(LOG_WARNING, "WARNING: EOF on dump device"); else - syslog(LOG_ERR, "%s: %m", rawp); + syslog(LOG_ERR, "%s: %m", ddname); goto err2; } if (compress) @@ -417,7 +409,6 @@ exit(1); } } - (void)close(ifd); if (compress) (void)fclose(fp); else @@ -497,25 +488,6 @@ closedir(dfd); syslog(LOG_ERR, "can't find device %d/%d", major(dev), minor(dev)); exit(1); -} - -char * -rawname(s) - char *s; -{ - char *sl, name[MAXPATHLEN]; - - if ((sl = rindex(s, '/')) == NULL || sl[1] == '0') { - syslog(LOG_ERR, - "can't make raw dump device name from %s", s); - return (s); - } - snprintf(name, sizeof(name), "%.*s/r%s", (int)(sl - s), s, sl + 1); - if ((sl = strdup(name)) == NULL) { - syslog(LOG_ERR, "%s", strerror(errno)); - exit(1); - } - return (sl); } int and if this isn't the right way we should at least avoid closing the file, with this patch: Index: savecore.c =================================================================== RCS file: /home/ncvs/src/sbin/savecore/savecore.c,v retrieving revision 1.28 diff -u -w -u -w -r1.28 savecore.c --- savecore.c 1999/12/21 07:41:07 1.28 +++ savecore.c 1999/12/25 19:37:04 @@ -383,7 +383,7 @@ rawp = rawname(ddname); if ((ifd = open(rawp, O_RDONLY)) == -1) { syslog(LOG_WARNING, "%s: %m; using block device", rawp); - ifd = dumpfd; + ifd = dup(dumpfd); } /* Seek to the start of the core. */ >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message