From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1JOb8J-0006zQ-4j for mharc-grub-devel@gnu.org; Mon, 11 Feb 2008 11:03:51 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JOb8H-0006wu-Mk for grub-devel@gnu.org; Mon, 11 Feb 2008 11:03:49 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JOb8G-0006wZ-8y for grub-devel@gnu.org; Mon, 11 Feb 2008 11:03:48 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JOb8G-0006wW-3C for grub-devel@gnu.org; Mon, 11 Feb 2008 11:03:48 -0500 Received: from aybabtu.com ([69.60.117.155]) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1JOb8F-0003Ct-Ft for grub-devel@gnu.org; Mon, 11 Feb 2008 11:03:47 -0500 Received: from [192.168.10.6] (helo=thorin) by aybabtu.com with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.63) (envelope-from ) id 1JOb89-0006SV-Up for grub-devel@gnu.org; Mon, 11 Feb 2008 17:03:46 +0100 Received: from rmh by thorin with local (Exim 4.63) (envelope-from ) id 1JOb6O-0001wZ-J0 for grub-devel@gnu.org; Mon, 11 Feb 2008 17:01:52 +0100 Date: Mon, 11 Feb 2008 17:01:52 +0100 From: Robert Millan To: grub-devel@gnu.org Message-ID: <20080211160152.GA7448@thorin> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="EVF5PPMfhYS0aIcm" Content-Disposition: inline Content-Transfer-Encoding: 8bit Organization: free as in freedom X-Message-Flag: Worried about Outlook viruses? Switch to Thunderbird! www.mozilla.com/thunderbird X-Debbugs-No-Ack: true User-Agent: Mutt/1.5.13 (2006-08-11) X-detected-kernel: by monty-python.gnu.org: Genre and OS details not recognized. Subject: [PATCH] improve error handling in util/ X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Feb 2008 16:03:49 -0000 --EVF5PPMfhYS0aIcm Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit This improves error handling notably in util/. For example, from: $ ./grub-probe -t fs / grub-probe: error: cannot find a GRUB drive for /dev/sda1. to: $ ./grub-probe -t fs / error: cannot open `/dev/sda1' (Permission denied) grub-probe: error: cannot find a GRUB drive for /dev/sda1. -- Robert Millan I know my rights; I want my phone call! What use is a phone call… if you are unable to speak? (as seen on /.) --EVF5PPMfhYS0aIcm Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="error.diff" 2008-02-11 Robert Millan * util/biosdisk.c (grub_util_biosdisk_open, open_device) (grub_util_biosdisk_read, grub_util_biosdisk_write) (grub_util_biosdisk_get_grub_dev): When issuing grub_error() calls, include `strerror (errno)' information in the message string. * util/misc.c (grub_util_error): Invoke grub_print_error() before printing the caller-provided string. diff -x configure -x config.h.in -x CVS -x '*~' -x '*.mk' -urp ../grub2/util/biosdisk.c ./util/biosdisk.c --- ../grub2/util/biosdisk.c 2008-02-11 16:48:18.000000000 +0100 +++ ./util/biosdisk.c 2008-02-11 16:49:36.000000000 +0100 @@ -168,7 +168,7 @@ grub_util_biosdisk_open (const char *nam fd = open (map[drive], O_RDONLY); if (fd == -1) - return grub_error (GRUB_ERR_BAD_DEVICE, "cannot open `%s'", map[drive]); + return grub_error (GRUB_ERR_BAD_DEVICE, "cannot open `%s' (%s)", map[drive], strerror (errno)); if (fstat (fd, &st) < 0 || ! S_ISBLK (st.st_mode)) { @@ -199,7 +199,7 @@ grub_util_biosdisk_open (const char *nam # warning "No special routine to get the size of a block device is implemented for your OS. This is not possibly fatal." #endif if (stat (map[drive], &st) < 0) - return grub_error (GRUB_ERR_BAD_DEVICE, "cannot stat `%s'", map[drive]); + return grub_error (GRUB_ERR_BAD_DEVICE, "cannot stat `%s' (%s)", map[drive], strerror (errno)); disk->total_sectors = st.st_size >> GRUB_DISK_SECTOR_BITS; @@ -307,7 +307,7 @@ open_device (const grub_disk_t disk, gru fd = open (dev, flags); if (fd < 0) { - grub_error (GRUB_ERR_BAD_DEVICE, "cannot open `%s'", dev); + grub_error (GRUB_ERR_BAD_DEVICE, "cannot open `%s' (%s)", dev, strerror (errno)); return -1; } @@ -321,7 +321,7 @@ open_device (const grub_disk_t disk, gru fd = open (map[disk->id], flags); if (fd < 0) { - grub_error (GRUB_ERR_BAD_DEVICE, "cannot open `%s'", map[disk->id]); + grub_error (GRUB_ERR_BAD_DEVICE, "cannot open `%s' (%s)", map[disk->id], strerror (errno)); return -1; } #endif /* ! __linux__ */ @@ -339,7 +339,7 @@ open_device (const grub_disk_t disk, gru offset = (loff_t) sector << GRUB_DISK_SECTOR_BITS; if (_llseek (fd, offset >> 32, offset & 0xffffffff, &result, SEEK_SET)) { - grub_error (GRUB_ERR_BAD_DEVICE, "cannot seek `%s'", map[disk->id]); + grub_error (GRUB_ERR_BAD_DEVICE, "cannot seek `%s' (%s)", map[disk->id], strerror (errno)); close (fd); return -1; } @@ -350,7 +350,7 @@ open_device (const grub_disk_t disk, gru if (lseek (fd, offset, SEEK_SET) != offset) { - grub_error (GRUB_ERR_BAD_DEVICE, "cannot seek `%s'", map[disk->id]); + grub_error (GRUB_ERR_BAD_DEVICE, "cannot seek `%s' (%s)", map[disk->id], strerror (errno)); close (fd); return -1; } @@ -431,7 +431,7 @@ grub_util_biosdisk_read (grub_disk_t dis parts. -jochen */ if (nread (fd, buf, GRUB_DISK_SECTOR_SIZE) != GRUB_DISK_SECTOR_SIZE) { - grub_error (GRUB_ERR_READ_ERROR, "cannot read `%s'", map[disk->id]); + grub_error (GRUB_ERR_READ_ERROR, "cannot read `%s' (%s)", map[disk->id], strerror (errno)); close (fd); return grub_errno; } @@ -443,7 +443,7 @@ grub_util_biosdisk_read (grub_disk_t dis if (nread (fd, buf, size << GRUB_DISK_SECTOR_BITS) != (ssize_t) (size << GRUB_DISK_SECTOR_BITS)) - grub_error (GRUB_ERR_READ_ERROR, "cannot read from `%s'", map[disk->id]); + grub_error (GRUB_ERR_READ_ERROR, "cannot read from `%s' (%s)", map[disk->id], strerror (errno)); close (fd); return grub_errno; @@ -461,7 +461,7 @@ grub_util_biosdisk_write (grub_disk_t di if (nwrite (fd, buf, size << GRUB_DISK_SECTOR_BITS) != (ssize_t) (size << GRUB_DISK_SECTOR_BITS)) - grub_error (GRUB_ERR_WRITE_ERROR, "cannot write to `%s'", map[disk->id]); + grub_error (GRUB_ERR_WRITE_ERROR, "cannot write to `%s' (%s)", map[disk->id], strerror (errno)); close (fd); return grub_errno; @@ -695,7 +695,7 @@ grub_util_biosdisk_get_grub_dev (const c if (stat (os_dev, &st) < 0) { - grub_error (GRUB_ERR_BAD_DEVICE, "cannot stat `%s'", os_dev); + grub_error (GRUB_ERR_BAD_DEVICE, "cannot stat `%s' (%s)", os_dev, strerror (errno)); return 0; } @@ -775,7 +775,7 @@ grub_util_biosdisk_get_grub_dev (const c fd = open (os_dev, O_RDONLY); if (fd == -1) { - grub_error (GRUB_ERR_BAD_DEVICE, "cannot open `%s'", os_dev); + grub_error (GRUB_ERR_BAD_DEVICE, "cannot open `%s' (%s)", os_dev, strerror (errno)); free (name); return 0; } @@ -783,7 +783,7 @@ grub_util_biosdisk_get_grub_dev (const c if (ioctl (fd, HDIO_GETGEO, &hdg)) { grub_error (GRUB_ERR_BAD_DEVICE, - "cannot get geometry of `%s'", os_dev); + "cannot get geometry of `%s' (%s)", os_dev, strerror (errno)); close (fd); free (name); return 0; diff -x configure -x config.h.in -x CVS -x '*~' -x '*.mk' -urp ../grub2/util/misc.c ./util/misc.c --- ../grub2/util/misc.c 2007-10-21 14:29:33.000000000 +0200 +++ ./util/misc.c 2008-02-11 16:49:36.000000000 +0100 @@ -61,6 +61,8 @@ void grub_util_error (const char *fmt, ...) { va_list ap; + + grub_print_error (); fprintf (stderr, "%s: error: ", progname); va_start (ap, fmt); --EVF5PPMfhYS0aIcm--