Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/shell/shell_common.c
- Timestamp:
- Jan 1, 2014, 12:47:38 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mindi-busybox/shell/shell_common.c
r2725 r3232 19 19 #include "libbb.h" 20 20 #include "shell_common.h" 21 #include <sys/resource.h> /* getrlimit */ 21 22 22 23 const char defifsvar[] ALIGN1 = "IFS= \t\n"; … … 37 38 /* read builtin */ 38 39 40 /* Needs to be interruptible: shell mush handle traps and shell-special signals 41 * while inside read. To implement this, be sure to not loop on EINTR 42 * and return errno == EINTR reliably. 43 */ 39 44 //TODO: use more efficient setvar() which takes a pointer to malloced "VAR=VAL" 40 45 //string. hush naturally has it, and ash has setvareq(). … … 52 57 ) 53 58 { 59 unsigned err; 54 60 unsigned end_ms; /* -t TIMEOUT */ 55 61 int fd; /* -u FD */ … … 62 68 int startword; 63 69 smallint backslash; 70 71 errno = err = 0; 64 72 65 73 pp = argv; … … 132 140 if (nchars) { 133 141 tty.c_lflag &= ~ICANON; 134 tty.c_cc[VMIN] = nchars < 256 ? nchars : 255; 142 // Setting it to more than 1 breaks poll(): 143 // it blocks even if there's data. !?? 144 //tty.c_cc[VMIN] = nchars < 256 ? nchars : 255; 145 /* reads would block only if < 1 char is available */ 146 tty.c_cc[VMIN] = 1; 147 /* no timeout (reads block forever) */ 148 tty.c_cc[VTIME] = 0; 135 149 } 136 150 if (read_flags & BUILTIN_READ_SILENT) { … … 153 167 do { 154 168 char c; 155 169 struct pollfd pfd[1]; 170 int timeout; 171 172 if ((bufpos & 0xff) == 0) 173 buffer = xrealloc(buffer, bufpos + 0x101); 174 175 timeout = -1; 156 176 if (end_ms) { 157 int timeout;158 struct pollfd pfd[1];159 160 pfd[0].fd = fd;161 pfd[0].events = POLLIN;162 177 timeout = end_ms - (unsigned)monotonic_ms(); 163 if (timeout <= 0 /* already late? */ 164 || safe_poll(pfd, 1, timeout) != 1 /* no? wait... */ 165 ) { /* timed out! */ 178 if (timeout <= 0) { /* already late? */ 166 179 retval = (const char *)(uintptr_t)1; 167 180 goto ret; … … 169 182 } 170 183 171 if ((bufpos & 0xff) == 0) 172 buffer = xrealloc(buffer, bufpos + 0x100); 173 if (nonblock_safe_read(fd, &buffer[bufpos], 1) != 1) { 184 /* We must poll even if timeout is -1: 185 * we want to be interrupted if signal arrives, 186 * regardless of SA_RESTART-ness of that signal! 187 */ 188 errno = 0; 189 pfd[0].fd = fd; 190 pfd[0].events = POLLIN; 191 if (poll(pfd, 1, timeout) != 1) { 192 /* timed out, or EINTR */ 193 err = errno; 194 retval = (const char *)(uintptr_t)1; 195 goto ret; 196 } 197 if (read(fd, &buffer[bufpos], 1) != 1) { 198 err = errno; 174 199 retval = (const char *)(uintptr_t)1; 175 200 break; 176 201 } 202 177 203 c = buffer[bufpos]; 178 204 if (c == '\0') … … 241 267 if (read_flags & BUILTIN_READ_SILENT) 242 268 tcsetattr(fd, TCSANOW, &old_tty); 269 270 errno = err; 243 271 return retval; 244 272 } … … 287 315 { RLIMIT_LOCKS, 0, 'w', "locks" }, 288 316 #endif 317 #ifdef RLIMIT_NICE 318 { RLIMIT_NICE, 0, 'e', "scheduling priority" }, 319 #endif 320 #ifdef RLIMIT_RTPRIO 321 { RLIMIT_RTPRIO, 0, 'r', "real-time priority" }, 322 #endif 289 323 }; 290 324 … … 328 362 #ifdef RLIMIT_LOCKS 329 363 "w::" 364 #endif 365 #ifdef RLIMIT_NICE 366 "e::" 367 #endif 368 #ifdef RLIMIT_RTPRIO 369 "r::" 330 370 #endif 331 371 ; … … 369 409 /* optarg = NULL; opterr = 0; optopt = 0; - do we need this?? */ 370 410 371 372 373 411 argc = 1; 412 while (argv[argc]) 413 argc++; 374 414 375 415 opts = 0;
Note:
See TracChangeset
for help on using the changeset viewer.