summary refs log tree commit diff
path: root/util.c
diff options
context:
space:
mode:
authorokan <okan>2015-09-23 14:09:40 +0000
committerokan <okan>2015-09-23 14:09:40 +0000
commitcd21e166754c24e9bbcde1ee3a689079a073cc5b (patch)
tree5e05f0156fa8d83c309af6e0e2c3ca17f23e0d7f /util.c
parent3f0b6cf4ea53d80ef7e2d9a96f4d93bb209aa2b6 (diff)
parent5fcf2516721dd441b435ba07f73c6315c104f5a3 (diff)
downloadcwm-cd21e166754c24e9bbcde1ee3a689079a073cc5b.tar.gz
cwm-cd21e166754c24e9bbcde1ee3a689079a073cc5b.tar.xz
cwm-cd21e166754c24e9bbcde1ee3a689079a073cc5b.zip
cvsimport
* refs/heads/master:
  Only when mapping clients from an initial wm start or restart, query the pointer and if it matches the child window, activate it; new clients will not need to make this roundtrip to the server.
  On execwm, we should properly release resources before exec'ing into a new window manager; so allow CWM_EXEC_WM to assign new wm to wm_argv and pass through cwm_status (now EXECWM) so that x_teardown() gets called before exec'ing the new window manager.  Removes the need for a separate x_restart() now, using new wm_argv; and consolidates errno for execvp.
Diffstat (limited to 'util.c')
-rw-r--r--util.c32
1 files changed, 28 insertions, 4 deletions
diff --git a/util.c b/util.c
index 3b28ba1..7b8e4c8 100644
--- a/util.c
+++ b/util.c
@@ -31,15 +31,12 @@
 
 #include "calmwm.h"
 
-#define MAXARGLEN 20
-
 void
 u_spawn(char *argstr)
 {
 	switch (fork()) {
 	case 0:
 		u_exec(argstr);
-		err(1, "%s", argstr);
 		break;
 	case -1:
 		warn("fork");
@@ -51,8 +48,10 @@ u_spawn(char *argstr)
 void
 u_exec(char *argstr)
 {
+#define MAXARGLEN 20
 	char	*args[MAXARGLEN], **ap = args;
 	char	**end = &args[MAXARGLEN - 1], *tmp;
+	char	*s = argstr;
 
 	while (ap < end && (*ap = strsep(&argstr, " \t")) != NULL) {
 		if (**ap == '\0')
@@ -75,8 +74,33 @@ u_exec(char *argstr)
 			}
 		}
 	}
-
 	*ap = NULL;
+
 	(void)setsid();
 	(void)execvp(args[0], args);
+	err(1, "%s", s);
+}
+
+char *
+u_argv(char * const *argv)
+{
+	size_t	 siz = 0;
+	int	 i;
+	char	*p;
+
+	if (argv == 0)
+		return(NULL);
+
+	for (i = 0; argv[i]; i++)
+		siz += strlen(argv[i]) + 1;
+	if (siz == 0)
+		return(NULL);
+
+	p = xmalloc(siz);
+	strlcpy(p, argv[0], siz);
+	for (i = 1; argv[i]; i++) {
+		strlcat(p, " ", siz);
+		strlcat(p, argv[i], siz);
+	}
+	return(p);
 }