Finished shell subsitution under linux

SVN revision: 1580
This commit is contained in:
Stefan Ritt 2005-12-20 08:03:57 +00:00
parent be1f4fe7ac
commit 9b421de0f7
2 changed files with 12 additions and 6 deletions

View File

@ -39,6 +39,9 @@ RM = /bin/rm -f
OSTYPE = $(shell uname) OSTYPE = $(shell uname)
# -lutil needed for forkpty()
LIBS += -lutil
ifeq ($(OSTYPE),solaris) ifeq ($(OSTYPE),solaris)
CC = gcc CC = gcc
LIBS += -lsocket -lnsl LIBS += -lsocket -lnsl

View File

@ -1028,22 +1028,23 @@ int subst_shell(char *cmd, char *result, int size)
#ifndef NO_PTY #ifndef NO_PTY
pid_t pid; pid_t pid;
int i, pipe; int i, pipe;
char line[32], buffer[1024], shell[32]; char line[32], buffer[256], shell[1024];
fd_set readfds; fd_set readfds;
struct timeval timeout;
if ((pid = forkpty(&pipe, line, NULL, NULL)) < 0) if ((pid = forkpty(&pipe, line, NULL, NULL)) < 0)
return 0; return 0;
else if (pid > 0) { else if (pid > 0) {
/* parent process */ /* parent process */
write(pipe, cmd, strlen(cmd));
result[0] = 0; result[0] = 0;
do { do {
FD_ZERO(&readfds); FD_ZERO(&readfds);
FD_SET(pipe, &readfds); FD_SET(pipe, &readfds);
timeout.tv_sec = 3;
timeout.tv_usec = 0;
select(FD_SETSIZE, (void *) &readfds, NULL, NULL, NULL); select(FD_SETSIZE, (void *) &readfds, NULL, NULL, (void *) &timeout);
if (FD_ISSET(pipe, &readfds)) { if (FD_ISSET(pipe, &readfds)) {
memset(buffer, 0, sizeof(buffer)); memset(buffer, 0, sizeof(buffer));
@ -1052,7 +1053,8 @@ int subst_shell(char *cmd, char *result, int size)
break; break;
buffer[i] = 0; buffer[i] = 0;
strlcat(result, buffer, size); strlcat(result, buffer, size);
} } else
break;
} while (1); } while (1);
@ -1067,7 +1069,8 @@ int subst_shell(char *cmd, char *result, int size)
strlcpy(shell, getenv("SHELL"), sizeof(shell)); strlcpy(shell, getenv("SHELL"), sizeof(shell));
else else
strcpy(shell, "/bin/sh"); strcpy(shell, "/bin/sh");
execl(shell, shell, 0);
execl(shell, shell, "-c", cmd, NULL);
} }
#else #else
assert(FALSE); assert(FALSE);