Esempio n. 1
0
/*
 * Log post-init: start logging threads.
 * Return -1 on errors, 0 otherwise.
 */
int
log_init(opts_t *opts, proxy_ctx_t *ctx, int clisock1, int clisock2)
{
	proxy_ctx = ctx;
	if (err_log)
		if (logger_start(err_log) == -1)
			return -1;
	if (!opts->debug) {
		err_shortcut_logger = 1;
	}
	if (connect_log)
		if (logger_start(connect_log) == -1)
			return -1;
	if (content_log) {
		content_clisock = clisock1;
		if (logger_start(content_log) == -1)
			return -1;
	} else {
		privsep_client_close(clisock1);
	}
	if (cert_log) {
		cert_clisock = clisock2;
		if (logger_start(cert_log) == -1)
			return -1;
	} else {
		privsep_client_close(clisock2);
	}
	return 0;
}
Esempio n. 2
0
/*
 * Log post-init: start logging threads.
 * Return -1 on errors, 0 otherwise.
 */
int
log_init(opts_t *opts)
{
	if (err_log)
		if (logger_start(err_log) == -1)
			return -1;
	if (!opts->debug) {
		err_started = 1;
	}
	if (connect_log)
		if (logger_start(connect_log) == -1)
			return -1;
	if (content_log)
		if (logger_start(content_log) == -1)
			return -1;
	return 0;
}
Esempio n. 3
0
void initialize()
{
    if (signal(SIGCHLD, SIG_IGN) == SIG_ERR)
    {
        exit_on_error("signal(SIGCHLD, SIG_IGN)\n");
    }

    if (!load_mysql_info())
    {
        exit_on_error("failed to load mysql account infomation\n");
    }

    if (false && drop_privileges() == false)
    {
        exit_on_error("failed to set privileges\n");
    }

    if (logger_start() == -1)
    {
        exit_on_error("Can't create a logger process\n");
    }
}
Esempio n. 4
0
void fc_step()
{
    //using fake data
#ifdef FAKE_ENABLE
    return;
#endif


    gps_step();

    bt_step();

    protocol_step();

    logger_step();

    wind_step();

    //logger always enabled
    if (config.autostart.flags & AUTOSTART_ALWAYS_ENABLED)
    {
        if (fc.vario.valid && fc.flight.state == FLIGHT_WAIT)
        {
            fc_takeoff();
        }
    }
    else
    {
        //auto start
        // baro valid, waiting to take off or landed, and enabled auto start
        if (fc.vario.valid && (fc.flight.state == FLIGHT_WAIT || fc.flight.state == FLIGHT_LAND) && config.autostart.start_sensititvity > 0)
        {
            if (abs(fc.altitude1 - fc.flight.autostart_altitude) > config.autostart.start_sensititvity)
            {
                fc_takeoff();
            }
            else
            {
                uint32_t t = task_get_ms_tick();

                if(t < fc.flight.autostart_timer)
                {
                    assert(0);
                    DEBUG("old %lu\n", fc.flight.autostart_timer);
                    DEBUG("act %lu\n", t);
                }

                //reset wait timer
                if (t - fc.flight.autostart_timer > (uint32_t)config.autostart.timeout * 1000ul)
                {
                    fc.flight.autostart_timer = t;
                    fc.flight.autostart_altitude = fc.altitude1;
                }
            }
        }

        //auto land
        // flying and auto land enabled
        if (fc.flight.state == FLIGHT_FLIGHT && config.autostart.land_sensititvity > 0)
        {
            if (abs(fc.altitude1 - fc.flight.autostart_altitude) < config.autostart.land_sensititvity)
            {
                uint32_t tick = task_get_ms_tick();

                if (tick < fc.flight.autostart_timer)
                {
                    assert(0);
                    DEBUG("TT %lu\n", tick);
                    DEBUG("AT %lu\n", fc.flight.autostart_timer);
                }
                else if (tick - fc.flight.autostart_timer > (uint32_t)config.autostart.timeout * 1000ul)
                {
                    //reduce timeout from flight time
                    fc.flight.timer += (uint32_t)config.autostart.timeout * 1000ul;

                    gui_reset_timeout();
                    fc_landing();
                }
            }
            else
            {
                fc.flight.autostart_altitude = fc.altitude1;
                fc.flight.autostart_timer = task_get_ms_tick();
            }
        }
    }


    //gps time sync
    if ((config.system.time_flags & TIME_SYNC) && fc.gps_data.fix_cnt == GPS_FIX_TIME_SYNC)
    {
        if (config.gui.menu_audio_flags & CFG_AUDIO_MENU_GPS)
            seq_start(&gps_ready, config.gui.alert_volume);

        fc_sync_gps_time();
        fc.gps_data.fix_cnt++;
    }

    //glide ratio
    //when you have GPS, baro and speed is higher than 2km/h and you are sinking <= -0.01
    if (fc.gps_data.valid && fc.vario.valid && fc.gps_data.groud_speed > FC_GLIDE_MIN_KNOTS && fc.vario.avg <= FC_GLIDE_MIN_SINK)
    {
        float spd_m = fc.gps_data.groud_speed * FC_KNOTS_TO_MPS;
        fc.glide_ratio = spd_m / abs(fc.vario.avg);

        fc.glide_ratio_valid = true;
    }
    else
    {
        fc.glide_ratio_valid = false;
    }

    //flight logger
    if (config.logger.enabled)
    {
        if (fc.flight.state == FLIGHT_FLIGHT && !logger_active() && time_is_set() && !logger_error())
        {
            logger_start();
        }
    }

    //flight statistic
    if (fc.flight.state == FLIGHT_FLIGHT)
    {
        int16_t t_vario = fc.vario.avg * 100;

        if (fc.altitude1 > fc.flight.stats.max_alt)
            fc.flight.stats.max_alt = fc.altitude1;
        if (fc.altitude1 < fc.flight.stats.min_alt)
            fc.flight.stats.min_alt = fc.altitude1;

        if (t_vario > fc.flight.stats.max_climb)
            fc.flight.stats.max_climb = t_vario;
        if (t_vario < fc.flight.stats.max_sink)
            fc.flight.stats.max_sink = t_vario;
    }
}
Esempio n. 5
0
int main(int argc, char **argv) {
  char *options, *path;
  int fd, inotify, option, pwd, waitargs;
  pid_t pid;
  time_t started;
  struct sigaction action;

  progname = argv[0];

  /* Redirect stdin from /dev/null. */
  if ((fd = open("/dev/null", O_RDWR)) < 0)
    error(EXIT_FAILURE, errno, "open /dev/null");
  if (fd != STDIN_FILENO)
    if ((dup2(fd, STDIN_FILENO)) < 0)
      error(EXIT_FAILURE, errno, "dup2");

  /* Redirect stdout and/or stderr to /dev/null if closed. */
  while (fd <= STDERR_FILENO)
    if ((fd = dup(fd)) < 0)
      error(EXIT_FAILURE, errno, "dup");
  close(fd);

  /* Close all file descriptors apart from stdin, stdout and stderr. */
  fd = getdtablesize() - 1;
  while (fd > STDERR_FILENO)
    close(fd--);

  options = "+:cfl:p:ru:w:", waitargs = 0;
  while ((option = getopt(argc, argv, options)) > 0)
    switch (option) {
      case 'c':
        command.chdir = 1;
        break;
      case 'f':
        /* On by default; ignored for compatibility with BSD daemon(1). */
        break;
      case 'l':
        logger_setup(optarg);
        break;
      case 'p':
        pidfile_open(optarg);
        break;
      case 'r':
        command.restart = 1;
        break;
      case 'u':
        user_setup(optarg);
        break;
      case 'w':
        waitargs++;
        break;
      default:
        usage(argv[0]);
    }

  if (argc <= optind)
    usage(argv[0]);

  switch (fork()) {
    case -1:
      error(EXIT_FAILURE, errno, "fork");
    case 0:
      setsid(); /* This should work after forking; ignore errors anyway. */
      break;
    default:
      _exit(EXIT_SUCCESS); /* Don't delete pidfile in atexit() handler. */
  }

  logger_start();
  pidfile_write();

  /* We can handle all -w command line arguments now we're daemonized. */
  if (waitargs > 0) {
    if ((inotify = inotify_init1(IN_CLOEXEC)) < 0)
      error(EXIT_FAILURE, errno, "inotify_init1");

    /* Open the working directory so we can restore it after each await(). */
    if ((pwd = open(".", O_RDONLY | O_DIRECTORY)) < 0)
      error(EXIT_FAILURE, errno, "open pwd");

    optind = 0; /* Need to reset optind to reprocess arguments. */
    while ((option = getopt(argc, argv, options)) > 0)
      if (option == 'w') {
        if (!(path = strdup(optarg)))
          error(EXIT_FAILURE, errno, "strdup");
        await(path, inotify, 0);
        free(path);
        fchdir(pwd);
      }

    close(inotify);
    close(pwd);
  }

  if (command.chdir && chdir("/") < 0)
    error(EXIT_FAILURE, errno, "chdir");

  command.argv = argv + optind;
  if (!command.restart && !pidfile.path) {
    /* We don't need to supervise in this case, so just exec. */
    if (command.gid > 0 && setgid(command.gid) < 0)
      error(EXIT_FAILURE, errno, "setgid");
    if (command.uid > 0 && setuid(command.uid) < 0)
      error(EXIT_FAILURE, errno, "setuid");
    execvp(command.argv[0], command.argv);
    error(EXIT_FAILURE, errno, "exec");
  }

  /* Handle and pass on HUP, INT, TERM, USR1, USR2 signals. */
  sigfillset(&action.sa_mask);
  action.sa_flags = SA_RESTART;
  action.sa_handler = handler;
  sigaction(SIGHUP, &action, NULL);
  sigaction(SIGINT, &action, NULL);
  sigaction(SIGTERM, &action, NULL);
  sigaction(SIGUSR1, &action, NULL);
  sigaction(SIGUSR2, &action, NULL);

  do {
    command.killed = 0; /* Have we signalled the child? */
    switch (command.pid = fork()) {
      case -1:
        error(EXIT_FAILURE, errno, "fork");
      case 0:
        if (command.gid > 0 && setgid(command.gid) < 0)
          error(EXIT_FAILURE, errno, "setgid");
        if (command.uid > 0 && setuid(command.uid) < 0)
          error(EXIT_FAILURE, errno, "setuid");
        setsid(); /* This should work after forking; ignore errors anyway. */
        execvp(command.argv[0], command.argv);
        error(EXIT_FAILURE, errno, "exec");
    }

    started = time(NULL);
    while (pid = wait(NULL), pid != (pid_t) command.pid)
      if (pid < 0 && errno != EINTR)
        error(EXIT_FAILURE, errno, "wait");

    /* Try to avoid restarting a crashing command in a tight loop. */
    if (command.restart && !command.killed && time(NULL) < started + 5)
      error(EXIT_FAILURE, 0, "Child died within 5 seconds: not restarting");
  } while (command.restart);

  return EXIT_SUCCESS;
}
Esempio n. 6
0
void
zdb_init()
{
    if(zdb_init_done)
    {
        return;
    }

    /* DO or DIE */

    if(dnscore_getfingerprint() != (dnsdb_getfingerprint() & dnscore_fingerprint_mask()))
    {
        osformatln(termerr, "Mismatched fingerprints: %08x != (%08x = %08x & %08x)",
                dnscore_getfingerprint(),
                dnsdb_getfingerprint() & dnscore_fingerprint_mask(),
                dnsdb_getfingerprint() , dnscore_fingerprint_mask());

        flusherr();
        
        exit(-1);
    }

    zdb_init_done = TRUE;

    /* Init the dns core */

    dnscore_init();

    /* Init the error table */

    zdb_register_errors();

    /* Init the hash tables */

    hash_init();

#if ZDB_OPENSSL_SUPPORT!=0

    /* Init openssl */

    ENGINE_load_openssl();
    ENGINE_load_builtin_engines();

    ssl_mutex_count = CRYPTO_num_locks();

    MALLOC_OR_DIE(pthread_mutex_t*, ssl_mutex, ssl_mutex_count * sizeof (pthread_mutex_t), ZDB_SSLMUTEX_TAG);

    int i;

    for(i = 0; i < ssl_mutex_count; i++)
    {
        pthread_mutex_init(&ssl_mutex[i], NULL);
    }

    CRYPTO_set_id_callback(ssl_thread_id);
    CRYPTO_set_locking_callback(ssl_lock);
#endif

#if ZDB_USE_THREADPOOL != 0
    /*
     *  The default value for the database.
     *  This initialization will do nothing if it has already been done.
     *
     *  The server will have to do it before calling zdb_init();
     *
     */
    
    u32 count = sys_get_cpu_count() + 2;
    
    ya_result return_value = thread_pool_init(count);
    
    if(FAIL(return_value))
    {
        log_crit("unable to initialise the thread pool to %d threads: %r", count, return_value); /* will ultimately lead to the end of the program */
        exit(-1);
    }
    
    thread_pool_initialized_by_zdb = (return_value == count);
#endif

#if ZDB_USES_ZALLOC != 0
    zdb_set_zowner(pthread_self());
#endif

    logger_start();

    zdb_rdtsc_registations();
}
int webcam_run() {

#ifdef HAVE_CAMERA
    // Our mandatory renderers, ensures they are run first being registered last
    struct Node *n = cameras.l_head;
    while (list_isNode(n)) {
        CAMERA camera = (CAMERA) n;
        n = n->n_succ;
        // Put annotated last
        list_addTail(&camera->renderers.renderers, &create_annotatedrenderer()->node);
        // These go first
        list_addHead(&camera->renderers.renderers, &create_thumbnailrenderer()->node);
        list_addHead(&camera->renderers.renderers, &create_rawrenderer()->node);
    }
#endif

    // Now start the system up
    webserver_initialise(config);

#ifdef HAVE_CAMERA
    // Initialise the renderers
    n = cameras.l_head;
    while (list_isNode(n)) {
        CAMERA camera = (CAMERA) n;
        n = n->n_succ;
        imagerenderer_init(camera);
    }
#endif

    // Initialise the loggers
    logger_start();

    // Finish off configuring the webserver, default port etc
    webserver_set_defaults();

#ifdef HAVE_CAMERA
    n = cameras.l_head;
    while (list_isNode(n)) {
        CAMERA camera = (CAMERA) n;
        n = n->n_succ;
        imagerenderer_postinit(camera);
    }
#endif

    sensor_postinit();

    // The camera home page
    //create_homepage();

    // Start everything up
    webserver_start();

#ifdef HAVE_CAMERA
    camera_start();
#endif

    // Now the main loop, monitor for sensor updates
    //sensor_loop();
    while (1)
        sleep(60);

    // Shutdown - we never actually get here
    webserver_stop();
    logger_stop();

#ifdef HAVE_CAMERA
    camera_stop();
#endif

    return 0;
}