summaryrefslogtreecommitdiff
path: root/net-dialup/sterm/files/0002-Print-more-descriptive-error-message.patch
blob: 46c4a9812a878ad03329a2c81c9de556304f3ec6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
From 613b8407347b063320ebf408d06bb120293c6c3a Mon Sep 17 00:00:00 2001
From: Michal Sojka <sojkam1@fel.cvut.cz>
Date: Thu, 4 May 2017 00:00:10 +0200
Subject: [PATCH 2/3] Print more descriptive error message

---
 sterm.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/sterm.c b/sterm.c
index b375caf..ea86573 100644
--- 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);
-- 
2.13.6