Beispiel #1
0
/* Start function. It may be called from the start script as well as from
   the OSE shell directly (using late start hooks). It spawns epmd as an
   OSE process which calls the epmd main function. */
int start_ose_epmd(int argc, char **argv) {
  union SIGNAL *sig;
  PROCESS epmd_;
  OSENTRYPOINT ose_epmd;
  int i;

  if(hunt("epmd", 0, &epmd_, NULL)) {
    fprintf(stderr, "Warning! EPMD already exists (%u).\n", epmd_);
    return 0;
  }
  else {
    /* copy start args to signal */
    sig = alloc(sizeof(struct args_sig), 0);
    sig->args.argc = argc;
    for(i=0; i<argc; i++) {
      strcpy((sig->args.argv)[i], argv[i]);
    }    
    /* start epmd and send signal */
    epmd_ = create_process(OS_BG_PROC, /* processtype */
			   "epmd",      /* name        */
			   ose_epmd,    /* entrypoint  */
			   16383,	/* stacksize   */
			   20,	        /* priority    */
			   0,	        /* timeslice   */
			   0,	        /* block       */
			   NULL,0,0);   /* not used    */
    efs_clone(epmd_);
    start(epmd_);
    send(&sig, epmd_);	
#ifdef DEBUG
    printf("EPMD ID: %li\n", epmd_);
#endif
  }
  return 0;
}
Beispiel #2
0
int start_erl(int argc, char **argv) {
  union SIGNAL *sig;
  PROCESS erts_;
  OSENTRYPOINT erts;

  if(hunt("erts", 0, NULL, NULL)) {
    erl_dbg_fprintf(stderr, "ERROR: erts already running\n");
    return 0;
  }

  erl_block = get_bid(erl_tmp_);
  erl_dbg_fprintf(stdout, "Erlang block id: %li\n", (unsigned long)erl_block);
  fflush(stderr);

  /* initialise DNS service, needed for distributed Erlang */
  config_dns();

  erl_argc = argc;
  erl_argv = argv;		/* so that erts may copy the struct */

  /* used by erts to detect shutdown of ose shell (interactive mode only) */
  erlang_starter_ = current_process(); 

  /* create and start the erlang emulator as ose process "erts" */
  erts_ = create_process(OS_BG_PROC, /* processtype */
			 "erts", /* name        */
			 erts,	 /* entrypoint  */
			 524288, /* stacksize   */
			 20,	 /* priority (if OS_PRI_PROC) */
			 0,	 /* timeslice */
			 erl_block, /* block */
			 NULL,0,0); /* not used    */

  set_fsem((OSFSEMVAL) 0, current_process());

  efs_clone(erts_);
  start(erts_);

  /* sync with erts, this function must not return until erts has copied argv */
  wait_fsem((OSFSEMVAL) 1);

  /* in interactive mode the ose shell will "hang", waiting for erts to terminate */
  if(!start_detached) {	
    static const SIGSELECT recv_attach_sig[2] = {1, OS_ATTACH_SIG};
    erl_dbg_fprintf(stdout, "erts started in interactive mode\n");
    attach(NULL, erts_);
    sig = receive((SIGSELECT*)recv_attach_sig);
    erl_dbg_fprintf(stderr, "\n*** Erlang finished ***\n");
    free_buf(&sig);
  }
  return 0;

}
Beispiel #3
0
int run_erl(int argc,char **argv) {
  char *pipename, *logdir, *command, *blockname = NULL;
  int pipename_len, logdir_len, command_len, blockname_len = 0;
  int i = 1, run_daemon = 0;
  PROCESS pid;
  SIGSELECT sigsel[] = {0};
  union SIGNAL *sig;

  if(argc < 4) {
    fprintf(stderr,RUN_ERL_USAGE,"run_erl");
    return 1;
  }

  while (1) {
    if (argv[i][0] != '-')
      break;
    if (!strcmp(argv[i],"-daemon")) {
      run_daemon = 1;
      i++;
      continue;
    }
    if (!strcmp(argv[i],"-block")) {
      blockname = argv[i+1];
      blockname_len = strlen(argv[i+1]) + 1;
      i+=2;
      continue;
    }
    fprintf(stderr,RUN_ERL_USAGE,"run_erl");
    return 1;
  }

  pipename = argv[i++];
  logdir = argv[i++];
  command = argv[i++];

  /* + 1 to include NULL at end */
  logdir_len = strlen(logdir) + 1;
  command_len = strlen(command) + 1;
  pipename_len = strlen(pipename) + 1;

  if (run_daemon) {
    /* We request that the run_erl_process should be started from the
       main process so that it does not die when the shell command
       returns */
    PROCESS main_pid;
    hunt_in_block("run_erl","main",&main_pid);
    sig = alloc(sizeof(*sig),ERTS_SIGNAL_RUN_ERL_DAEMON);
    send(&sig,main_pid);
    sig = receive(sigsel);
    pid = sender(&sig);
    free_buf(&sig);
  } else {
    pid = create_process(OS_BG_PROC,"run_erl_process",
			 run_erl_process, 0x800,
			 0, 0, 0, NULL, 0, 0);
  }

  sig = alloc(sizeof(RunErlSetup)+
	      logdir_len+command_len+pipename_len+blockname_len,
	      ERTS_SIGNAL_RUN_ERL_SETUP);
  sig->setup.run_daemon = run_daemon;
  sig->setup.logdir = ((char*)sig)+sizeof(RunErlSetup);
  sig->setup.command = ((char*)sig)+sizeof(RunErlSetup)+logdir_len;
  sig->setup.pipename = ((char*)sig)+sizeof(RunErlSetup)+logdir_len+command_len;
  if (blockname)
    sig->setup.blockname = ((char*)sig)+sizeof(RunErlSetup)+
      logdir_len+command_len+pipename_len;
  else
    sig->setup.blockname = NULL;

  strcpy(sig->setup.logdir,logdir);
  strcpy(sig->setup.command,command);
  strcpy(sig->setup.pipename,pipename);
  if (blockname) strcpy(sig->setup.blockname,blockname);

  send(&sig,pid);

  if (run_daemon) {
    /* We are a daemon, error msgs will be sent to ramlog */
    start(pid);
    return 1;
  }

  /* We are not daemon, error msgs will be sent to stderr and we block here */
  efs_clone(pid);
  start(pid);

  attach(NULL,pid);
  sig = receive(sigsel);

  return 1;
}