From 4642216f70dd98134a79f9299b7ca4bc876649c7 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Sun, 28 Aug 2016 00:36:53 -0700 Subject: *: refactor all the things Long overdue house cleaning. The addition of compositing/monitoring overlays in vwm3 pushed vwm well past what is a reasonable size for a simple thousand line file. This is a first step towards restoring sanity in the code, but no behavioral differences are intended, this is mostly just shuffling around and organizing code. I expect some performance regressions initially, follow-on commits will make more improvements to that end as the dust settles. --- src/launch.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/launch.c (limited to 'src/launch.c') diff --git a/src/launch.c b/src/launch.c new file mode 100644 index 0000000..123e850 --- /dev/null +++ b/src/launch.c @@ -0,0 +1,45 @@ +/* + * \/\/\ + * + * Copyright (C) 2012-2016 Vito Caputo - + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + /* launching of external processes / X clients */ + +#include +#include +#include +#include +#include +#include + +#include "launch.h" +#include "vwm.h" + +#define LAUNCHED_RELATIVE_PRIORITY 10 /* the wm priority plus this is used as the priority of launched processes */ + +/* launch a child command specified in argv, mode decides if we wait for the child to exit before returning. */ +void vwm_launch(vwm_t *vwm, char **argv, vwm_launch_mode_t mode) +{ + /* XXX: in BG mode I double fork and let init inherit the orphan so I don't have to collect the return status */ + if (mode == VWM_LAUNCH_MODE_FG || !fork()) { + if (!fork()) { + /* child */ + setpriority(PRIO_PROCESS, getpid(), vwm->priority + LAUNCHED_RELATIVE_PRIORITY); + execvp(argv[0], argv); + } + if (mode == VWM_LAUNCH_MODE_BG) exit(0); + } + wait(NULL); /* TODO: could wait for the specific pid, particularly in FG mode ... */ +} -- cgit v1.2.3