mirror of
https://github.com/fluencelabs/musl
synced 2025-06-26 21:22:11 +00:00
initial check-in, version 0.5.0
This commit is contained in:
20
src/process/execl.c
Normal file
20
src/process/execl.c
Normal file
@ -0,0 +1,20 @@
|
||||
#include <unistd.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
int execl(const char *path, ...)
|
||||
{
|
||||
int argc;
|
||||
va_list ap;
|
||||
va_start(ap, path);
|
||||
for (argc=0; va_arg(ap, const char *); argc++);
|
||||
va_end(ap);
|
||||
{
|
||||
int i;
|
||||
char *argv[argc+1];
|
||||
va_start(ap, path);
|
||||
for (i=0; i<argc; i++)
|
||||
argv[i] = va_arg(ap, char *);
|
||||
argv[i] = NULL;
|
||||
return execv(path, argv);
|
||||
}
|
||||
}
|
22
src/process/execle.c
Normal file
22
src/process/execle.c
Normal file
@ -0,0 +1,22 @@
|
||||
#include <unistd.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
int execle(const char *path, ...)
|
||||
{
|
||||
int argc;
|
||||
va_list ap;
|
||||
va_start(ap, path);
|
||||
for (argc=0; va_arg(ap, const char *); argc++);
|
||||
va_end(ap);
|
||||
{
|
||||
int i;
|
||||
char *argv[argc+1];
|
||||
char **envp;
|
||||
va_start(ap, path);
|
||||
for (i=0; i<argc; i++)
|
||||
argv[i] = va_arg(ap, char *);
|
||||
argv[i] = NULL;
|
||||
envp = va_arg(ap, char **);
|
||||
return execve(path, argv, envp);
|
||||
}
|
||||
}
|
20
src/process/execlp.c
Normal file
20
src/process/execlp.c
Normal file
@ -0,0 +1,20 @@
|
||||
#include <unistd.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
int execlp(const char *file, ...)
|
||||
{
|
||||
int argc;
|
||||
va_list ap;
|
||||
va_start(ap, file);
|
||||
for (argc=0; va_arg(ap, const char *); argc++);
|
||||
va_end(ap);
|
||||
{
|
||||
int i;
|
||||
char *argv[argc+1];
|
||||
va_start(ap, file);
|
||||
for (i=0; i<argc; i++)
|
||||
argv[i] = va_arg(ap, char *);
|
||||
argv[i] = NULL;
|
||||
return execvp(file, argv);
|
||||
}
|
||||
}
|
8
src/process/execv.c
Normal file
8
src/process/execv.c
Normal file
@ -0,0 +1,8 @@
|
||||
#include <unistd.h>
|
||||
|
||||
extern char **__environ;
|
||||
|
||||
int execv(const char *path, char *const argv[])
|
||||
{
|
||||
return execve(path, argv, __environ);
|
||||
}
|
8
src/process/execve.c
Normal file
8
src/process/execve.c
Normal file
@ -0,0 +1,8 @@
|
||||
#include <unistd.h>
|
||||
#include "syscall.h"
|
||||
|
||||
int execve(const char *path, char *const argv[], char *const envp[])
|
||||
{
|
||||
/* do we need to use environ if envp is null? */
|
||||
return syscall3(__NR_execve, (long)path, (long)argv, (long)envp);
|
||||
}
|
34
src/process/execvp.c
Normal file
34
src/process/execvp.c
Normal file
@ -0,0 +1,34 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
extern char **__environ;
|
||||
|
||||
int execvp(const char *file, char *const argv[])
|
||||
{
|
||||
const char *p, *z, *path = getenv("PATH");
|
||||
int l;
|
||||
|
||||
if (strchr(file, '/'))
|
||||
return execve(file, argv, __environ);
|
||||
|
||||
/* FIXME: integer overflows */
|
||||
if (!path) path = "/usr/local/bin:/bin:/usr/bin";
|
||||
l = strlen(file) + strlen(path) + 2;
|
||||
|
||||
for(p=path; p && *p; p=z) {
|
||||
char b[l];
|
||||
z = strchr(p, ':');
|
||||
if (z) {
|
||||
memcpy(b, p, z-p);
|
||||
b[z++-p] = 0;
|
||||
} else strcpy(b, p);
|
||||
strcat(b, "/");
|
||||
strcat(b, file);
|
||||
if (!access(b, X_OK))
|
||||
return execve(b, argv, __environ);
|
||||
}
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
9
src/process/fork.c
Normal file
9
src/process/fork.c
Normal file
@ -0,0 +1,9 @@
|
||||
#include <unistd.h>
|
||||
#include "syscall.h"
|
||||
|
||||
/* FIXME: add support for atfork stupidity */
|
||||
|
||||
pid_t fork(void)
|
||||
{
|
||||
return syscall0(__NR_fork);
|
||||
}
|
45
src/process/system.c
Normal file
45
src/process/system.c
Normal file
@ -0,0 +1,45 @@
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <sys/wait.h>
|
||||
#include <errno.h>
|
||||
|
||||
int system(const char *cmd)
|
||||
{
|
||||
pid_t pid;
|
||||
sigset_t old, new;
|
||||
struct sigaction sa, oldint, oldquit;
|
||||
int status;
|
||||
|
||||
if (!cmd) return 1;
|
||||
|
||||
sa.sa_handler = SIG_IGN;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sa.sa_flags = 0;
|
||||
|
||||
sigaction(SIGINT, &sa, &oldint);
|
||||
sigaction(SIGQUIT, &sa, &oldquit);
|
||||
sigaddset(&sa.sa_mask, SIGCHLD);
|
||||
sigprocmask(SIG_BLOCK, &new, &old);
|
||||
|
||||
pid = fork();
|
||||
if (pid <= 0) {
|
||||
sigaction(SIGINT, &oldint, NULL);
|
||||
sigaction(SIGQUIT, &oldquit, NULL);
|
||||
sigprocmask(SIG_SETMASK, &old, NULL);
|
||||
if (pid == 0) {
|
||||
execl("/bin/sh", "sh", "-c", cmd, (char *)0);
|
||||
_exit(127);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
while (waitpid(pid, &status, 0) == -1)
|
||||
if (errno != EINTR) {
|
||||
status = -1;
|
||||
break;
|
||||
}
|
||||
sigaction(SIGINT, &oldint, NULL);
|
||||
sigaction(SIGQUIT, &oldquit, NULL);
|
||||
sigprocmask(SIG_SETMASK, &old, NULL);
|
||||
return status;
|
||||
}
|
8
src/process/vfork.c
Normal file
8
src/process/vfork.c
Normal file
@ -0,0 +1,8 @@
|
||||
#include <unistd.h>
|
||||
#include "syscall.h"
|
||||
|
||||
pid_t vfork(void)
|
||||
{
|
||||
/* vfork syscall cannot be made from C code */
|
||||
return syscall0(__NR_fork);
|
||||
}
|
6
src/process/wait.c
Normal file
6
src/process/wait.c
Normal file
@ -0,0 +1,6 @@
|
||||
#include <sys/wait.h>
|
||||
|
||||
pid_t wait(int *status)
|
||||
{
|
||||
return waitpid((pid_t)-1, status, 0);
|
||||
}
|
7
src/process/waitid.c
Normal file
7
src/process/waitid.c
Normal file
@ -0,0 +1,7 @@
|
||||
#include <sys/wait.h>
|
||||
#include "syscall.h"
|
||||
|
||||
int waitid(idtype_t type, id_t id, siginfo_t *info, int options)
|
||||
{
|
||||
return syscall5(__NR_waitid, type, id, (long)info, options, 0);
|
||||
}
|
7
src/process/waitpid.c
Normal file
7
src/process/waitpid.c
Normal file
@ -0,0 +1,7 @@
|
||||
#include <sys/wait.h>
|
||||
#include "syscall.h"
|
||||
|
||||
pid_t waitpid(pid_t pid, int *status, int options)
|
||||
{
|
||||
return syscall4(__NR_wait4, pid, (long)status, options, 0);
|
||||
}
|
Reference in New Issue
Block a user