Esempio n. 1
0
int main(int argc, char *argv[])
{
    char *conffile = NULL;
    int request_kill = 0, show_message = 0;
    
    if (!read_parameters(argc, argv, &conffile, &request_kill, &show_message)) {
	print_usage(argv[0]);
	return 1;
    }
    
    /* read the config file; conffile = NULL means use the default. */
    if (!read_config(conffile))
	return 1; /* error reading the config file */
    setup_defaults();
    
    if (request_kill) {
	kill_server();
	return 0;
    }
    
    if (show_message) {
	signal_message();
	return 0;
    }
    
    setup_signals();
    
    /* Init files and directories.
     * Start logging last, so that the log is only created if startup succeeds. */
    if (!init_workdir() ||
	!init_database() ||
	!check_database() ||
	!begin_logging())
	return 1;
    
    if (!settings.nodaemon) {
    	if (daemon(0, 0) == -1) {
	    settings.nodaemon = TRUE;
	    log_msg("could not detach from terminal: %s", strerror(errno));
	    return 1;
	}
	if (!create_pidfile())
	    return 1;
    }

    /* give this process and its children their own process group id for kill() */
    setpgid(0, 0);
    report_startup();
    
    runserver();
        
    /* shutdown */
    remove_pidfile();
    end_logging();
    close_database();
    remove_unix_socket();
    free_config();
    
    return 0;
}
Esempio n. 2
0
void inbox(DictionaryIterator *iter, void *context) {
  Tuple *t = dict_read_first(iter);
  do {
    switch (t->key) {
      case DISPLAY_MESSAGE:
        set_text(strcpy(DisplayMessage, t->value->cstring));
        break;
      case MESSAGE:
        switch(t->value->int32) {
          case IS_LEVEL:
            car_is_level();
          break;
          case BEGIN_LOGGING:
            begin_logging();
          break;
        };
        break;
      default:
        break;
    };
  } while ((t = dict_read_next(iter)) != NULL);
}