From 505e209e5bc209a9ee7518da0f70124d25572789 Mon Sep 17 00:00:00 2001 From: dos-reis Date: Wed, 30 Sep 2009 04:40:18 +0000 Subject: * sman/sman.c (fix_env): Simplify. (exec_command_env): Lose second parameter. (fork_Axiom): Take a new parameter. (start_the_Axiom): Adjust. (main): Likewise. * interp/int-top.boot (printFirstPrompt?): New. (SpadInterpretStream): Use it. * driver/utils.h (openaxiom_allocate_command_argv): Declare. * driver/utils.c (openaxiom_allocate_command_argv): Define. * driver/Makefile.in (open-axiom$(EXEEXT)): Link statically. --- src/sman/sman.c | 64 ++++++++++++++++++++++++--------------------------------- 1 file changed, 27 insertions(+), 37 deletions(-) (limited to 'src/sman') diff --git a/src/sman/sman.c b/src/sman/sman.c index 0b2cc8e6..0dcbcbbb 100644 --- a/src/sman/sman.c +++ b/src/sman/sman.c @@ -64,21 +64,21 @@ static void set_up_defaults(void); static void process_options(openaxiom_command*, int, char**); static void death_handler(int); static void sman_catch_signals(void); -static void fix_env(char** , int); +static void fix_env(int); static void init_term_io(void); static char* strPrefix(char* , char*); static void check_spad_proc(char* , char*); static void clean_up_old_sockets(void); static SpadProcess* fork_you(int); -static void exec_command_env(char* , char**); +static void exec_command_env(char*); static SpadProcess* spawn_of_hell(char* , int); static void start_the_spadclient(void); static void start_the_local_spadclient(void); static void start_the_session_manager(void); static void start_the_hypertex(void); static void start_the_graphics(void); -static void fork_Axiom(void); -static void start_the_Axiom(char**); +static void fork_Axiom(openaxiom_command*); +static void start_the_Axiom(openaxiom_command*); static void clean_up_sockets(void); static void clean_hypertex_socket(void); static void read_from_spad_io(int); @@ -90,6 +90,9 @@ static void kill_all_children(void); static void clean_up_terminal(void); static void monitor_children(void); +/* System defined pointer to array or environment variables. */ +extern char** environ; + char *ws_path; /* location of the core executable */ int start_clef; /* start clef under spad */ int start_graphics; /* start the viewman */ @@ -140,7 +143,6 @@ unsigned char _INTR, _QUIT, _ERASE, _KILL, _EOF, _EOL, _RES1, _RES2; int ptsNum, ptcNum; char ptsPath[20]; -char **new_envp; /* new environment for the core executable */ int child_pid; /* child's process id */ struct termios oldbuf; /* the original settings */ struct termios childbuf; /* terminal structure for user i/o */ @@ -300,18 +302,12 @@ sman_catch_signals(void) } static void -fix_env(char **envp, int spadnum) +fix_env(int spadnum) { - int len, i; - char *sn; - for(len = 0; envp[len] != NULL; len++); - new_envp = (char **) malloc((len + 3) * sizeof(char *)); - new_envp[0] = "SPADSERVER=TRUE"; - sn = (char *) malloc(20 * sizeof(char)); - sprintf(sn, "SPADNUM=%d", spadnum); - new_envp[1] = sn; - for(i=0; i<=len; i++) - new_envp[i+2] = envp[i]; + char sn[20]; + sprintf(sn, "%d", spadnum); + oa_setenv("SPADNUM", sn); + oa_setenv("SPADSERVER", "TRUE"); } static void @@ -407,11 +403,11 @@ fork_you(int death_action) } static void -exec_command_env(char *command,char ** env) +exec_command_env(char *command) { char new_command[512]; sprintf(new_command, "exec %s", command); - execle("/bin/sh","/bin/sh", "-c", new_command, (char*)NULL, env); + execle("/bin/sh","/bin/sh", "-c", new_command, (char*)NULL, environ); } static SpadProcess * @@ -422,7 +418,7 @@ spawn_of_hell(char *command, int death_action) proc->command = command; return proc; } - exec_command_env(command, new_envp); + exec_command_env(command); return NULL; } @@ -487,10 +483,8 @@ start_the_graphics(void) /* Start the core executable session in a separate process, */ /* using a pseudo-terminal to catch all input and output */ static void -fork_Axiom(void) +fork_Axiom(openaxiom_command* cmd) { - char augmented_ws_path[256]; /* will append directory path */ - char *tmp_pointer; SpadProcess *proc; proc = fork_you(Die); @@ -542,22 +536,18 @@ fork_Axiom(void) perror("setting the term buffer"); exit(-1); } - strcpy(augmented_ws_path,ws_path); /* write the name */ - strcat(augmented_ws_path," "); /* space */ - strcat(augmented_ws_path,ws_path); /* name again */ - tmp_pointer = (char *) - strrchr(augmented_ws_path,'/'); /*pointer to last / */ - *(++tmp_pointer) = '\0'; - exec_command_env(augmented_ws_path, new_envp); - - /* fprintf(stderr, "Cannot execute the %s system.\n", ws_path); */ - exit(0); + /* Tell the Core that it is being invoked in server mode. */ + openaxiom_allocate_command_argv(cmd, 2); + cmd->core_argv[0] = + openaxiom_make_path_for(cmd->root_dir, openaxiom_core_driver); + cmd->core_argv[1] = "--role=server"; + openaxiom_execute_core(cmd, openaxiom_core_driver); } } static void -start_the_Axiom(char **envp) +start_the_Axiom(openaxiom_command* cmd) { server_num = make_server_number(); clean_up_old_sockets(); @@ -569,8 +559,8 @@ start_the_Axiom(char **envp) perror("start_the_Axiom: ptyopen failed"); exit(-1); } - fix_env(envp, server_num); - fork_Axiom(); + fix_env(server_num); + fork_Axiom(cmd); close(ptsNum); } @@ -777,7 +767,7 @@ monitor_children(void) } int -main(int argc, char *argv[],char *envp[]) +main(int argc, char *argv[]) { openaxiom_command command = { }; command.root_dir = openaxiom_get_systemdir(argc, argv); @@ -788,7 +778,7 @@ main(int argc, char *argv[],char *envp[]) bsdSignal(SIGINT, SIG_IGN,RestartSystemCalls); init_term_io(); init_spad_process_list(); - start_the_Axiom(envp); + start_the_Axiom(&command); if (open_server(SessionIOName) == -2) { fprintf(stderr, "Fatal error opening I/O socket\n"); clean_up_sockets(); -- cgit v1.2.3