just use wait in "system" call for awk, get rid of unix dependent status code divisor
This commit is contained in:
parent
ee68dedf53
commit
9ccbf1dcb1
|
@ -62,11 +62,11 @@ Node *curnode = nil; /* the node being executed, for debugging */
|
||||||
int
|
int
|
||||||
system(const char *s)
|
system(const char *s)
|
||||||
{
|
{
|
||||||
char status[512], *statfld[5];
|
Waitmsg *status;
|
||||||
int n, pid;
|
int pid;
|
||||||
|
|
||||||
if(!s)
|
if(s == nil)
|
||||||
return 1; /* a command interpreter is available */
|
return 1;
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if(pid == 0) {
|
if(pid == 0) {
|
||||||
execl("/bin/rc", "rc", "-c", s, nil);
|
execl("/bin/rc", "rc", "-c", s, nil);
|
||||||
|
@ -76,17 +76,19 @@ system(const char *s)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
for(;;) {
|
for(;;) {
|
||||||
n = await(status, sizeof(status) - 1);
|
status = wait();
|
||||||
status[n] = '\0';
|
if(status == nil)
|
||||||
if(n == -1)
|
FATAL("Out of memory");
|
||||||
return -1;
|
if(status->pid == pid)
|
||||||
tokenize(status, statfld, nelem(statfld));
|
|
||||||
if(strtol(statfld[0], nil, 0) == pid)
|
|
||||||
break;
|
break;
|
||||||
|
free(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(*statfld[4] != '\0')
|
if(status->msg[0] != '\0') {
|
||||||
|
free(status);
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
|
free(status);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1582,7 +1584,7 @@ Cell *bltin(Node **a, int) /* builtin functions. a[0] is type, a[1] is arg list
|
||||||
break;
|
break;
|
||||||
case FSYSTEM:
|
case FSYSTEM:
|
||||||
Bflush(&stdout); /* in case something is buffered already */
|
Bflush(&stdout); /* in case something is buffered already */
|
||||||
u = (Awkfloat) system(getsval(x)) / 256; /* 256 is unix-dep */
|
u = (Awkfloat) system(getsval(x));
|
||||||
break;
|
break;
|
||||||
case FRAND:
|
case FRAND:
|
||||||
/* in principle, rand() returns something in 0..RAND_MAX */
|
/* in principle, rand() returns something in 0..RAND_MAX */
|
||||||
|
|
Loading…
Reference in a new issue