blob: 497b0e1f179361f72bda288453276685c5291c33 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#include "lib.h"
#include <stdlib.h>
#include <stdio.h>
#include <sys/wait.h>
#include <unistd.h>
int
system(const char *s)
{
int w, status;
pid_t pid;
char cmd[30], *oty;
oty = getenv("cputype");
if(!oty)
return -1;
if(!s)
return 1; /* a command interpreter is available */
pid = fork();
snprintf(cmd, sizeof cmd, "/%s/bin/ape/sh", oty);
if(pid == 0) {
execl(cmd, "sh", "-c", s, NULL);
_exit(1);
}
if(pid < 0){
_syserrno();
return -1;
}
for(;;) {
w = wait(&status);
if(w == -1 || w == pid)
break;
}
if(w == -1){
_syserrno();
return w;
}
return status;
}
|