| ︙ | | |
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
-
-
-
-
-
-
-
+
+
+
+
+
+
+
|
static const char *gotsig = "0";
/*
* Forward declarations of functions defined later in this file:
*/
static Tcl_ObjCmdProc TestalarmCmd;
static Tcl_ObjCmdProc TestchmodCmd;
static Tcl_ObjCmdProc TestfilehandlerCmd;
static Tcl_ObjCmdProc TestfilewaitCmd;
static Tcl_ObjCmdProc TestfindexecutableCmd;
static Tcl_ObjCmdProc TestforkCmd;
static Tcl_ObjCmdProc TestgotsigCmd;
static Tcl_ObjCmdProc2 TestalarmCmd;
static Tcl_ObjCmdProc2 TestchmodCmd;
static Tcl_ObjCmdProc2 TestfilehandlerCmd;
static Tcl_ObjCmdProc2 TestfilewaitCmd;
static Tcl_ObjCmdProc2 TestfindexecutableCmd;
static Tcl_ObjCmdProc2 TestforkCmd;
static Tcl_ObjCmdProc2 TestgotsigCmd;
static Tcl_FileProc TestFileHandlerProc;
static void AlarmHandler(int signum);
/*
*----------------------------------------------------------------------
*
* TclplatformtestInit --
|
| ︙ | | |
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
-
+
-
+
-
+
-
+
-
+
-
+
-
+
|
*----------------------------------------------------------------------
*/
int
TclplatformtestInit(
Tcl_Interp *interp) /* Interpreter to add commands to. */
{
Tcl_CreateObjCommand(interp, "testchmod", TestchmodCmd,
Tcl_CreateObjCommand2(interp, "testchmod", TestchmodCmd,
NULL, NULL);
Tcl_CreateObjCommand(interp, "testfilehandler", TestfilehandlerCmd,
Tcl_CreateObjCommand2(interp, "testfilehandler", TestfilehandlerCmd,
NULL, NULL);
Tcl_CreateObjCommand(interp, "testfilewait", TestfilewaitCmd,
Tcl_CreateObjCommand2(interp, "testfilewait", TestfilewaitCmd,
NULL, NULL);
Tcl_CreateObjCommand(interp, "testfindexecutable", TestfindexecutableCmd,
Tcl_CreateObjCommand2(interp, "testfindexecutable", TestfindexecutableCmd,
NULL, NULL);
Tcl_CreateObjCommand(interp, "testfork", TestforkCmd,
Tcl_CreateObjCommand2(interp, "testfork", TestforkCmd,
NULL, NULL);
Tcl_CreateObjCommand(interp, "testalarm", TestalarmCmd,
Tcl_CreateObjCommand2(interp, "testalarm", TestalarmCmd,
NULL, NULL);
Tcl_CreateObjCommand(interp, "testgotsig", TestgotsigCmd,
Tcl_CreateObjCommand2(interp, "testgotsig", TestgotsigCmd,
NULL, NULL);
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
|
| ︙ | | |
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
-
+
-
+
-
+
|
* None.
*
*----------------------------------------------------------------------
*/
static int
TestfilehandlerCmd(
TCL_UNUSED(ClientData),
TCL_UNUSED(void *),
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
size_t objc, /* Number of arguments. */
Tcl_Obj *const *objv) /* Argument strings. */
{
Pipe *pipePtr;
int i, mask, timeout;
static int initialized = 0;
char buffer[4000];
TclFile file;
/*
* NOTE: When we make this code work on Windows also, the following
* variable needs to be made Unix-only.
*/
if (!initialized) {
for (i = 0; i < MAX_PIPES; i++) {
testPipes[i].readFile = NULL;
}
initialized = 1;
}
if (objc < 2) {
if (objc + 1 < 3) {
Tcl_WrongNumArgs(interp, 1, objv, "option ...");
return TCL_ERROR;
}
pipePtr = NULL;
if (objc >= 3) {
if (Tcl_GetIntFromObj(interp, objv[2], &i) != TCL_OK) {
return TCL_ERROR;
|
| ︙ | | |
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
|
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
|
-
+
|
return TCL_ERROR;
}
return TCL_OK;
}
static void
TestFileHandlerProc(
ClientData clientData, /* Points to a Pipe structure. */
void *clientData, /* Points to a Pipe structure. */
int mask) /* Indicates which events happened:
* TCL_READABLE or TCL_WRITABLE. */
{
Pipe *pipePtr = (Pipe *)clientData;
if (mask & TCL_READABLE) {
pipePtr->readCount++;
|
| ︙ | | |
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
|
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
|
-
+
-
+
-
+
|
* None.
*
*----------------------------------------------------------------------
*/
static int
TestfilewaitCmd(
TCL_UNUSED(ClientData),
TCL_UNUSED(void *),
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
size_t objc, /* Number of arguments. */
Tcl_Obj *const *objv) /* Argument strings. */
{
int mask, result, timeout;
Tcl_Channel channel;
int fd;
ClientData data;
void *data;
if (objc != 4) {
Tcl_WrongNumArgs(interp, 2, objv, "file readable|writable|both timeout");
return TCL_ERROR;
}
channel = Tcl_GetChannel(interp, Tcl_GetString(objv[1]), NULL);
if (channel == NULL) {
|
| ︙ | | |
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
|
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
|
-
+
|
} else {
Tcl_AppendResult(interp, "bad argument \"", Tcl_GetString(objv[2]),
"\": must be readable, writable, or both", NULL);
return TCL_ERROR;
}
if (Tcl_GetChannelHandle(channel,
(mask & TCL_READABLE) ? TCL_READABLE : TCL_WRITABLE,
(ClientData*) &data) != TCL_OK) {
(void **) &data) != TCL_OK) {
Tcl_AppendResult(interp, "couldn't get channel file", NULL);
return TCL_ERROR;
}
fd = PTR2INT(data);
if (Tcl_GetIntFromObj(interp, objv[3], &timeout) != TCL_OK) {
return TCL_ERROR;
}
|
| ︙ | | |
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
|
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
|
-
+
-
+
|
* None.
*
*----------------------------------------------------------------------
*/
static int
TestfindexecutableCmd(
TCL_UNUSED(ClientData),
TCL_UNUSED(void *),
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
size_t objc, /* Number of arguments. */
Tcl_Obj *const *objv) /* Argument strings. */
{
Tcl_Obj *saveName;
if (objc != 2) {
Tcl_WrongNumArgs(interp, 1, objv, "argv0");
return TCL_ERROR;
|
| ︙ | | |
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
|
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
|
-
+
-
+
|
* None.
*
*----------------------------------------------------------------------
*/
static int
TestforkCmd(
TCL_UNUSED(ClientData),
TCL_UNUSED(void *),
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
size_t objc, /* Number of arguments. */
Tcl_Obj *const *objv) /* Argument strings. */
{
pid_t pid;
if (objc != 1) {
Tcl_WrongNumArgs(interp, 1, objv, "");
return TCL_ERROR;
|
| ︙ | | |
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
|
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
|
-
+
-
+
|
* Sets up an signal and async handlers.
*
*----------------------------------------------------------------------
*/
static int
TestalarmCmd(
TCL_UNUSED(ClientData),
TCL_UNUSED(void *),
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
size_t objc, /* Number of arguments. */
Tcl_Obj *const *objv) /* Argument strings. */
{
#ifdef SA_RESTART
unsigned int sec = 1;
struct sigaction action;
if (objc > 1) {
|
| ︙ | | |
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
|
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
|
-
+
-
+
|
* Resets the value of gotsig back to '0'.
*
*----------------------------------------------------------------------
*/
static int
TestgotsigCmd(
TCL_UNUSED(ClientData),
TCL_UNUSED(void *),
Tcl_Interp *interp, /* Current interpreter. */
TCL_UNUSED(int) /*objc*/,
TCL_UNUSED(size_t) /*objc*/,
TCL_UNUSED(Tcl_Obj *const *))
{
Tcl_AppendResult(interp, gotsig, NULL);
gotsig = "0";
return TCL_OK;
}
|
| ︙ | | |
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
|
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
|
-
+
-
+
+
-
+
-
+
|
* Changes permissions of specified files.
*
*---------------------------------------------------------------------------
*/
static int
TestchmodCmd(
TCL_UNUSED(ClientData),
TCL_UNUSED(void *),
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
size_t objc, /* Number of arguments. */
Tcl_Obj *const *objv) /* Argument strings. */
{
size_t i;
int i, mode;
int mode;
if (objc < 2) {
if (objc + 1 < 3) {
Tcl_WrongNumArgs(interp, 1, objv, "mode file ?file ...?");
return TCL_ERROR;
}
if (Tcl_GetIntFromObj(interp, objv[1], &mode) != TCL_OK) {
return TCL_ERROR;
}
|
| ︙ | | |