[hackers] [dwm][PATCH] Proper restart function

From: toluschr <toluschr_AT_protonmail.com>
Date: Sat, 06 Mar 2021 15:59:54 +0000

The currently available patch reads /proc/self/exe, which fails when recompiling (Why else would I want to restart dwm?)
This patch simply saves the commandline arguments on startup and re-executes them.
---
 dwm.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/dwm.c b/dwm.c
index 664c527..9e8160f 100644
--- a/dwm.c
+++ b/dwm.c
_AT_@ -234,6 +234,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 restart(const Arg *arg);
 
 /* variables */
 static const char broken[] = "broken";
_AT_@ -268,6 +269,7 @@ static Display *dpy;
 static Drw *drw;
 static Monitor *mons, *selmon;
 static Window root, wmcheckwin;
+static char **argv;
 
 /* configuration, allows nested code to access above variables */
 #include "config.h"
_AT_@ -2127,9 +2129,17 @@ zoom(const Arg *arg)
 	pop(c);
 }
 
+void
+restart(const Arg *arg)
+{
+	execvp(argv[0], argv);
+}
+
 int
-main(int argc, char *argv[])
+main(int argc, char *_argv[])
 {
+	argv = _argv;
+
 	if (argc == 2 && !strcmp("-v", argv[1]))
 		die("dwm-"VERSION);
 	else if (argc != 1)
-- 
2.30.1
Received on Sat Mar 06 2021 - 16:59:54 CET

This archive was generated by hypermail 2.3.0 : Sat Mar 06 2021 - 17:00:41 CET