int main(int argc, char *argv[]) { (void) argc; (void) argv; struct log *l; l = log_new("/tmp/log_test.txt", LOG_ALL); assert(l); log_clear(l); log_set_level(l, LOG_INFO); log_debug(l, "module-1", "debug message\n"); log_set_level(l, LOG_DEBUG); log_debug(l, "module-1", "debug message\n"); log_info(l, "module-2", "info message\n"); log_warning(l, NULL, "warning message\n"); log_error(l, "module-1","error message\n"); log_printf(l, LOG_WARNING, "module-3", "more warnings - "); log_append(l, "%s\n", "\"this string is appended\""); fprintf(stdout, "log_print():\n"); log_print(l, STDOUT_FILENO); log_delete(l); return 0; }
raft_server_t* raft_new() { raft_server_private_t* me = (raft_server_private_t*)calloc(1, sizeof(raft_server_private_t)); if (!me) return NULL; me->current_term = 0; me->voted_for = -1; me->current_idx = 1; me->timeout_elapsed = 0; me->request_timeout = 200; me->election_timeout = 1000; me->log = log_new(); raft_set_state((raft_server_t*)me, RAFT_STATE_FOLLOWER); return (raft_server_t*)me; }
static gint init_log (gchar *log_path) { gint ret; _log = log_new ("log_path", log_path, NULL); ret = log_set_log_handler (_log); if (ret != 0) { return ret; } /* remove gstInfo default handler. */ gst_debug_remove_log_function (gst_debug_log_default); return 0; }
static int init_server_data() { data.config.idx = data.input->server_idx; data.config.len = MAX_SERVER_COUNT; data.config.cid.size = data.input->group_size; data.config.servers = (server_t*)malloc(data.config.len * sizeof(server_t)); if (NULL == data.config.servers) { error_return(1, log_fp, "Cannot allocate configuration array\n"); } memset(data.config.servers, 0, data.config.len * sizeof(server_t)); /* Set up log */ data.log = log_new(); if (NULL == data.log) { error_return(1, log_fp, "Cannot allocate log\n"); } return 0; }
struct index *index_new(const char *basedir, int max_mtbl_size, int tolog) { char dbfile[FILE_PATH_SIZE]; struct index *idx = malloc(sizeof(struct index)); struct idx_park *park = malloc(sizeof(struct idx_park)); ensure_dir_exists(basedir); idx->lsn = 0; idx->bloom_hits = 0; idx->bg_merge_count = 0; idx->max_mtbl = 1; idx->max_mtbl_size = max_mtbl_size; memset(idx->basedir, 0, FILE_PATH_SIZE); memcpy(idx->basedir, basedir, FILE_PATH_SIZE); /* sst */ idx->sst = sst_new(idx->basedir); idx->list = skiplist_new(max_mtbl_size); pthread_mutex_init(&idx->merge_mutex, NULL); /* container */ park->list = NULL; park->lsn = idx->lsn; idx->park = park; /* log */ idx->log = log_new(idx->basedir, idx->lsn, tolog); /* * Log Recovery Processes : * 1) read old log file and add entries to memtable * 2) read new log file abd add entries to memtable * 3) merge the current active log's memtable * 4) remove old log file, new log file * 5) create new memtable and log file */ if (log_recovery(idx->log, idx->list)) { __DEBUG(LEVEL_DEBUG, "prepare to merge logs, merge count #%d....", idx->list->count); sst_merge(idx->sst, idx->list, 1); remove(idx->log->log_new); remove(idx->log->log_old); idx->list = skiplist_new(idx->max_mtbl_size); } /* Create new log : 0.log */ log_next(idx->log, 0); memset(dbfile, 0, FILE_PATH_SIZE); snprintf(dbfile, FILE_PATH_SIZE, "%s/ness.db", idx->basedir); idx->db_rfd = open(dbfile, LSM_OPEN_FLAGS, 0644); /* Detached thread attr */ pthread_attr_init(&idx->attr); pthread_attr_setdetachstate(&idx->attr, PTHREAD_CREATE_DETACHED); return idx; }
int main(int argc, char **argv) { fko_ctx_t ctx = NULL; fko_ctx_t ctx2 = NULL; int res; char *spa_data=NULL, *version=NULL; char access_buf[MAX_LINE_LEN] = {0}; char key[MAX_KEY_LEN+1] = {0}; char hmac_key[MAX_KEY_LEN+1] = {0}; int key_len = 0, orig_key_len = 0, hmac_key_len = 0, enc_mode; int tmp_port = 0; char dump_buf[CTX_DUMP_BUFSIZE]; fko_cli_options_t options; memset(&options, 0x0, sizeof(fko_cli_options_t)); /* Initialize the log module */ log_new(); /* Handle command line */ config_init(&options, argc, argv); #if HAVE_LIBFIU /* Set any fault injection points early */ if(! enable_fault_injections(&options)) clean_exit(ctx, &options, key, &key_len, hmac_key, &hmac_key_len, EXIT_FAILURE); #endif /* Handle previous execution arguments if required */ if(prev_exec(&options, argc, argv) != 1) clean_exit(ctx, &options, key, &key_len, hmac_key, &hmac_key_len, EXIT_FAILURE); if(options.show_last_command) clean_exit(ctx, &options, key, &key_len, hmac_key, &hmac_key_len, EXIT_SUCCESS); /* Intialize the context */ res = fko_new(&ctx); if(res != FKO_SUCCESS) { errmsg("fko_new", res); clean_exit(ctx, &options, key, &key_len, hmac_key, &hmac_key_len, EXIT_FAILURE); } /* Display version info and exit. */ if(options.version) { fko_get_version(ctx, &version); fprintf(stdout, "fwknop client %s, FKO protocol version %s\n", MY_VERSION, version); clean_exit(ctx, &options, key, &key_len, hmac_key, &hmac_key_len, EXIT_SUCCESS); } /* Set client timeout */ if(options.fw_timeout >= 0) { res = fko_set_spa_client_timeout(ctx, options.fw_timeout); if(res != FKO_SUCCESS) { errmsg("fko_set_spa_client_timeout", res); clean_exit(ctx, &options, key, &key_len, hmac_key, &hmac_key_len, EXIT_FAILURE); } } /* Set the SPA packet message type based on command line options */ res = set_message_type(ctx, &options); if(res != FKO_SUCCESS) { errmsg("fko_set_spa_message_type", res); clean_exit(ctx, &options, key, &key_len, hmac_key, &hmac_key_len, EXIT_FAILURE); } /* Adjust the SPA timestamp if necessary */ if(options.time_offset_plus > 0) { res = fko_set_timestamp(ctx, options.time_offset_plus); if(res != FKO_SUCCESS) { errmsg("fko_set_timestamp", res); clean_exit(ctx, &options, key, &key_len, hmac_key, &hmac_key_len, EXIT_FAILURE); } } if(options.time_offset_minus > 0) { res = fko_set_timestamp(ctx, -options.time_offset_minus); if(res != FKO_SUCCESS) { errmsg("fko_set_timestamp", res); clean_exit(ctx, &options, key, &key_len, hmac_key, &hmac_key_len, EXIT_FAILURE); } } if(options.server_command[0] != 0x0) { /* Set the access message to a command that the server will * execute */ snprintf(access_buf, MAX_LINE_LEN, "%s%s%s", options.allow_ip_str, ",", options.server_command); } else { /* Resolve the client's public facing IP address if requestesd. * if this fails, consider it fatal. */ if (options.resolve_ip_http_https) { if(options.resolve_http_only) { if(resolve_ip_http(&options) < 0) { clean_exit(ctx, &options, key, &key_len, hmac_key, &hmac_key_len, EXIT_FAILURE); } } else { /* Default to HTTPS */ if(resolve_ip_https(&options) < 0) { clean_exit(ctx, &options, key, &key_len, hmac_key, &hmac_key_len, EXIT_FAILURE); } } } /* Set a message string by combining the allow IP and the * port/protocol. The fwknopd server allows no port/protocol * to be specified as well, so in this case append the string * "none/0" to the allow IP. */ if(set_access_buf(ctx, &options, access_buf) != 1) clean_exit(ctx, &options, key, &key_len, hmac_key, &hmac_key_len, EXIT_FAILURE); } res = fko_set_spa_message(ctx, access_buf); if(res != FKO_SUCCESS) { errmsg("fko_set_spa_message", res); clean_exit(ctx, &options, key, &key_len, hmac_key, &hmac_key_len, EXIT_FAILURE); } /* Set NAT access string */ if (options.nat_local || options.nat_access_str[0] != 0x0) { res = set_nat_access(ctx, &options, access_buf); if(res != FKO_SUCCESS) { errmsg("fko_set_nat_access_str", res); clean_exit(ctx, &options, key, &key_len, hmac_key, &hmac_key_len, EXIT_FAILURE); } } /* Set username */ if(options.spoof_user[0] != 0x0) { res = fko_set_username(ctx, options.spoof_user); if(res != FKO_SUCCESS) { errmsg("fko_set_username", res); clean_exit(ctx, &options, key, &key_len, hmac_key, &hmac_key_len, EXIT_FAILURE); } } /* Set up for using GPG if specified. */ if(options.use_gpg) { /* If use-gpg-agent was not specified, then remove the GPG_AGENT_INFO * ENV variable if it exists. */ #ifndef WIN32 if(!options.use_gpg_agent) unsetenv("GPG_AGENT_INFO"); #endif res = fko_set_spa_encryption_type(ctx, FKO_ENCRYPTION_GPG); if(res != FKO_SUCCESS) { errmsg("fko_set_spa_encryption_type", res); clean_exit(ctx, &options, key, &key_len, hmac_key, &hmac_key_len, EXIT_FAILURE); } /* Set gpg path if necessary */ if(strlen(options.gpg_exe) > 0) { res = fko_set_gpg_exe(ctx, options.gpg_exe); if(res != FKO_SUCCESS) { errmsg("fko_set_gpg_exe", res); clean_exit(ctx, &options, key, &key_len, hmac_key, &hmac_key_len, EXIT_FAILURE); } } /* If a GPG home dir was specified, set it here. Note: Setting * this has to occur before calling any of the other GPG-related * functions. */ if(strlen(options.gpg_home_dir) > 0) { res = fko_set_gpg_home_dir(ctx, options.gpg_home_dir); if(res != FKO_SUCCESS) { errmsg("fko_set_gpg_home_dir", res); clean_exit(ctx, &options, key, &key_len, hmac_key, &hmac_key_len, EXIT_FAILURE); } } res = fko_set_gpg_recipient(ctx, options.gpg_recipient_key); if(res != FKO_SUCCESS) { errmsg("fko_set_gpg_recipient", res); if(IS_GPG_ERROR(res)) log_msg(LOG_VERBOSITY_ERROR, "GPG ERR: %s", fko_gpg_errstr(ctx)); clean_exit(ctx, &options, key, &key_len, hmac_key, &hmac_key_len, EXIT_FAILURE); } if(strlen(options.gpg_signer_key) > 0) { res = fko_set_gpg_signer(ctx, options.gpg_signer_key); if(res != FKO_SUCCESS) { errmsg("fko_set_gpg_signer", res); if(IS_GPG_ERROR(res)) log_msg(LOG_VERBOSITY_ERROR, "GPG ERR: %s", fko_gpg_errstr(ctx)); clean_exit(ctx, &options, key, &key_len, hmac_key, &hmac_key_len, EXIT_FAILURE); } } res = fko_set_spa_encryption_mode(ctx, FKO_ENC_MODE_ASYMMETRIC); if(res != FKO_SUCCESS) { errmsg("fko_set_spa_encryption_mode", res); clean_exit(ctx, &options, key, &key_len, hmac_key, &hmac_key_len, EXIT_FAILURE); } } if(options.encryption_mode && !options.use_gpg) { res = fko_set_spa_encryption_mode(ctx, options.encryption_mode); if(res != FKO_SUCCESS) { errmsg("fko_set_spa_encryption_mode", res); clean_exit(ctx, &options, key, &key_len, hmac_key, &hmac_key_len, EXIT_FAILURE); } } /* Set Digest type. */ if(options.digest_type) { res = fko_set_spa_digest_type(ctx, options.digest_type); if(res != FKO_SUCCESS) { errmsg("fko_set_spa_digest_type", res); clean_exit(ctx, &options, key, &key_len, hmac_key, &hmac_key_len, EXIT_FAILURE); } } /* Acquire the necessary encryption/hmac keys */ if(get_keys(ctx, &options, key, &key_len, hmac_key, &hmac_key_len) != 1) clean_exit(ctx, &options, key, &key_len, hmac_key, &hmac_key_len, EXIT_FAILURE); orig_key_len = key_len; if(options.encryption_mode == FKO_ENC_MODE_CBC_LEGACY_IV && key_len > 16) { log_msg(LOG_VERBOSITY_ERROR, "WARNING: Encryption key in '-M legacy' mode must be <= 16 bytes"); log_msg(LOG_VERBOSITY_ERROR, "long - truncating before sending SPA packet. Upgrading remote"); log_msg(LOG_VERBOSITY_ERROR, "fwknopd is recommended."); key_len = 16; } /* Finalize the context data (encrypt and encode the SPA data) */ res = fko_spa_data_final(ctx, key, key_len, hmac_key, hmac_key_len); if(res != FKO_SUCCESS) { errmsg("fko_spa_data_final", res); if(IS_GPG_ERROR(res)) log_msg(LOG_VERBOSITY_ERROR, "GPG ERR: %s", fko_gpg_errstr(ctx)); clean_exit(ctx, &options, key, &orig_key_len, hmac_key, &hmac_key_len, EXIT_FAILURE); } /* Display the context data. */ if (options.verbose || options.test) { res = dump_ctx_to_buffer(ctx, dump_buf, sizeof(dump_buf)); if (res == FKO_SUCCESS) log_msg(LOG_VERBOSITY_NORMAL, "%s", dump_buf); else log_msg(LOG_VERBOSITY_WARNING, "Unable to dump FKO context: %s", fko_errstr(res)); } /* Save packet data payload if requested. */ if (options.save_packet_file[0] != 0x0) write_spa_packet_data(ctx, &options); /* SPA packet random destination port handling */ if (options.rand_port) { tmp_port = get_rand_port(ctx); if(tmp_port < 0) clean_exit(ctx, &options, key, &orig_key_len, hmac_key, &hmac_key_len, EXIT_FAILURE); options.spa_dst_port = tmp_port; } /* If we are using one the "raw" modes (normally because * we're going to spoof the SPA packet source IP), then select * a random source port unless the source port is already set */ if ((options.spa_proto == FKO_PROTO_TCP_RAW || options.spa_proto == FKO_PROTO_UDP_RAW || options.spa_proto == FKO_PROTO_ICMP) && !options.spa_src_port) { tmp_port = get_rand_port(ctx); if(tmp_port < 0) clean_exit(ctx, &options, key, &orig_key_len, hmac_key, &hmac_key_len, EXIT_FAILURE); options.spa_src_port = tmp_port; } res = send_spa_packet(ctx, &options); if(res < 0) { log_msg(LOG_VERBOSITY_ERROR, "send_spa_packet: packet not sent."); clean_exit(ctx, &options, key, &orig_key_len, hmac_key, &hmac_key_len, EXIT_FAILURE); } else { log_msg(LOG_VERBOSITY_INFO, "send_spa_packet: bytes sent: %i", res); } /* Run through a decode cycle in test mode (--DSS XXX: This test/decode * portion should be moved elsewhere). */ if (options.test) { /************** Decoding now *****************/ /* Now we create a new context based on data from the first one. */ res = fko_get_spa_data(ctx, &spa_data); if(res != FKO_SUCCESS) { errmsg("fko_get_spa_data", res); clean_exit(ctx, &options, key, &orig_key_len, hmac_key, &hmac_key_len, EXIT_FAILURE); } /* Pull the encryption mode. */ res = fko_get_spa_encryption_mode(ctx, &enc_mode); if(res != FKO_SUCCESS) { errmsg("fko_get_spa_encryption_mode", res); if(fko_destroy(ctx) == FKO_ERROR_ZERO_OUT_DATA) log_msg(LOG_VERBOSITY_ERROR, "[*] Could not zero out sensitive data buffer."); ctx = NULL; clean_exit(ctx, &options, key, &orig_key_len, hmac_key, &hmac_key_len, EXIT_FAILURE); } /* If gpg-home-dir is specified, we have to defer decrypting if we * use the fko_new_with_data() function because we need to set the * gpg home dir after the context is created, but before we attempt * to decrypt the data. Therefore we either pass NULL for the * decryption key to fko_new_with_data() or use fko_new() to create * an empty context, populate it with the encrypted data, set our * options, then decode it. * * This also verifies the HMAC and truncates it if there are no * problems. */ res = fko_new_with_data(&ctx2, spa_data, NULL, 0, enc_mode, hmac_key, hmac_key_len, options.hmac_type); if(res != FKO_SUCCESS) { errmsg("fko_new_with_data", res); if(fko_destroy(ctx2) == FKO_ERROR_ZERO_OUT_DATA) log_msg(LOG_VERBOSITY_ERROR, "[*] Could not zero out sensitive data buffer."); ctx2 = NULL; clean_exit(ctx, &options, key, &orig_key_len, hmac_key, &hmac_key_len, EXIT_FAILURE); } res = fko_set_spa_encryption_mode(ctx2, enc_mode); if(res != FKO_SUCCESS) { errmsg("fko_set_spa_encryption_mode", res); if(fko_destroy(ctx2) == FKO_ERROR_ZERO_OUT_DATA) log_msg(LOG_VERBOSITY_ERROR, "[*] Could not zero out sensitive data buffer."); ctx2 = NULL; clean_exit(ctx, &options, key, &orig_key_len, hmac_key, &hmac_key_len, EXIT_FAILURE); } /* See if we are using gpg and if we need to set the GPG home dir. */ if(options.use_gpg) { if(strlen(options.gpg_home_dir) > 0) { res = fko_set_gpg_home_dir(ctx2, options.gpg_home_dir); if(res != FKO_SUCCESS) { errmsg("fko_set_gpg_home_dir", res); if(fko_destroy(ctx2) == FKO_ERROR_ZERO_OUT_DATA) log_msg(LOG_VERBOSITY_ERROR, "[*] Could not zero out sensitive data buffer."); ctx2 = NULL; clean_exit(ctx, &options, key, &orig_key_len, hmac_key, &hmac_key_len, EXIT_FAILURE); } } } /* Decrypt */ res = fko_decrypt_spa_data(ctx2, key, key_len); if(res != FKO_SUCCESS) { errmsg("fko_decrypt_spa_data", res); if(IS_GPG_ERROR(res)) { /* we most likely could not decrypt the gpg-encrypted data * because we don't have access to the private key associated * with the public key we used for encryption. Since this is * expected, return 0 instead of an error condition (so calling * programs like the fwknop test suite don't interpret this as * an unrecoverable error), but print the error string for * debugging purposes. The test suite does run a series of * tests that use a single key pair for encryption and * authentication, so decryption become possible for these * tests. */ log_msg(LOG_VERBOSITY_ERROR, "GPG ERR: %s\n%s", fko_gpg_errstr(ctx2), "No access to recipient private key?"); } if(fko_destroy(ctx2) == FKO_ERROR_ZERO_OUT_DATA) log_msg(LOG_VERBOSITY_ERROR, "[*] Could not zero out sensitive data buffer."); ctx2 = NULL; clean_exit(ctx, &options, key, &orig_key_len, hmac_key, &hmac_key_len, EXIT_FAILURE); } res = dump_ctx_to_buffer(ctx2, dump_buf, sizeof(dump_buf)); if (res == FKO_SUCCESS) log_msg(LOG_VERBOSITY_NORMAL, "\nDump of the Decoded Data\n%s", dump_buf); else log_msg(LOG_VERBOSITY_WARNING, "Unable to dump FKO context: %s", fko_errstr(res)); if(fko_destroy(ctx2) == FKO_ERROR_ZERO_OUT_DATA) log_msg(LOG_VERBOSITY_ERROR, "[*] Could not zero out sensitive data buffer."); ctx2 = NULL; } clean_exit(ctx, &options, key, &orig_key_len, hmac_key, &hmac_key_len, EXIT_SUCCESS); return EXIT_SUCCESS; /* quiet down a gcc warning */ }
/** * main function for FOSSology scheduler, does command line parsing, * Initialization and then simply enters the event loop. * * @param argc the command line argument cound * @param argv the command line argument values * @return if the program ran correctly */ int main(int argc, char** argv) { /* locals */ gboolean db_reset = FALSE; // flag to reset the job queue upon database connection gboolean ki_kill = FALSE; // flag that indicates all schedulers should be forcibly shutdown gboolean ki_shut = FALSE; // flag that indicates all schedulers should be gracefully shutdown gboolean db_init = FALSE; // flag indicating a database test gboolean test_die = FALSE; // flag to run the tests then die gboolean s_daemon = FALSE; // falg to run the scheduler as a daemon gchar* logdir = NULL; // used when a different log from the default is used GOptionContext* options; // option context used for command line parsing GError* error = NULL; // error object used during parsing uint16_t port = 0; gchar* sysconfigdir = DEFAULT_SETUP; /* THE SCHEDULER */ scheduler_t* scheduler; if(getenv("FO_SYSCONFDIR") != NULL) sysconfigdir = getenv("FO_SYSCONFDIR"); /* get this done first */ srand(time(NULL)); #if !(GLIB_MAJOR_VERSION >= 2 && GLIB_MINOR_VERSION >= 32) g_thread_init(NULL); #endif #if !(GLIB_MAJOR_VERSION >= 2 && GLIB_MINOR_VERSION >= 36) g_type_init(); #endif /* the options for the command line parser */ GOptionEntry entries[] = { { "daemon", 'd', 0, G_OPTION_ARG_NONE, &s_daemon, " Run scheduler as daemon" }, { "database", 'i', 0, G_OPTION_ARG_NONE, &db_init, " Initialize database connection and exit" }, { "kill", 'k', 0, G_OPTION_ARG_NONE, &ki_kill, " Forcibly kills all running schedulers" }, { "shutdown", 's', 0, G_OPTION_ARG_NONE, &ki_shut, " Gracefully shutdown of all running schedulers" }, { "log", 'L', 0, G_OPTION_ARG_STRING, &logdir, "[str] Specify location of log file" }, { "port", 'p', 0, G_OPTION_ARG_INT, &port, "[num] Set the interface port" }, { "reset", 'R', 0, G_OPTION_ARG_NONE, &db_reset, " Reset the job queue upon startup" }, { "test", 't', 0, G_OPTION_ARG_NONE, &test_die, " Close the scheduler after running tests" }, { "verbose", 'v', 0, G_OPTION_ARG_INT, &verbose, "[num] Set the scheduler verbose level" }, { "config", 'c', 0, G_OPTION_ARG_STRING, &sysconfigdir, "[str] Specify system configuration directory" }, {NULL} }; /* ********************* */ /* *** parse options *** */ /* ********************* */ options = g_option_context_new("- scheduler for FOSSology"); g_option_context_add_main_entries(options, entries, NULL); g_option_context_parse(options, &argc, &argv, &error); if(error) { fprintf(stderr, "ERROR: %s\n", error->message); fprintf(stderr, "%s", g_option_context_get_help(options, FALSE, NULL)); fflush(stderr); return -1; } g_option_context_free(options); /* check changes to the process first */ if(ki_shut) { return kill_scheduler(FALSE); } if(ki_kill) { return kill_scheduler(TRUE); } /* initialize the scheduler */ scheduler = scheduler_init(sysconfigdir, log_new("stdout", "initializing", getpid())); if(logdir) { scheduler->logdir = logdir; scheduler->logcmdline = TRUE; scheduler->main_log = log_new(scheduler->logdir, NULL, scheduler->s_pid); log_destroy(main_log); main_log = scheduler->main_log; } scheduler->process_name = g_strdup(argv[0]); scheduler->s_daemon = s_daemon; scheduler_foss_config(scheduler); if(s_daemon && scheduler_daemonize(scheduler) == -1) { return -1; } scheduler_agent_config(scheduler); database_init(scheduler); email_init(scheduler); NOTIFY("*****************************************************************"); NOTIFY("*** FOSSology scheduler started ***"); NOTIFY("*** pid: %-33d ***", getpid()); NOTIFY("*** verbose: %-33d ***", verbose); NOTIFY("*** config: %-33s ***", sysconfigdir); NOTIFY("*****************************************************************"); interface_init(scheduler); fo_RepOpenFull(scheduler->sysconfig); signal(SIGCHLD, scheduler_sig_handle); signal(SIGTERM, scheduler_sig_handle); signal(SIGQUIT, scheduler_sig_handle); signal(SIGHUP, scheduler_sig_handle); /* ***************************************************** */ /* *** we have finished initialization without error *** */ /* ***************************************************** */ if(db_reset) database_reset_queue(scheduler); if(test_die) closing = 1; event_loop_enter(scheduler, scheduler_update, scheduler_signal); NOTIFY("*****************************************************************"); NOTIFY("*** FOSSology scheduler closed ***"); NOTIFY("*** pid: %-34d ***", scheduler->s_pid); NOTIFY("*****************************************************************\n"); interface_destroy(scheduler); scheduler_destroy(scheduler); return 0; }
static int load_config(int reload) { struct navit_cfg *cfg; struct cfg_varval *var; struct cfg_category *cat = NULL; struct log *log; int id, type; struct attr **attrs; cfg = navit_cfg_load(TFLOG_CFG); if (!cfg) return -1; while ((cat = navit_cfg_cats_walk(cfg, cat))) { log = NULL; var = navit_cat_find_var(cat, "source"); id = gps_get_source_id(cfg_var_value(var)); if (id == -1) id = cfg_var_intvalue(var); if (!id) { debug(0, "ERROR: Can not find source:[%s]\n", cfg_var_value(var)); continue; } var = navit_cat_find_var(cat, "type"); if (var) { if (!strcmp(cfg_var_value(var), "textfile")) { type = TFL_TEXTFILE; attrs = navit_cfg_cat2attrs(cat); if (attrs) { log = log_new(attrs); navit_cfg_attrs_free(attrs); if (log) { log_set_header(log, tfheader, strlen(tfheader)); } } } else if (!strcmp(cfg_var_value(var), "gpx")) { type = TFL_GPX; attrs = navit_cfg_cat2attrs(cat); if (attrs) { log = log_new(attrs); navit_cfg_attrs_free(attrs); if (log) { log_set_header(log, gpxheader, strlen(gpxheader)); log_set_trailer(log, gpxtrailer, strlen(gpxtrailer)); } } } else if (!strcmp(cfg_var_value(var), "nmea")) { type = TFL_NMEA; attrs = navit_cfg_cat2attrs(cat); if (attrs) { log = log_new(attrs); navit_cfg_attrs_free(attrs); } } else { debug(0, "ERROR: Unknown log type:[%s]\n", cfg_var_value(var)); continue; } if (log) { if (tf_add_log(log, cfg_cat_name(cat), id, type) < 0) { log_destroy(log); debug(0, "ERROR: Adding log %s\n", cfg_cat_name(cat)); } } } } navit_cfg_free(cfg); return 1; }