/** * Main function * @param argc : number of arguments given on the command line. * @param argv : an array of strings that contains command line arguments. * @returns always 0 */ int main(int argc, char **argv) { options_t *opt = NULL; /** Structure to manage options from the command line can be freed when no longer needed */ main_struct_t *main_struct = NULL; #if !GLIB_CHECK_VERSION(2, 36, 0) g_type_init(); /** g_type_init() is deprecated since glib 2.36 */ #endif init_international_languages(); /* Global curl initialisation to avoid curl_easy_init() calls to call it. */ curl_global_init(CURL_GLOBAL_ALL); opt = do_what_is_needed_from_command_line_options(argc, argv); if (opt != NULL) { /** * Inits the main structure and launches two threads one that * will save the files with an asynchronous queue and a second * that will do directory carving. Threads communicates with * the asynchronous queue. */ main_struct = init_main_structure(opt); /** Launching an infinite loop to get modifications done on * the filesystem (on directories we watch). * @note fanotify's kernel interface does not provide the events * needed to know if a file has been deleted or it's attributes * changed. Enabling this feature even if we know that files * will never get deleted in our database. */ fanotify_loop(main_struct); free_options_t(main_struct->opt); } return 0; }
/** * main program * options : * --version * --help */ int main (int argc, char ** argv) { Options *opt; /* A structure to manage the command line options */ gboolean exit_value = TRUE; opt = (Options *) g_malloc0(sizeof(Options)); opt->usage = FALSE; init_international_languages(); /* Command line options evaluation */ exit_value = manage_command_line_options(opt, argc, argv); if (opt->usage != TRUE) { print_int_types(); print_ids(); print_files_related(); } g_free(opt); return exit_value; }
/** * Main function * @param argc : number of arguments given on the command line. * @param argv : an array of strings that contains command line arguments. * @returns always 0 */ int main(int argc, char **argv) { server_struct_t *server_struct = NULL; /** main structure for 'server' program. */ guint id_int = 0; guint id_term = 0; #if !GLIB_CHECK_VERSION(2, 36, 0) g_type_init(); /** g_type_init() is deprecated since glib 2.36 */ #endif ignore_sigpipe(); /** into order to get libmicrohttpd portable */ init_international_languages(); server_struct = init_server_main_structure(argc, argv); if (server_struct != NULL && server_struct->opt != NULL && server_struct->backend != NULL) { server_struct->loop = g_main_loop_new(g_main_context_default(), FALSE); id_int = g_unix_signal_add(SIGINT, int_signal_handler, server_struct); id_term = g_unix_signal_add(SIGTERM, int_signal_handler, server_struct); if (id_int <= 0 || id_term <= 0) { print_error(__FILE__, __LINE__, _("Unable to add signal handler\n")); } /* Initializing the choosen backend by calling it's function */ if (server_struct->backend->init_backend != NULL) { server_struct->backend->init_backend(server_struct); } /* Before starting anything else, start the threads */ server_struct->meta_thread = g_thread_new("meta-data", meta_data_thread, server_struct); server_struct->data_thread = g_thread_new("data", data_thread, server_struct); /* Starting the libmicrohttpd daemon */ server_struct->d = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG, server_struct->opt->port, NULL, NULL, &ahc, server_struct, MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) 131070 , MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120, MHD_OPTION_END); if (server_struct->d == NULL) { print_error(__FILE__, __LINE__, _("Error while spawning libmicrohttpd daemon\n")); return 1; } /* Unless on error we will never join the threads as they * contain a while (TRUE) loop ! */ g_main_loop_run(server_struct->loop); /* g_thread_join(server_struct->meta_thread); */ /* g_thread_join(server_struct->data_thread); */ } else { print_error(__FILE__, __LINE__, _("Error: initialization failed.\n")); } return 0; }