Refactor/simplify, use execApplication in stead of plain fork/exec.
SVN revision: 25691
This commit is contained in:
parent
d363bf0c08
commit
35c8f904df
3
src/E.h
3
src/E.h
|
@ -553,7 +553,8 @@ void ActionsHandleMotion(void);
|
|||
int ActionsEnd(EWin * ewin);
|
||||
void About(void);
|
||||
|
||||
int execApplication(const char *params);
|
||||
#define EXEC_SET_LANG 0x01
|
||||
int execApplication(const char *params, int flags);
|
||||
void Espawn(int argc, char **argv);
|
||||
void EspawnCmd(const char *cmd);
|
||||
|
||||
|
|
|
@ -26,37 +26,48 @@
|
|||
#include "file.h"
|
||||
#include "user.h"
|
||||
|
||||
static void
|
||||
runApp(const char *exe, const char *params)
|
||||
int
|
||||
execApplication(const char *params, int flags)
|
||||
{
|
||||
char exe[FILEPATH_LEN_MAX];
|
||||
char *sh;
|
||||
char *path;
|
||||
char *real_exec;
|
||||
int fd;
|
||||
|
||||
if (!params)
|
||||
return -1;
|
||||
|
||||
sscanf(params, "%4000s", exe);
|
||||
if (exe[0] == '\0')
|
||||
return -1;
|
||||
|
||||
if (fork())
|
||||
return;
|
||||
return 0;
|
||||
|
||||
setsid();
|
||||
/* Close all file descriptors except the std 3 */
|
||||
for (fd = 3; fd < 1024; fd++)
|
||||
close(fd);
|
||||
|
||||
/* Set up env stuff */
|
||||
if (flags & EXEC_SET_LANG)
|
||||
LangExport();
|
||||
|
||||
sh = usershell(getuid());
|
||||
if (exe)
|
||||
{
|
||||
|
||||
path = pathtoexec(exe);
|
||||
if (path)
|
||||
{
|
||||
Efree(path);
|
||||
|
||||
real_exec = Emalloc(strlen(params) + 6);
|
||||
if (!real_exec)
|
||||
return;
|
||||
return -1;
|
||||
sprintf(real_exec, "exec %s", params);
|
||||
|
||||
execl(sh, sh, "-c", real_exec, NULL);
|
||||
exit(0);
|
||||
/* We should not get here - invalid shell? */
|
||||
}
|
||||
|
||||
if (!Mode.wm.startup)
|
||||
|
@ -139,28 +150,6 @@ runApp(const char *exe, const char *params)
|
|||
}
|
||||
}
|
||||
exit(100);
|
||||
}
|
||||
real_exec = Emalloc(strlen(params) + 6);
|
||||
if (!real_exec)
|
||||
return;
|
||||
sprintf(real_exec, "exec %s", params);
|
||||
execl(sh, sh, "-c", real_exec, NULL);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int
|
||||
execApplication(const char *params)
|
||||
{
|
||||
char exe[FILEPATH_LEN_MAX];
|
||||
const char *s = params;
|
||||
|
||||
if (!s)
|
||||
return -1;
|
||||
|
||||
sscanf(s, "%4000s", exe);
|
||||
runApp(exe, s);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
33
src/main.c
33
src/main.c
|
@ -443,39 +443,26 @@ EoptHelp(void)
|
|||
static void
|
||||
RunDocBrowser(void)
|
||||
{
|
||||
char file[FILEPATH_LEN_MAX];
|
||||
char buf[FILEPATH_LEN_MAX];
|
||||
|
||||
Esnprintf(file, sizeof(file), "%s/edox", EDirBin());
|
||||
if (!canexec(file))
|
||||
Esnprintf(buf, sizeof(buf), "%s/edox", EDirBin());
|
||||
if (!canexec(buf))
|
||||
return;
|
||||
Esnprintf(file, sizeof(file), "%s/E-docs", EDirRoot());
|
||||
if (!canread(file))
|
||||
Esnprintf(buf, sizeof(buf), "%s/E-docs", EDirRoot());
|
||||
if (!canread(buf))
|
||||
return;
|
||||
|
||||
if (fork())
|
||||
return;
|
||||
|
||||
Esnprintf(file, sizeof(file), "exec %s/edox %s/E-docs",
|
||||
EDirBin(), EDirRoot());
|
||||
|
||||
execl(usershell(getuid()), usershell(getuid()), "-c", (char *)file, NULL);
|
||||
|
||||
exit(0);
|
||||
Esnprintf(buf, sizeof(buf), "%s/edox %s/E-docs", EDirBin(), EDirRoot());
|
||||
execApplication(buf, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
RunMenuGen(void)
|
||||
{
|
||||
char file[FILEPATH_LEN_MAX];
|
||||
char buf[FILEPATH_LEN_MAX];
|
||||
|
||||
if (fork())
|
||||
return;
|
||||
|
||||
LangExport();
|
||||
|
||||
Esnprintf(file, sizeof(file), "exec %s/scripts/e_gen_menu", EDirRoot());
|
||||
execl(usershell(getuid()), usershell(getuid()), "-c", (char *)file, NULL);
|
||||
exit(0);
|
||||
Esnprintf(buf, sizeof(buf), "%s/scripts/e_gen_menu", EDirRoot());
|
||||
execApplication(buf, EXEC_SET_LANG);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -173,7 +173,7 @@ static void
|
|||
MiscIpcExec(const char *params, Client * c __UNUSED__)
|
||||
{
|
||||
if (params)
|
||||
execApplication(params);
|
||||
execApplication(params, EXEC_SET_LANG);
|
||||
else
|
||||
IpcPrintf("exec what?\n");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue