diff options
author | Aaron Ball <nullspoon@oper.io> | 2020-03-21 12:55:39 -0600 |
---|---|---|
committer | Aaron Ball <nullspoon@oper.io> | 2020-03-21 12:55:39 -0600 |
commit | ad3b04713df7ed28922c005ba6346afbd77331c0 (patch) | |
tree | 922bd2f59ad97a80e6383cd5d274bb7a536050a1 | |
parent | 984109bec054fa3fcd5599996288c2969631133e (diff) | |
download | luminous-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.c | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -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; } |