DRAFT lib: Implement system.
* lib/stub/system.c: Move to... * lib/stdlib/system.c: ...here. Implement. * build-aux/configure-lib.sh (libc_gnu_SOURCES): Update file name. * include/stdlib.h (system): Add prototype.
This commit is contained in:
parent
5281b8e611
commit
5e0e66dcf0
|
@ -353,6 +353,7 @@ lib/stdlib/atexit.c
|
|||
lib/stdlib/atof.c
|
||||
lib/stdlib/atol.c
|
||||
lib/stdlib/mbstowcs.c
|
||||
lib/stdlib/system.c
|
||||
lib/string/bcmp.c
|
||||
lib/string/bcopy.c
|
||||
lib/string/bzero.c
|
||||
|
@ -406,7 +407,6 @@ lib/stub/strftime.c
|
|||
lib/stub/strsignal.c
|
||||
lib/stub/sys_siglist.c
|
||||
lib/stub/sysconf.c
|
||||
lib/stub/system.c
|
||||
lib/stub/times.c
|
||||
lib/stub/ttyname.c
|
||||
lib/stub/umask.c
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
* Copyright © 2017,2018,2019,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* This file is part of GNU Mes.
|
||||
*
|
||||
|
@ -59,6 +59,7 @@ long strtol (char const *string, char **tailptr, int base);
|
|||
long long strtoll (char const *string, char **tailptr, int base);
|
||||
unsigned long strtoul (char const *string, char **tailptr, int base);
|
||||
unsigned long long strtoull (char const *string, char **tailptr, int base);
|
||||
int system (char const *command);
|
||||
|
||||
#define EXIT_FAILURE 1
|
||||
#define EXIT_SUCCESS 0
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
* Copyright © 2018,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* This file is part of GNU Mes.
|
||||
*
|
||||
|
@ -20,14 +20,40 @@
|
|||
|
||||
#include <mes/lib.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifndef SHELL_FILE_NAME
|
||||
#define SHELL_FILE_NAME "/bin/sh"
|
||||
#endif
|
||||
#ifndef SHELL_COMMAND_NAME
|
||||
#define SHELL_COMMAND_NAME "sh"
|
||||
#endif
|
||||
|
||||
int
|
||||
system (int x)
|
||||
system (char const *command)
|
||||
{
|
||||
static int stub = 0;
|
||||
if (__mes_debug () && !stub)
|
||||
eputs ("system stub\n");
|
||||
stub = 1;
|
||||
errno = 0;
|
||||
return 0;
|
||||
pid_t pid = fork ();
|
||||
if (pid == -1)
|
||||
return -1;
|
||||
else if (pid == 0)
|
||||
{
|
||||
// child
|
||||
char const *argv[4];
|
||||
argv[0] = SHELL_COMMAND_NAME;
|
||||
argv[1] = "-c";
|
||||
argv[2] = command;
|
||||
argv[3] = 0;
|
||||
execve (SHELL_FILE_NAME, (char *const *) argv, environ);
|
||||
_exit (127);
|
||||
}
|
||||
|
||||
// parent
|
||||
int status;
|
||||
pid_t child_pid = waitpid (pid, &status, 0);
|
||||
if (child_pid != pid)
|
||||
return -1;
|
||||
|
||||
return status;
|
||||
}
|
Loading…
Reference in New Issue