int main(const int argc, const char *argv[]) { char buf[BUFFER_MAX]; struct sockaddr addr; socklen_t alen; int lsocket, s, count; if (initialize_globals() < 0) { LOGE("Could not initialize globals; exiting.\n"); exit(1); } if (initialize_directories() < 0) { LOGE("Could not create directories; exiting.\n"); exit(1); } lsocket = android_get_control_socket(SOCKET_PATH); if (lsocket < 0) { LOGE("Failed to get socket from environment: %s\n", strerror(errno)); exit(1); } if (listen(lsocket, 5)) { LOGE("Listen on socket failed: %s\n", strerror(errno)); exit(1); } fcntl(lsocket, F_SETFD, FD_CLOEXEC); for (;;) { alen = sizeof(addr); s = accept(lsocket, &addr, &alen); if (s < 0) { LOGE("Accept failed: %s\n", strerror(errno)); continue; } fcntl(s, F_SETFD, FD_CLOEXEC); LOGI("new connection\n"); for (;;) { unsigned short count; if (readx(s, &count, sizeof(count))) { LOGE("failed to read size\n"); break; } if ((count < 1) || (count >= BUFFER_MAX)) { LOGE("invalid size %d\n", count); break; } if (readx(s, buf, count)) { LOGE("failed to read command\n"); break; } buf[count] = 0; if (execute(s, buf)) break; } LOGI("closing connection\n"); close(s); } return 0; }
static directory_t * create_structure(int depth, char *pathname) { directory_t *dir; unsigned i; assert(depth == 0); /* Create the root directory descriptor. */ dir = allocate_directory(1); dir->depth = 0; dir->pathname = strdup(pathname); allocate_directories(dir, 0); dir->n_sources = 0; /* top level directory never has sources */ dir->sources = NULL; initialize_sources(dir, depth); initialize_directories(dir, depth + 1); for (i = 0; i < dir->n_directories; ++i) { create_subdirectory_tree(&dir->directories[i], dir->pathname, depth + 2, i); } return dir; }
static void create_subdirectory_tree(directory_t *dir, const char *parent_name, int depth, unsigned directory_number) { if (depth < arg_depth) { char *pathname = create_path(parent_name, "d", "", directory_number); unsigned i; dir->pathname = strdup(pathname); if (depth < arg_depth - 1) { /* Only allocate directories if they will be present. */ allocate_directories(dir, 1); initialize_directories(dir, depth); } allocate_sources(dir); initialize_sources(dir, depth - 1); for (i = 0; i < dir->n_directories; ++i) { create_subdirectory_tree(&dir->directories[i], dir->pathname, depth + 1, i); } } }
static int installd_main(const int argc ATTRIBUTE_UNUSED, char *argv[]) { int ret; int selinux_enabled = (is_selinux_enabled() > 0); setenv("ANDROID_LOG_TAGS", "*:v", 1); android::base::InitLogging(argv); SLOGI("installd firing up"); union selinux_callback cb; cb.func_log = log_callback; selinux_set_callback(SELINUX_CB_LOG, cb); if (!initialize_globals()) { SLOGE("Could not initialize globals; exiting.\n"); exit(1); } if (initialize_directories() < 0) { SLOGE("Could not create directories; exiting.\n"); exit(1); } if (selinux_enabled && selinux_status_open(true) < 0) { SLOGE("Could not open selinux status; exiting.\n"); exit(1); } if ((ret = InstalldNativeService::start()) != android::OK) { SLOGE("Unable to start InstalldNativeService: %d", ret); exit(1); } IPCThreadState::self()->joinThreadPool(); LOG(INFO) << "installd shutting down"; return 0; }
int main (int argc, char *argv[]) { GOptionContext *context; GError *error = NULL; TrackerExtract *extract; TrackerDecorator *decorator; TrackerExtractController *controller; gchar *log_filename = NULL; GMainLoop *my_main_loop; bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); /* Translators: this message will appear immediately after the */ /* usage string - Usage: COMMAND [OPTION]... <THIS_MESSAGE> */ context = g_option_context_new (_("- Extract file meta data")); g_option_context_add_main_entries (context, entries, NULL); g_option_context_parse (context, &argc, &argv, &error); if (!filename && mime_type) { gchar *help; g_printerr ("%s\n\n", _("Filename and mime type must be provided together")); help = g_option_context_get_help (context, TRUE, NULL); g_option_context_free (context); g_printerr ("%s", help); g_free (help); return EXIT_FAILURE; } g_option_context_free (context); if (version) { g_print ("\n" ABOUT "\n" LICENSE "\n"); return EXIT_SUCCESS; } g_set_application_name ("tracker-extract"); setlocale (LC_ALL, ""); config = tracker_config_new (); /* Set conditions when we use stand alone settings */ if (filename) { return run_standalone (config); } /* Initialize subsystems */ initialize_directories (); /* Extractor command line arguments */ if (verbosity > -1) { tracker_config_set_verbosity (config, verbosity); } tracker_log_init (tracker_config_get_verbosity (config), &log_filename); if (log_filename != NULL) { g_message ("Using log file:'%s'", log_filename); g_free (log_filename); } sanity_check_option_values (config); /* This makes sure we don't steal all the system's resources */ initialize_priority_and_scheduling (tracker_config_get_sched_idle (config), tracker_db_manager_get_first_index_done () == FALSE); extract = tracker_extract_new (TRUE, force_module); if (!extract) { g_object_unref (config); tracker_log_shutdown (); return EXIT_FAILURE; } decorator = tracker_extract_decorator_new (extract, NULL, &error); if (error) { g_critical ("Could not start decorator: %s\n", error->message); g_object_unref (config); tracker_log_shutdown (); return EXIT_FAILURE; } #ifdef THREAD_ENABLE_TRACE g_debug ("Thread:%p (Main) --- Waiting for extract requests...", g_thread_self ()); #endif /* THREAD_ENABLE_TRACE */ tracker_locale_init (); controller = tracker_extract_controller_new (decorator); tracker_miner_start (TRACKER_MINER (decorator)); /* Main loop */ main_loop = g_main_loop_new (NULL, FALSE); initialize_signal_handler (); g_main_loop_run (main_loop); my_main_loop = main_loop; main_loop = NULL; g_main_loop_unref (my_main_loop); tracker_miner_stop (TRACKER_MINER (decorator)); /* Shutdown subsystems */ tracker_locale_shutdown (); g_object_unref (extract); g_object_unref (decorator); g_object_unref (controller); tracker_log_shutdown (); g_object_unref (config); return EXIT_SUCCESS; }
vint8 class_interpreter::initialize() { initialize_directories(); input_file_pointer = 0; // current_action_mode = vCopyString(graphical_module::mode_pixel_info_response); // previous_action_mode = 0; exit_request = 0; // The goal here is to instantiate some template functions, so // that I can call them while debugging. vMatrix<uchar> junk1(1,1); vMatrix<vint4> junk2(1,1); vMatrix<float> junk3(1,1); vMatrix<double> junk4(1,1); vMatrix<vint8> junk5(1,1); vint8 a = 0; if (a) { junk1.Print(0); junk1.PrintRange(1,1,1,1,0); junk1.PrintInt(0); junk1.PrintRangeInt(1,1,1,1,0); junk1.PrintRangem(1,1,1,1,0); junk1.PrintRangeIntm(1,1,1,1,0); junk1.PrintTrans(0); junk1.PrintRangeTrans(1,1,1,1,0); junk1.PrintIntTrans(0); junk1.PrintRangeIntTrans(1,1,1,1,0); junk1.PrintRangemTrans(1,1,1,1,0); junk1.PrintRangeIntmTrans(1,1,1,1,0); junk1.WriteDebug("trash"); junk2.Print(0); junk2.PrintRange(1,1,1,1,0); junk2.PrintInt(0); junk2.PrintRangeInt(1,1,1,1,0); junk2.PrintRangem(1,1,1,1,0); junk2.PrintRangeIntm(1,1,1,1,0); junk2.PrintTrans(0); junk2.PrintRangeTrans(1,1,1,1,0); junk2.PrintIntTrans(0); junk2.PrintRangeIntTrans(1,1,1,1,0); junk2.PrintRangemTrans(1,1,1,1,0); junk2.PrintRangeIntmTrans(1,1,1,1,0); junk2.WriteDebug("trash"); junk3.Print(0); junk3.PrintRange(1,1,1,1,0); junk3.PrintInt(0); junk3.PrintRangeInt(1,1,1,1,0); junk3.PrintRangem(1,1,1,1,0); junk3.PrintRangeIntm(1,1,1,1,0); junk3.PrintTrans(0); junk3.PrintRangeTrans(1,1,1,1,0); junk3.PrintIntTrans(0); junk3.PrintRangeIntTrans(1,1,1,1,0); junk3.PrintRangemTrans(1,1,1,1,0); junk3.PrintRangeIntmTrans(1,1,1,1,0); junk3.WriteDebug("trash"); junk4.Print(0); junk4.PrintRange(1,1,1,1,0); junk4.PrintInt(0); junk4.PrintRangeInt(1,1,1,1,0); junk4.PrintRangem(1,1,1,1,0); junk4.PrintRangeIntm(1,1,1,1,0); junk4.PrintTrans(0); junk4.PrintRangeTrans(1,1,1,1,0); junk4.PrintIntTrans(0); junk4.PrintRangeIntTrans(1,1,1,1,0); junk4.PrintRangemTrans(1,1,1,1,0); junk4.PrintRangeIntmTrans(1,1,1,1,0); junk4.WriteDebug("trash"); junk5.Print(0); junk5.PrintRange(1,1,1,1,0); junk5.PrintInt(0); junk5.PrintRangeInt(1,1,1,1,0); junk5.PrintRangem(1,1,1,1,0); junk5.PrintRangeIntm(1,1,1,1,0); junk5.PrintTrans(0); junk5.PrintRangeTrans(1,1,1,1,0); junk5.PrintIntTrans(0); junk5.PrintRangeIntTrans(1,1,1,1,0); junk5.PrintRangemTrans(1,1,1,1,0); junk5.PrintRangeIntmTrans(1,1,1,1,0); junk5.WriteDebug("trash"); } input_file_pointer = 0; return 1; }
int main(const int argc, const char *argv[]) { char buf[BUFFER_MAX]; struct sockaddr addr; socklen_t alen; int lsocket, s, count; pthread_t worker_threads, signal_thread; pthread_attr_t pthread_custom_attr; sigset_t sigs_to_block; pthread_mutex_init(&io_mutex, NULL); pthread_cond_init(&io_wait, NULL); pthread_attr_init(&pthread_custom_attr); sigemptyset(&sigs_to_block); sigaddset(&sigs_to_block, SIGIO); pthread_sigmask(SIG_BLOCK, &sigs_to_block, NULL); pthread_create(&signal_thread, &pthread_custom_attr, io_signal_handler, NULL); ALOGI("installd firing up\n"); if (initialize_globals() < 0) { ALOGE("Could not initialize globals; exiting.\n"); exit(1); } if (initialize_directories() < 0) { ALOGE("Could not create directories; exiting.\n"); exit(1); } drop_privileges(); lsocket = android_get_control_socket(SOCKET_PATH); if (lsocket < 0) { ALOGE("Failed to get socket from environment: %s\n", strerror(errno)); exit(1); } if (listen(lsocket, 5)) { ALOGE("Listen on socket failed: %s\n", strerror(errno)); exit(1); } fcntl(lsocket, F_SETFD, FD_CLOEXEC); for (;;) { alen = sizeof(addr); s = accept(lsocket, &addr, &alen); if (s < 0) { ALOGE("Accept failed: %s\n", strerror(errno)); continue; } fcntl(s, F_SETFD, FD_CLOEXEC); fcntl(s, F_SETFL, O_ASYNC | O_NONBLOCK); fcntl(s, F_SETSIG, 0); fcntl(s, F_SETOWN, getpid()); write_error = 0; ALOGI("new connection\n"); for (;;) { unsigned short count; int id; if (readx(s, &id, sizeof(id))) { ALOGE("failed to read transaction id\n"); break; } if (readx(s, &count, sizeof(count))) { ALOGE("failed to read size\n"); break; } if ((count < 1) || (count >= BUFFER_MAX)) { ALOGE("invalid size %d\n", count); break; } if (readx(s, buf, count)) { ALOGE("failed to read command\n"); break; } buf[count] = 0; thread_parm *args = (thread_parm*) malloc(sizeof(thread_parm)); args->s = s; strncpy(args->cmd, buf, count + 1); args->id = id; pthread_create(&worker_threads, &pthread_custom_attr, executeAsync, (void*) args); } ALOGI("closing connection\n"); close(s); } pthread_kill(&signal_thread, SIGKILL); pthread_join(&signal_thread, NULL); return 0; }