From ea3954427e3e3453eba49e302bf4e3a0272b172e Mon Sep 17 00:00:00 2001 From: okan Date: Wed, 16 Sep 2015 17:58:25 +0000 Subject: 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. --- util.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'util.c') diff --git a/util.c b/util.c index 9480448..e74797e 100644 --- a/util.c +++ b/util.c @@ -15,7 +15,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * $OpenBSD: util.c,v 1.17 2015/01/19 14:54:16 okan Exp $ + * $OpenBSD: util.c,v 1.18 2015/09/16 17:58:25 okan Exp $ */ #include @@ -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); } -- cgit v1.2.3-2-gb3c3