script.c (da52b4caaf187775f6b56a72c6b16e94ad728f7b) | script.c (29da75477bd86b4efa5afb5fe9c131ad86099bf7) |
---|---|
1/* 2 * Copyright (c) 1980, 1992, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 72 unchanged lines hidden (view full) --- 81 struct winsize win; 82 int aflg, kflg, ch, n; 83 struct timeval tv, *tvp; 84 time_t tvec, start; 85 char obuf[BUFSIZ]; 86 char ibuf[BUFSIZ]; 87 fd_set rfd; 88 int flushtime = 30; | 1/* 2 * Copyright (c) 1980, 1992, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 72 unchanged lines hidden (view full) --- 81 struct winsize win; 82 int aflg, kflg, ch, n; 83 struct timeval tv, *tvp; 84 time_t tvec, start; 85 char obuf[BUFSIZ]; 86 char ibuf[BUFSIZ]; 87 fd_set rfd; 88 int flushtime = 30; |
89 int readstdin; |
|
89 90 aflg = kflg = 0; 91 while ((ch = getopt(argc, argv, "aqkt:")) != -1) 92 switch(ch) { 93 case 'a': 94 aflg = 1; 95 break; 96 case 'q': --- 53 unchanged lines hidden (view full) --- 150 if (child < 0) { 151 warn("fork"); 152 done(1); 153 } 154 if (child == 0) 155 doshell(argv); 156 close(slave); 157 | 90 91 aflg = kflg = 0; 92 while ((ch = getopt(argc, argv, "aqkt:")) != -1) 93 switch(ch) { 94 case 'a': 95 aflg = 1; 96 break; 97 case 'q': --- 53 unchanged lines hidden (view full) --- 151 if (child < 0) { 152 warn("fork"); 153 done(1); 154 } 155 if (child == 0) 156 doshell(argv); 157 close(slave); 158 |
158 if (flushtime > 0) 159 tvp = &tv; 160 else 161 tvp = NULL; 162 163 start = time(0); 164 FD_ZERO(&rfd); | 159 start = tvec = time(0); 160 readstdin = 1; |
165 for (;;) { | 161 for (;;) { |
162 FD_ZERO(&rfd); |
|
166 FD_SET(master, &rfd); | 163 FD_SET(master, &rfd); |
167 FD_SET(STDIN_FILENO, &rfd); 168 if (flushtime > 0) { 169 tv.tv_sec = flushtime; | 164 if (readstdin) 165 FD_SET(STDIN_FILENO, &rfd); 166 if ((!readstdin && ttyflg) || flushtime > 0) { 167 tv.tv_sec = !readstdin && ttyflg ? 1 : 168 flushtime - (tvec - start); |
170 tv.tv_usec = 0; | 169 tv.tv_usec = 0; |
170 tvp = &tv; 171 readstdin = 1; 172 } else { 173 tvp = NULL; |
|
171 } 172 n = select(master + 1, &rfd, 0, 0, tvp); 173 if (n < 0 && errno != EINTR) 174 break; 175 if (n > 0 && FD_ISSET(STDIN_FILENO, &rfd)) { 176 cc = read(STDIN_FILENO, ibuf, BUFSIZ); 177 if (cc < 0) 178 break; | 174 } 175 n = select(master + 1, &rfd, 0, 0, tvp); 176 if (n < 0 && errno != EINTR) 177 break; 178 if (n > 0 && FD_ISSET(STDIN_FILENO, &rfd)) { 179 cc = read(STDIN_FILENO, ibuf, BUFSIZ); 180 if (cc < 0) 181 break; |
179 if (cc == 0) 180 (void)write(master, ibuf, 0); | 182 if (cc == 0) { 183 if (tcgetattr(master, &stt) == 0 && 184 (stt.c_lflag & ICANON) != 0) { 185 (void)write(master, &stt.c_cc[VEOF], 1); 186 } 187 readstdin = 0; 188 } |
181 if (cc > 0) { 182 (void)write(master, ibuf, cc); 183 if (kflg && tcgetattr(master, &stt) >= 0 && 184 ((stt.c_lflag & ECHO) == 0)) { 185 (void)fwrite(ibuf, 1, cc, fscript); 186 } 187 } 188 } --- 93 unchanged lines hidden --- | 189 if (cc > 0) { 190 (void)write(master, ibuf, cc); 191 if (kflg && tcgetattr(master, &stt) >= 0 && 192 ((stt.c_lflag & ECHO) == 0)) { 193 (void)fwrite(ibuf, 1, cc, fscript); 194 } 195 } 196 } --- 93 unchanged lines hidden --- |