summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2016-02-25 10:41:51 +1000
committerBenjamin Tissoires <benjamin.tissoires@gmail.com>2016-02-25 10:06:28 +0100
commit7b2c1032258355a1a1d30b7973d7fe4df75b6841 (patch)
tree2e7810bf96a24685105d7c84bc03736253b77710
parent152f562f0d6f7438fe6471ff4c69cd9250548ff1 (diff)
evemu-record: Unify the error path
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
-rw-r--r--tools/evemu-record.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/tools/evemu-record.c b/tools/evemu-record.c
index eedf4fa..9d215ab 100644
--- a/tools/evemu-record.c
+++ b/tools/evemu-record.c
@@ -90,10 +90,13 @@ enum mode {
int main(int argc, char *argv[])
{
enum mode mode = EVEMU_RECORD;
- int fd;
+ int fd = -1;
struct sigaction act;
char *prgm_name = program_invocation_short_name;
- char *device;
+ char *device = NULL;
+ int rc = 1;
+
+ output = stdout;
if (prgm_name && (strcmp(prgm_name, "evemu-describe") == 0 ||
/* when run directly from the sources (not installed) */
@@ -104,12 +107,12 @@ int main(int argc, char *argv[])
if (device == NULL) {
fprintf(stderr, "Usage: %s <device> [output file]\n", argv[0]);
- return -1;
+ goto out;
}
fd = open(device, O_RDONLY | O_NONBLOCK);
if (fd < 0) {
fprintf(stderr, "error: could not open device (%m)\n");
- return -1;
+ goto out;
}
memset (&act, '\0', sizeof(act));
@@ -117,11 +120,11 @@ int main(int argc, char *argv[])
if (sigaction(SIGTERM, &act, NULL) < 0) {
fprintf (stderr, "Could not attach TERM signal handler (%m)\n");
- return 1;
+ goto out;
}
if (sigaction(SIGINT, &act, NULL) < 0) {
fprintf (stderr, "Could not attach INT signal handler (%m)\n");
- return 1;
+ goto out;
}
if (argc < 3)
@@ -146,7 +149,7 @@ int main(int argc, char *argv[])
if (ioctl(fd, EVIOCGRAB, (void*)1) < 0) {
fprintf(stderr, "error: this device is grabbed and I cannot record events\n");
fprintf(stderr, "see the evemu-record man page for more information\n");
- return -1;
+ goto out;
} else
ioctl(fd, EVIOCGRAB, (void*)0);
@@ -157,6 +160,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "error: could not describe device\n");
}
+ rc = 0;
out:
free(device);
close(fd);
@@ -164,5 +168,5 @@ out:
fclose(output);
output = stdout;
}
- return 0;
+ return rc;
}