diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2013-07-23 09:27:59 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2013-07-23 09:27:59 (GMT) |
commit | 07d10b8a58badcd2bcd882286b3f1caec5bc3476 (patch) | |
tree | 3e4760c8a483b0ec1b2493584a2e9fe47f39362d /unix/tclUnixTest.c | |
parent | 17ebc3cd20794e0246b5c6b5f86b128cf1e7b69b (diff) | |
parent | bc28cd1ac82705c2452e11f441e3fd0796c6d692 (diff) | |
download | tcl-07d10b8a58badcd2bcd882286b3f1caec5bc3476.zip tcl-07d10b8a58badcd2bcd882286b3f1caec5bc3476.tar.gz tcl-07d10b8a58badcd2bcd882286b3f1caec5bc3476.tar.bz2 |
Add "testfork" test command. Not used in any test-case yet
Diffstat (limited to 'unix/tclUnixTest.c')
-rw-r--r-- | unix/tclUnixTest.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/unix/tclUnixTest.c b/unix/tclUnixTest.c index c10225d..f64a29e 100644 --- a/unix/tclUnixTest.c +++ b/unix/tclUnixTest.c @@ -67,6 +67,7 @@ static Tcl_CmdProc TestchmodCmd; static Tcl_CmdProc TestfilehandlerCmd; static Tcl_CmdProc TestfilewaitCmd; static Tcl_CmdProc TestfindexecutableCmd; +static Tcl_ObjCmdProc TestforkObjCmd; static Tcl_CmdProc TestgetdefencdirCmd; static Tcl_CmdProc TestgetopenfileCmd; static Tcl_CmdProc TestgotsigCmd; @@ -103,6 +104,8 @@ TclplatformtestInit( NULL, NULL); Tcl_CreateCommand(interp, "testfindexecutable", TestfindexecutableCmd, NULL, NULL); + Tcl_CreateObjCommand(interp, "testfork", TestforkObjCmd, + NULL, NULL); Tcl_CreateCommand(interp, "testgetopenfile", TestgetopenfileCmd, NULL, NULL); Tcl_CreateCommand(interp, "testgetdefenc", TestgetdefencdirCmd, @@ -526,6 +529,52 @@ TestsetdefencdirCmd( Tcl_SetDefaultEncodingDir(argv[1]); return TCL_OK; } + +/* + *---------------------------------------------------------------------- + * + * TestforkObjCmd -- + * + * This function implements the "testfork" command. It is used to + * fork the Tcl process for specific test cases. + * + * Results: + * A standard Tcl result. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +static int +TestforkObjCmd( + ClientData clientData, /* Not used. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *const *objv) /* Argument strings. */ +{ + pid_t pid; + + if (objc != 1) { + Tcl_WrongNumArgs(interp, 1, objv, ""); + return TCL_ERROR; + } + pid = fork(); + if (pid == -1) { + Tcl_AppendResult(interp, + "Cannot fork", NULL); + return TCL_ERROR; + } +#ifndef HAVE_PTHREAD_ATFORK + /* Only needed when pthread_atfork is not present. */ + if (pid==0) { + Tcl_InitNotifier(); + } +#endif + Tcl_SetObjResult(interp, Tcl_NewIntObj(pid)); + return TCL_OK; +} /* *---------------------------------------------------------------------- |