|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T p
Length: 4634 (0x121a) Types: TextFile Names: »pipe.c«
└─⟦3d0c2be1b⟧ Bits:30001254 ISODE-5.0 Tape └─⟦eba4602b1⟧ »./isode-5.0.tar.Z« └─⟦d3ac74d73⟧ └─⟦this⟧ »isode-5.0/others/quipu/uips/dish/pipe.c«
/* pipe.c - Dish shell command handler */ #ifndef lint static char *rcsid = "$Header: /f/osi/others/quipu/uips/dish/RCS/pipe.c,v 6.0 89/03/18 23:34:30 mrose Rel $"; #endif /* * $Header: /f/osi/others/quipu/uips/dish/RCS/pipe.c,v 6.0 89/03/18 23:34:30 mrose Rel $ * * * $Log: pipe.c,v $ * Revision 6.0 89/03/18 23:34:30 mrose * Release 5.0 * */ /* * NOTICE * * Acquisition, use, and distribution of this module and related * materials are subject to the restrictions of a license agreement. * Consult the Preface in the User's Manual for the full terms of * this agreement. * */ #include <stdio.h> #include <fcntl.h> #include <sys/types.h> #include <sys/stat.h> #include <signal.h> #include "quipu/util.h" #ifndef BINDIR #define BINDIR "/usr" #endif #define BIGBUF 100000 extern int errno; char retfile[LINESIZE]; int fd; int wfd; main (argc, argv) int argc; char **argv; { int res; char buffer[BIGBUF]; char sendfile[LINESIZE]; char dishname[LINESIZE]; int i; char *ptr, *getenv(), *sprintf(), *ttyname (), *getwd (); void pipe_quit (); (void) umask (0); (void) sprintf (retfile, "/tmp/dish%d", getpid ()); (void) sprintf (sendfile, "/tmp/dish-%s-%d", rindex (ttyname (0), '/') + 1, getuid()); setbuf (stdout,NULLCP); setbuf (stderr,NULLCP); if (mknod (retfile, S_IFIFO | 0600, 0) == -1) { (void) fprintf (stderr,"Can't create pipe '%s'\n",retfile); exit (-12); } for (i = 1; i <= 15; i++) (void) signal (i, pipe_quit); if ((fd = open (sendfile, O_WRONLY | O_NDELAY)) == -1) { (void) fprintf (stderr, "(Dish starting)\n"); if (mknod (sendfile, S_IFIFO | 0600, 0) == -1) { (void) fprintf (stderr,"Can't create pipe '%s'\n",sendfile); exit (-11); } if (fork () == 0) { /* child */ (void) sprintf (dishname, "%s/dish", BINDIR); execl (dishname, "dish","-pipe",0); (void) fprintf (stderr, "Can't exec %s/dish !!!\n", BINDIR); (void) unlink (retfile); exit (-2); } else { fd = open (sendfile, O_WRONLY); setbuf (stderr,NULLCP); } } argc--; if ((ptr = rindex (argv[0], '/')) == NULLCP) (void) sprintf (buffer, "%s:%s", retfile, argv[0]); else (void) sprintf (buffer, "%s:%s", retfile, ++ptr); argv++; while (argc--) { (void) strcat (buffer, " \""); (void) strcat (buffer, *argv++); (void) strcat (buffer, "\""); } if ((res = write (fd, buffer, strlen (buffer))) == -1) { (void) fprintf (stderr, "Write to DUA failed... Please retry\n"); (void) close (fd); (void) unlink (retfile); exit (-3); } (void) close (fd); /* get results */ if ((fd = open (retfile, O_RDONLY)) < 0) { (void) fprintf (stderr, "Can't read results\n"); (void) unlink (retfile); exit (-4); } if ((wfd = open (retfile, O_WRONLY)) < 0) { (void) fprintf (stderr, "Can't lock results failed\n"); (void) unlink (retfile); (void) close (fd); exit (-5); } do { if ((res = read (fd, buffer, BIGBUF)) == -1) { (void) fprintf (stderr, "Read failed (%d)\n", errno); (void) unlink (retfile); (void) close (fd); (void) close (wfd); exit (-6); } *(buffer + res) = 0; if (*buffer == '2') fputs (&buffer[1], stderr); else if (*buffer == '1') fputs (&buffer[1], stdout); else { /* 'e' or 'p' */ int res2, nfd; char where[LINESIZE]; if (*buffer == 'e') { (void) getwd (where); (void) system (&buffer[1]); } else getpassword (buffer,&where[0]); if ((nfd = open (sendfile, O_WRONLY)) == -1) { (void) fprintf (stderr, "re-write open error\n"); (void) close (wfd); (void) close (fd); (void) unlink (retfile); exit (-9); } if ((res2 = write (nfd, where, strlen (where))) == -1) { (void) fprintf (stderr, "Write to DUA failed (%d)... Please retry\n", res2); (void) close (fd); (void) close (nfd); (void) close (wfd); (void) unlink (retfile); exit (-10); } (void) close (nfd); } } while ((*buffer == 'e') || (*buffer == 'p')); (void) close (fd); (void) close (wfd); (void) unlink (retfile); if (*buffer == '2') exit (-1); } void pipe_quit (sig) int sig; { extern char *sys_siglist[]; (void) unlink (retfile); (void) fprintf (stderr,"(%s) exiting...\n",sys_siglist[sig]); } getpassword (buffer,where) char * buffer; char * where; { (void) system ("stty -echo"); (void) printf ("Enter password for \"%s\": ",++buffer); (void) gets (where); (void) system ("stty echo"); (void) printf ("\n"); }