<commit_before>/*
 *  einit.c
 *  einit
 *
 *  Created by <NAME> on 06/02/2006.
 *  Copyright 2006, 2007 <NAME>. All rights reserved.
 *
 */

/*
Copyright (c) 2006, 2007, <NAME>
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice,
	  this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
	  this list of conditions and the following disclaimer in the documentation
	  and/or other materials provided with the distribution.
    * Neither the name of the project nor the names of its contributors may be
	  used to endorse or promote products derived from this software without
	  specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <einit/bitch.h>
#include <einit/config.h>
#include <einit/module.h>
#include <einit/utility.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/stat.h>
#include <pthread.h>
#include <errno.h>
#include <string.h>
#include <time.h>
#include <sys/utsname.h>
#include <sys/wait.h>
#include <einit-modules/ipc.h>
#include <einit-modules/configuration.h>
#include <einit/configuration.h>

#include <fcntl.h>

char shutting_down = 0;

#ifndef NONIXENVIRON
int main(int, char **, char **);
#else
int main(int, char **);
#endif
int print_usage_info ();
int cleanup ();

pid_t einit_sub = 0;
char isinit = 1, initoverride = 0;

char **einit_global_environment = NULL, **einit_initial_environment = NULL, **einit_argv = NULL;
struct stree *hconfiguration = NULL;

struct cfgnode *cmode = NULL, *amode = NULL;
enum einit_mode coremode = einit_mode_init;
unsigned char *gdebug = 0;
char einit_quietness = 0;

pthread_key_t einit_function_macro_key;

/* some more variables that are only of relevance to main() */
char **einit_startup_mode_switches = NULL;
char **einit_startup_configuration_files = NULL;

char *einit_default_startup_mode_switches[] = { "default", NULL };  // the list of modes to activate by default

// the list of files to  parse by default
char *einit_default_startup_configuration_files[] = { "/lib/einit/einit.xml", NULL };

int einit_have_feedback = 0;

#ifdef NONIXENVIRON
char ** environ;
#endif

char *bootstrapmodulepath = BOOTSTRAP_MODULE_PATH;

int print_usage_info () {
 eputs ("eINIT " EINIT_VERSION_LITERAL "\nCopyright (c) 2006, 2007, <NAME>\n"
  "Usage:\n"
  " einit [-c <filename>] [options]\n"
  "\n"
  "Options:\n"
  "-c <filename>         load <filename> instead of/lib/einit/einit.xml\n"
  "-h, --help            display this text\n"
  "-v                    print version, then exit\n"
  "-L                    print copyright notice, then exit\n"
  "--bootstrap-modules   use this path to load bootstrap-modules\n"
  "--ipc-command         don't boot, only run specified ipc-command\n"
  "                      (you can use this more than once)\n"
  "--override-init-check einit will check if it's pid=1, override with this flag\n"
  "--check-configuration tell all modules to check for configuration errors. use this!\n"
  "--checkup, --wtf      synonymous to --check-configuration\n"
  "\n"
  "--sandbox             run einit in \"sandbox mode\"\n"
  "--metadaemon          run einit in \"metadaemon mode\"\n"
  "\n"
  "Environment Variables (or key=value kernel parametres):\n"
  "mode=<mode>[:<mode>] a colon-separated list of modes to switch to.\n", stderr);
 return -1;
}

/* cleanups are only required to check for memory leaks, OS kernels will usually
   clean up after a program terminates -- especially with an init this shouldn't be much of
   a problem, since it's THE program that doesn't terminate. */
int cleanup () {
 mod_freemodules ();
 config_cleanup();

// bitch (BTCH_DL + BTCH_ERRNO);

 if (einit_startup_mode_switches != einit_default_startup_mode_switches) {
  free (einit_startup_mode_switches);
 }

 return 0;
}

void einit_sigint (int signal, siginfo_t *siginfo, void *context) {
 kill (einit_sub, SIGINT);
}

struct lmodule *mlist;

