Commit b23d1446 authored by Chris Allegretta's avatar Chris Allegretta
Browse files

Redo open_pipe with just pipes and no FIFOs

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1138 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
No related merge requests found
Showing with 23 additions and 26 deletions
+23 -26
...@@ -291,37 +291,34 @@ int read_file(int fd, char *filename, int quiet) ...@@ -291,37 +291,34 @@ int read_file(int fd, char *filename, int quiet)
#ifndef NANO_SMALL #ifndef NANO_SMALL
int open_pipe(char *command) int open_pipe(char *command)
{ {
int forkpid, fd; int fd[2], pid;
char *pipefile, *execute;
execute = charalloc(strlen(command) + 24); /* Make our pipes. */
if ((pipefile = safe_tempnam(0, "nano.")) == NULL) {
statusbar(_("Could not create a temporary filename: %s"), if (pipe(fd) == -1) {
strerror(errno)); statusbar("Could not pipe");
free(execute);
free(pipefile);
return 1; return 1;
} }
sprintf(execute,"%s 2>&1 > %s",command,pipefile); /* Fork a child */
umask(0);
mkfifo(pipefile,0700); if ((pid = fork()) == 0) {
forkpid = fork(); close(fd[0]);
if (forkpid == -1) { dup2(fd[1], fileno(stdout));
dup2(fd[1], fileno(stderr));
/* If execl() returns at all, there was an error. */
execl("/bin/sh","/bin/sh","-c",command,0);
exit(0);
}
else if (pid == -1) {
statusbar(_("Could not fork")); statusbar(_("Could not fork"));
free(execute);
free(pipefile);
return 1; return 1;
} }
else if (forkpid == 0) {
execl("/bin/sh","/bin/sh","-c",execute,0); /* Else continue as parent */
exit(0); close(fd[1]);
} read_file(fd[0],"stdin",0);
fd = open(pipefile,O_RDONLY);
read_file(fd,"stdin",0);
unlink(pipefile);
free(execute);
free(pipefile);
set_modified(); set_modified();
return 0; return 0;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment