linput

Listen to input events
git clone git://git.akobets.xyz/linput
Log | Files | Refs | README | LICENSE

commit 866e11de0c69be74ae426b3f95e5de8f30b6a8f3
parent 347cf390289e543716c1c85445afeaae0da20267
Author: Artem Kobets <artem@akobets.xyz>
Date:   Mon, 20 Apr 2020 17:35:58 +0300

docs, refactor

Diffstat:
MREADME | 4++--
Mlinput.c | 30+++++++++++++++++-------------
2 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/README b/README @@ -38,8 +38,8 @@ Recommendations linput opens device files, and it might not have permission to do this if it is not executed as root. If you'd like to execute it as normal user, you can achieve this with one of the following: - - add user to a group that has read permission on input device files (e.g. 'input') - - modify makefile to use setuid or setgid on executable, so it always gets needed permissions. + - add user to a group that has read permission on input device files (e.g. 'input' group) + - modify makefile to use setuid or setgid on the executable, so it always has needed permissions. Author diff --git a/linput.c b/linput.c @@ -217,17 +217,21 @@ run(char **cmd) switch (fork()) { case -1: - fprintf(stderr, "fork: %s\n", strerror(errno)); + fprintf(stderr, "linput: fork: %s\n", strerror(errno)); break; case 0: /* drop setuid/setgid privileges */ - if (setuid(getuid()) == -1) + if (setuid(getuid()) == -1) { + fprintf(stderr, "linput: setuid: %s\n", strerror(errno)); _exit(EXIT_FAILURE); - if (setgid(getgid()) == -1) + } + if (setgid(getgid()) == -1) { + fprintf(stderr, "linput: setgid: %s\n", strerror(errno)); _exit(EXIT_FAILURE); + } execvp(cmd[0], cmd); - fprintf(stderr, "execvp %s: %s\n", cmd[0], strerror(errno)); + fprintf(stderr, "linput: execvp %s: %s\n", cmd[0], strerror(errno)); _exit(EXIT_FAILURE); break; } @@ -240,11 +244,11 @@ add_fd(int fd, const char *path) new = (fd_node *) malloc(sizeof(fd_node)); if (new == NULL) - die("malloc: %s\n", strerror(errno)); + die("linput: malloc: %s\n", strerror(errno)); new->fd = fd; new->path = strdup(path); if (new->path == NULL) - die("strdup: %s\n", strerror(errno)); + die("linput: strdup: %s\n", strerror(errno)); new->next = NULL; if (fd_head == NULL) { @@ -310,7 +314,7 @@ generate_poll_array() nfds = n; pfds = realloc(pfds, sizeof(struct pollfd) * n); if (pfds == NULL) - die("malloc: %s\n", strerror(errno)); + die("linput: malloc: %s\n", strerror(errno)); } pfds[0].fd = inotify_fd; @@ -359,13 +363,13 @@ init_input_files() res = glob("/dev/input/event*", 0, NULL, &pglob); if (res != 0) - die("glob: can't find files in /dev/input/event*", strerror(errno)); + die("linput: glob: can't find files in /dev/input/event*", strerror(errno)); for (i = 0; i < pglob.gl_pathc; i++) if (open_input_file(pglob.gl_pathv[i]) != -1) success = 1; if (!success) - die("can't open any files in /dev/input/event*\n"); + die("linput: can't open any files in /dev/input/event*\n"); globfree(&pglob); } @@ -376,12 +380,12 @@ init_inotify() inotify_fd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC); poll_change = 1; if (inotify_fd == -1) { - fprintf(stderr, "inotify init failed (inotify_init): %s\n", strerror(errno)); + fprintf(stderr, "linput: inotify init failed (inotify_init): %s\n", strerror(errno)); return; } if (inotify_add_watch(inotify_fd, "/dev/input", IN_CREATE | IN_ATTRIB) == -1) { - fprintf(stderr, "inotify init failed (inotify_add_watch): %s\n", strerror(errno)); + fprintf(stderr, "linput: inotify init failed (inotify_add_watch): %s\n", strerror(errno)); return; } } @@ -541,7 +545,7 @@ main(int argc, char **argv) } if (res == -1) - die("poll: %s\n", strerror(errno)); + die("linput: poll: %s\n", strerror(errno)); - die("poll: unexpected error\n"); + die("linput: poll: unexpected error\n"); }