Exemple #1
0
int load_module2(struct mod **modp, const struct pl *name)
{
	struct mod *m = NULL;
	int err = 0;

	if (!name)
		return EINVAL;

	/* Try static */
	err = mod_add(&m, find_module(name));
	if (err)
		goto out;

	err = mod_call_init(m);
	if (err)
		goto out;

	if (modp)
		*modp = m;

 out:
	if (err) {
		DEBUG_WARNING("module %r: %m\n", name, err);
	}

	return err;
}
Exemple #2
0
void
mod_on(void)
{
	sprintf(min_default, "Seen on the last %d (default) minutes: ", DEFAULT_MINUTES);
	mod_lastseen();
	mod_add(&on);
}
Exemple #3
0
M operator * (const M& a, const M& b)
{
	M z;
	std::memset(z.x, 0, sizeof(z.x));
	for(int i = 0; i != x; ++i)
		for(int j = 0; j < x; ++j)
			mod_add(z.x[(i + factor * j) % x], 1ll * a.x[i] * b.x[j]);
	return z;
}
Exemple #4
0
int main()
{
	int num;
	std::scanf("%d %d %d %d", &num, &b, &k, &x);
	for(int i = 0; i != num; ++i)
	{
		int x;
		std::scanf("%d", &x);
		++n[x];
	}

	occ[0][0] = 1;
	for(int i = 1, r = 1; i < x; ++i, r = r * 10 % x)
		for(int j = 0; j != x; ++j)
			for(int k = 0; k != 10; ++k)
				mod_add(occ[i][(r * k + j) % x], (long long)occ[i - 1][j] * n[k]);

	rem[0] = 1;
	int start = 0;
	for(int i = 1; i <= x; ++i)
	{
		rem[i] = rem[i - 1] * 10 % x;
		for(int j = 0; j != i; ++j)
		{
			if(rem[i] == rem[j])
			{
				start = j;
				factor = rem[i];
				loop = i - j;
				break;
			}
		}

		if(loop) break;
	}
	
	M m0, m1;
	for(int i = 0; i != x; ++i)
	{
		m0.x[i] = occ[start][i];
		m1.x[i] = occ[(b - start) % loop][i];
	}
	m0 = m0 * conv((b - start) / loop);
	m0 = m0 * m1;
	std::printf("%d\n", m0.x[k]);

	return 0;
}
Exemple #5
0
static int load_module(struct mod **modp, const struct pl *modpath,
		       const struct pl *name)
{
	char file[FS_PATH_MAX];
	char namestr[256];
	struct mod *m = NULL;
	int err = 0;

	if (!name)
		return EINVAL;

#ifdef STATIC
	/* Try static first */
	pl_strcpy(name, namestr, sizeof(namestr));

	if (mod_find(namestr)) {
		info("static module already loaded: %r\n", name);
		return EALREADY;
	}

	err = mod_add(&m, lookup_static_module(name));
	if (!err)
		goto out;
#else
	(void)namestr;
#endif

	/* Then dynamic */
	if (re_snprintf(file, sizeof(file), "%r/%r", modpath, name) < 0) {
		err = ENOMEM;
		goto out;
	}
	err = mod_load(&m, file);
	if (err)
		goto out;

 out:
	if (err) {
		warning("module %r: %m\n", name, err);
	}
	else if (modp)
		*modp = m;

	return err;
}
Exemple #6
0
static int load_module(struct mod **modp, const struct pl *modpath,
		       const struct pl *name)
{
	char file[256];
	struct mod *m = NULL;
	int err = 0;

	if (!name)
		return EINVAL;

#ifdef STATIC
	/* Try static first */
	err = mod_add(&m, find_module(name));
	if (!err)
		goto out;
#endif

	/* Then dynamic */
	if (re_snprintf(file, sizeof(file), "%r/%r", modpath, name) < 0) {
		err = ENOMEM;
		goto out;
	}
	err = mod_load(&m, file);
	if (err)
		goto out;

	if (modp)
		*modp = m;

 out:
	if (err) {
		DEBUG_WARNING("module %r: %m\n", name, err);
	}

	return err;
}
static void mrg_update_cache(mrg_transition_matrix* p) { /* Set a, b, c, and d */
  p->a = mod_add(mod_mul_x(p->s), p->t);
  p->b = mod_add(mod_mul_x(p->a), p->u);
  p->c = mod_add(mod_mul_x(p->b), p->v);
  p->d = mod_add(mod_mul_x(p->c), p->w);
}
int checkpoint_scanmodules (struct lmodule *list) {
 struct cfgnode *node = NULL;

/* scan all modes... */
 while ((node = cfg_findnode ("mode-enable", 0, node))) {
  if (node->mode && node->mode->arbattrs) {
   size_t i = 0;
   char do_add = 0;
   char *base = NULL;
   uintptr_t cooldown = 0;

   for (; node->mode->arbattrs[i]; i+=2) {
    if (strmatch (node->mode->arbattrs[i], "wait-for-base") && parse_boolean (node->mode->arbattrs[i+1])) {
     do_add = 1;
    } else if (strmatch (node->mode->arbattrs[i], "cooldown")) {
     cooldown = parse_integer (node->mode->arbattrs[i+1]);
    } else if (strmatch (node->mode->arbattrs[i], "base")) {
     base = node->mode->arbattrs[i+1];
    }
   }

   if (do_add) {
    char buffer[BUFFERSIZE];

    esprintf (buffer, BUFFERSIZE, "checkpoint-mode-%s", node->mode->id);

    if (checkpoint_scanmodules_check_update (list, buffer)) {
     continue;
    } else {
     struct smodule *sm = emalloc (sizeof (struct smodule));
     char **base_services = checkpoint_scanmodules_find_services_from_modes (NULL, base);
     char **services = checkpoint_scanmodules_find_services_from_mode (NULL, node->mode->id);
     struct lmodule *nm;

     memset (sm, 0, sizeof (struct smodule));

     sm->rid = estrdup (buffer);
     if (checkpoint_count < CHECKPOINT_NAME_COUNT) {
      esprintf (buffer, BUFFERSIZE, "Checkpoint %s", checkpoint_names[checkpoint_count]);
      checkpoint_count++;
     } else {
      esprintf (buffer, BUFFERSIZE, "Checkpoint %i", checkpoint_count);
      checkpoint_count++;
     }
     sm->name = estrdup (buffer);

     if (base_services) {
      char *comb = set2str ('|', (const char **)base_services);
      size_t aflen = strlen (comb) + 5;
      char *af = emalloc (aflen);

      esprintf (af, aflen, "^(%s)$", comb);

      sm->si.after = str2set ('\0', af);

      free (comb);
      free (base_services);
      free (af);
     }

     if (services) {
      char *comb = set2str ('|', (const char **)services);
      size_t belen = strlen (comb) + 5;
      char *be = emalloc (belen);

      esprintf (be, belen, "^(%s)$", comb);

      sm->si.before = str2set ('\0', be);

      free (comb);
      free (services);
      free (be);
     }

     sm->eiversion = EINIT_VERSION;
     sm->eibuild = BUILDNUMBER;
     sm->configure = checkpoint_module_configure;
     sm->mode = einit_module_generic | einit_feedback_job;

     if ((nm = mod_add (NULL, sm))) {
      nm->param = (void *)cooldown;
     }
    }
   }
  }
 }

 return status_ok;
}
Exemple #9
0
module_t* mod_load(const char* path_name) {
	module_t* mod = mod_create();
	int* api_version;
	int* type;
	int err = 0;

	boolean_t flag = B_FALSE;

	assert(mod != NULL);

	logmsg(LOG_INFO, "Loading module %s ...", path_name);

	err = plat_mod_open(&mod->mod_library, path_name);

	if(err != 0) {
		logmsg(LOG_WARN, "Failed loading, platform-specific error code: %d", err);
		logerror();

		goto fail;
	}

	strcpy(mod->mod_path, path_name);

	/*Load module api version and name*/

	MOD_LOAD_SYMBOL(api_version, mod, "mod_api_version", flag);
	MOD_LOAD_SYMBOL(type, mod, "mod_type", flag);
	MOD_LOAD_SYMBOL(mod->mod_name, mod, "mod_name", flag);

	if(flag)
		goto fail;

	if(*type != mod_type) {
		logmsg(LOG_INFO, "Ignoring module - wrong type %d", *type);

		goto fail;
	}

	if(*api_version != MOD_API_VERSION) {
		logmsg(LOG_WARN, "Wrong api version %d", *api_version);

		goto fail;
	}

	if(mod_search(mod->mod_name) != NULL) {
		logmsg(LOG_WARN, "Module %s already exists", mod->mod_name);

		goto fail;
	}

	MOD_LOAD_SYMBOL(mod->mod_config, mod, "mod_config", flag);
	MOD_LOAD_SYMBOL(mod->mod_unconfig, mod, "mod_unconfig", flag);

	/*Call helper*/
	mod->mod_status = MOD_UNCONFIGURED;

	if(mod->mod_config(mod) != MOD_OK) {
		logmsg(LOG_INFO, "Failed to configure module %s (path: %s)", mod->mod_name, path_name);

		goto fail;
	}

	logmsg(LOG_INFO, "Loaded module %s (path: %s)", mod->mod_name, path_name);

	mod->mod_status = MOD_READY;
	mod_add(mod);

	return mod;

fail:
	if(err != 0)
		plat_mod_close(&mod->mod_library);

	logmsg(LOG_WARN, "Failed to load module %s!", path_name);

	mod_destroy(mod);

	return NULL;
}
Exemple #10
0
void
mod_autorejoin(void)
{
	mod_add(&mod);
}
Exemple #11
0
/*       [b   v   w   s*y a*y]                                           */
/*       [a   u   v   w   s*y]                                           */
/*       [s   t   u   v   w  ]                                           */
/* for some values of s, t, u, v, and w                                  */
/* Note that A^n is determined by its bottom row (and x and y, which are */
/* fixed), and that it has a large part that is a Toeplitz matrix.  You  */
/* can multiply two A-like matrices by:                                  */
/* (defining a..d1 and a..d2 for the two matrices)                       */
/* s3 = s1 d2 + t1 c2 + u1 b2 + v1 a2 + w1 s2,                           */
/* t3 = s1 s2 y + t1 w2 + u1 v2 + v1 u2 + w1 t2,                         */
/* u3 = s1 a2 y + t1 s2 y + u1 w2 + v1 v2 + w1 u2,                       */
/* v3 = s1 b2 y + t1 a2 y + u1 s2 y + v1 w2 + w1 v2,                     */
/* w3 = s1 c2 y + t1 b2 y + u1 a2 y + v1 s2 y + w1 w2                    */

