mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-08-27 15:32:52 +02:00
helpers: improve my_system function
Instead of hardcoding the maximum number of arguments to the
my_system helper, pass a variable argument list.
The function is deliberately source-incompatible with the old
implementation (as opposed to a variant with a sentinel NULL
argument, which would be compatible) to find all users and to
make sure that new future users of this function are not
overlooked during merges with other branches.
Signed-off-by: Jacek Jendrzej <crashdvb@googlemail.com>
Origin commit data
------------------
Branch: ni/coolstream
Commit: 988a8ebec2
Author: Stefan Seyfried <seife@tuxbox-git.slipkontur.de>
Date: 2013-03-03 (Sun, 03 Mar 2013)
------------------
This commit was generated by Migit
This commit is contained in:
committed by
Jacek Jendrzej
parent
915c34bd15
commit
767be83e22
@@ -37,7 +37,7 @@
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <dirent.h>
|
||||
#include <zapit/debug.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <system/helpers.h>
|
||||
#include <gui/update_ext.h>
|
||||
@@ -70,12 +70,32 @@ int my_system(const char * cmd)
|
||||
if (!file_exists(cmd))
|
||||
return -1;
|
||||
|
||||
return my_system(cmd, NULL);
|
||||
return my_system(1, cmd);
|
||||
}
|
||||
|
||||
int my_system(const char * cmd, const char * arg1, const char * arg2, const char * arg3, const char * arg4, const char * arg5, const char * arg6)
|
||||
int my_system(int argc, const char *arg, ...)
|
||||
{
|
||||
int i=0 ,ret=0, childExit=0;
|
||||
int i = 0, ret = 0, childExit = 0;
|
||||
#define ARGV_MAX 64
|
||||
/* static right now but could be made dynamic if necessary */
|
||||
int argv_max = ARGV_MAX;
|
||||
const char *argv[ARGV_MAX];
|
||||
va_list args;
|
||||
argv[0] = arg;
|
||||
va_start(args, arg);
|
||||
|
||||
while(++i < argc)
|
||||
{
|
||||
if (i == argv_max)
|
||||
{
|
||||
fprintf(stderr, "my_system: too many arguments!\n");
|
||||
return -1;
|
||||
}
|
||||
argv[i] = va_arg(args, const char *);
|
||||
}
|
||||
argv[i] = NULL; /* sentinel */
|
||||
//fprintf(stderr,"%s:", __func__);for(i=0;argv[i];i++)fprintf(stderr," '%s'",argv[i]);fprintf(stderr,"\n");
|
||||
|
||||
pid_t pid;
|
||||
int maxfd = getdtablesize();// sysconf(_SC_OPEN_MAX);
|
||||
switch (pid = vfork())
|
||||
@@ -88,9 +108,9 @@ int my_system(const char * cmd, const char * arg1, const char * arg2, const char
|
||||
close(i);
|
||||
if (setsid() == -1)
|
||||
perror("my_system setsid");
|
||||
if(execlp(cmd, cmd, arg1, arg2, arg3, arg4, arg5, arg6, (char*)NULL))
|
||||
if (execvp(argv[0], (char * const *)argv))
|
||||
{
|
||||
std::string txt = "ERROR: my_system \"" + (std::string) cmd + "\"";
|
||||
std::string txt = "ERROR: my_system \"" + (std::string) argv[0] + "\"";
|
||||
perror(txt.c_str());
|
||||
ret = -1;
|
||||
}
|
||||
@@ -101,6 +121,7 @@ int my_system(const char * cmd, const char * arg1, const char * arg2, const char
|
||||
waitpid(pid, &childExit, 0);
|
||||
if(childExit != 0)
|
||||
ret = childExit;
|
||||
va_end(args);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user