From d021510bad6848471cfd20ece8a3fb377ab151ec Mon Sep 17 00:00:00 2001 From: Ashish Kumar Yadav Date: Sun, 10 Jan 2021 05:26:10 +0530 Subject: [PATCH] Major bugfix related to pidfile --- dwmblocks.c | 4 +-- patches/dwm-dwmblocks-6.2.diff | 38 +++++++++++++++++--------- patches/dwm-systray-dwmblocks-6.2.diff | 38 +++++++++++++++++--------- sigdwmblocks.c | 4 ++- 4 files changed, 55 insertions(+), 29 deletions(-) diff --git a/dwmblocks.c b/dwmblocks.c index 29cf63e..d592a5b 100644 --- a/dwmblocks.c +++ b/dwmblocks.c @@ -326,14 +326,14 @@ writepid() int fd; struct flock fl; - fd = open(LOCKFILE, O_RDWR|O_CREAT, 0644); + fd = open(LOCKFILE, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if (fd == -1) { perror("writepid - open"); exit(1); } fl.l_type = F_WRLCK; - fl.l_start = 0; fl.l_whence = SEEK_SET; + fl.l_start = 0; fl.l_len = 0; if (fcntl(fd, F_SETLK, &fl) == -1) { if (errno == EACCES || errno == EAGAIN) { diff --git a/patches/dwm-dwmblocks-6.2.diff b/patches/dwm-dwmblocks-6.2.diff index 34a4de5..d442918 100644 --- a/patches/dwm-dwmblocks-6.2.diff +++ b/patches/dwm-dwmblocks-6.2.diff @@ -43,7 +43,7 @@ diff -ruN dwm-6.2-ori/config.def.h dwm-6.2/config.def.h { ClkClientWin, MODKEY, Button3, resizemouse, {0} }, diff -ruN dwm-6.2-ori/dwm.c dwm-6.2/dwm.c --- dwm-6.2-ori/dwm.c 2019-02-02 18:25:28.000000000 +0530 -+++ dwm-6.2/dwm.c 2020-12-30 16:24:10.847012386 +0530 ++++ dwm-6.2/dwm.c 2021-01-10 05:23:06.472038418 +0530 @@ -40,6 +40,7 @@ #include #endif /* XINERAMA */ @@ -277,28 +277,40 @@ diff -ruN dwm-6.2-ori/dwm.c dwm-6.2/dwm.c cursor[CurResize] = drw_cur_create(drw, XC_sizing); cursor[CurMove] = drw_cur_create(drw, XC_fleur); /* init appearance */ -@@ -1637,6 +1689,28 @@ +@@ -1637,6 +1689,40 @@ } void +sigdwmblocks(const Arg *arg) +{ -+ int fd; ++ static int fd = -1; + struct flock fl; + union sigval sv; + + if (!dwmblockssig) + return; -+ sv.sival_int = (dwmblockssig << 8) | arg->i; -+ fd = open(DWMBLOCKSLOCKFILE, O_RDONLY); -+ if (fd == -1) -+ return; + fl.l_type = F_WRLCK; -+ fl.l_start = 0; + fl.l_whence = SEEK_SET; ++ fl.l_start = 0; + fl.l_len = 0; -+ if (fcntl(fd, F_GETLK, &fl) == -1 || fl.l_type == F_UNLCK) -+ return; ++ if (fd == -1) { ++ if ((fd = open(DWMBLOCKSLOCKFILE, O_RDONLY)) == -1) ++ return; ++ if (fcntl(fd, F_GETLK, &fl) == -1 || fl.l_type == F_UNLCK) ++ return; ++ } else { ++ if (fcntl(fd, F_GETLK, &fl) == -1) ++ return; ++ if (fl.l_type == F_UNLCK) { ++ close(fd); ++ if ((fd = open(DWMBLOCKSLOCKFILE, O_RDONLY)) == -1) ++ return; ++ fl.l_type = F_WRLCK; ++ if (fcntl(fd, F_GETLK, &fl) == -1 || fl.l_type == F_UNLCK) ++ return; ++ } ++ } ++ sv.sival_int = (dwmblockssig << 8) | arg->i; + sigqueue(fl.l_pid, SIGRTMIN, sv); +} + @@ -306,7 +318,7 @@ diff -ruN dwm-6.2-ori/dwm.c dwm-6.2/dwm.c spawn(const Arg *arg) { if (arg->v == dmenucmd) -@@ -1805,7 +1879,7 @@ +@@ -1805,7 +1891,7 @@ XSetWindowAttributes wa = { .override_redirect = True, .background_pixmap = ParentRelative, @@ -315,7 +327,7 @@ diff -ruN dwm-6.2-ori/dwm.c dwm-6.2/dwm.c }; XClassHint ch = {"dwm", "dwm"}; for (m = mons; m; m = m->next) { -@@ -1847,6 +1921,41 @@ +@@ -1847,6 +1933,41 @@ (unsigned char *) &(c->win), 1); } @@ -357,7 +369,7 @@ diff -ruN dwm-6.2-ori/dwm.c dwm-6.2/dwm.c int updategeom(void) { -@@ -1987,9 +2096,27 @@ +@@ -1987,9 +2108,27 @@ void updatestatus(void) { diff --git a/patches/dwm-systray-dwmblocks-6.2.diff b/patches/dwm-systray-dwmblocks-6.2.diff index f166ceb..744e7fd 100644 --- a/patches/dwm-systray-dwmblocks-6.2.diff +++ b/patches/dwm-systray-dwmblocks-6.2.diff @@ -43,7 +43,7 @@ diff -ruN dwm-6.2-ori/config.def.h dwm-6.2/config.def.h { ClkClientWin, MODKEY, Button3, resizemouse, {0} }, diff -ruN dwm-6.2-ori/dwm.c dwm-6.2/dwm.c --- dwm-6.2-ori/dwm.c 2020-08-17 23:51:19.057243495 +0530 -+++ dwm-6.2/dwm.c 2020-12-30 16:26:04.168439847 +0530 ++++ dwm-6.2/dwm.c 2021-01-10 05:24:06.575894250 +0530 @@ -40,6 +40,7 @@ #include #endif /* XINERAMA */ @@ -314,28 +314,40 @@ diff -ruN dwm-6.2-ori/dwm.c dwm-6.2/dwm.c cursor[CurResize] = drw_cur_create(drw, XC_sizing); cursor[CurMove] = drw_cur_create(drw, XC_fleur); /* init appearance */ -@@ -1825,6 +1881,28 @@ +@@ -1825,6 +1881,40 @@ } void +sigdwmblocks(const Arg *arg) +{ -+ int fd; ++ static int fd = -1; + struct flock fl; + union sigval sv; + + if (!dwmblockssig) + return; -+ sv.sival_int = (dwmblockssig << 8) | arg->i; -+ fd = open(DWMBLOCKSLOCKFILE, O_RDONLY); -+ if (fd == -1) -+ return; + fl.l_type = F_WRLCK; -+ fl.l_start = 0; + fl.l_whence = SEEK_SET; ++ fl.l_start = 0; + fl.l_len = 0; -+ if (fcntl(fd, F_GETLK, &fl) == -1 || fl.l_type == F_UNLCK) -+ return; ++ if (fd == -1) { ++ if ((fd = open(DWMBLOCKSLOCKFILE, O_RDONLY)) == -1) ++ return; ++ if (fcntl(fd, F_GETLK, &fl) == -1 || fl.l_type == F_UNLCK) ++ return; ++ } else { ++ if (fcntl(fd, F_GETLK, &fl) == -1) ++ return; ++ if (fl.l_type == F_UNLCK) { ++ close(fd); ++ if ((fd = open(DWMBLOCKSLOCKFILE, O_RDONLY)) == -1) ++ return; ++ fl.l_type = F_WRLCK; ++ if (fcntl(fd, F_GETLK, &fl) == -1 || fl.l_type == F_UNLCK) ++ return; ++ } ++ } ++ sv.sival_int = (dwmblockssig << 8) | arg->i; + sigqueue(fl.l_pid, SIGRTMIN, sv); +} + @@ -343,7 +355,7 @@ diff -ruN dwm-6.2-ori/dwm.c dwm-6.2/dwm.c spawn(const Arg *arg) { if (arg->v == dmenucmd) -@@ -2011,7 +2089,7 @@ +@@ -2011,7 +2101,7 @@ XSetWindowAttributes wa = { .override_redirect = True, .background_pixmap = ParentRelative, @@ -352,7 +364,7 @@ diff -ruN dwm-6.2-ori/dwm.c dwm-6.2/dwm.c }; XClassHint ch = {"dwm", "dwm"}; for (m = mons; m; m = m->next) { -@@ -2058,6 +2136,41 @@ +@@ -2058,6 +2148,41 @@ (unsigned char *) &(c->win), 1); } @@ -394,7 +406,7 @@ diff -ruN dwm-6.2-ori/dwm.c dwm-6.2/dwm.c int updategeom(void) { -@@ -2198,10 +2311,27 @@ +@@ -2198,10 +2323,27 @@ void updatestatus(void) { diff --git a/sigdwmblocks.c b/sigdwmblocks.c index d7c9030..7739b49 100644 --- a/sigdwmblocks.c +++ b/sigdwmblocks.c @@ -60,13 +60,15 @@ sendsignal(int sig, union sigval sv) exit(1); } fl.l_type = F_WRLCK; - fl.l_start = 0; fl.l_whence = SEEK_SET; + fl.l_start = 0; fl.l_len = 0; if (fcntl(fd, F_GETLK, &fl) == -1) { perror("sendsignal - fcntl"); + close(fd); exit(1); } + close(fd); if (fl.l_type == F_UNLCK) { fputs("Error: no running instance of dwmblocks.\n", stderr); exit(3);