Changeset 321 for trunk/src/sh_sub.c
- Timestamp:
- Mar 17, 2011, 10:07:44 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/sh_sub.c
r316 r321 20 20 #include "config_xor.h" 21 21 22 /* 0->1 for debug */ 23 #if 0 24 #define SH_SUB_DBG 1 25 #endif 26 22 27 #ifndef NULL 23 28 #if !defined(__cplusplus) … … 62 67 static ssize_t sh_sub_read(int fd, void *buf, size_t count); 63 68 64 staticvoid sh_kill_sub()69 void sh_kill_sub() 65 70 { 66 71 SH_MUTEX_LOCK(mutex_sub); 72 67 73 if (sh_child_pid != -1) 68 74 { 69 75 int status; 76 #ifdef WCONTINUED 77 int wflags = WNOHANG|WUNTRACED|WCONTINUED; 78 #else 79 int wflags = WNOHANG|WUNTRACED; 80 #endif 70 81 71 82 close (parent2child[1]); 72 83 close (child2parent[0]); 73 84 74 fprintf(stderr, "FIXME kill_sub %d\n", (int) sh_child_pid);85 /* fprintf(stderr, "FIXME kill_sub %d\n", (int) sh_child_pid); */ 75 86 76 87 /* Let's be rude. */ … … 80 91 81 92 if (sh_wait_ret == 0) 82 sh_wait_ret = waitpid( -1, &status, WNOHANG|WUNTRACED);93 sh_wait_ret = waitpid( -1, &status, wflags); 83 94 else 84 sh_wait_ret = waitpid(sh_child_pid, &status, WNOHANG|WUNTRACED);95 sh_wait_ret = waitpid(sh_child_pid, &status, wflags); 85 96 86 97 sh_child_pid = -1; 87 98 } 99 88 100 SH_MUTEX_UNLOCK(mutex_sub); 89 101 return; … … 93 105 { 94 106 pid_t res; 95 int retval = 0;107 volatile int retval = 0; 96 108 97 109 SH_MUTEX_LOCK(mutex_sub); … … 162 174 ++fd; 163 175 } 176 177 /* 178 for (i = 0; i < 3; ++i) 179 { 180 if ( fcntl(i, F_GETFL, 0) == (-1)) 181 (void) open(_("/dev/null"), O_RDWR, 0); 182 } 183 */ 164 184 165 185 /* reset signal handling … … 275 295 do { 276 296 277 / / fprintf(stderr, "FIXME wait_com polling..\n");297 /* fprintf(stderr, "FIXME wait_com polling..\n"); */ 278 298 279 299 do { … … 307 327 outbuf.errnum = errno; 308 328 309 / / fprintf(stderr, "FIXME wait_com writing..\n");329 /* fprintf(stderr, "FIXME wait_com writing..\n"); */ 310 330 311 331 ret = sh_sub_write(child2parent[1], &outbuf, sizeof(outbuf)); 312 332 if (ret < 0) 313 333 { 314 fprintf(stderr, "FIXME wait_com return 1\n");334 /* fprintf(stderr, "FIXME wait_com return 1\n"); */ 315 335 return; 316 336 } … … 318 338 else /* sh_sub_read() < 0 */ 319 339 { 320 fprintf(stderr, "FIXME wait_com return 2\n");340 /* fprintf(stderr, "FIXME wait_com return 2\n"); */ 321 341 return; 322 342 } 323 343 } 324 344 325 / / fprintf(stderr, "FIXME wait_com next..\n");345 /* fprintf(stderr, "FIXME wait_com next..\n"); */ 326 346 327 347 } while (1 == 1); … … 362 382 } 363 383 384 #ifdef SH_SUB_DBG 385 #include <stdarg.h> 386 static void debug_it (const char *fmt, ...) 387 { 388 char msg[256]; 389 va_list ap; 390 391 int fd = open("debug.it", O_CREAT|O_WRONLY|O_APPEND, 0666); 392 393 va_start(ap, fmt); 394 vsnprintf(msg, sizeof(msg), fmt, ap); /* flawfinder: ignore */ 395 va_end(ap); 396 397 write(fd, msg, strlen(msg)); 398 write(fd, "\n", 1); 399 close(fd); 400 return; 401 } 402 #endif 403 364 404 static int sh_sub_stat_int(const char *path, struct stat *buf, char command) 365 405 { … … 397 437 start: 398 438 439 #ifdef SH_SUB_DBG 440 debug_it("%d sh_child_pid %d\n", (int)getpid(), (int) sh_child_pid); 441 #endif 442 399 443 if (sh_child_pid == -1) 400 444 sh_create_sub(); 401 445 402 // fprintf(stderr, "FIXME stat_sub %s\n", inbuf.path); 446 #ifdef SH_SUB_DBG 447 debug_it("%d stat_sub %s (%d)\n", (int)getpid(), inbuf.path, (int) sh_child_pid); 448 #endif 403 449 404 450 SH_MUTEX_LOCK(mutex_sub_work); … … 412 458 } 413 459 414 // fprintf(stderr, "FIXME stat_sub polling..\n"); 460 #ifdef SH_SUB_DBG 461 debug_it("%d stat_sub polling..\n", (int)getpid()); 462 #endif 415 463 416 464 pfds.fd = child2parent[0]; … … 428 476 } 429 477 430 // fprintf(stderr, "FIXME stat_sub reading..\n"); 478 #ifdef SH_SUB_DBG 479 debug_it("%d stat_sub reading..\n", (int)getpid()); 480 #endif 431 481 432 482 retval = sh_sub_read (child2parent[0], &outbuf, sizeof(outbuf)); … … 444 494 if (sflag == 0) 445 495 { 446 // fprintf(stderr, "FIXME stat_sub done..\n"); 496 #ifdef SH_SUB_DBG 497 debug_it("%d stat_sub done..\n", (int)getpid()); 498 #endif 447 499 memcpy(buf, &(outbuf.sbuf), sizeof(struct stat)); 448 500 errno = outbuf.errnum; … … 451 503 else if (sflag == 1) 452 504 { 505 #ifdef SH_SUB_DBG 506 debug_it("%d stat_sub error..\n", (int)getpid()); 507 #endif 453 508 /* could not read, thus subprocess may have gone */ 509 sflag = 0; 454 510 goto start; 455 511 }
Note:
See TracChangeset
for help on using the changeset viewer.