2007-09-05 20:15:00 +02:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
void
|
|
|
|
eprint(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vfprintf(stderr, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
spawn(Display * disp,
|
2007-09-10 12:06:54 +02:00
|
|
|
awesome_config * awesomeconf __attribute__ ((unused)),
|
2007-09-05 20:15:00 +02:00
|
|
|
const char *arg)
|
|
|
|
{
|
|
|
|
static char *shell = NULL;
|
|
|
|
|
|
|
|
if(!shell && !(shell = getenv("SHELL")))
|
|
|
|
shell = strdup("/bin/sh");
|
|
|
|
if(!arg)
|
|
|
|
return;
|
|
|
|
/* The double-fork construct avoids zombie processes and keeps the code
|
|
|
|
* * clean from stupid signal handlers. */
|
|
|
|
if(fork() == 0)
|
|
|
|
{
|
|
|
|
if(fork() == 0)
|
|
|
|
{
|
|
|
|
if(disp)
|
|
|
|
close(ConnectionNumber(disp));
|
|
|
|
setsid();
|
|
|
|
execl(shell, shell, "-c", arg, (char *) NULL);
|
2007-09-10 12:06:54 +02:00
|
|
|
fprintf(stderr, "awesome: execl '%s -c %s'", shell, arg);
|
2007-09-05 20:15:00 +02:00
|
|
|
perror(" failed");
|
|
|
|
}
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
wait(0);
|
|
|
|
}
|