12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
-
+
-
-
|
*/
#include "tclInt.h"
#include "tclPort.h"
/*
* The headers are needed for the testalarm command that verifies the
* EINITR bug has been fixed (Handling of this signal was forgotten after
* use of SA_RESTART in signal handlers.
* Tcl7.4.)
*/
#include <tcl.h>
#include <signal.h>
#include <sys/resource.h>
/*
* The following macros convert between TclFile's and fd's. The conversion
* simple involves shifting fd's up by one to ensure that no valid fd is ever
* the same as NULL. Note that this code is duplicated from tclUnixPipe.c
|
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
-
+
|
#define MAX_PIPES 10
static Pipe testPipes[MAX_PIPES];
/*
* The stuff below is used by the testalarm and testgotsig ommands.
*/
static char gotsig = '0';
static char *gotsig = "0";
/*
* Forward declarations of procedures defined later in this file:
*/
static void TestFileHandlerProc _ANSI_ARGS_((ClientData clientData,
int mask));
|
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
|
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
|
-
-
+
+
+
-
+
-
+
+
+
+
+
-
-
+
+
-
-
+
+
+
+
+
|
}
/*
*----------------------------------------------------------------------
* TestalarmCmd --
*
* Test that EINTR is handled correctly by generating and
* handling a signal. This was handled correctly in Tcl7.4
* but was lost when channel drivers were created.
* handling a signal. This requires using the SA_RESTART
* flag when registering the signal handler.
*
* Results:
* None.
*
* Side Effects:
* Sets up an signal and async handlers.
*
*----------------------------------------------------------------------
*/
int
TestalarmCmd(clientData, interp, argc, argv)
ClientData clientData; /* Not used. */
Tcl_Interp *interp; /* Current interpreter. */
int argc; /* Number of arguments. */
char **argv; /* Argument strings. */
{
#ifdef SA_RESTART
unsigned int sec;
RETSIGTYPE (*oldhandler)();
struct sigaction action;
if (argc > 1) {
Tcl_GetInt(interp, argv[1], (int *)&sec);
} else {
sec = 1;
}
/*
* Setup the signal handling.
* Setup the signal handling that automatically retries
* any interupted I/O system calls.
*/
action.sa_handler = AlarmHandler;
memset((void *)&action.sa_mask, 0, sizeof(sigset_t));
action.sa_flags = SA_RESTART;
oldhandler = signal(SIGALRM, AlarmHandler);
if (sigaction(SIGALRM, &action, NULL) < 0) {
if ((int)oldhandler == -1) {
Tcl_AppendResult(interp, "signal: ", Tcl_PosixError(interp), NULL);
Tcl_AppendResult(interp, "sigaction: ", Tcl_PosixError(interp), NULL);
return TCL_ERROR;
}
if (alarm(sec) < 0) {
Tcl_AppendResult(interp, "alarm: ", Tcl_PosixError(interp), NULL);
return TCL_ERROR;
}
return TCL_OK;
#else
Tcl_AppendResult(interp, "warning: sigaction SA_RESTART not support on this platform", NULL);
return TCL_ERROR;
#endif
}
/*
*----------------------------------------------------------------------
*
* AlarmHandler --
*
|
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
|
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
|
-
+
|
*
*----------------------------------------------------------------------
*/
void
AlarmHandler()
{
gotsig = '1';
gotsig = "1";
}
/*
*----------------------------------------------------------------------
* TestgotsigCmd --
*
* Verify the signal was handled after the testalarm command.
|
590
591
592
593
594
595
596
597
598
599
600
|
596
597
598
599
600
601
602
603
604
605
606
|
-
-
+
+
|
int
TestgotsigCmd(clientData, interp, argc, argv)
ClientData clientData; /* Not used. */
Tcl_Interp *interp; /* Current interpreter. */
int argc; /* Number of arguments. */
char **argv; /* Argument strings. */
{
Tcl_AppendResult(interp, &gotsig, (char *) NULL);
gotsig = '0';
Tcl_AppendResult(interp, gotsig, (char *) NULL);
gotsig = "0";
return TCL_OK;
}
|