diff --git a/src/clipmenud.c b/src/clipmenud.c index 3a1f718..118e5b2 100644 --- a/src/clipmenud.c +++ b/src/clipmenud.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -385,6 +386,14 @@ int main(int argc, char *argv[]) { int evt_base; cfg = setup("clipmenud"); + + _drop_(close) int session_fd = + open(get_session_lock_path(&cfg), O_WRONLY | O_CREAT | O_CLOEXEC, 0600); + die_on(session_fd < 0, "Failed to open session file: %s\n", + strerror(errno)); + die_on(flock(session_fd, LOCK_EX | LOCK_NB) < 0, + "Failed to lock session file -- is another clipmenud running?\n"); + write_status(); _drop_(close) int content_dir_fd = open(get_cache_dir(&cfg), O_RDONLY); diff --git a/src/config.h b/src/config.h index e464ab2..55759ee 100644 --- a/src/config.h +++ b/src/config.h @@ -79,6 +79,7 @@ char *get_cache_dir(struct config *cfg); DEFINE_GET_PATH_FUNCTION(line_cache) DEFINE_GET_PATH_FUNCTION(enabled) +DEFINE_GET_PATH_FUNCTION(session_lock) extern const char *prog_name; struct config _nonnull_ setup(const char *inner_prog_name);