]> rtime.felk.cvut.cz Git - sojka/sterm.git/commitdiff
Print more descriptive error message
authorMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 3 May 2017 22:00:10 +0000 (00:00 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 3 May 2017 22:00:10 +0000 (00:00 +0200)
sterm.c

diff --git a/sterm.c b/sterm.c
index b375caf1d624fe4acf8ddc7805652b15f7edf064..ea8657326d84f61f69b5d9a06626efc01ab64641 100644 (file)
--- a/sterm.c
+++ b/sterm.c
@@ -31,6 +31,7 @@
 
 #define _BSD_SOURCE
 #define _DEFAULT_SOURCE
+#define _GNU_SOURCE
 #include <sys/ioctl.h>
 #include <sys/types.h>
 #include <unistd.h>
@@ -44,6 +45,7 @@
 #include <string.h>
 #include <signal.h>
 #include <lockdev.h>
+#include <errno.h>
 
 #define STRINGIFY(val) #val
 #define TOSTRING(val) STRINGIFY(val)
@@ -269,7 +271,12 @@ int main(int argc, char *argv[])
                fprintf(stderr, "%s is used by PID %d\n", dev, pid);
                exit(1);
        } else if (pid < 0) {
-               perror("dev_lock()");
+               char *msg;
+               asprintf(&msg, "dev_lock('%s')", dev); /* No free() because we exit() immediately */
+               if (errno)
+                       perror(msg);
+               else
+                       fprintf(stderr, "%s: Error\n", msg);
                exit(1);
        }
        atexit(unlock);