int Ns_ModuleInit(char *srv, char *mod) { struct mydata *md = NULL; md = (struct mydata*)ns_malloc(sizeof(struct mydata)); md->modname = strcpy(ns_malloc(strlen(mod)+1), mod); md->server = strcpy(ns_malloc(strlen(srv)+1), srv); return (Ns_TclInitInterps(srv, NsThread_Init, (void*)md) == TCL_OK) ? NS_OK : NS_ERROR; }
int NsPerl2_ModInit(char *server, char *module) { extern perl_master_context *nsperl2_master_context; int perl_exitstatus; Ns_Log(Notice,"nsperl2: loading"); if (!(nsperl2_master_context = ns_malloc (sizeof(perl_master_context)))) return TCL_ERROR; /* determine initial perl script */ nsperl2_master_context->param_path = Ns_ConfigGetPath(server, module, NULL); nsperl2_master_context->init_script = Ns_ConfigGetValue(nsperl2_master_context->param_path, "init_script"); nsperl2_master_context->init_sub = Ns_ConfigGetValue(nsperl2_master_context->param_path, "init_sub"); nsperl2_master_context->server = Ns_ConfigGetValue(nsperl2_master_context->param_path, "server"); /* TODO: what to do if multiple servers? probably need a master context per server */ Ns_Log (Notice, "nsperl2: init_script is %s", nsperl2_master_context->init_script); char *embedding[] = { "", nsperl2_master_context->init_script }; PerlInterpreter *perl_interp; int perl_argc = 0; char **perl_argv = NULL; PERL_SYS_INIT3( &perl_argc, &perl_argv, environ_h ); /* create perl interpreter */ if((perl_interp = perl_alloc()) == NULL) { Ns_Log (Error, "Couldn't alloc perl interp"); return TCL_ERROR; } perl_construct(perl_interp); PL_exit_flags |= PERL_EXIT_DESTRUCT_END; /* run END blocks at destruction */ PERL_SET_CONTEXT (perl_interp); perl_exitstatus = perl_parse(perl_interp, xs_init, 2, embedding, NULL); /* TODO: check perl_exitstatus */ nsperl2_master_context->perl_master_interp = perl_interp; /* call the init_sub - eg. where urls are registered etc. you could do the same in a BEGIN block, but this is cleaner */ dSP; PUSHMARK (SP); Tcl_Interp *tcl_interp; tcl_interp = Ns_TclAllocateInterp (server); set_nsperl2_globals (perl_interp, tcl_interp, NULL); call_pv (nsperl2_master_context->init_sub, G_NOARGS | G_VOID | G_DISCARD); /* not doing G_EVAL - if init_sub fails, we want to bail. */ /* should I destroy that tcl interp?? */ Ns_RegisterShutdown (nsperl2_free_master_context, NULL); Ns_TclInitInterps(server,NsPerl2InitInterp, NULL); return NS_OK; }