void core_einit_event_handler (struct einit_event *ev) {
 if (ev->type == einit_core_configuration_update) {
  struct cfgnode *node;
  ev->chain_type = einit_core_update_modules;

  if ((node = cfg_getnode ("core-mortality-bad-malloc", NULL)))
   mortality[bitch_emalloc] = node->value;

  if ((node = cfg_getnode ("core-mortality-bad-stdio", NULL)))
   mortality[bitch_stdio] = node->value;

  if ((node = cfg_getnode ("core-mortality-bad-regex", NULL)))
   mortality[bitch_regex] = node->value;

  if ((node = cfg_getnode ("core-mortality-bad-expat", NULL)))
   mortality[bitch_expat] = node->value;

  if ((node = cfg_getnode ("core-mortality-bad-dl", NULL)))
   mortality[bitch_dl] = node->value;

  if ((node = cfg_getnode ("core-mortality-bad-lookup", NULL)))
   mortality[bitch_lookup] = node->value;

  if ((node = cfg_getnode ("core-mortality-bad-pthreads", NULL)))
   mortality[bitch_epthreads] = node->value;

 } else if (ev->type == einit_core_update_modules) {
  struct lmodule *lm;

  repeat:

  lm = mlist;
  einit_new_node = 0;

  while (lm) {
   if (lm->source && strmatch(lm->source, "core")) {
    lm = mod_update (lm);

// tell module to scan for changes if it's a module-loader
    if (lm->module && (lm->module->mode & einit_module_loader) && (lm->scanmodules != NULL)) {
     notice (1, "updating modules (%s)", lm->module->rid ? lm->module->rid : "unknown");

     lm->scanmodules (mlist);

/* if an actual new node has been added to the configuration,
   repeat this step */
     if (einit_new_node) goto repeat;
    }
<commit_msg>made the 'updating modules' message have less of a priority<commit_after>/*
 *  einit.c
 *  einit
 *
 *  Created by <NAME> on 06/02/2006.
 *  Copyright 2006, 2007 <NAME>. All rights reserved.
 *
 */

/*
Copyright (c) 2006, 2007, <NAME>
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice,
	  this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
	  this list of conditions and the following disclaimer in the documentation
	  and/or other materials provided with the distribution.
    * Neither the name of the project nor the names of its contributors may be
	  used to endorse or promote products derived from this software without
	  specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <einit/bitch.h>
#include <einit/config.h>
#include <einit/module.h>
#include <einit/utility.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/stat.h>
#include <pthread.h>
#include <errno.h>
#include <string.h>
#include <time.h>
#include <sys/utsname.h>
#include <sys/wait.h>
#include <einit-modules/ipc.h>
#include <einit-modules/configuration.h>
#include <einit/configuration.h>

#include <fcntl.h>

char shutting_down = 0;

#ifndef NONIXENVIRON
int main(int, char **, char **);
#else
int main(int, char **);
#endif
int print_usage_info ();
int cleanup ();

pid_t einit_sub = 0;
char isinit = 1, initoverride = 0;

char **einit_global_environment = NULL, **einit_initial_environment = NULL, **einit_argv = NULL;
struct stree *hconfiguration = NULL;

struct cfgnode *cmode = NULL, *amode = NULL;
enum einit_mode coremode = einit_mode_init;
unsigned char *gdebug = 0;
char einit_quietness = 0;

pthread_key_t einit_function_macro_key;

/* some more variables that are only of relevance to main() */
char **einit_startup_mode_switches = NULL;
char **einit_startup_configuration_files = NULL;

char *einit_default_startup_mode_switches[] = { "default", NULL };  // the list of modes to activate by default

// the list of files to  parse by default
char *einit_default_startup_configuration_files[] = { "/lib/einit/einit.xml", NULL };

int einit_have_feedback = 0;

#ifdef NONIXENVIRON
char ** environ;
#endif

char *bootstrapmodulepath = BOOTSTRAP_MODULE_PATH;

int print_usage_info () {
 eputs ("eINIT " EINIT_VERSION_LITERAL "\nCopyright (c) 2006, 2007, <NAME>\n"
  "Usage:\n"
  " einit [-c <filename>] [options]\n"
  "\n"
  "Options:\n"
  "-c <filename>         load <filename> instead of/lib/einit/einit.xml\n"
  "-h, --help            display this text\n"
  "-v                    print version, then exit\n"
  "-L                    print copyright notice, then exit\n"
  "--bootstrap-modules   use this path to load bootstrap-modules\n"
  "--ipc-command         don't boot, only run specified ipc-command\n"
  "                      (you can use this more than once)\n"
  "--override-init-check einit will check if it's pid=1, override with this flag\n"
  "--check-configuration tell all modules to check for configuration errors. use this!\n"
  "--checkup, --wtf      synonymous to --check-configuration\n"
  "\n"
  "--sandbox             run einit in \"sandbox mode\"\n"
  "--metadaemon          run einit in \"metadaemon mode\"\n"
  "\n"
  "Environment Variables (or key=value kernel parametres):\n"
  "mode=<mode>[:<mode>] a colon-separated list of modes to switch to.\n", stderr);
 return -1;
}

/* cleanups are only required to check for memory leaks, OS kernels will usually
   clean up after a program terminates -- especially with an init this shouldn't be much of
   a problem, since it's THE program that doesn't terminate. */
int cleanup () {
 mod_freemodules ();
 config_cleanup();

// bitch (BTCH_DL + BTCH_ERRNO);

 if (einit_startup_mode_switches != einit_default_startup_mode_switches) {
  free (einit_startup_mode_switches);
 }

 return 0;
}

void einit_sigint (int signal, siginfo_t *siginfo, void *context) {
 kill (einit_sub, SIGINT);
}

struct lmodule *mlist;

void core_einit_event_handler (struct einit_event *ev) {
 if (ev->type == einit_core_configuration_update) {
  struct cfgnode *node;
  ev->chain_type = einit_core_update_modules;

  if ((node = cfg_getnode ("core-mortality-bad-malloc", NULL)))
   mortality[bitch_emalloc] = node->value;

  if ((node = cfg_getnode ("core-mortality-bad-stdio", NULL)))
   mortality[bitch_stdio] = node->value;

  if ((node = cfg_getnode ("core-mortality-bad-regex", NULL)))
   mortality[bitch_regex] = node->value;

  if ((node = cfg_getnode ("core-mortality-bad-expat", NULL)))
   mortality[bitch_expat] = node->value;

  if ((node = cfg_getnode ("core-mortality-bad-dl", NULL)))
   mortality[bitch_dl] = node->value;

  if ((node = cfg_getnode ("core-mortality-bad-lookup", NULL)))
   mortality[bitch_lookup] = node->value;

  if ((node = cfg_getnode ("core-mortality-bad-pthreads", NULL)))
   mortality[bitch_epthreads] = node->value;

 } else if (ev->type == einit_core_update_modules) {
  struct lmodule *lm;

  repeat:

  lm = mlist;
  einit_new_node = 0;

  while (lm) {
   if (lm->source && strmatch(lm->source, "core")) {
    lm = mod_update (lm);

// tell module to scan for changes if it's a module-loader
    if (lm->module && (lm->module->mode & einit_module_loader) && (lm->scanmodules != NULL)) {
     notice (8, "updating modules (%s)", lm->module->rid ? lm->module->rid : "unknown");

     lm->scanmodules (mlist);

/* if an actual new node has been added to the configuration,
   repeat this step */
     if (einit_new_node) goto repeat;
    }

{'fraction_non_alphanumeric': 0.11546138492246277, 'fraction_numerical': 0.00675571933056963, 'mean_word_length': 3.9307342922028767, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 105, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6297377', 'n_tokens_mistral': 4395, 'n_tokens_neox': 4108, 'n_words': 1399}