@@ -187,6 +187,8 @@ static stack_t signal_stack;
187187
188188/* initialise asynchronous i/o */
189189
190+ static int stderrIsAFile = 0 ; // for pollpip to avoid cluttering logs
191+
190192void
191193aioInit (void )
192194{
@@ -199,6 +201,8 @@ aioInit(void)
199201 FD_ZERO (& xdMask );
200202 maxFd = 0 ;
201203
204+ stderrIsAFile = !isatty (fileno (stderr ));
205+
202206 signal (SIGPIPE , SIG_IGN );
203207#if !USE_SIGALTSTACK
204208 signal (SIGIO , forceInterruptCheck );
@@ -275,12 +279,14 @@ extern long disownCount;
275279static char * ticks = "-\\|/" ;
276280static char * ticker = "" ;
277281static int tickCount = 0 ;
282+ long pollpipOutput = 0 ;
278283
279284#define TICKS_PER_CHAR 10
280- #define DO_TICK (bool ) \
281- do if ((bool) && !(++tickCount % TICKS_PER_CHAR)) { \
282- fprintf(stderr, "\r%c\r", *ticker); \
283- if (!*ticker++) ticker= ticks; \
285+ #define DO_TICK (bool ) \
286+ do if ((bool) && !(++tickCount % TICKS_PER_CHAR)) { \
287+ if (!*ticker) ticker = ticks; \
288+ fprintf(stderr, stderrIsAFile ? "%c" : "\r%c\r", *ticker++);\
289+ pollpipOutput = 1; \
284290} while (0)
285291
286292long
@@ -294,18 +300,17 @@ aioPoll(long microSeconds)
294300 extern void forceInterruptCheck (int ); /* not really, but hey */
295301#endif
296302
297- #if defined(AIO_DEBUG ) && AIO_DEBUG >= 2
298- FPRINTF ((stderr , "aioPoll(%ld)\n" , microSeconds ));
299- #endif
303+ DO_TICK (SHOULD_TICK ());
300304
305+ #if defined(AIO_DEBUG )
306+ # if AIO_DEBUG >= 2
307+ FPRINTF ((stderr , "aioPoll(%ld)\n" , microSeconds ));
308+ # endif
301309 // check that our signal handler is in place.
302310 // If it isn't, things aren't right.
303- #if AIO_DEBUG
304311 sigaction (SIGIO , NULL , & current_sigio_action );
305312 assert (current_sigio_action .sa_handler == forceInterruptCheck );
306313#endif
307- DO_TICK (SHOULD_TICK ());
308-
309314 /*
310315 * get out early if there is no pending i/o and no need to relinquish
311316 * cpu
@@ -315,7 +320,7 @@ aioPoll(long microSeconds)
315320 if (maxFd == 0 )
316321 return 0 ;
317322#else
318- if (( maxFd == 0 ) && ( microSeconds == 0 ) )
323+ if (maxFd == 0 && microSeconds == 0 )
319324 return 0 ;
320325#endif
321326
@@ -403,7 +408,6 @@ aioSleepForUsecs(long microSeconds)
403408void
404409aioEnable (int fd , void * data , int flags )
405410{
406- FPRINTF ((stderr , "aioEnable(%d)\n" , fd ));
407411 if (fd < 0 ) {
408412 FPRINTF ((stderr , "aioEnable(%d): IGNORED\n" , fd ));
409413 return ;
@@ -423,6 +427,7 @@ aioEnable(int fd, void *data, int flags)
423427 if (flags & AIO_EXT ) {
424428 FD_SET (fd , & xdMask );
425429 /* we should not set NBIO ourselves on external descriptors! */
430+ FPRINTF ((stderr , "aioEnable(%d): external\n" , fd ));
426431 }
427432 else {
428433 /*
@@ -440,6 +445,7 @@ aioEnable(int fd, void *data, int flags)
440445 perror ("fcntl(F_GETFL)" );
441446 if (fcntl (fd , F_SETFL , arg | O_NONBLOCK | O_ASYNC ) < 0 )
442447 perror ("fcntl(F_SETFL, O_ASYNC)" );
448+ FPRINTF ((stderr , "aioEnable(%d): Elicit SIGIO via O_ASYNC/fcntl\n" , fd ));
443449
444450#elif defined(FASYNC )
445451 if (fcntl (fd , F_SETOWN , getpid ()) < 0 )
@@ -448,6 +454,7 @@ aioEnable(int fd, void *data, int flags)
448454 perror ("fcntl(F_GETFL)" );
449455 if (fcntl (fd , F_SETFL , arg | O_NONBLOCK | FASYNC ) < 0 )
450456 perror ("fcntl(F_SETFL, FASYNC)" );
457+ FPRINTF ((stderr , "aioEnable(%d): Elicit SIGIO via FASYNC/fcntl\n" , fd ));
451458
452459#elif defined(FIOASYNC )
453460 arg = getpid ();
@@ -456,6 +463,9 @@ aioEnable(int fd, void *data, int flags)
456463 arg = 1 ;
457464 if (ioctl (fd , FIOASYNC , & arg ) < 0 )
458465 perror ("ioctl(FIOASYNC, 1)" );
466+ FPRINTF ((stderr , "aioEnable(%d): Elicit SIGIO via FIOASYNC/fcntl\n" , fd ));
467+ #else
468+ FPRINTF ((stderr , "aioEnable(%d): UNABLE TO ELICIT SIGIO!!\n" , fd ));
459469#endif
460470 }
461471}
0 commit comments