Environment filtering is not needed. Instead, open applications through SHELL, double-fork
This commit is contained in:
37
src/util.c
37
src/util.c
@ -2,25 +2,38 @@
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include "i3.h"
|
||||
|
||||
/*
|
||||
* Starts the given application with the given args.
|
||||
* Starts the given application by passing it through a shell. We use double fork
|
||||
* to avoid zombie processes. As the started application’s parent exits (immediately),
|
||||
* the application is reparented to init (process-id 1), which correctly handles
|
||||
* childs, so we don’t have to do it :-).
|
||||
*
|
||||
* The shell is determined by looking for the SHELL environment variable. If it
|
||||
* does not exist, /bin/sh is used.
|
||||
*
|
||||
*/
|
||||
void start_application(const char *path, const char *args) {
|
||||
pid_t pid;
|
||||
if ((pid = vfork()) == 0) {
|
||||
/* This is the child */
|
||||
char *argv[2];
|
||||
/* TODO: For now, we ignore args. Later on, they should be parsed
|
||||
correctly (like in the shell?) */
|
||||
argv[0] = strdup(path);
|
||||
argv[1] = NULL;
|
||||
execve(path, argv, environment);
|
||||
/* not reached */
|
||||
void start_application(const char *command) {
|
||||
if (fork() == 0) {
|
||||
/* Child process */
|
||||
if (fork() == 0) {
|
||||
/* Stores the path of the shell */
|
||||
static const char *shell = NULL;
|
||||
|
||||
if (shell == NULL)
|
||||
if ((shell = getenv("SHELL")) == NULL)
|
||||
shell = "/bin/sh";
|
||||
|
||||
/* This is the child */
|
||||
execl(shell, shell, "-c", command, NULL);
|
||||
/* not reached */
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
wait(0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user