static void mrg_update_cache(mrg_transition_matrix* restrict p) { /* Set a, b, c, and d */
  p->a = mod_add(mod_mul_x(p->s), p->t);
  p->b = mod_add(mod_mul_x(p->a), p->u);
  p->c = mod_add(mod_mul_x(p->b), p->v);
  p->d = mod_add(mod_mul_x(p->c), p->w);
}

static void mrg_make_identity(mrg_transition_matrix* result) {
  result->s = result->t = result->u = result->v = 0;
  result->w = 1;
  mrg_update_cache(result);
}

static void mrg_make_A(mrg_transition_matrix* result) { /* Initial RNG transition matrix */
  result->s = result->t = result->u = result->w = 0;
  result->v = 1;
  mrg_update_cache(result);
int main(int argc, char **argv, char **environ) {
#else
int main(int argc, char **argv) {
#endif
 int i, ret = EXIT_SUCCESS;
 pid_t pid = getpid(), wpid = 0;
 char **ipccommands = NULL;
 int pthread_errno;
 FILE *commandpipe_in, *commandpipe_out;
 int commandpipe[2];
 int debugsocket[2];
 char need_recovery = 0;
 char debug = 0;
 int debugme_pipe = 0;
 char crash_threshold = 5;
 char *einit_crash_data = NULL;

 boottime = time(NULL);

 uname (&osinfo);
 config_configure();

// initialise subsystems
 ipc_configure(NULL);

// is this the system's init-process?
 isinit = getpid() == 1;

 event_listen (einit_event_subsystem_core, core_einit_event_handler);
 event_listen (einit_event_subsystem_timer, core_timer_event_handler);

 if (argv) einit_argv = (char **)setdup ((const void **)argv, SET_TYPE_STRING);

/* check command line arguments */
 for (i = 1; i < argc; i++) {
  if (argv[i][0] == '-')
   switch (argv[i][1]) {
    case 'c':
     if ((++i) < argc)
      einit_default_startup_configuration_files[0] = argv[i];
     else
      return print_usage_info ();
     break;
    case 'h':
     return print_usage_info ();
     break;
    case 'v':
     eputs("eINIT " EINIT_VERSION_LITERAL "\n", stdout);
     return 0;
    case 'L':
     eputs("eINIT " EINIT_VERSION_LITERAL
          "\nThis Program is Free Software, released under the terms of this (BSD) License:\n"
          "--------------------------------------------------------------------------------\n"
          "Copyright (c) 2006, 2007, Magnus Deininger\n"
          BSDLICENSE "\n", stdout);
     return 0;
    case '-':
     if (strmatch(argv[i], "--check-configuration") || strmatch(argv[i], "--checkup") || strmatch(argv[i], "--wtf")) {
      ipccommands = (char **)setadd ((void **)ipccommands, "examine configuration", SET_TYPE_STRING);
     } else if (strmatch(argv[i], "--help"))
      return print_usage_info ();
     else if (strmatch(argv[i], "--ipc-command") && argv[i+1])
      ipccommands = (char **)setadd ((void **)ipccommands, (void *)argv[i+1], SET_TYPE_STRING);
     else if (strmatch(argv[i], "--override-init-check"))
      initoverride = 1;
     else if (strmatch(argv[i], "--sandbox")) {
      einit_default_startup_configuration_files[0] = "lib/einit/einit.xml";
      coremode = einit_mode_sandbox;
      need_recovery = 1;
     } else if (strmatch(argv[i], "--metadaemon")) {
      coremode = einit_mode_metadaemon;
     } else if (strmatch(argv[i], "--bootstrap-modules")) {
      bootstrapmodulepath = argv[i+1];
     } else if (strmatch(argv[i], "--debugme")) {
      debugme_pipe = parse_integer (argv[i+1]);
      i++;
      initoverride = 1;
     } else if (strmatch(argv[i], "--debug")) {
      debug = 1;
     }

     break;
   }
 }

/* check environment */
 if (environ) {
  uint32_t e = 0;
  for (e = 0; environ[e]; e++) {
   char *ed = estrdup (environ[e]);
   char *lp = strchr (ed, '=');

   *lp = 0;
   lp++;

   if (strmatch (ed, "softlevel")) {
    einit_startup_mode_switches = str2set (':', lp);
   } if (strmatch (ed, "mode")) {
/* override default mode-switches with the ones in the environment variable mode= */
    einit_startup_mode_switches = str2set (':', lp);
   } else if (strmatch (ed, "einit")) {
/* override default configuration files and/or mode-switches with the ones in the variable einit= */
    char **tmpstrset = str2set (',', lp);
    uint32_t rx = 0;

    for (rx = 0; tmpstrset[rx]; rx++) {
     char **atom = str2set (':', tmpstrset[rx]);

     if (strmatch (atom[0], "file")) {
/* specify configuration files */
      einit_startup_configuration_files = (char **)setdup ((const void **)atom, SET_TYPE_STRING);
      einit_startup_configuration_files = (char **)strsetdel (einit_startup_configuration_files, (void *)"file");
     } else if (strmatch (atom[0], "mode")) {
/* specify mode-switches */
      einit_startup_mode_switches = (char **)setdup ((const void **)atom, SET_TYPE_STRING);
      einit_startup_mode_switches = (char **)strsetdel (einit_startup_mode_switches, (void *)"mode");
     } else if (strmatch (atom[0], "stfu")) {
      einit_quietness = 3;
     } else if (strmatch (atom[0], "silent")) {
      einit_quietness = 2;
     } else if (strmatch (atom[0], "quiet")) {
      einit_quietness = 1;
     }

     free (atom);
    }

    free (tmpstrset);
   }

   free (ed);
  }

  einit_initial_environment = (char **)setdup ((const void **)environ, SET_TYPE_STRING);
 }

 if (!einit_startup_mode_switches) einit_startup_mode_switches = einit_default_startup_mode_switches;
 if (!einit_startup_configuration_files) einit_startup_configuration_files = einit_default_startup_configuration_files;

 respawn:

 pipe (commandpipe);

 fcntl (commandpipe[1], F_SETFD, FD_CLOEXEC);

 socketpair (AF_UNIX, SOCK_STREAM, 0, debugsocket);
 fcntl (debugsocket[0], F_SETFD, FD_CLOEXEC);
 fcntl (debugsocket[1], F_SETFD, FD_CLOEXEC);

 if (!debug) {
  fcntl (commandpipe[0], F_SETFD, FD_CLOEXEC);
  commandpipe_in = fdopen (commandpipe[0], "r");
 }
 commandpipe_out = fdopen (commandpipe[1], "w");

 if (!initoverride && ((pid == 1) || ((coremode & einit_mode_sandbox) && !ipccommands))) {
// if (pid == 1) {
  initoverride = 1;
#if 0
#ifdef LINUX
  if ((einit_sub = syscall(__NR_clone, CLONE_PTRACE | SIGCHLD, 0, NULL, NULL, NULL)) < 0) {
   bitch (bitch_stdio, errno, "Could not fork()");
   eputs (" !! Haven't been able to fork a secondary worker process. This is VERY bad, you will get a lot of zombie processes! (provided that things work at all)\n", stderr);
  }
#else
#endif
#endif
  if ((einit_sub = fork()) < 0) {
   bitch (bitch_stdio, errno, "Could not fork()");
   eputs (" !! Haven't been able to fork a secondary worker process. This is VERY bad, you will get a lot of zombie processes! (provided that things work at all)\n", stderr);
  }
 }

 if (einit_sub) {
/* PID==1 part */
  int rstatus;
  struct sigaction action;

/* signal handlers */
  action.sa_sigaction = einit_sigint;
  sigemptyset(&(action.sa_mask));
  action.sa_flags = SA_SIGINFO | SA_RESTART | SA_NODEFER;
  if ( sigaction (SIGINT, &action, NULL) ) bitch (bitch_stdio, 0, "calling sigaction() failed.");

/* ignore sigpipe */
  action.sa_sigaction = (void (*)(int, siginfo_t *, void *))SIG_IGN;

  if ( sigaction (SIGPIPE, &action, NULL) ) bitch (bitch_stdio, 0, "calling sigaction() failed.");

  close (debugsocket[1]);
  if (einit_crash_data) {
   free (einit_crash_data);
   einit_crash_data = NULL;
  }

  while (1) {
   wpid = waitpid(-1, &rstatus, 0); /* this ought to wait for ANY process */

   if (wpid == einit_sub) {
//    goto respawn; /* try to recover by re-booting */
    if (!debug) if (commandpipe_in) fclose (commandpipe_in);
    if (commandpipe_out) fclose (commandpipe_out);

    if (WIFEXITED(rstatus) && (WEXITSTATUS(rstatus) != einit_exit_status_die_respawn)) {
     fprintf (stderr, "eINIT has quit properly.\n");

     if (!(coremode & einit_mode_sandbox)) {
      if (WEXITSTATUS(rstatus) == einit_exit_status_last_rites_halt) {
       execl (EINIT_LIB_BASE "/bin/last-rites", EINIT_LIB_BASE "/bin/last-rites", "h", NULL);
      } else if (WEXITSTATUS(rstatus) == einit_exit_status_last_rites_reboot) {
       execl (EINIT_LIB_BASE "/bin/last-rites", EINIT_LIB_BASE "/bin/last-rites", "r", NULL);
      } else if (WEXITSTATUS(rstatus) == einit_exit_status_last_rites_kexec) {
       execl (EINIT_LIB_BASE "/bin/last-rites", EINIT_LIB_BASE "/bin/last-rites", "k", NULL);
      }
     }

     exit (EXIT_SUCCESS);
    }

    int n = 5;
    fprintf (stderr, "The secondary eINIT process has died, waiting a while before respawning.\n");
    if ((einit_crash_data = readfd (debugsocket[0]))) {
     fprintf (stderr, " > neat, received crash data\n");
    }
    while ((n = sleep (n)));
    fprintf (stderr, "Respawning secondary eINIT process.\n");

    if (crash_threshold) crash_threshold--;
    else debug = 1;
    need_recovery = 1;
    initoverride = 0;

    close (debugsocket[0]);

    goto respawn;
   } else {
    if (commandpipe_out) {
     if (WIFEXITED(rstatus)) {
      fprintf (commandpipe_out, "pid %i terminated\n\n", wpid);
     } else {
      fprintf (commandpipe_out, "pid %i died\n\n", wpid);
     }
     fflush (commandpipe_out);
    }
   }
  }
 } else {
  enable_core_dumps ();

  close (debugsocket[0]);
  sched_trace_target = debugsocket[1];

  if (debug) {
   char **xargv = (char **)setdup ((const void **)argv, SET_TYPE_STRING);
   char tbuffer[BUFFERSIZE];
   struct stat st;
   char have_valgrind = 0;
   char have_gdb = 0;

   fputs ("eINIT needs to be debugged, starting in debugger mode\n.", stderr);

   xargv = (char **)setadd ((void **)xargv, (void *)"--debugme", SET_TYPE_STRING);
   snprintf (tbuffer, BUFFERSIZE, "%i", commandpipe[0]);
   xargv = (char **)setadd ((void **)xargv, (void *)tbuffer, SET_TYPE_STRING);

   xargv = strsetdel (xargv, "--debug"); // don't keep the --debug flag

   if (!stat ("/usr/bin/valgrind", &st)) have_valgrind = 1;
   if (!stat ("/usr/bin/gdb", &st)) have_gdb = 1;

   if (have_valgrind) {
    char **nargv = NULL;
    uint32_t i = 1;

#ifdef LINUX
    if (!(coremode & einit_mode_sandbox)) {
     mount ("proc", "/proc", "proc", 0, NULL);
     mount ("sys", "/sys", "sysfs", 0, NULL);

     system ("mount / -o remount,rw");
    }
#endif

    nargv = (char **)setadd ((void **)nargv, "/usr/bin/valgrind", SET_TYPE_STRING);
    nargv = (char **)setadd ((void **)nargv, "--log-file=/einit.valgrind", SET_TYPE_STRING);
    nargv = (char **)setadd ((void **)nargv, (coremode & einit_mode_sandbox) ? "sbin/einit" : "/sbin/einit", SET_TYPE_STRING);

    for (; xargv[i]; i++) {
     nargv = (char **)setadd ((void **)nargv, xargv[i], SET_TYPE_STRING);
    }

    execv ("/usr/bin/valgrind", nargv);
   } else {
    execv ((coremode & einit_mode_sandbox) ? "sbin/einit" : "/sbin/einit", xargv);
   }
  }

  if (debugme_pipe) { // commandpipe[0]
   fcntl (commandpipe[0], F_SETFD, FD_CLOEXEC);
   commandpipe_in = fdopen (debugme_pipe, "r");
  }

/* actual system initialisation */
  struct einit_event cev = evstaticinit(einit_core_update_configuration);

  if (ipccommands && (coremode != einit_mode_sandbox)) {
   coremode = einit_mode_ipconly;
  }

  eprintf (stderr, "eINIT " EINIT_VERSION_LITERAL ": Initialising: %s\n", osinfo.sysname);

  if ((pthread_errno = pthread_attr_init (&thread_attribute_detached))) {
   bitch(bitch_epthreads, pthread_errno, "pthread_attr_init() failed.");

   if (einit_initial_environment) free (einit_initial_environment);
   return -1;
  } else {
   if ((pthread_errno = pthread_attr_setdetachstate (&thread_attribute_detached, PTHREAD_CREATE_DETACHED))) {
    bitch(bitch_epthreads, pthread_errno, "pthread_attr_setdetachstate() failed.");
   }
  }

  if ((pthread_errno = pthread_key_create(&einit_function_macro_key, NULL))) {
   bitch(bitch_epthreads, pthread_errno, "pthread_key_create(einit_function_macro_key) failed.");

   if (einit_initial_environment) free (einit_initial_environment);
   return -1;
  }

/* this should be a good place to initialise internal modules */
   if (coremodules) {
    uint32_t cp = 0;

    eputs (" >> initialising in-core modules:", stderr);

    for (; coremodules[cp]; cp++) {
     struct lmodule *lmm;
     eprintf (stderr, " [%s]", (*coremodules[cp])->rid);
     lmm = mod_add(NULL, (*coremodules[cp]));

     lmm->source = estrdup("core");
    }

    eputs (" OK\n", stderr);
   }

/* emit events to read configuration files */
  if (einit_startup_configuration_files) {
   uint32_t rx = 0;
   for (; einit_startup_configuration_files[rx]; rx++) {
    cev.string = einit_startup_configuration_files[rx];
    event_emit (&cev, einit_event_flag_broadcast);
   }

   if (einit_startup_configuration_files != einit_default_startup_configuration_files) {
    free (einit_startup_configuration_files);
   }
  }

  cev.string = NULL;
  cev.type = einit_core_configuration_update;

// make sure we keep updating until everything is sorted out
  while (cev.type == einit_core_configuration_update) {
//   notice (2, "stuff changed, updating configuration.");

   cev.type = einit_core_update_configuration;
   event_emit (&cev, einit_event_flag_broadcast);
  }
  evstaticdestroy(cev);

  if (ipccommands) {
   uint32_t rx = 0;
   for (; ipccommands[rx]; rx++) {
    ret = ipc_process (ipccommands[rx], stdout);
   }

//   if (gmode == EINIT_GMODE_SANDBOX)
//    cleanup ();

   free (ipccommands);
   if (einit_initial_environment) free (einit_initial_environment);
   return ret;
  } else if ((coremode == einit_mode_init) && !isinit && !initoverride) {
   eputs ("WARNING: eINIT is configured to run as init, but is not the init-process (pid=1) and the --override-init-check flag was not specified.\nexiting...\n\n", stderr);
   exit (EXIT_FAILURE);
  } else {
/* actual init code */
   uint32_t e = 0;

   nice (einit_core_niceness_increment);

   if (need_recovery) {
    notice (1, "need to recover from something...");

    struct einit_event eml = evstaticinit(einit_core_recover);
    event_emit (&eml, einit_event_flag_broadcast);
    evstaticdestroy(eml);
   }

   if (einit_crash_data) {
    notice (1, "submitting crash data...");

    struct einit_event eml = evstaticinit(einit_core_crash_data);
    eml.string = einit_crash_data;
    event_emit (&eml, einit_event_flag_broadcast);
    evstaticdestroy(eml);

    free (einit_crash_data);
    einit_crash_data = NULL;
   }

   {
    notice (3, "running early bootup code...");

    struct einit_event eml = evstaticinit(einit_boot_early);
    event_emit (&eml, einit_event_flag_broadcast | einit_event_flag_spawn_thread_multi_wait);
    evstaticdestroy(eml);
   }

   notice (2, "scheduling startup switches.\n");

   for (e = 0; einit_startup_mode_switches[e]; e++) {
    struct einit_event ee = evstaticinit(einit_core_switch_mode);

    ee.string = einit_startup_mode_switches[e];
    event_emit (&ee, einit_event_flag_broadcast | einit_event_flag_spawn_thread | einit_event_flag_duplicate);
    evstaticdestroy(ee);
   }

   struct einit_event eml = evstaticinit(einit_core_main_loop_reached);
   eml.file = commandpipe_in;
   event_emit (&eml, einit_event_flag_broadcast);
   evstaticdestroy(eml);
  }

  if (einit_initial_environment) free (einit_initial_environment);
  return ret;
 }

/* this should never be reached... */
 if (einit_initial_environment) free (einit_initial_environment);
 return 0;
}
Exemple #13
0
void
mod_1337(void)
{
	FILE *f;
	int i, j, nnlines, nchars = 0;
	char c, *act;

	f = fopen(FILENAME_1337, "r");

	while(1) {
		c = getc(f);
		if(feof(f)) break;
		if((i=conv_ind(c)) == -1) goto err;
		if(getc(f)!=':') goto err;
		if(getc(f)!='\n') goto err;

		nnlines = 0;
		conv_tab[i].n = 0;
		do {
			c = getc(f);
			nchars++;
			if(c=='\n') {
				if(nnlines==0)
					conv_tab[i].n++;
				else
					nchars--;
				nnlines++;
			} else {
				nnlines = 0;
			}
		} while(nnlines<2 && !feof(f));
	}

	act = conv_buf = (char *) malloc(nchars*sizeof(char));
	CHECK_MALLOC(conv_buf);
	atexit(conv_buf_free);
	rewind(f);

	while(1) {
		c = getc(f);
		if(feof(f)) break;
		if((i=conv_ind(c)) == -1) goto err; 
		if(getc(f)!=':') goto err;
		if(getc(f)!='\n') goto err;

		conv_tab[i].beg = act;
		for(j=0; j<conv_tab[i].n; j++) {
			while((*act=getc(f)) != '\n')
				act++;
			*act = '\0';
			act++;
		}
		if(getc(f)!='\n' && !feof(f)) goto err;
	}

	fclose(f);
	mod_add(&leet);
	return;
err:
	fclose(f);
	puts("Error loading module \"1337\"");
}
Exemple #14
0
void
mod_ask(void)
{
	mod_add(&mod);
}