Refactor/simplify, use execApplication in stead of plain fork/exec.

SVN revision: 25691
This commit is contained in:
Kim Woelders 2006-09-10 14:29:05 +00:00
parent d363bf0c08
commit 35c8f904df
4 changed files with 118 additions and 141 deletions

View File

@ -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);

View File

@ -26,141 +26,130 @@
#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);
LangExport();
/* Set up env stuff */
if (flags & EXEC_SET_LANG)
LangExport();
sh = usershell(getuid());
if (exe)
path = pathtoexec(exe);
if (path)
{
path = pathtoexec(exe);
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);
}
Efree(path);
if (!Mode.wm.startup)
{
path = pathtofile(exe);
if (!path)
{
/* absolute path */
if (isabspath(exe))
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 -1;
sprintf(real_exec, "exec %s", params);
execl(sh, sh, "-c", real_exec, NULL);
/* We should not get here - invalid shell? */
}
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;
if (!Mode.wm.startup)
{
path = pathtofile(exe);
if (!path)
{
/* absolute path */
if (isabspath(exe))
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);
}
void

View File

@ -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

View File

@ -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");
}