diff options
author | Vito Caputo <vcaputo@gnugeneration.com> | 2016-08-28 00:36:53 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@gnugeneration.com> | 2016-09-09 14:14:31 -0700 |
commit | 4642216f70dd98134a79f9299b7ca4bc876649c7 (patch) | |
tree | bdf9fd892bc54a2f2a678a9828c6af9d9fc8bed2 /src/launch.c | |
parent | e99f5ac1293a0ae1f498bc4c73c4c04e4edb8665 (diff) |
*: 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.
Diffstat (limited to 'src/launch.c')
-rw-r--r-- | src/launch.c | 45 |
1 files changed, 45 insertions, 0 deletions
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 - <vcaputo@gnugeneration.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + /* launching of external processes / X clients */ + +#include <stdlib.h> +#include <sys/resource.h> +#include <sys/time.h> +#include <sys/types.h> +#include <sys/wait.h> +#include <unistd.h> + +#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 ... */ +} |