<commit_before>#include <autodim.h>

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <syslog.h>
#include <fcntl.h>

int main(void)
{
  pid_t pid;

  /* Fork off the parent process */
  pid = fork();

  /* An error occurred */
  if (pid < 0)
      exit(EXIT_FAILURE);

  printf("Forked successful: %d\n", pid);
  /* Success: Let the parent terminate */
  if (pid > 0)
      exit(EXIT_SUCCESS);

  printf("Terminating parent successful\n");
  /* On success: The child process becomes session leader */
  if (setsid() < 0)
      exit(EXIT_FAILURE);

  /* Catch, ignore and handle signals */
  //TODO: Implement a working signal handler */
  signal(SIGCHLD, SIG_IGN);
  signal(SIGHUP, SIG_IGN);

  /* Set new file permissions */
  umask(0);

  /* Change the working directory to the root directory */
  /* or another appropriated directory */
  if (chdir("/") < 0) {
    exit(EXIT_FAILURE);
  }
  printf("Change directory successful\n");
  /* Close all open file descriptors */
  int x;
  for (x = sysconf(_SC_OPEN_MAX); x>=0; x--)
  {
    close (x);
  }
  /* Open the log file */
  openlog ("autodim", LOG_PID, LOG_DAEMON);

  syslog (LOG_NOTICE, "autodim started.");

  if (autodim())  exit(EXIT_FAILURE);

  syslog (LOG_NOTICE, "autodim terminated.");
  closelog();

  return EXIT_SUCCESS;
}<commit_msg>Manually merged some changes from independent branch<commit_after>#include <autodim.h>

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <syslog.h>
#include <fcntl.h>

int main(void)
{

  pid_t pid;

  pid = fork();

  if (pid < 0)
      exit(EXIT_FAILURE);

  printf("Forked successful: %d\n", pid);

  if (pid > 0)
      exit(EXIT_SUCCESS);

  printf("Terminating parent successful\n");

  if (setsid() < 0)
      exit(EXIT_FAILURE);

  //TODO: Implement signal handler
  signal(SIGCHLD, SIG_IGN);
  signal(SIGHUP, SIG_IGN);

  umask(0);

  if (chdir("/") < 0) {
    exit(EXIT_FAILURE);
  }
  printf("Change directory successful\n");


  for (int i = getdtablesize(); i>=0; i--)
    close (i);

  openlog ("autodim", LOG_PID, LOG_DAEMON);

  syslog (LOG_NOTICE, "autodim started.");


  if (autodim())  exit(EXIT_FAILURE);

  syslog (LOG_NOTICE, "autodim terminated.");
  closelog();

  return EXIT_SUCCESS;
}
{'fraction_non_alphanumeric': 0.15785054575986565, 'fraction_numerical': 0.005037783375314861, 'mean_word_length': 3.4793233082706765, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 25, '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': '7335143', 'n_tokens_mistral': 907, 'n_tokens_neox': 880, 'n_words': 230}