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);
|
int ActionsEnd(EWin * ewin);
|
||||||
void About(void);
|
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 Espawn(int argc, char **argv);
|
||||||
void EspawnCmd(const char *cmd);
|
void EspawnCmd(const char *cmd);
|
||||||
|
|
||||||
|
|
221
src/actions.c
221
src/actions.c
|
@ -26,141 +26,130 @@
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
#include "user.h"
|
#include "user.h"
|
||||||
|
|
||||||
static void
|
int
|
||||||
runApp(const char *exe, const char *params)
|
execApplication(const char *params, int flags)
|
||||||
{
|
{
|
||||||
|
char exe[FILEPATH_LEN_MAX];
|
||||||
char *sh;
|
char *sh;
|
||||||
char *path;
|
char *path;
|
||||||
char *real_exec;
|
char *real_exec;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
|
if (!params)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
sscanf(params, "%4000s", exe);
|
||||||
|
if (exe[0] == '\0')
|
||||||
|
return -1;
|
||||||
|
|
||||||
if (fork())
|
if (fork())
|
||||||
return;
|
return 0;
|
||||||
|
|
||||||
setsid();
|
setsid();
|
||||||
/* Close all file descriptors except the std 3 */
|
/* Close all file descriptors except the std 3 */
|
||||||
for (fd = 3; fd < 1024; fd++)
|
for (fd = 3; fd < 1024; fd++)
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
LangExport();
|
/* Set up env stuff */
|
||||||
|
if (flags & EXEC_SET_LANG)
|
||||||
|
LangExport();
|
||||||
|
|
||||||
sh = usershell(getuid());
|
sh = usershell(getuid());
|
||||||
if (exe)
|
|
||||||
|
path = pathtoexec(exe);
|
||||||
|
if (path)
|
||||||
{
|
{
|
||||||
path = pathtoexec(exe);
|
Efree(path);
|
||||||
if (path)
|
|
||||||
{
|
|
||||||
Efree(path);
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Mode.wm.startup)
|
real_exec = Emalloc(strlen(params) + 6);
|
||||||
{
|
if (!real_exec)
|
||||||
path = pathtofile(exe);
|
return -1;
|
||||||
if (!path)
|
sprintf(real_exec, "exec %s", params);
|
||||||
{
|
|
||||||
/* absolute path */
|
execl(sh, sh, "-c", real_exec, NULL);
|
||||||
if (isabspath(exe))
|
/* We should not get here - invalid shell? */
|
||||||
DialogAlertOK(_
|
|
||||||
("There was an error running the program:\n"
|
|
||||||
"%s\n"
|
|
||||||
"This program could not be executed.\n"
|
|
||||||
"This is because the file does not exist.\n"),
|
|
||||||
exe);
|
|
||||||
/* relative path */
|
|
||||||
else
|
|
||||||
DialogAlertOK(_
|
|
||||||
("There was an error running the program:\n"
|
|
||||||
"%s\n"
|
|
||||||
"This program could not be executed.\n"
|
|
||||||
"This is most probably because this "
|
|
||||||
"program is not in the\n"
|
|
||||||
"path for your shell which is %s. "
|
|
||||||
"I suggest you read the manual\n"
|
|
||||||
"page for that shell and read up how to "
|
|
||||||
"change or add to your\n"
|
|
||||||
"execution path.\n"), exe, sh);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
/* it is a node on the filing sys */
|
|
||||||
{
|
|
||||||
/* it's a file */
|
|
||||||
if (isfile(path))
|
|
||||||
{
|
|
||||||
/* can execute it */
|
|
||||||
if (canexec(path))
|
|
||||||
DialogAlertOK(_
|
|
||||||
("There was an error running the program:\n"
|
|
||||||
"%s\n"
|
|
||||||
"This program could not be executed.\n"
|
|
||||||
"I am unsure as to why you could not "
|
|
||||||
"do this. The file exists,\n"
|
|
||||||
"is a file, and you are allowed to "
|
|
||||||
"execute it. I suggest you look\n"
|
|
||||||
"into this.\n"), path);
|
|
||||||
/* not executable file */
|
|
||||||
else
|
|
||||||
DialogAlertOK(_
|
|
||||||
("There was an error running the program:\n"
|
|
||||||
"%s\n"
|
|
||||||
"This program could not be executed.\n"
|
|
||||||
"This is because the file exists, is a "
|
|
||||||
"file, but you are unable\n"
|
|
||||||
"to execute it because you do not "
|
|
||||||
"have execute "
|
|
||||||
"access to this file.\n"), path);
|
|
||||||
}
|
|
||||||
/* it's not a file */
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* its a dir */
|
|
||||||
if (isdir(path))
|
|
||||||
DialogAlertOK(_
|
|
||||||
("There was an error running the program:\n"
|
|
||||||
"%s\n"
|
|
||||||
"This program could not be executed.\n"
|
|
||||||
"This is because the file is in fact "
|
|
||||||
"a directory.\n"), path);
|
|
||||||
/* its not a file or a dir */
|
|
||||||
else
|
|
||||||
DialogAlertOK(_
|
|
||||||
("There was an error running the program:\n"
|
|
||||||
"%s\n"
|
|
||||||
"This program could not be executed.\n"
|
|
||||||
"This is because the file is not a "
|
|
||||||
"regular file.\n"), path);
|
|
||||||
}
|
|
||||||
Efree(path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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
|
if (!Mode.wm.startup)
|
||||||
execApplication(const char *params)
|
{
|
||||||
{
|
path = pathtofile(exe);
|
||||||
char exe[FILEPATH_LEN_MAX];
|
if (!path)
|
||||||
const char *s = params;
|
{
|
||||||
|
/* absolute path */
|
||||||
if (!s)
|
if (isabspath(exe))
|
||||||
return -1;
|
DialogAlertOK(_
|
||||||
|
("There was an error running the program:\n"
|
||||||
sscanf(s, "%4000s", exe);
|
"%s\n"
|
||||||
runApp(exe, s);
|
"This program could not be executed.\n"
|
||||||
|
"This is because the file does not exist.\n"),
|
||||||
return 0;
|
exe);
|
||||||
|
/* relative path */
|
||||||
|
else
|
||||||
|
DialogAlertOK(_
|
||||||
|
("There was an error running the program:\n"
|
||||||
|
"%s\n"
|
||||||
|
"This program could not be executed.\n"
|
||||||
|
"This is most probably because this "
|
||||||
|
"program is not in the\n"
|
||||||
|
"path for your shell which is %s. "
|
||||||
|
"I suggest you read the manual\n"
|
||||||
|
"page for that shell and read up how to "
|
||||||
|
"change or add to your\n"
|
||||||
|
"execution path.\n"), exe, sh);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
/* it is a node on the filing sys */
|
||||||
|
{
|
||||||
|
/* it's a file */
|
||||||
|
if (isfile(path))
|
||||||
|
{
|
||||||
|
/* can execute it */
|
||||||
|
if (canexec(path))
|
||||||
|
DialogAlertOK(_
|
||||||
|
("There was an error running the program:\n"
|
||||||
|
"%s\n"
|
||||||
|
"This program could not be executed.\n"
|
||||||
|
"I am unsure as to why you could not "
|
||||||
|
"do this. The file exists,\n"
|
||||||
|
"is a file, and you are allowed to "
|
||||||
|
"execute it. I suggest you look\n"
|
||||||
|
"into this.\n"), path);
|
||||||
|
/* not executable file */
|
||||||
|
else
|
||||||
|
DialogAlertOK(_
|
||||||
|
("There was an error running the program:\n"
|
||||||
|
"%s\n"
|
||||||
|
"This program could not be executed.\n"
|
||||||
|
"This is because the file exists, is a "
|
||||||
|
"file, but you are unable\n"
|
||||||
|
"to execute it because you do not "
|
||||||
|
"have execute "
|
||||||
|
"access to this file.\n"), path);
|
||||||
|
}
|
||||||
|
/* it's not a file */
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* its a dir */
|
||||||
|
if (isdir(path))
|
||||||
|
DialogAlertOK(_
|
||||||
|
("There was an error running the program:\n"
|
||||||
|
"%s\n"
|
||||||
|
"This program could not be executed.\n"
|
||||||
|
"This is because the file is in fact "
|
||||||
|
"a directory.\n"), path);
|
||||||
|
/* its not a file or a dir */
|
||||||
|
else
|
||||||
|
DialogAlertOK(_
|
||||||
|
("There was an error running the program:\n"
|
||||||
|
"%s\n"
|
||||||
|
"This program could not be executed.\n"
|
||||||
|
"This is because the file is not a "
|
||||||
|
"regular file.\n"), path);
|
||||||
|
}
|
||||||
|
Efree(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exit(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
33
src/main.c
33
src/main.c
|
@ -443,39 +443,26 @@ EoptHelp(void)
|
||||||
static void
|
static void
|
||||||
RunDocBrowser(void)
|
RunDocBrowser(void)
|
||||||
{
|
{
|
||||||
char file[FILEPATH_LEN_MAX];
|
char buf[FILEPATH_LEN_MAX];
|
||||||
|
|
||||||
Esnprintf(file, sizeof(file), "%s/edox", EDirBin());
|
Esnprintf(buf, sizeof(buf), "%s/edox", EDirBin());
|
||||||
if (!canexec(file))
|
if (!canexec(buf))
|
||||||
return;
|
return;
|
||||||
Esnprintf(file, sizeof(file), "%s/E-docs", EDirRoot());
|
Esnprintf(buf, sizeof(buf), "%s/E-docs", EDirRoot());
|
||||||
if (!canread(file))
|
if (!canread(buf))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (fork())
|
Esnprintf(buf, sizeof(buf), "%s/edox %s/E-docs", EDirBin(), EDirRoot());
|
||||||
return;
|
execApplication(buf, 0);
|
||||||
|
|
||||||
Esnprintf(file, sizeof(file), "exec %s/edox %s/E-docs",
|
|
||||||
EDirBin(), EDirRoot());
|
|
||||||
|
|
||||||
execl(usershell(getuid()), usershell(getuid()), "-c", (char *)file, NULL);
|
|
||||||
|
|
||||||
exit(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
RunMenuGen(void)
|
RunMenuGen(void)
|
||||||
{
|
{
|
||||||
char file[FILEPATH_LEN_MAX];
|
char buf[FILEPATH_LEN_MAX];
|
||||||
|
|
||||||
if (fork())
|
Esnprintf(buf, sizeof(buf), "%s/scripts/e_gen_menu", EDirRoot());
|
||||||
return;
|
execApplication(buf, EXEC_SET_LANG);
|
||||||
|
|
||||||
LangExport();
|
|
||||||
|
|
||||||
Esnprintf(file, sizeof(file), "exec %s/scripts/e_gen_menu", EDirRoot());
|
|
||||||
execl(usershell(getuid()), usershell(getuid()), "-c", (char *)file, NULL);
|
|
||||||
exit(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
@ -173,7 +173,7 @@ static void
|
||||||
MiscIpcExec(const char *params, Client * c __UNUSED__)
|
MiscIpcExec(const char *params, Client * c __UNUSED__)
|
||||||
{
|
{
|
||||||
if (params)
|
if (params)
|
||||||
execApplication(params);
|
execApplication(params, EXEC_SET_LANG);
|
||||||
else
|
else
|
||||||
IpcPrintf("exec what?\n");
|
IpcPrintf("exec what?\n");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue