From a823f7923f8d2006eedc013ca1c1ba7a496543d5 Mon Sep 17 00:00:00 2001
From: choc <notchoc@disroot.org>
Date: Wed, 3 Jul 2024 11:21:33 +0800
Subject: [PATCH] startargv: allow passing startup command on argv

---
 dwl.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/dwl.c b/dwl.c
index 9fb50a7..43b1ac1 100644
--- a/dwl.c
+++ b/dwl.c
@@ -320,7 +320,7 @@ static void requestdecorationmode(struct wl_listener *listener, void *data);
 static void requeststartdrag(struct wl_listener *listener, void *data);
 static void requestmonstate(struct wl_listener *listener, void *data);
 static void resize(Client *c, struct wlr_box geo, int interact);
-static void run(char *startup_cmd);
+static void run(char **startup_cmd);
 static void setcursor(struct wl_listener *listener, void *data);
 static void setcursorshape(struct wl_listener *listener, void *data);
 static void setfloating(Client *c, int floating);
@@ -2158,7 +2158,7 @@ resize(Client *c, struct wlr_box geo, int interact)
 }
 
 void
-run(char *startup_cmd)
+run(char **startup_cmd)
 {
 	/* Add a Unix socket to the Wayland display. */
 	const char *socket = wl_display_add_socket_auto(dpy);
@@ -2183,7 +2183,7 @@ run(char *startup_cmd)
 			dup2(piperw[0], STDIN_FILENO);
 			close(piperw[0]);
 			close(piperw[1]);
-			execl("/bin/sh", "/bin/sh", "-c", startup_cmd, NULL);
+			execvp(startup_cmd[0], startup_cmd);
 			die("startup: execl:");
 		}
 		dup2(piperw[1], STDOUT_FILENO);
@@ -3124,12 +3124,12 @@ xwaylandready(struct wl_listener *listener, void *data)
 int
 main(int argc, char *argv[])
 {
-	char *startup_cmd = NULL;
+	char **startup_cmd = NULL;
 	int c;
 
 	while ((c = getopt(argc, argv, "s:hdv")) != -1) {
 		if (c == 's')
-			startup_cmd = optarg;
+			*(startup_cmd = &argv[optind-1]) = optarg, argc = 0;
 		else if (c == 'd')
 			log_level = WLR_DEBUG;
 		else if (c == 'v')
-- 
2.43.0

