Skip to content

Commit

Permalink
acquire lockfile
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixKratz committed Feb 20, 2022
1 parent 55ffe4f commit 30f53ca
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,26 @@

void* g_workspace;

static void acquire_lockfile(void) {
int handle = open("/tmp/svim.lock", O_CREAT | O_WRONLY, 0600);
if (handle == -1) printf("Error: Could not create lock-file.\n"), exit(1);

struct flock lockfd = {
.l_start = 0,
.l_len = 0,
.l_pid = getpid(),
.l_type = F_WRLCK,
.l_whence = SEEK_SET
};

if (fcntl(handle, F_SETLK, &lockfd) == -1)
printf("Error: Could not acquire lock-file.\n"), exit(1);
}

int main (int argc, char *argv[]) {
NSApplicationLoad();

acquire_lockfile();
ax_begin(&g_ax);
event_tap_begin(&g_event_tap);
workspace_begin(&g_workspace);
Expand Down

0 comments on commit 30f53ca

Please sign in to comment.