summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Ball <nullspoon@oper.io>2020-03-21 12:55:39 -0600
committerAaron Ball <nullspoon@oper.io>2020-03-21 12:55:39 -0600
commitad3b04713df7ed28922c005ba6346afbd77331c0 (patch)
tree922bd2f59ad97a80e6383cd5d274bb7a536050a1
parent984109bec054fa3fcd5599996288c2969631133e (diff)
downloadluminous-ad3b04713df7ed28922c005ba6346afbd77331c0.tar.gz
luminous-ad3b04713df7ed28922c005ba6346afbd77331c0.tar.xz
Add file locking support
This will prevent duplicate luminous processes from running simultaneously, which causes strange blipping artifacts.
-rw-r--r--src/main.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
index 0e67623..3bce0f0 100644
--- a/src/main.c
+++ b/src/main.c
@@ -19,6 +19,7 @@
#include <string.h>
#include <time.h>
#include <errno.h>
+#include <sys/file.h>
#include "config.h"
@@ -131,6 +132,14 @@ int fade(struct props* props) {
return -1;
}
+ // Lock the file descriptor so we can't have conflicting brightness change
+ // operations
+ if(flock(fileno(fd), LOCK_EX | LOCK_NB) != 0) {
+ fprintf(stderr, "Could not obtain brightness file lock\n");
+ fclose(fd);
+ return -1;
+ }
+
while(opcount > 0) {
nanosleep(&tim, &tim2);
@@ -144,6 +153,7 @@ int fade(struct props* props) {
opcount--;
}
+ // Do not need to explicitly release the file lock
fclose(fd);
return 0;
}

Generated by cgit