|
|
1.1 ! root 1: /* ttym.c - miscellaneous routines */ ! 2: ! 3: #include "../h/mh.h" ! 4: #include <pwd.h> ! 5: #ifndef NSIG ! 6: #include <signal.h> ! 7: #endif NSIG ! 8: #include <sys/time.h> ! 9: ! 10: static int ttyf(); ! 11: ! 12: /* */ ! 13: ! 14: ! 15: static void ! 16: ttym(fd, command, line, user, vec) ! 17: int fd; ! 18: char *command, *line, *user, **vec; ! 19: { ! 20: SIGDECL (*pstat)(); ! 21: char *ap, ! 22: *term, ! 23: *myself, ! 24: *getlogin (), ! 25: *rindex (), ! 26: *ttyname (); ! 27: struct passwd *pw, ! 28: *getpwuid (); ! 29: ! 30: if ((term = ap = ttyname (2)) && (term = rindex (term, '/'))) ! 31: term++; ! 32: if (term == NULL || *term == NULL) ! 33: term = ap; ! 34: if ((myself = getlogin ()) == NULL || *myself == NULL) ! 35: myself = (pw = getpwuid (getuid ())) ? pw -> pw_name : NULL; ! 36: ! 37: pstat = signal (SIGPIPE, SIG_IGN); ! 38: (void) write (fd, command, strlen (command)); ! 39: (void) write (fd, "", 1); ! 40: ! 41: if (term) ! 42: (void) write (fd, term, strlen (term)); ! 43: (void) write (fd, "", 1); ! 44: ! 45: if (myself) ! 46: (void) write (fd, myself, strlen (myself)); ! 47: (void) write (fd, "", 1); ! 48: ! 49: if (line && *line) ! 50: (void) write (fd, line, strlen (line)); ! 51: (void) write (fd, "", 1); ! 52: ! 53: if (user && *user) ! 54: (void) write (fd, user, strlen (user)); ! 55: (void) write (fd, "", 1); ! 56: ! 57: if (vec) ! 58: while (ap = *vec++) { ! 59: (void) write (fd, ap, strlen (ap)); ! 60: (void) write (fd, "", 1); ! 61: } ! 62: ! 63: (void) write (fd, "", 1); ! 64: (void) signal (SIGPIPE, pstat); ! 65: } ! 66: ! 67: /* */ ! 68: ! 69: static int ! 70: ttyv(fd) ! 71: int fd; ! 72: { ! 73: int ifds, ! 74: nbits; ! 75: char c; ! 76: struct timeval tv; ! 77: ! 78: ifds = 1 << fd; ! 79: nbits = getdtablesize(); ! 80: tv.tv_sec = SMLWAIT; ! 81: tv.tv_usec = 0; ! 82: if (select (nbits, &ifds, (int *) 0, (int *) 0, &tv) <= 0 ! 83: || read (fd, &c, 1) != 1) ! 84: return NOTOK; ! 85: if (c == NULL) ! 86: return fd; ! 87: putc (c, stderr); ! 88: ! 89: (void) ttyf (fd, stderr); ! 90: return NOTOK; ! 91: } ! 92: ! 93: ! 94: static int ! 95: ttyf(fd, f) ! 96: int fd; ! 97: FILE *f; ! 98: { ! 99: int i; ! 100: char buffer[BUFSIZ]; ! 101: ! 102: while ((i = read (fd, buffer, sizeof buffer)) > 0) ! 103: (void) fwrite (buffer, sizeof (char), i, f); ! 104: return i; ! 105: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.