diff options
-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; } |