diff options
-rw-r--r-- | app/cwm/calmwm.c | 18 | ||||
-rw-r--r-- | app/cwm/calmwm.h | 6 | ||||
-rw-r--r-- | app/cwm/conf.c | 4 | ||||
-rw-r--r-- | app/cwm/kbfunc.c | 7 | ||||
-rw-r--r-- | app/cwm/util.c | 34 |
5 files changed, 44 insertions, 25 deletions
diff --git a/app/cwm/calmwm.c b/app/cwm/calmwm.c index f0d009b12..c0e93fe3a 100644 --- a/app/cwm/calmwm.c +++ b/app/cwm/calmwm.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: calmwm.c,v 1.93 2015/01/19 14:54:16 okan Exp $ + * $OpenBSD: calmwm.c,v 1.94 2015/09/16 17:58:25 okan Exp $ */ #include <sys/types.h> @@ -46,12 +46,12 @@ struct screen_ctx_q Screenq = TAILQ_HEAD_INITIALIZER(Screenq); int HasRandr, Randr_ev; struct conf Conf; const char *homedir; +char *wm_argv; volatile sig_atomic_t cwm_status; static void sighdlr(int); static int x_errorhandler(Display *, XErrorEvent *); static void x_init(const char *); -static void x_restart(char **); static void x_teardown(void); static int x_wmerrorhandler(Display *, XErrorEvent *); @@ -60,7 +60,6 @@ main(int argc, char **argv) { const char *conf_file = NULL; char *conf_path, *display_name = NULL; - char **cwm_argv; int ch; struct passwd *pw; @@ -68,7 +67,7 @@ main(int argc, char **argv) warnx("no locale support"); mbtowc(NULL, NULL, MB_CUR_MAX); - cwm_argv = argv; + wm_argv = u_argv(argv); while ((ch = getopt(argc, argv, "c:d:")) != -1) { switch (ch) { case 'c': @@ -117,8 +116,8 @@ main(int argc, char **argv) while (cwm_status == CWM_RUNNING) xev_process(); x_teardown(); - if (cwm_status == CWM_RESTART) - x_restart(cwm_argv); + if (cwm_status == CWM_EXECWM) + u_exec(wm_argv); return(0); } @@ -146,13 +145,6 @@ x_init(const char *dpyname) } static void -x_restart(char **args) -{ - (void)setsid(); - (void)execvp(args[0], args); -} - -static void x_teardown(void) { struct screen_ctx *sc; diff --git a/app/cwm/calmwm.h b/app/cwm/calmwm.h index 9d0233f40..9147c6538 100644 --- a/app/cwm/calmwm.h +++ b/app/cwm/calmwm.h @@ -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: calmwm.h,v 1.304 2015/08/27 18:53:14 okan Exp $ + * $OpenBSD: calmwm.h,v 1.305 2015/09/16 17:58:25 okan Exp $ */ #ifndef _CALMWM_H_ @@ -88,7 +88,7 @@ #define CWM_QUIT 0x0000 #define CWM_RUNNING 0x0001 -#define CWM_RESTART 0x0002 +#define CWM_EXECWM 0x0002 union arg { char *c; @@ -334,6 +334,7 @@ extern Display *X_Dpy; extern Time Last_Event_Time; extern struct screen_ctx_q Screenq; extern struct conf Conf; +extern char *wm_argv; extern const char *homedir; extern int HasRandr, Randr_ev; @@ -581,6 +582,7 @@ void xu_ewmh_handle_net_wm_state_msg(struct client_ctx *, void xu_ewmh_set_net_wm_state(struct client_ctx *); void xu_ewmh_restore_net_wm_state(struct client_ctx *); +char *u_argv(char * const *); void u_exec(char *); void u_spawn(char *); diff --git a/app/cwm/conf.c b/app/cwm/conf.c index 92594c4bb..7d5bfab79 100644 --- a/app/cwm/conf.c +++ b/app/cwm/conf.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: conf.c,v 1.197 2015/08/24 15:42:57 okan Exp $ + * $OpenBSD: conf.c,v 1.198 2015/09/16 17:58:25 okan Exp $ */ #include <sys/types.h> @@ -400,7 +400,7 @@ static const struct { { "vmaximize", kbfunc_client_toggle_vmaximize, CWM_WIN, {0} }, { "hmaximize", kbfunc_client_toggle_hmaximize, CWM_WIN, {0} }, { "freeze", kbfunc_client_toggle_freeze, CWM_WIN, {0} }, - { "restart", kbfunc_cwm_status, 0, {.i = CWM_RESTART} }, + { "restart", kbfunc_cwm_status, 0, {.i = CWM_EXECWM} }, { "quit", kbfunc_cwm_status, 0, {.i = CWM_QUIT} }, { "exec", kbfunc_exec, 0, {.i = CWM_EXEC_PROGRAM} }, { "exec_wm", kbfunc_exec, 0, {.i = CWM_EXEC_WM} }, diff --git a/app/cwm/kbfunc.c b/app/cwm/kbfunc.c index 2c2bd6866..038834baf 100644 --- a/app/cwm/kbfunc.c +++ b/app/cwm/kbfunc.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: kbfunc.c,v 1.117 2015/08/28 12:07:28 okan Exp $ + * $OpenBSD: kbfunc.c,v 1.118 2015/09/16 17:58:25 okan Exp $ */ #include <sys/types.h> @@ -325,8 +325,9 @@ kbfunc_exec(struct client_ctx *cc, union arg *arg) u_spawn(mi->text); break; case CWM_EXEC_WM: - u_exec(mi->text); - warn("%s", mi->text); + cwm_status = CWM_EXECWM; + free(wm_argv); + wm_argv = xstrdup(mi->text); break; default: errx(1, "kb_func: egad, cmd changed value!"); diff --git a/app/cwm/util.c b/app/cwm/util.c index 9480448de..e74797ede 100644 --- a/app/cwm/util.c +++ b/app/cwm/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 <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); } |