|
|
1.1 ! root 1: /* ! 2: * File: server.c ! 3: * ! 4: * Purpose: main program for recording process ! 5: * ! 6: * $Log: server.c,v $ ! 7: * Revision 1.2 92/06/15 10:04:57 bin ! 8: * *** empty log message *** ! 9: * ! 10: */ ! 11: ! 12: /* ! 13: * Includes. ! 14: */ ! 15: #include <stdio.h> ! 16: ! 17: /* ! 18: * Definitions. ! 19: * Constants. ! 20: * Macros with argument lists. ! 21: * Typedefs. ! 22: * Enums. ! 23: */ ! 24: ! 25: typedef unsigned char uchar; ! 26: typedef unsigned int uint; ! 27: typedef unsigned long ulong; ! 28: ! 29: /* ! 30: * Functions. ! 31: * Import Functions. ! 32: * Export Functions. ! 33: * Local Functions. ! 34: */ ! 35: main(); ! 36: ! 37: /* ! 38: * Global Data. ! 39: * Import Variables. ! 40: * Export Variables. ! 41: * Local Variables. ! 42: */ ! 43: ! 44: /* ! 45: * main() ! 46: * ! 47: * Usage is script [-l logfile] [command] ! 48: * ! 49: * All output from the specified command, including echoing of user ! 50: * input, is recorded to the logfile. ! 51: * ! 52: * "logfile" defaults to L.pid, where "pid" is the number of the ! 53: * recording process. ! 54: * ! 55: * "command" defaults to the whatever environment variable SHELL ! 56: * specifies, and to "/bin/sh" if SHELL is not set. ! 57: */ ! 58: main(argc, argv, envp) ! 59: int argc; ! 60: char ** argv, ** envp; ! 61: { ! 62: int master_fd, slave_fd, childpid; ! 63: static char master_pty[32]; ! 64: static char slave_pty[32]; ! 65: static char log_file[60]; ! 66: int argn, n; ! 67: ! 68: sprintf(log_file, "Log.%d", getpid()); ! 69: argv++; ! 70: for (argn = 1; argn < argc; argn++, argv++) { ! 71: if (strncmp(*argv, "-l", 2) == 0) { ! 72: if (strlen(*argv) > 2) { ! 73: if (strlen(*argv) < 62) ! 74: strcpy(log_file, *argv + 2); ! 75: } else ! 76: strcpy(log_file, *++argv); ! 77: continue; ! 78: } ! 79: break; ! 80: } ! 81: ! 82: if (!isatty(0) || !isatty(1)) { ! 83: fprintf(stderr, "stdin and stdout must be tty devices\n"); ! 84: exit(1); ! 85: } ! 86: ! 87: if ((master_fd = getpseudotty(master_pty, slave_pty)) < 0) { ! 88: fprintf(stderr, "can't open master pty\n"); ! 89: exit(1); ! 90: } ! 91: ! 92: if (tty_getmode(0) < 0) { ! 93: fprintf(stderr, "can't getmode of stdin\n"); ! 94: exit(1); ! 95: } ! 96: ! 97: if ((childpid = fork()) < 0) { ! 98: fprintf(stderr, "forking error\n"); ! 99: exit(1); ! 100: } ! 101: ! 102: if (childpid == 0) { /* child */ ! 103: setpgrp(); ! 104: ! 105: if ((slave_fd = open(slave_pty, 2)) < 0) { ! 106: fprintf(stderr, "can't open slave pty\n"); ! 107: exit(1); ! 108: } ! 109: close(master_fd); ! 110: ! 111: if (tty_setmode(slave_fd) < 0) { ! 112: fprintf(stderr, "can't setmode of slave fd\n"); ! 113: exit(1); ! 114: } ! 115: exec_shell(slave_fd, argv, envp); ! 116: } ! 117: ! 118: if (tty_raw(0) < 0) { ! 119: fprintf(stderr, "tty_raw error on stdin\n"); ! 120: exit(1); ! 121: } ! 122: ! 123: pass_all(master_fd, log_file); ! 124: ! 125: if (tty_reset(0) < 0) { ! 126: fprintf(stderr, "tty_reset error on stdin\n"); ! 127: exit(1); ! 128: } ! 129: ! 130: exit(0); ! 131: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.