Minor bugfix

This commit is contained in:
Ariela Wenner 2018-11-24 19:16:50 -03:00
parent 3205532668
commit f5f0e1f756
6 changed files with 40 additions and 33 deletions

View File

@ -37,7 +37,8 @@ buffer_size=16
# Note that keywords are *not* case sensitive.
#
example=notify-send example
order66=notify-send "it is done"
# needless to say, you should be careful with these
poweroffnow=poweroff
```
Now you can run it and it'll launch as a daemon. It will respond to `SIGTERM` and shutdown gracefully.
@ -48,9 +49,9 @@ Now you can run it and it'll launch as a daemon. It will respond to `SIGTERM` an
### Requirements
* Recent GCC version in a Linux system.
* Your usual build essentials, especifically `make`.
* Your tipycal build essentials.
* Somewhat recent version of glibc -- we use some non-standard features.
* `linux/input.h` header which you probably have, but check for it anyways at `/usr/include/linux`.
* Linux susbsystem input headers -- you probably have these already.
From there, do either `make debug` or `make release` and you can run it `sudo ./w3panik` (preferably after configuring it).

View File

@ -1,28 +1,28 @@
/*
/*
* This file is part of w3panik
*
*
* w3panik - (C) 2018 Ariela Wenner - <arisunz@disroot.org>
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*
*/
#include "Commands.h"
uint32_t command_check(char* klist[], char* clist[], size_t list_size, char* buffer) {
for (uint32_t i = 0; i < list_size; ++i) {
/*
/*
* we use strcasestr() here, which is non-standard
* but in turn it will save us some headaches
* since we can compare strings ignoring their case
@ -32,7 +32,7 @@ uint32_t command_check(char* klist[], char* clist[], size_t list_size, char* buf
return 0; // command found OK, caller should clear buffer
}
}
return 1;
}
@ -43,7 +43,7 @@ int32_t command_execute(char* command) {
void command_list_append(
char* klist[], char* clist[], size_t* list_size,
char* keyword, char* command) {
klist[*list_size] = keyword;
clist[*list_size] = command;
*list_size += 1;

View File

@ -1,21 +1,21 @@
/*
/*
* This file is part of w3panik
*
*
* w3panik - (C) 2018 Ariela Wenner - <arisunz@disroot.org>
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*
*/
#ifndef COMMANDS_H

View File

@ -1,21 +1,21 @@
/*
/*
* This file is part of w3panik
*
*
* w3panik - (C) 2018 Ariela Wenner - <arisunz@disroot.org>
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*
*/
#ifndef KEYBUFFER_H
@ -26,7 +26,7 @@
typedef struct keydeque {
uint32_t buffer_size;
unsigned char buffer[];
char buffer[];
} keydeque;
void buffer_append(keydeque* key_deque, char ch);

View File

@ -19,6 +19,7 @@
*/
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <signal.h>
@ -44,7 +45,7 @@ int main(int argc, char* argv[]) {
FILE* fconfig = fopen("/etc/w3panik/w3panik.conf", "r");
if (fconfig == NULL) {
fprintf(stderr, "Failed to load configuration file.\n");
perror("Fatal error");
return EXIT_FAILURE;
}
section_t* options = config_init();
@ -82,7 +83,7 @@ int main(int argc, char* argv[]) {
char* buffer_size = config_get(options, "buffer_size");
if (buffer_size != NULL) {
key_deque = buffer_allocate(atoi(buffer_size));
} else if (argc == 2) {
} else {
key_deque = buffer_allocate(32);
}
@ -96,11 +97,11 @@ int main(int argc, char* argv[]) {
kclist_populate(commands, &list_size, klist, clist);
FILE* event_stream;
if (event_stream = fopen(event_path, "rb")) {
FILE* event_stream = fopen(event_path, "rb");
if (event_stream != NULL) {
fprintf(stderr, "Event stream opened!\n");
} else {
fprintf(stderr, "Failed to open event stream...\n");
perror("Fatal error");
free(key_deque);
config_dealloc(options);
config_dealloc(commands);
@ -113,7 +114,11 @@ int main(int argc, char* argv[]) {
sigaction(SIGTERM, &term, NULL);
fprintf(stderr, "Lift off!\n");
daemon(0, 0); // we don't need much more than this at the moment
int32_t daemonize_rc = daemon(0, 0); // we don't need much more than this at the moment
if (daemonize_rc == -1) {
perror("Fatal error");
goto DAEMON_FAIL_CLEANUP;
}
struct input_event* ev = (struct input_event*) malloc(sizeof(struct input_event));
while (fread(ev, sizeof(struct input_event), 1, event_stream)) {
@ -133,6 +138,8 @@ int main(int argc, char* argv[]) {
}
free(ev);
DAEMON_FAIL_CLEANUP:
free(key_deque);
config_dealloc(options);

View File

@ -19,5 +19,4 @@ buffer_size=16
#
# Note that keywords are *not* case sensitive.
#
example=notify-send example
order66=notify-send "it is done"
example=notify-send "example"