From: Robert Millan <rmh@aybabtu.com>
To: grub-devel@gnu.org
Subject: [PATCH] improve error handling in util/
Date: Mon, 11 Feb 2008 17:01:52 +0100 [thread overview]
Message-ID: <20080211160152.GA7448@thorin> (raw)
[-- Attachment #1: Type: text/plain, Size: 436 bytes --]
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
<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)
[-- Attachment #2: error.diff --]
[-- Type: text/x-diff, Size: 5281 bytes --]
2008-02-11 Robert Millan <rmh@aybabtu.com>
* 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);
next reply other threads:[~2008-02-11 16:03 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-11 16:01 Robert Millan [this message]
2008-02-11 18:39 ` [PATCH] improve error handling in util/ Jan Nieuwenhuizen
2008-02-11 19:48 ` Robert Millan
2008-02-12 8:24 ` Jan Nieuwenhuizen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080211160152.GA7448@thorin \
--to=rmh@aybabtu.com \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.