<commit_before>/* einit: main.c */
/*
Copyright (c) 2006, <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 <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>

int main(int, char **);
int print_usage_info ();
int switchmode (char *);
int ipc_wait ();

char *currentmode = "void";
char *newmode = "void";

int switchmode (char *mode) {
 if (!mode) return -1;
 printf ("switching to mode \"%s\": ", mode);
 if (sconfiguration) {
  struct cfgnode *cur = cfg_findnode (mode, EI_NODETYPE_MODE, NULL);
  struct cfgnode *opt;
  struct mloadplan *plan;
  char **elist;
  unsigned int optmask = 0;

  if (!cur) {
   puts ("mode not defined, aborting");
   return -1;
  }
  opt = NULL;
  while (opt = cfg_findnode ("disable-unspecified", 0, opt)) {
   if (opt->mode == cur) {
    if (opt->flag) optmask |= MOD_DISABLE_UNSPEC;
    else optmask &= !MOD_DISABLE_UNSPEC;
   }
  }
  elist = strsetdup (cur->enable);
  newmode = mode;

  if (cur->base) {
   int y = 0;
   struct cfgnode *cno;
   while (cur->base[y]) {
	cno = cfg_findnode (cur->base[y], EI_NODETYPE_MODE, NULL);
	if (cno) {
     elist = (char **)setcombine ((void **)strsetdup (cno->enable), (void **)elist);
    }
    y++;
   }
  }

  elist = strsetdeldupes (elist);

  plan = mod_plan (NULL, elist, MOD_ENABLE | optmask);
  if (!plan) {
   puts ("I guess I'm... clueless");
  } else {
#ifdef DEBUG
   mod_plan_ls (plan);
#endif
   puts ("commencing");
   mod_plan_commit (plan);
   currentmode = mode;
   mod_plan_free (plan);
  }
 }

 return 0;
}

int print_usage_info () {
 fputs ("eINIT " EINIT_VERSION_LITERAL "\nCopyright (c) 2006, <NAME>\nUsage:\n einit [-c configfile] [-v] [-h]\n", stderr);
 return -1;
}

int ipc_wait () {
 struct cfgnode *node = cfg_findnode ("control-socket", 0, NULL);
 int sock = socket (AF_UNIX, SOCK_STREAM, 0);
 struct sockaddr_un saddr;
 int nfd;
 if (sock == -1)
  return bitch (BTCH_ERRNO);

 saddr.sun_family = AF_UNIX;
 if (!node || !node->svalue) strncpy (saddr.sun_path, "/etc/einit-control", sizeof(saddr.sun_path) - 1);
 else strncpy (saddr.sun_path, node->svalue, sizeof(saddr.sun_path) - 1);

 if (bind(sock, (struct sockaddr *) &saddr, sizeof(struct sockaddr_un))) {
  close (sock);
  return bitch (BTCH_ERRNO);
 }

 listen (sock, 2);

 while ((nfd = accept (sock, NULL, NULL)) != -1) {
  printf ("new connection: %i", nfd);
  close (nfd);
 }
 if (nfd == -1)
  bitch (BTCH_ERRNO);

 close (sock);
 if (unlink (saddr.sun_path)) bitch (BTCH_ERRNO);
 return 0;
}

int main(int argc, char **argv) {<commit_msg>connection test works<commit_after>/* einit: main.c */
/*
Copyright (c) 2006, <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 <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>

int main(int, char **);
int print_usage_info ();
int switchmode (char *);
int ipc_wait ();

char *currentmode = "void";
char *newmode = "void";

int switchmode (char *mode) {
 if (!mode) return -1;
 printf ("switching to mode \"%s\": ", mode);
 if (sconfiguration) {
  struct cfgnode *cur = cfg_findnode (mode, EI_NODETYPE_MODE, NULL);
  struct cfgnode *opt;
  struct mloadplan *plan;
  char **elist;
  unsigned int optmask = 0;

  if (!cur) {
   puts ("mode not defined, aborting");
   return -1;
  }
  opt = NULL;
  while (opt = cfg_findnode ("disable-unspecified", 0, opt)) {
   if (opt->mode == cur) {
    if (opt->flag) optmask |= MOD_DISABLE_UNSPEC;
    else optmask &= !MOD_DISABLE_UNSPEC;
   }
  }
  elist = strsetdup (cur->enable);
  newmode = mode;

  if (cur->base) {
   int y = 0;
   struct cfgnode *cno;
   while (cur->base[y]) {
	cno = cfg_findnode (cur->base[y], EI_NODETYPE_MODE, NULL);
	if (cno) {
     elist = (char **)setcombine ((void **)strsetdup (cno->enable), (void **)elist);
    }
    y++;
   }
  }

  elist = strsetdeldupes (elist);

  plan = mod_plan (NULL, elist, MOD_ENABLE | optmask);
  if (!plan) {
   puts ("I guess I'm... clueless");
  } else {
#ifdef DEBUG
   mod_plan_ls (plan);
#endif
   puts ("commencing");
   mod_plan_commit (plan);
   currentmode = mode;
   mod_plan_free (plan);
  }
 }

 return 0;
}

int print_usage_info () {
 fputs ("eINIT " EINIT_VERSION_LITERAL "\nCopyright (c) 2006, <NAME>\nUsage:\n einit [-c configfile] [-v] [-h]\n", stderr);
 return -1;
}

int ipc_wait () {
 struct cfgnode *node = cfg_findnode ("control-socket", 0, NULL);
 int sock = socket (AF_UNIX, SOCK_STREAM, 0);
 struct sockaddr_un saddr;
 int nfd;
 if (sock == -1)
  return bitch (BTCH_ERRNO);

 saddr.sun_family = AF_UNIX;
 if (!node || !node->svalue) strncpy (saddr.sun_path, "/etc/einit-control", sizeof(saddr.sun_path) - 1);
 else strncpy (saddr.sun_path, node->svalue, sizeof(saddr.sun_path) - 1);

 if (bind(sock, (struct sockaddr *) &saddr, sizeof(struct sockaddr_un))) {
  close (sock);
  return bitch (BTCH_ERRNO);
 }

 if (listen (sock, 5)) {
  close (sock);
  return bitch (BTCH_ERRNO);
 }

 while ((nfd = accept (sock, NULL, NULL)) != -1) {
  printf ("new connection: %i", nfd);
  puts ("");
  close (nfd);
 }
 if (nfd == -1)
  bitch (BTCH_ERRNO);

 close (sock);
 if (unlink (saddr.sun_path)) bitch (BTCH_ERRNO);
 return 0;
}

int main(int argc, char **argv) {
{'fraction_non_alphanumeric': 0.12295380138232084, 'fraction_numerical': 0.005820298290287377, 'mean_word_length': 4.010935601458081, 'pattern_counts': {'":': 2, '<': 25, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '1601050', 'n_tokens_mistral': 2858, 'n_tokens_neox': 2700, 'n_words': 985}