diff options
| author | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2025-03-18 13:33:37 +0900 |
|---|---|---|
| committer | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2025-03-18 13:33:37 +0900 |
| commit | cc4026163f0195e417700db7ddce352e89be87ab (patch) | |
| tree | b646cff238000f679fd2fb805ebbee8f47452b85 | |
| parent | 86195bb8f2c1e24cbbb183f8defb555ffedd6e02 (diff) | |
modified dwm/dwm.c, created dwm/dwm-cool-autostart-20240312-9f88553.diff
| -rw-r--r-- | dwm/dwm-cool-autostart-20240312-9f88553.diff | 133 | ||||
| -rw-r--r-- | dwm/dwm.c | 4 |
2 files changed, 135 insertions, 2 deletions
diff --git a/dwm/dwm-cool-autostart-20240312-9f88553.diff b/dwm/dwm-cool-autostart-20240312-9f88553.diff new file mode 100644 index 0000000..b0890d9 --- /dev/null +++ b/dwm/dwm-cool-autostart-20240312-9f88553.diff @@ -0,0 +1,133 @@ +From feeaa839d2c6c1d0e66649cb64c4added563d4e4 Mon Sep 17 00:00:00 2001 +From: Son Phan Trung <phantrungson17@gmail.com> +Date: Tue, 12 Mar 2024 18:37:32 +0700 +Subject: [PATCH] patches/cool-autostart: Update patch + +Updated for the removal of the sigchld() function. +--- + config.def.h | 5 +++++ + dwm.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++- + 2 files changed, 61 insertions(+), 1 deletion(-) + +diff --git a/config.def.h b/config.def.h +index 9efa774..aba210d 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -18,6 +18,11 @@ static const char *colors[][3] = { + [SchemeSel] = { col_gray4, col_cyan, col_cyan }, + }; + ++static const char *const autostart[] = { ++ "st", NULL, ++ NULL /* terminate */ ++}; ++ + /* tagging */ + static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; + +diff --git a/dwm.c b/dwm.c +index f1d86b2..c2eb07d 100644 +--- a/dwm.c ++++ b/dwm.c +@@ -233,6 +233,7 @@ static int xerror(Display *dpy, XErrorEvent *ee); + static int xerrordummy(Display *dpy, XErrorEvent *ee); + static int xerrorstart(Display *dpy, XErrorEvent *ee); + static void zoom(const Arg *arg); ++static void autostart_exec(void); + + /* variables */ + static const char broken[] = "broken"; +@@ -274,6 +275,34 @@ static Window root, wmcheckwin; + /* compile-time check if all tags fit into an unsigned int bit array. */ + struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; }; + ++/* dwm will keep pid's of processes from autostart array and kill them at quit */ ++static pid_t *autostart_pids; ++static size_t autostart_len; ++ ++/* execute command from autostart array */ ++static void ++autostart_exec() { ++ const char *const *p; ++ size_t i = 0; ++ ++ /* count entries */ ++ for (p = autostart; *p; autostart_len++, p++) ++ while (*++p); ++ ++ autostart_pids = malloc(autostart_len * sizeof(pid_t)); ++ for (p = autostart; *p; i++, p++) { ++ if ((autostart_pids[i] = fork()) == 0) { ++ setsid(); ++ execvp(*p, (char *const *)p); ++ fprintf(stderr, "dwm: execvp %s\n", *p); ++ perror(" failed"); ++ _exit(EXIT_FAILURE); ++ } ++ /* skip arguments */ ++ while (*++p); ++ } ++} ++ + /* function implementations */ + void + applyrules(Client *c) +@@ -1258,6 +1287,16 @@ propertynotify(XEvent *e) + void + quit(const Arg *arg) + { ++ size_t i; ++ ++ /* kill child processes */ ++ for (i = 0; i < autostart_len; i++) { ++ if (0 < autostart_pids[i]) { ++ kill(autostart_pids[i], SIGTERM); ++ waitpid(autostart_pids[i], NULL, 0); ++ } ++ } ++ + running = 0; + } + +@@ -1540,6 +1579,7 @@ void + setup(void) + { + int i; ++ pid_t pid; + XSetWindowAttributes wa; + Atom utf8string; + struct sigaction sa; +@@ -1551,7 +1591,21 @@ setup(void) + sigaction(SIGCHLD, &sa, NULL); + + /* clean up any zombies (inherited from .xinitrc etc) immediately */ +- while (waitpid(-1, NULL, WNOHANG) > 0); ++ while ((pid = waitpid(-1, NULL, WNOHANG)) > 0) { ++ pid_t *p, *lim; ++ ++ if (!(p = autostart_pids)) ++ continue; ++ lim = &p[autostart_len]; ++ ++ for (; p < lim; p++) { ++ if (*p == pid) { ++ *p = -1; ++ break; ++ } ++ } ++ ++ } + + /* init screen */ + screen = DefaultScreen(dpy); +@@ -2152,6 +2206,7 @@ main(int argc, char *argv[]) + if (!(dpy = XOpenDisplay(NULL))) + die("dwm: cannot open display"); + checkotherwm(); ++ autostart_exec(); + setup(); + #ifdef __OpenBSD__ + if (pledge("stdio rpath proc exec", NULL) == -1) +-- +2.44.0 + @@ -450,7 +450,6 @@ unsigned int tagw[LENGTH(tags)]; struct NumTags { char limitexceeded[LENGTH(tags) > 28 ? -1 : 1]; }; /* function implementations */ - static void alttab(const Arg *arg) { @@ -2099,6 +2098,7 @@ void quit(const Arg *arg) { if (arg->i) restart = 1; + running = 0; } @@ -2259,7 +2259,7 @@ run(void) void runAutostart(void) { - system("killall -q dwmblocks; dwmblocks &"); + system("killall -q -9 dwmblocks; dwmblocks &"); } void |
