Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

TCL(Tool Command Language) Scripting

inet.d start/stop of Tcl scripts


I am building a server farm, each of which will be running three to five
persistent Tcl scripts.  They respond to SIGHUP and SIGTERM in the usual
way, but I've been unable to get an init.d-style script to work for
them. The problem seems to be that startproc and killproc and all expect
argv[0] to stay the same.

I tried making a simple main() that invoked Tcl_Main with a AppInit that
simply looked at argv[0] and invoked
Tcl_EvalFile on strcat(argv[0], ".tcl")
but then argc and argv inside the script didn't get set up properly, as
well as having auto_path be something different (including the
executable's directory in the auto_path and stuff like that). I haven't
done much access-Tcl-from-C stuff, but it looked like Tcl_Main should be
sufficient to set up everything needed.

Has anyone already done this? Am I missing something obvious?

Tcl 8.4 (most recent stable)
SuSE 10.2 Linux

--
   Darren New / San Diego, CA, USA (PST)
     His kernel fu is strong.
     He studied at the Shao Linux Temple.

Your AppInit routine should call Tcl_Init().

Instead of calling Tcl_EvalFile directly, you might try (ab)using
some Tcl internal routines to signal to Tcl_Main what you want the
startup script file to be:

   TclSetStartupScriptFileName(strcat(argv[0], "*.tcl"));

and then just return TCL_OK and let Tcl_Main() drive things.

--
| Don Porter          Mathematical and Computational Sciences Division |
| donald.por@nist.gov             Information Technology Laboratory |
| http://math.nist.gov/~DPorter/                                  NIST |
|______________________________________________________________________|

Don Porter wrote:
> Your AppInit routine should call Tcl_Init().

Duh. Yes, I was missing that.  It's still not quite the same as invoking
Tclsh though...

If I use Tcl_AppInit to call Tcl_EvalFile, then after the EvalFile
returns, Tcl_Main tries to invoke argv[1].  I.e., if I call
invoke one two three four
I get
AppInit: buf=uplevel #0 {source Invoke.tcl}
Invoked invoke.tcl  <- (Here on down is from the Invoke.tcl script.)
Argc = 3
Argv = two three four
Argv0 = one
auto_path = /usr/share/tcl/tcl8.4 /usr/share/tcl /SkyClix/src/lib/lib
/usr/lib
<- Here on down is from the C code again.
couldn't read file "one": no such file or directory
make: *** [test] Error 1

With just tclsh Invoke.tcl one two three four, I get
Invoked invoke.tcl
Argc = 4
Argv = one two three four
Argv0 = Invoke.tcl
auto_path = /usr/share/tcl/tcl8.4 /usr/share/tcl /usr/lib

Note the lack of any extraneous /SkyClix/src/lib/lib in auto_path,
and that "one" actually gets passed in argv.

Using the TclSetStartupScriptFileName trick, I get the same thing
as the first output above, except without the "can't find one" on
return.

Is the easiest solution to simply build a new argv[] in C and put a
dummy script name in front or something? I'll give that a try next. I'd
prefer not to get arbitrary directories plugged into the auto_path, but
I'm willing to kludge around that if necessary.

--
   Darren New / San Diego, CA, USA (PST)
     His kernel fu is strong.
     He studied at the Shao Linux Temple.

Darren New wrote:
> Is the easiest solution to simply build a new argv[] in C and put a
> dummy script name in front or something?

The answer to this appears to be "yes".  Just for the record.

--
   Darren New / San Diego, CA, USA (PST)
     His kernel fu is strong.
     He studied at the Shao Linux Temple.

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc