diff options
author | okan | 2015-09-16 17:58:25 +0000 |
---|---|---|
committer | okan | 2015-09-16 17:58:25 +0000 |
commit | ea3954427e3e3453eba49e302bf4e3a0272b172e (patch) | |
tree | 6c8c6c794afa080f95f35faa5c8ba69a756d4a90 /util.c | |
parent | 7d8a5a92b3e6bba227470f31a83772cf42b00fa9 (diff) | |
download | cwm-ea3954427e3e3453eba49e302bf4e3a0272b172e.tar.gz |
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.c | 34 |
1 files changed, 29 insertions, 5 deletions
@@ -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 <sys/types.h> @@ -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); } |