* [PATCH] Set errno in is_loopdev on error
@ 2016-08-30 19:00 Tobias Stoeckmann
2016-08-31 7:50 ` Karel Zak
0 siblings, 1 reply; 2+ messages in thread
From: Tobias Stoeckmann @ 2016-08-30 19:00 UTC (permalink / raw)
To: util-linux
The function is_loopdev does not set errno if the supplied string does
not reference a valid loop device. Fix this to avoid an error message
like this one:
losetup: /: failed to use device: Success
I prefer this one:
losetup: /: failed to use device: No such device
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
---
lib/loopdev.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/lib/loopdev.c b/lib/loopdev.c
index b3941dd..a57e7a7 100644
--- a/lib/loopdev.c
+++ b/lib/loopdev.c
@@ -633,12 +633,13 @@ int is_loopdev(const char *device)
{
struct stat st;
- if (!device)
- return 0;
-
- return (stat(device, &st) == 0 &&
+ if (device && stat(device, &st) == 0 &&
S_ISBLK(st.st_mode) &&
- major(st.st_rdev) == LOOPDEV_MAJOR);
+ major(st.st_rdev) == LOOPDEV_MAJOR)
+ return 1;
+
+ errno = ENODEV;
+ return 0;
}
/*
--
2.9.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] Set errno in is_loopdev on error
2016-08-30 19:00 [PATCH] Set errno in is_loopdev on error Tobias Stoeckmann
@ 2016-08-31 7:50 ` Karel Zak
0 siblings, 0 replies; 2+ messages in thread
From: Karel Zak @ 2016-08-31 7:50 UTC (permalink / raw)
To: Tobias Stoeckmann; +Cc: util-linux
On Tue, Aug 30, 2016 at 09:00:38PM +0200, Tobias Stoeckmann wrote:
> lib/loopdev.c | 11 ++++++-----
> 1 file changed, 6 insertions(+), 5 deletions(-)
Good catch. Applied, thanks.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-08-31 7:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-30 19:00 [PATCH] Set errno in is_loopdev on error Tobias Stoeckmann
2016-08-31 7:50 ` Karel Zak
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.