aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Stack <bgstack15@gmail.com>2022-09-30 19:35:50 -0400
committerB. Stack <bgstack15@gmail.com>2022-09-30 19:35:50 -0400
commit2c9bb4fe87ad9d2bf355140c9133a0eb658d7c6a (patch)
treec46201bf68fac9ab1a1255d4432b7662374e9783
parentadded major C improvements (diff)
downloadkeyboard-leds-trayicons-2c9bb4fe87ad9d2bf355140c9133a0eb658d7c6a.tar.gz
keyboard-leds-trayicons-2c9bb4fe87ad9d2bf355140c9133a0eb658d7c6a.tar.bz2
keyboard-leds-trayicons-2c9bb4fe87ad9d2bf355140c9133a0eb658d7c6a.zip
improvements from rwp code review
-rw-r--r--experimental/keyboard-leds-trayicons.c41
1 files changed, 22 insertions, 19 deletions
diff --git a/experimental/keyboard-leds-trayicons.c b/experimental/keyboard-leds-trayicons.c
index f2c6a4a..676849e 100644
--- a/experimental/keyboard-leds-trayicons.c
+++ b/experimental/keyboard-leds-trayicons.c
@@ -1,7 +1,7 @@
/*
* File: keyboard-leds-trayicons.c
* Location: https://bgstack15.ddns.net/cgit/keyboard-leds-trayicons/
- * Author: bgstack15
+ * Authors: bgstack15, jonhoo
* Startdate: 2022-09-28-4 13:30
* SPDX-License-Identifier: GPL-3.0
* Title: Proof of Concept C utility for polling capslock and numlock
@@ -20,6 +20,8 @@
* https://qnaplus.com/c-program-to-sleep-in-milliseconds/
* https://stackoverflow.com/questions/47107311/sending-signal-from-child-to-parent
* https://stackoverflow.com/questions/108183/how-to-prevent-sigpipes-or-handle-them-properly
+ * https://cboard.cprogramming.com/c-programming/150795-signal-sigaction-conversion-printable-thread.html
+ * http://maemo.cloud-7.de/irclogs/freenode/_devuan-dev/_devuan-dev.2022-10-01.log.html
* Improvements:
* Use getopts, -h, -c conffile, -d (debug)
* fix all return values at end
@@ -30,19 +32,19 @@
* exit when both trayicons have exited
*/
-#include<ctype.h>
-#include<fcntl.h>
-#include<glib.h>
-#include<gtk/gtk.h>
-#include<ini.h>
-#include<stdio.h>
-#include<stdlib.h>
-#include<string.h>
-#include<sys/stat.h>
-#include<unistd.h>
-#include<X11/XKBlib.h>
-#include<X11/Xlib.h>
-#include<signal.h>
+#include <ctype.h>
+#include <fcntl.h>
+#include <glib.h>
+#include <gtk/gtk.h>
+#include <ini.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <X11/XKBlib.h>
+#include <X11/Xlib.h>
+#include <signal.h>
/* START inclusion of mktrayicon.c, 536 lines */
/*
@@ -768,13 +770,12 @@ int main(int argc, char **argv) {
}
else {
// parent 1
- signal(SIGPIPE, SIG_IGN);
/* prevents breakage when C or N tray icon is closed.
However, now this daemon will never quit without the closed_icon counter!
*/
- fd_C = open(config.caps_fifo, O_WRONLY);
+ fd_C = open(config.caps_fifo, O_RDWR);
stream_C = fdopen(fd_C,"w");
- fd_N = open(config.num_fifo, O_WRONLY);
+ fd_N = open(config.num_fifo, O_RDWR);
stream_N = fdopen(fd_N,"w");
strcpy(msg, "m quit,echo 'q' > ");
strcat(msg, config.caps_fifo);
@@ -797,8 +798,10 @@ int main(int argc, char **argv) {
status_capslock = get_indicator(dpy, "Caps Lock");
status_numlock = get_indicator(dpy, "Num Lock");
//printf("Capslock: %d\tNumlock: %d\n",status_capslock,status_numlock);
- if(signal(SIGUSR1,sig_usr) == SIG_ERR)
- printf("Signal processed.");
+ struct sigaction san;
+ memset(&san,0,sizeof(san));
+ san.sa_handler = sig_usr;
+ sigaction(SIGUSR1,&san,NULL);
if(status_capslock != status_caps_old) {
kill_result = kill(pid_C, 0);
printf("Checking for capslock change, pid %d, result %d\n", pid_C, kill_result);
bgstack15