5407 extern void __signalIoInterrupt(); |
5407 extern void __signalIoInterrupt(); |
5408 #endif |
5408 #endif |
5409 static int firstCall = 1; |
5409 static int firstCall = 1; |
5410 |
5410 |
5411 #if (defined(F_GETFL) && defined(F_SETFL) && defined(FASYNC)) || defined(SYSV4) |
5411 #if (defined(F_GETFL) && defined(F_SETFL) && defined(FASYNC)) || defined(SYSV4) |
5412 /* |
5412 /* |
5413 * SIGIO/SIGPOLL - data available for I/O |
5413 * SIGIO/SIGPOLL - data available for I/O |
5414 * (used to wake up waiting processes) |
5414 * (used to wake up waiting processes) |
5415 */ |
5415 */ |
5416 #ifdef SIGIO |
5416 # ifdef SIGIO |
5417 # define THESIGNAL SIGIO |
5417 # define THESIGNAL SIGIO |
5418 #else |
|
5419 # ifdef SIGPOLL |
|
5420 # define THESIGNAL SIGPOLL |
|
5421 # else |
5418 # else |
5422 # ifdef SIGURG |
5419 # ifdef SIGPOLL |
5423 # define THESIGNAL SIGURG |
5420 # define THESIGNAL SIGPOLL |
|
5421 # else |
|
5422 # ifdef SIGURG |
|
5423 # define THESIGNAL SIGURG |
|
5424 # endif |
5424 # endif |
5425 # endif |
5425 # endif |
5426 # endif |
5426 #endif |
|
5427 |
5427 |
5428 if (__isSmallInteger(fd)) { |
5428 if (__isSmallInteger(fd)) { |
5429 if (firstCall) { |
5429 if (firstCall) { |
5430 #ifdef HAS_SIGACTION |
5430 # ifdef HAS_SIGACTION |
5431 struct sigaction act = {0}; |
5431 struct sigaction act; |
5432 |
5432 |
5433 /* |
5433 /* |
5434 * Do not add SA_RESTART here. A signal can cause a |
5434 * Do not add SA_RESTART here. A signal can cause a |
5435 * thread switch, another thread can do a garbage collect |
5435 * thread switch, another thread can do a garbage collect |
5436 * and restarted system calls may write into old |
5436 * and restarted system calls may write into old |
5439 |
5439 |
5440 act.sa_flags = SA_SIGINFO; /* <- if you add more, remember dummys at the top */ |
5440 act.sa_flags = SA_SIGINFO; /* <- if you add more, remember dummys at the top */ |
5441 sigemptyset(&act.sa_mask); |
5441 sigemptyset(&act.sa_mask); |
5442 act.sa_handler = __signalIoInterrupt; |
5442 act.sa_handler = __signalIoInterrupt; |
5443 sigaction(THESIGNAL, &act, 0); |
5443 sigaction(THESIGNAL, &act, 0); |
5444 #else |
5444 # else |
5445 # ifdef HAS_SIGVEC |
5445 # ifdef HAS_SIGVEC |
5446 struct sigvec vec; |
5446 struct sigvec vec; |
5447 |
5447 |
5448 vec.sv_flags = SV_INTERRUPT; |
5448 vec.sv_flags = SV_INTERRUPT; |
5449 sigemptyset(&vec.sv_mask); |
5449 sigemptyset(&vec.sv_mask); |
5450 vec.sv_handler = __signalIoInterrupt; |
5450 vec.sv_handler = __signalIoInterrupt; |
5451 sigvec(THESIGNAL, &vec, NULL); |
5451 sigvec(THESIGNAL, &vec, NULL); |
5452 # else |
5452 # else |
5453 signal(THESIGNAL, __signalIoInterrupt); |
5453 signal(THESIGNAL, __signalIoInterrupt); |
5454 # endif |
5454 # endif /* SIGVEC */ |
5455 #endif |
5455 # endif /* SIGACTION */ |
5456 firstCall = 0; |
5456 firstCall = 0; |
5457 } |
5457 } |
5458 #undef THESIGNAL |
5458 #undef THESIGNAL |
5459 |
5459 |
5460 f = __intVal(fd); |
5460 f = __intVal(fd); |
5471 ret = fcntl(f, F_SETFL, flags | FASYNC); |
5471 ret = fcntl(f, F_SETFL, flags | FASYNC); |
5472 if (ret >= 0) ret = flags; |
5472 if (ret >= 0) ret = flags; |
5473 } |
5473 } |
5474 # endif /*!SYSV4*/ |
5474 # endif /*!SYSV4*/ |
5475 |
5475 |
5476 #if defined(F_SETOWN) || defined(FIOSETOWN) |
5476 # if defined(F_SETOWN) || defined(FIOSETOWN) |
5477 { |
5477 { |
5478 int pid; |
5478 int pid; |
5479 int ok; |
5479 int ok; |
5480 |
5480 |
5481 pid = getpid(); |
5481 pid = getpid(); |
5482 |
5482 |
5483 # if defined(F_SETOWN) |
5483 # if defined(F_SETOWN) |
5484 ok = fcntl(f, F_SETOWN, pid); |
5484 ok = fcntl(f, F_SETOWN, pid); |
5485 /* printf("F_SETOWN returns %d (%d)\n", ret, errno); */ |
5485 /* printf("F_SETOWN returns %d (%d)\n", ret, errno); */ |
5486 # else |
5486 # else |
5487 ok = ioctl(f, FIOSETOWN, &pid); |
5487 ok = ioctl(f, FIOSETOWN, &pid); |
5488 /* printf("FIOSETOWN returns %d (%d)\n", ret, errno); */ |
5488 /* printf("FIOSETOWN returns %d (%d)\n", ret, errno); */ |
5489 # endif |
5489 # endif |
5490 if (ok < 0) { |
5490 if (ok < 0) { |
5491 ret = ok; |
5491 ret = ok; |
5492 } |
5492 } |
5493 } |
5493 } |
5494 #endif |
5494 # endif |
5495 RETURN ( __MKUINT(ret) ); |
5495 RETURN ( __MKUINT(ret) ); |
5496 } |
5496 } |
5497 #endif |
5497 #endif |
5498 %}. |
5498 %}. |
5499 " |
5499 " |
5676 break; |
5676 break; |
5677 } |
5677 } |
5678 |
5678 |
5679 { |
5679 { |
5680 #ifdef HAS_SIGACTION |
5680 #ifdef HAS_SIGACTION |
5681 struct sigaction act = {0}; |
5681 struct sigaction act; |
5682 |
5682 |
5683 /* |
5683 /* |
5684 * Do not add SA_RESTART here. A signal can cause a |
5684 * Do not add SA_RESTART here. A signal can cause a |
5685 * thread switch, another thread can do a garbage collect |
5685 * thread switch, another thread can do a garbage collect |
5686 * and restarted system calls may write into old |
5686 * and restarted system calls may write into old |
5735 extern void __signalTimerInterrupt(SIGHANDLER_ARG); |
5735 extern void __signalTimerInterrupt(SIGHANDLER_ARG); |
5736 # endif |
5736 # endif |
5737 |
5737 |
5738 if (firstCall) { |
5738 if (firstCall) { |
5739 # ifdef HAS_SIGACTION |
5739 # ifdef HAS_SIGACTION |
5740 struct sigaction act = {0}; |
5740 struct sigaction act; |
5741 |
5741 |
5742 act.sa_flags = SA_SIGINFO; /* <- if you add more, remember dummys at the top */ |
5742 act.sa_flags = SA_SIGINFO; /* <- if you add more, remember dummys at the top */ |
5743 sigemptyset(&act.sa_mask); |
5743 sigemptyset(&act.sa_mask); |
5744 act.sa_handler = __signalTimerInterrupt; |
5744 act.sa_handler = __signalTimerInterrupt; |
5745 sigaction(SIGALRM, &act, 0); |
5745 sigaction(SIGALRM, &act, 0); |