/** * @brief LOGInit */ void LOGInit() { g_log_set_default_handler(logFilter, NULL); }
int main(int argc, char **argv) { g_log_set_default_handler(logger, NULL); if (parse_options(argc, argv)) { return 1; } /* Set the loglevel (amount of messages to output) for libsigrok. */ if (sr_log_loglevel_set(opt_loglevel) != SR_OK) goto done; if (sr_init(&sr_ctx) != SR_OK) goto done; #ifdef HAVE_SRD /* Set the loglevel (amount of messages to output) for libsigrokdecode. */ if (srd_log_loglevel_set(opt_loglevel) != SRD_OK) goto done; if (opt_pds) { if (srd_init(NULL) != SRD_OK) goto done; if (srd_session_new(&srd_sess) != SRD_OK) { g_critical("Failed to create new decode session."); goto done; } if (register_pds(opt_pds, opt_pd_annotations) != 0) goto done; if (setup_pd_stack(opt_pds, opt_pd_stack, opt_pd_annotations) != 0) goto done; /* Only one output type is ever shown. */ if (opt_pd_binary) { if (setup_pd_binary(opt_pd_binary) != 0) goto done; if (srd_pd_output_callback_add(srd_sess, SRD_OUTPUT_BINARY, show_pd_binary, NULL) != SRD_OK) goto done; } else if (opt_pd_meta) { if (setup_pd_meta(opt_pd_meta) != 0) goto done; if (srd_pd_output_callback_add(srd_sess, SRD_OUTPUT_META, show_pd_meta, NULL) != SRD_OK) goto done; } else { if (opt_pd_annotations) if (setup_pd_annotations(opt_pd_annotations) != 0) goto done; if (srd_pd_output_callback_add(srd_sess, SRD_OUTPUT_ANN, show_pd_annotations, NULL) != SRD_OK) goto done; } } #endif if (opt_version) show_version(); else if (opt_input_format && opt_show) show_input(); else if (opt_output_format && opt_show) show_output(); else if (opt_transform_module && opt_show) show_transform(); else if (opt_scan_devs) show_dev_list(); #ifdef HAVE_SRD else if (opt_pds && opt_show) show_pd_detail(); #endif else if (opt_show) show_dev_detail(); else if (opt_input_file) load_input_file(); else if (opt_get) get_option(); else if (opt_set) set_options(); else if (opt_samples || opt_time || opt_frames || opt_continuous) run_session(); else show_help(); #ifdef HAVE_SRD if (opt_pds) srd_exit(); #endif done: if (sr_ctx) sr_exit(sr_ctx); return 0; }
static void fini(void) { if (old_logger) g_log_set_default_handler(old_logger, NULL); }
int main (int argc, char **argv) { GOptionContext *ctx; GError *error = NULL; CinnamonSessionType session_type; int ecode; TpDebugSender *sender; g_type_init (); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); ctx = meta_get_option_context (); g_option_context_add_main_entries (ctx, gnome_cinnamon_options, GETTEXT_PACKAGE); if (!g_option_context_parse (ctx, &argc, &argv, &error)) { g_printerr ("%s: %s\n", argv[0], error->message); exit (1); } g_option_context_free (ctx); meta_plugin_type_register (gnome_cinnamon_plugin_get_type ()); /* Prevent meta_init() from causing gtk to load gail and at-bridge */ g_setenv ("NO_GAIL", "1", TRUE); g_setenv ("NO_AT_BRIDGE", "1", TRUE); meta_init (); g_unsetenv ("NO_GAIL"); g_unsetenv ("NO_AT_BRIDGE"); /* FIXME: Add gjs API to set this stuff and don't depend on the * environment. These propagate to child processes. */ g_setenv ("GJS_DEBUG_OUTPUT", "stderr", TRUE); g_setenv ("GJS_DEBUG_TOPICS", "JS ERROR;JS LOG", TRUE); cinnamon_dbus_init (meta_get_replace_current_wm ()); cinnamon_a11y_init (); cinnamon_fonts_init (); cinnamon_perf_log_init (); cinnamon_prefs_init (); gdk_event_handler_set (gnome_cinnamon_gdk_event_handler, NULL, NULL); g_irepository_prepend_search_path (CINNAMON_PKGLIBDIR); #if HAVE_BLUETOOTH g_irepository_prepend_search_path (BLUETOOTH_DIR); #endif /* Disable debug spew from various libraries */ g_log_set_handler ("Gvc", G_LOG_LEVEL_DEBUG, muted_log_handler, NULL); g_log_set_handler ("AccountsService", G_LOG_LEVEL_DEBUG, muted_log_handler, NULL); g_log_set_handler ("Bluetooth", G_LOG_LEVEL_DEBUG | G_LOG_LEVEL_MESSAGE, muted_log_handler, NULL); g_log_set_handler ("tp-glib/proxy", G_LOG_LEVEL_DEBUG, muted_log_handler, NULL); /* Turn on telepathy-glib debugging but filter it out in * default_log_handler. This handler also exposes all the logs over D-Bus * using TpDebugSender. */ tp_debug_set_flags ("all"); sender = tp_debug_sender_dup (); g_log_set_default_handler (default_log_handler, sender); /* Initialize the global object */ if (is_gdm_mode) session_type = CINNAMON_SESSION_GDM; else session_type = CINNAMON_SESSION_USER; _cinnamon_global_init ("session-type", session_type, NULL); ecode = meta_run (); if (g_getenv ("CINNAMON_ENABLE_CLEANUP")) { g_printerr ("Doing final cleanup...\n"); g_object_unref (cinnamon_global_get ()); } g_object_unref (sender); return ecode; }
void eel_make_warnings_and_criticals_stop_in_debugger (void) { g_log_set_default_handler (log_handler, NULL); }
int main(int argc, char *argv[]) { pid_t pid; struct sigaction sa; if (init_preferences(argc, argv) == FALSE) g_error("Config file parsing failed"); /* Open the log file before forking, so that if there is an error, the * user will get some idea what is going on */ open_log(prefs.log_file); g_log_set_default_handler(scmpc_log, NULL); /* Check if scmpc is already running */ if ((pid = scmpc_is_running()) > 0) { clear_preferences(); g_error("Daemon is already running with PID: %ld", (long)pid); } /* Daemonise if wanted */ if (prefs.fork) daemonise(); /* Signal handler */ open_signal_pipe(); sa.sa_handler = sighandler; sigfillset(&sa.sa_mask); sa.sa_flags = SA_RESTART; sigaction(SIGINT, &sa, NULL); sigaction(SIGTERM, &sa, NULL); sigaction(SIGQUIT, &sa, NULL); if (as_connection_init() == FALSE) { scmpc_cleanup(); exit(EXIT_FAILURE); } as_authenticate(); queue_init(); queue_load(); // submit the loaded queue as_check_submit(); mpd.song_pos = g_timer_new(); mpd.idle_source = 0; if (!mpd_connect()) { mpd_disconnect(); mpd_schedule_reconnect(); } // set up main loop events loop = g_main_loop_new(NULL, FALSE); // save queue if (prefs.cache_interval > 0) { cache_save_source = g_timeout_add_seconds(prefs.cache_interval * 60, queue_save, NULL); } g_main_loop_run(loop); scmpc_cleanup(); }
int main(int argc, char *argv[]) { GdkPixbuf *icon; /* Redirect standard output to a file - printing to the Windows terminal slows operation down way too much */ #ifdef __WIN32__ gchar *tmp; FILE *log_file; tmp = g_strconcat(g_get_home_dir(), G_DIR_SEPARATOR_S, LOG_FILE, NULL); log_file = g_fopen(tmp, "wt"); g_free(tmp); if (log_file != NULL) g_log_set_default_handler(&default_log_handler, log_file); #endif // Force GLib 2.32+ to print info and debug messages like older versions did, unless this variable is already set. // No effect on earlier GLib versions. g_setenv("G_MESSAGES_DEBUG", "all", /* overwrite = */ FALSE); /* Init the tilp core */ tilp_init(&argc, &argv); /* Init GTK+ */ gtk_init(&argc, &argv); add_pixmap_directory(inst_paths.pixmap_dir); add_pixmap_directory(inst_paths.icon_dir); splash_screen_start(); /* Get rid of glib, gdk, gtk warnings when compiled in Release mode */ #if !defined(_DEBUG) g_log_set_handler ("GLib", G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, my_blackhole_log_handler, NULL); g_log_set_handler ("Gdk", G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, my_blackhole_log_handler, NULL); g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, my_blackhole_log_handler, NULL); g_log_set_handler ("GLib", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, my_blackhole_log_handler, NULL); #endif /* Init the GUI-independent functions */ tilp_gif_set_gtk(); tilp_update_set_gtk(); /* Create the main window */ if(!(working_mode & MODE_CMD)) { #if WITH_KDE splash_screen_set_label(_("Initializing KDE...")); sp_kde_init(argc, argv, "tilp", _("TiLP"), VERSION, _("Tilp Is a Linking Program"), "Copyright (c) 1999-2008 Romain Lievin", "http://lpg.ticalc.org/prj_tilp/", "*****@*****.**"); atexit(sp_kde_finish); // Not needed unless we want to add a DCOP interface. // g_timeout_add(26, sp_kde_process_qt_events, NULL); #endif splash_screen_set_label(_("Loading GUI...")); main_wnd = display_tilp_dbox(); } /* Do a local directory list */ g_free(local.cwdir); local.cwdir = g_get_current_dir(); /* Update the local view (not visible yet) */ if(!(working_mode & MODE_CMD)) { clist_refresh(); labels_refresh(); } /* Inits are done ! */ working_mode &= ~MODE_INI; tilp_err(0); // pop errors (display console mode) /* In cmdline, does not display the entire window, only the pbar */ if(!(working_mode & MODE_CMD)) { gtk_widget_show(main_wnd); toolbar_refresh_buttons(); icon = create_pixbuf("tilp.xpm"); gtk_window_set_icon(GTK_WINDOW(main_wnd), icon); gdk_window_set_icon_name(main_wnd->window, _("TiLP2")); } /* If variables have been passed on the command line in GUI mode then send them */ if((working_mode & MODE_GUI) && (working_mode & MODE_CMD)) { splash_screen_set_label(_("Command line...")); if(local.selection0 || local.selection2 || local.selection5) on_tilp_send(""); else if(local.selection4) tilp_cmdline_send(); } /* GTK main loop */ splash_screen_stop(); if(!(working_mode & MODE_CMD)) gtk_main(); tilp_exit(); return 0; }
static void VMToolsConfigLogDomain(const gchar *domain, GKeyFile *cfg, LogHandler *oldDefault, GPtrArray *oldDomains) { gchar *handler = NULL; gchar *level = NULL; gchar *confData = NULL; gchar key[128]; gboolean isDefault = strcmp(domain, gLogDomain) == 0; GLogLevelFlags levelsMask; LogHandler *data = NULL; /* Arbitrary limit. */ if (strlen(domain) > MAX_DOMAIN_LEN) { g_warning("Domain name too long: %s\n", domain); goto exit; } else if (strlen(domain) == 0) { g_warning("Invalid domain declaration, missing name.\n"); goto exit; } g_snprintf(key, sizeof key, "%s.level", domain); level = g_key_file_get_string(cfg, LOGGING_GROUP, key, NULL); if (level == NULL) { level = g_strdup(VMTOOLS_LOGGING_LEVEL_DEFAULT); } /* Parse the handler information. */ g_snprintf(key, sizeof key, "%s.handler", domain); handler = g_key_file_get_string(cfg, LOGGING_GROUP, key, NULL); g_snprintf(key, sizeof key, "%s.data", domain); confData = g_key_file_get_string(cfg, LOGGING_GROUP, key, NULL); if (handler == NULL && isDefault) { /* * If no handler defined and we're configuring the default domain, * then instantiate the default handler. */ handler = g_strdup(DEFAULT_HANDLER); } if (confData == NULL) { if ((g_strcmp0(handler, "file") == 0) || (g_strcmp0(handler, "file+") == 0)) { confData = VMToolsDefaultLogFilePath(domain); } } /* Parse the log level configuration, and build the mask. */ if (strcmp(level, "error") == 0) { levelsMask = G_LOG_LEVEL_ERROR; } else if (strcmp(level, "critical") == 0) { levelsMask = G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL; } else if (strcmp(level, "warning") == 0) { levelsMask = G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING; } else if (strcmp(level, "message") == 0) { levelsMask = G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE; } else if (strcmp(level, "info") == 0) { levelsMask = G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO; } else if (strcmp(level, "debug") == 0) { levelsMask = G_LOG_LEVEL_MASK; } else if (strcmp(level, "none") == 0) { levelsMask = 0; } else { g_warning("Unknown log level (%s): %s\n", domain, level); goto exit; } if (handler != NULL) { /* * Check whether there's an old domain with the same type configured * for the same domain. If there is, use it instead. Otherwise, * instantiate a new logger. For the check, consider both file logger * types as the same. */ const char *oldtype = oldDefault != NULL ? oldDefault->type : NULL; const char *oldData = oldDefault != NULL ? oldDefault->confData : NULL; if (g_strcmp0(oldtype, "file+") == 0) { oldtype = "file"; } if (isDefault && g_strcmp0(oldtype, handler) == 0) { /* check for a filename change */ if (g_strcmp0(oldData, confData) == 0) { data = oldDefault; } } else if (oldDomains != NULL) { guint i; for (i = 0; i < oldDomains->len; i++) { LogHandler *old = g_ptr_array_index(oldDomains, i); if (old != NULL && !old->inherited && strcmp(old->domain, domain) == 0) { if (g_strcmp0(old->type, handler) == 0 && g_strcmp0(old->confData, confData) == 0) { data = old; oldDomains->pdata[i] = NULL; } break; } } } if (data == NULL) { data = VMToolsGetLogHandler(handler, domain, levelsMask, cfg); } else { data->mask = levelsMask; } } else { /* An inherited handler. Just create a dummy instance. */ ASSERT(gDefaultData != NULL); data = g_new0(LogHandler, 1); data->domain = g_strdup(domain); data->inherited = TRUE; data->mask = levelsMask; data->isSysLog = FALSE; data->confData = g_strdup(confData); } if (isDefault) { gDefaultData = data; g_log_set_default_handler(VMToolsLog, gDefaultData); } else { if (gDomains == NULL) { gDomains = g_ptr_array_new(); } g_ptr_array_add(gDomains, data); if (data->handlerId == 0) { data->handlerId = g_log_set_handler(domain, G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, VMToolsLog, data); } } exit: g_free(handler); g_free(level); g_free(confData); }
/** * nmt_newt_finished: * * Wrapper for newtFinished(). Should be called at the end of the program. */ void nmt_newt_finished (void) { newtFinished (); g_log_set_default_handler (g_log_default_handler, NULL); }
void InstallSignalHandlers(const char *ProgramName) { PL_strncpy(_progname,ProgramName, (sizeof(_progname)-1) ); const char *gdbSleep = PR_GetEnv("MOZ_GDB_SLEEP"); if (gdbSleep && *gdbSleep) { unsigned int s; if (1 == sscanf(gdbSleep, "%u", &s)) { _gdb_sleep_duration = s; } } #if defined(CRAWL_STACK_ON_SIGSEGV) if (!getenv("XRE_NO_WINDOWS_CRASH_DIALOG")) { void (*crap_handler)(int) = GeckoProcessType_Default != XRE_GetProcessType() ? child_ah_crap_handler : ah_crap_handler; signal(SIGSEGV, crap_handler); signal(SIGILL, crap_handler); signal(SIGABRT, crap_handler); } #endif // CRAWL_STACK_ON_SIGSEGV #ifdef SA_SIGINFO /* Install a handler for floating point exceptions and disable them if they occur. */ struct sigaction sa, osa; sa.sa_flags = SA_ONSTACK | SA_RESTART | SA_SIGINFO; sa.sa_sigaction = fpehandler; sigemptyset(&sa.sa_mask); sigaction(SIGFPE, &sa, &osa); #endif #if defined(DEBUG) && defined(LINUX) const char *memLimit = PR_GetEnv("MOZ_MEM_LIMIT"); if (memLimit && *memLimit) { long m = atoi(memLimit); m *= (1024*1024); struct rlimit r; r.rlim_cur = m; r.rlim_max = m; setrlimit(RLIMIT_AS, &r); } #endif #if defined(SOLARIS) #define NOFILES 512 // Boost Solaris file descriptors { struct rlimit rl; if (getrlimit(RLIMIT_NOFILE, &rl) == 0) if (rl.rlim_cur < NOFILES) { rl.rlim_cur = NOFILES; if (setrlimit(RLIMIT_NOFILE, &rl) < 0) { perror("setrlimit(RLIMIT_NOFILE)"); fprintf(stderr, "Cannot exceed hard limit for open files"); } #if defined(DEBUG) if (getrlimit(RLIMIT_NOFILE, &rl) == 0) printf("File descriptors set to %d\n", rl.rlim_cur); #endif //DEBUG } } #endif //SOLARIS #if defined(MOZ_WIDGET_GTK2) && (GLIB_MAJOR_VERSION > 2 || (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION >= 6)) const char *assertString = PR_GetEnv("XPCOM_DEBUG_BREAK"); if (assertString && (!strcmp(assertString, "suspend") || !strcmp(assertString, "stack") || !strcmp(assertString, "abort") || !strcmp(assertString, "trap") || !strcmp(assertString, "break"))) { // Override the default glib logging function so we get stacks for it too. orig_log_func = g_log_set_default_handler(my_glib_log_func, NULL); } #endif }
/** * CGstMediaManager::Init(). * * @param data user-defined data. Pointer to this. * @return Java long reference to the media. */ uint32_t CGstMediaManager::Init() { GError* pError = NULL; uint32_t uRetCode = ERROR_NONE; #if ENABLE_LOWLEVELPERF && TARGET_OS_MAC g_mem_set_vtable (glib_mem_profiler_table); #endif #if ENABLE_VISUAL_STUDIO_MEMORY_LEAKS_DETECTION && TARGET_OS_WIN32 _CrtSetDbgFlag ( 0 ); #endif // ENABLE_VISUAL_STUDIO_MEMORY_LEAKS_DETECTION //***** Try to initialize the GStreamer system if (!g_thread_supported()) g_thread_init (NULL); LOWLEVELPERF_EXECTIMESTART("gst_init_check()"); // disable installing SIGSEGV signal handling as it interferes with Java's signal handling gst_segtrap_set_enabled(false); if (!gst_init_check(NULL, NULL, NULL)) { LOGGER_LOGMSG(LOGGER_DEBUG, "Could not init GStreamer!\n"); return ERROR_MANAGER_ENGINEINIT_FAIL; } LOWLEVELPERF_EXECTIMESTOP("gst_init_check()"); #if ENABLE_VISUAL_STUDIO_MEMORY_LEAKS_DETECTION && TARGET_OS_WIN32 _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); #endif // ENABLE_VISUAL_STUDIO_MEMORY_LEAKS_DETECTION //***** Create mutex and condition variable m_pRunloopCond = g_cond_new(); m_pRunloopMutex = g_mutex_new(); #if ENABLE_VISUAL_STUDIO_MEMORY_LEAKS_DETECTION && TARGET_OS_WIN32 _CrtSetDbgFlag(0); #endif // ENABLE_VISUAL_STUDIO_MEMORY_LEAKS_DETECTION //***** Create the primary run loop m_pMainLoopThread = g_thread_create((GThreadFunc)run_loop, this, FALSE, &pError); if (m_pMainLoopThread == NULL) { LOGGER_LOGMSG(LOGGER_DEBUG, "Could not create main GThread!!\n"); LOGGER_LOGMSG(LOGGER_DEBUG, pError->message); return ERROR_MANAGER_RUNLOOP_FAIL; } #if ENABLE_VISUAL_STUDIO_MEMORY_LEAKS_DETECTION && TARGET_OS_WIN32 _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); #endif // ENABLE_VISUAL_STUDIO_MEMORY_LEAKS_DETECTION //***** Wait till the run loop has fully initialized. Bad things happen if we do not do this, including crashers. g_mutex_lock(m_pRunloopMutex); while (NULL == m_pMainLoop) g_cond_wait(m_pRunloopCond, m_pRunloopMutex); g_mutex_unlock(m_pRunloopMutex); if (m_bMainLoopCreateFailed) uRetCode = ERROR_GSTREAMER_MAIN_LOOP_CREATE; // Free no longer needed GCond. if (NULL != m_pRunloopCond) { g_cond_free(m_pRunloopCond); m_pRunloopCond = NULL; } // Free no longer needed GMutex. if (NULL != m_pRunloopMutex) { g_mutex_free(m_pRunloopMutex); m_pRunloopMutex = NULL; } // Set the default Glib log handler. g_log_set_default_handler (GlibLogFunc, this); return uRetCode; }
int main(int argc, char **argv) { bool interactive = false; bool timing = false; bool signal = false; bool use_public_bus = false; char *serviceName = NULL; int optionCount = 0; int opt; while ((opt = getopt(argc, argv, "hdisPrlfn:t:m:a:q:")) != -1) { switch (opt) { case 'i': interactive = true; optionCount++; break; case 's': signal = true; optionCount++; break; case 'P': use_public_bus = true; optionCount++; break; case 'd': sLogLevel = G_LOG_LEVEL_DEBUG; optionCount++; break; case 'n': interactive = true; count = atoi(optarg); optionCount+=2; break; case 't': timing = true; count = atoi(optarg); optionCount+=2; break; case 'm': serviceName = g_strdup(optarg); optionCount+=2; break; case 'a': appId = g_strdup(optarg); optionCount+=2; break; case 'l': line_number = true; optionCount++; break; case 'f': format_response = true; optionCount++; break; case 'q': query_list = g_list_append(query_list, g_strdup(optarg)); optionCount+=2; break; case 'h': default: PrintUsage(argv[0]); return 0; } } if (argc < 3 + optionCount) { PrintUsage(argv[0]); return 0; } g_log_set_default_handler(g_log_filter, NULL); GMainLoop *mainLoop = g_main_loop_new(NULL, FALSE); if (mainLoop == NULL) { g_critical("Unable to create mainloop"); exit(EXIT_FAILURE); } LSError lserror; LSErrorInit(&lserror); LSHandle *sh = NULL; bool serviceInit = LSRegisterPubPriv(serviceName, &sh, use_public_bus, &lserror); if (!serviceInit) goto exit; bool gmainAttach = LSGmainAttach(sh, mainLoop, &lserror); if (!gmainAttach) goto exit; url = g_strdup(argv[optionCount + 1]); message = g_strdup(argv[optionCount + 2]); LSMessageToken sessionToken; bool retVal; if (timing) { /* Timing loop */ clock_gettime(CLOCK_MONOTONIC, &startTime); retVal = LSCallFromApplication(sh, url, message, appId, timingServiceResponse, mainLoop, &sessionToken, &lserror); if (!retVal) goto exit; g_main_loop_run(mainLoop); printf("Total time %.02f ms, %d iterations, %.02f ms per iteration\n", roundtripTime * 1000.0, roundtripCount, (roundtripTime / roundtripCount) * 1000.0); printf("%d bytes sent, %d bytes received\n", sentBytes, rcvdBytes); } else { if (signal) { retVal = LSSignalSend(sh, url, message, &lserror); } else { /* Basic sending */ retVal = LSCallFromApplication(sh, url, message, appId, serviceResponse, mainLoop, &sessionToken, &lserror); } if (!retVal) goto exit; if (interactive && !signal) { g_io_add_watch(g_io_channel_unix_new(0), G_IO_ERR|G_IO_HUP, input_closed, mainLoop); g_main_loop_run(mainLoop); } else if (!signal) { /* * NOV-93580: In the non-interactive case, we can't guarantee that * an LSCall() will necessarily get the QueryNameReply before * shutting down if it does not wait for (or have) a reply from the * far side. */ g_critical("WARNING: you must always call luna-send with \"-i\" or \"-n\". Exiting with failure return code."); exit(EXIT_FAILURE); } } exit: if (LSErrorIsSet(&lserror)) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } if (sh != NULL) { if (!LSUnregister(sh, &lserror)) { LSErrorPrint(&lserror, stderr); LSErrorFree(&lserror); } } g_main_loop_unref(mainLoop); if (url) g_free (url); if (message) g_free (message); return 0; }
/** * Main program entry point * * This function is the one called by the operating system to start Luna. * * This function sets {@link appArgc appArgc} and {@link appArgv appArgv}. * * @see appArgc * @see appArgv * * @param argc Number of command-line arguments * @param argv Pointer to list of char* of each of the arguments * * @return 0 = success, anything else = failure */ int main( int argc, char** argv) { appArgc = argc; appArgv = argv; std::set_terminate(generateGoodBacktraceTerminateHandler); g_thread_init(NULL); const char *renderMode; #if defined(TARGET_DEVICE) && defined(HAVE_OPENGL) ::setenv("QT_PLUGIN_PATH", "/usr/plugins", 1); renderMode = "HW egl"; #elif defined(TARGET_DEVICE) || defined(TARGET_EMULATOR) ::setenv("QT_PLUGIN_PATH", "/usr/plugins", 1); renderMode = "Software"; #elif defined(HAVE_OPENGL) renderMode = "HW OpenGL"; #else renderMode = "Software"; #endif WindowServer::markBootStart(); g_debug("SysMgr compiled against Qt %s, running on %s, %s render mode requested", QT_VERSION_STR, qVersion(), renderMode); // Command-Line options parseCommandlineOptions(argc, argv); if (s_debugTrapStr && 0 == strcasecmp(s_debugTrapStr, "on")) { debugCrashes = true; } if (s_mallocStatsFileStr) { setupMallocStats(s_mallocStatsFileStr); } sysmgrPid = getpid(); // Load Settings (first!) Settings* settings = Settings::LunaSettings(); // Initialize logging handler g_log_set_default_handler(logFilter, NULL); #if defined(TARGET_DESKTOP) // use terminal logging when running on desktop settings->logger_useTerminal = true; #endif // disable color logging using an environment variable. Useful when run from QtCreator const char* useColor = ::getenv("COLOR_LOGGING"); if (useColor) settings->logger_useColor = (useColor[0] != 0 && useColor[0] != '0'); HostBase* host = HostBase::instance(); // the resolution is just a hint, the actual // resolution may get picked up from the fb driver on arm host->init(settings->displayWidth, settings->displayHeight); #if defined(TARGET_DEVICE) pid_t animPid= spawnBootupAnimationProcess(); if(animPid < 0) { // failed to start the Animation process return -1; } #endif #if defined(TARGET_DEVICE) && defined(HAVE_OPENGL) && defined(HAVE_QPA) if (settings->forceSoftwareRendering) ::setenv("QT_QPA_PLATFORM", "palm-soft", 1); else ::setenv("QT_QPA_PLATFORM", "palm", 1); #endif #if defined(TARGET_DEVICE) && defined(HAVE_OPENGL) if (!settings->forceSoftwareRendering) ::setenv("QWS_DISPLAY", "egl", 1); #endif pid_t webKitPid= spawnWebKitProcess(); if(webKitPid < 0) { // failed to start the WebKit process return -1; } // Tie LunaSysMgr to Processor 0 setCpuAffinity(getpid(), 1); // Tie WebAppMgr to Processor 1 setCpuAffinity(webKitPid, 0); // Safe to create logging threads now logInit(); // Initialize Ipc Server (void) IpcServer::instance(); // Ipc Server is ready, so signal the WebAppMgr process (via pipe) to go ahead and connect ::write(WebAppMgrPipeFd, &msgOkToContinue, 1); ::close(WebAppMgrPipeFd); WebAppMgrPipeFd = -1; #if !defined(TARGET_DESKTOP) // Set "nice" property setpriority(PRIO_PROCESS,getpid(),-1); #endif #if !defined(TARGET_DESKTOP) && !defined(HAVE_QPA) QWSServer::setDefaultMouse("HiddTp"); QWSServer::setDefaultKeyboard("HiddKbd"); ::setenv("QWS_DBLCLICK_DISTANCE", QString("%0").arg(Settings::LunaSettings()->tapRadius).toAscii().constData(), 1); #endif qInstallMsgHandler(qtMsgHandler); QApplication app(argc, argv); QApplication::setStartDragDistance(settings->tapRadius); QApplication::setDoubleClickInterval (Settings::LunaSettings()->tapDoubleClickDuration); host->show(); initMallocStatsCb(HostBase::instance()->mainLoop(), s_mallocStatsInterval); // Initialize Preferences handler (void) Preferences::instance(); // Initialize Localization handler (void) Localization::instance(); //Register vibration/haptics support HapticsController::instance()->startService(); (void) DeviceInfo::instance(); // Initialize Security handler (void) Security::instance(); // Initialize the System Service SystemService::instance()->init(); // Initialize the application mgr ApplicationManager::instance()->init(); // Initialize the Application Installer ApplicationInstaller::instance(); // Start the window manager WindowServer *windowServer = WindowServer::instance(); windowServer->installEventFilter(windowServer); // Initialize the SysMgr MemoryMonitor MemoryMonitor::instance(); // load all set policies EASPolicyManager::instance()->load(); // Launching of the System UI launcher and headless apps has been moved to WebAppMgrProxy::connectWebAppMgr // Did user specify an app to launch if (s_appToLaunchStr) { WebAppMgrProxy::setAppToLaunchUponConnection(s_appToLaunchStr); } app.exec(); return 0; }
static void _load_config() { GKeyFile *keyfile; GKeyFileFlags flags; GError *error = NULL; char *debug_level = NULL; char *logpath = NULL; char *s = NULL; /* Read the phonefsod preferences */ keyfile = g_key_file_new(); flags = G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS; if (g_key_file_load_from_file (keyfile, PHONEFSOD_CONFIG, flags, &error)) { /* --- [logging] --- */ logpath = g_key_file_get_string(keyfile, "logging", "log_file", NULL); debug_level = g_key_file_get_string(keyfile, "logging", "log_level", NULL); /* --- [gsm] --- */ offline_mode = g_key_file_get_boolean(keyfile, "gsm", "offline_mode", &error); if (error) { offline_mode = FALSE; g_error_free(error); error = NULL; } inhibit_suspend_on_startup_time = g_key_file_get_integer(keyfile, "gsm", "inhibit_suspend_on_startup_time", &error); if (error) { inhibit_suspend_on_startup_time = 360; g_error_free(error); error = NULL; } show_incoming_sms = g_key_file_get_boolean(keyfile, "gsm", "show_incoming_sms", &error); if (error) { show_incoming_sms = TRUE; g_error_free(error); error = NULL; } gsm_reregister_timeout = g_key_file_get_integer(keyfile, "gsm", "reregister_timeout", &error); if (error) { gsm_reregister_timeout = DEFAULT_GSM_REREGISTER_TIMEOUT; g_error_free(error); error = NULL; } /* ensure a sane value for the timeout... minimum is 60s */ else if (gsm_reregister_timeout < MINIMUM_GSM_REREGISTER_TIMEOUT) { g_message("invalid reregister_timeout - setting to %ds", MINIMUM_GSM_REREGISTER_TIMEOUT); gsm_reregister_timeout = MINIMUM_GSM_REREGISTER_TIMEOUT; } s = g_key_file_get_string(keyfile, "gsm", "calling_identification", &error); if (error) { calling_identification = FREE_SMARTPHONE_GSM_CALLING_IDENTIFICATION_STATUS_NETWORK; g_error_free(error); error = NULL; } else { if (!strncmp("off", s, 3)) { calling_identification = FREE_SMARTPHONE_GSM_CALLING_IDENTIFICATION_STATUS_OFF; } else if (!strncmp("on", s, 2)) { calling_identification = FREE_SMARTPHONE_GSM_CALLING_IDENTIFICATION_STATUS_ON; } else if (!strncmp("network", s, 7)) { calling_identification = FREE_SMARTPHONE_GSM_CALLING_IDENTIFICATION_STATUS_NETWORK; } else { g_warning("Invalid value '%s' for calling_identification in [gsm] section of %s", s, PHONEFSOD_CONFIG); g_message("Defaulting to network"); calling_identification = FREE_SMARTPHONE_GSM_CALLING_IDENTIFICATION_STATUS_NETWORK; } } pdp_apn = g_key_file_get_string(keyfile, "gsm", "pdp_apn", &error); if (error) { g_error_free(error); error = NULL; } pdp_user = g_key_file_get_string(keyfile, "gsm", "pdp_user", &error); if (error) { g_error_free(error); error = NULL; } pdp_password = g_key_file_get_string(keyfile, "gsm", "pdp_password", &error); if (error) { g_error_free(error); error = NULL; } sim_pin = g_key_file_get_string(keyfile, "gsm", "pin", &error); if (error) { g_error_free(error); error = NULL; } /* --- [idle] --- */ default_brightness = g_key_file_get_integer(keyfile, "idle", "default_brightness", &error); if (error) { default_brightness = DEFAULT_DEFAULT_BRIGHTNESS; g_error_free(error); error = NULL; } s = g_key_file_get_string(keyfile, "idle", "dim_screen", &error); if (error) { dim_screen = DIM_SCREEN_ALWAYS; g_error_free(error); error = NULL; } else { if (!strncmp("never", s, 5)) { dim_screen = DIM_SCREEN_NEVER; } else if (!strncmp("onbat", s, 5)) { dim_screen = DIM_SCREEN_ONBAT; } else if (!strncmp("always", s, 6)) { dim_screen = DIM_SCREEN_ALWAYS; } else { g_warning("Invalid value '%s' for dim_screen in [idle] section of %s", s, PHONEFSOD_CONFIG); g_message("Defaulting to DIM_SCREEN_ALWAYS"); dim_screen = DIM_SCREEN_ALWAYS; } } minimum_brightness = g_key_file_get_integer(keyfile, "idle", "minimum_brightness", &error); if (error) { minimum_brightness = DEFAULT_MINIMUM_BRIGHTNESS; g_error_free(error); error = NULL; } dim_idle_percent = g_key_file_get_integer(keyfile, "idle", "dim_idle_percent", &error); if (error) { dim_idle_percent = -1; g_error_free(error); error = NULL; } dim_idle_dim_percent = g_key_file_get_integer(keyfile, "idle", "dim_idle_dim_percent", &error); if (error) { dim_idle_dim_percent = -1; g_error_free(error); error = NULL; } dim_idle_prelock_percent = g_key_file_get_integer(keyfile, "idle", "dim_idle_prelock_percent", &error); if (error) { dim_idle_prelock_percent = -1; g_error_free(error); error = NULL; } s = g_key_file_get_string(keyfile, "idle", "idle_screen", &error); if (error) { g_debug("no idle_screen found in config - defaulting to lock,aux,suspend"); idle_screen = IDLE_SCREEN_LOCK | IDLE_SCREEN_AUX | IDLE_SCREEN_SUSPEND; g_error_free(error); error = NULL; } else { int i; gchar **flags = g_strsplit(s, ",", 0); idle_screen = IDLE_SCREEN_NEVER; for (i = 0; flags[i]; i++) { if (strcmp(flags[i], "lock") == 0) { g_debug("adding LOCK to idle_screen"); idle_screen |= IDLE_SCREEN_LOCK; } else if (strcmp(flags[i], "aux") == 0) { g_debug("adding AUX to idle_scren"); idle_screen |= IDLE_SCREEN_AUX; } else if (strcmp(flags[i], "phone") == 0) { g_debug("adding PHONE to idle_screen"); idle_screen |= IDLE_SCREEN_PHONE; } else if (strcmp(flags[i], "suspend") == 0) { g_debug("adding SUSPEND to idle_screen"); idle_screen |= IDLE_SCREEN_SUSPEND; } } g_strfreev(flags); free(s); } s = g_key_file_get_string(keyfile, "idle", "auto_suspend", &error); if (error) { auto_suspend = SUSPEND_NORMAL; g_error_free(error); error = NULL; } else if (strcmp(s, "never") == 0) { auto_suspend = SUSPEND_NEVER; } else if (strcmp(s, "always") == 0) { auto_suspend = SUSPEND_ALWAYS; } else { auto_suspend = SUSPEND_NORMAL; } /* --- [settings] --- */ quick_settings_power = g_key_file_get_boolean(keyfile, "settings", "quick_settings_power", &error); if (error) { quick_settings_power = FALSE; g_error_free(error); error = NULL; } if (s) free(s); g_debug("Configuration file read"); } else { g_warning(error->message); g_error_free(error); } debug_level = (debug_level) ? debug_level : DEFAULT_DEBUG_LEVEL; logpath = (logpath) ? logpath : LOGFILE; log_flags = G_LOG_FLAG_FATAL; if (!strcmp(debug_level, "DEBUG")) { log_flags |= G_LOG_LEVEL_MASK; } else if (!strcmp(debug_level, "INFO")) { log_flags |= G_LOG_LEVEL_MASK ^ (G_LOG_LEVEL_DEBUG); } else if (!strcmp(debug_level, "MESSAGE")) { log_flags |= G_LOG_LEVEL_MASK ^ (G_LOG_LEVEL_DEBUG | G_LOG_LEVEL_INFO); } else if (!strcmp(debug_level, "WARNING")) { log_flags |= G_LOG_LEVEL_MASK ^ (G_LOG_LEVEL_DEBUG | G_LOG_LEVEL_INFO | G_LOG_LEVEL_MESSAGE); } else if (!strcmp(debug_level, "CRITICAL")) { log_flags |= G_LOG_LEVEL_MASK ^ (G_LOG_LEVEL_DEBUG | G_LOG_LEVEL_INFO | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_WARNING); } else if (!strcmp(debug_level, "ERROR")) { log_flags |= G_LOG_LEVEL_MASK ^ (G_LOG_LEVEL_DEBUG | G_LOG_LEVEL_INFO | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL); } else { } /* initialize logging */ logfile = fopen(logpath, "a"); if (!logfile) { printf("Error creating the logfile (%s) !!!", logpath); } else { g_log_set_default_handler(_log_handler, NULL); } }
static void log_init_stdout(void) { g_log_set_default_handler(file_log_func, NULL); }
int main(int argc, char **argv) { bool retVal; int opt; bool invertCarrier = false; LSPalmService * lsps = NULL; while ((opt = getopt(argc, argv, "chdst")) != -1) { switch (opt) { case 'c': invertCarrier = true; break; case 'd': setLogLevel(G_LOG_LEVEL_DEBUG); break; case 's': setUseSyslog(true); break; case 'h': default: PrintUsage(argv[0]); return EXIT_SUCCESS; } } // make sure we aren't already running. if (!LockProcess("storaged")) { g_error("%s: %s daemon is already running.\n", __func__, argv[0]); exit(EXIT_FAILURE); } g_log_set_default_handler(logFilter, NULL); g_debug( "entering %s in %s", __func__, __FILE__ ); signal(SIGTERM, term_handler); g_mainloop = g_main_loop_new(NULL, FALSE); int ret = nyx_device_open(NYX_DEVICE_SYSTEM, "Main", &nyxSystem); if(ret != NYX_ERROR_NONE) { g_critical("Unable to open the nyx device system"); abort(); } else g_debug("Initialized nyx system device"); /** * initialize the lunaservice and we want it before all the init * stuff happening. */ LSError lserror; LSErrorInit(&lserror); retVal = LSRegisterPalmService("com.palm.storage", &lsps, &lserror); if (!retVal) { g_critical ("failed in function %s with erro %s", lserror.func, lserror.message); LSErrorFree(&lserror); return EXIT_FAILURE; } SignalsInit( lsps ); LSHandle *lsh_priv = LSPalmServiceGetPrivateConnection(lsps); LSHandle *lsh_pub = LSPalmServiceGetPublicConnection(lsps); DiskModeInterfaceInit( g_mainloop, lsh_priv, lsh_pub, invertCarrier ); EraseInit(g_mainloop, lsh_priv); retVal = LSGmainAttach( lsh_priv, g_mainloop, &lserror ); if ( !retVal ) { g_critical( "LSGmainAttach private returned %s", lserror.message ); LSErrorFree(&lserror); } retVal = LSGmainAttach( lsh_pub, g_mainloop, &lserror ); if ( !retVal ) { g_critical( "LSGmainAttach public returned %s", lserror.message ); LSErrorFree(&lserror); } g_main_loop_run(g_mainloop); g_main_loop_unref(g_mainloop); if (!LSUnregister( lsh_priv, &lserror)) { g_critical( "LSUnregister private returned %s", lserror.message ); } if (!LSUnregister( lsh_pub, &lserror)) { g_critical( "LSUnregister public returned %s", lserror.message ); } UnlockProcess(); g_debug( "exiting %s in %s", __func__, __FILE__ ); if (!retVal) return EXIT_FAILURE; else return EXIT_SUCCESS; }
int main (int argc, char **argv) { g_debug (G_STRLOC ": %s", G_STRFUNC); DasomServer *server; GMainLoop *loop; GError *error = NULL; gboolean is_no_daemon = FALSE; gboolean is_debug = FALSE; gboolean is_version = FALSE; GOptionContext *context; GOptionEntry entries[] = { {"no-daemon", 0, 0, G_OPTION_ARG_NONE, &is_no_daemon, N_("Do not daemonize"), NULL}, {"debug", 0, 0, G_OPTION_ARG_NONE, &is_debug, N_("Log debugging message"), NULL}, {"version", 0, 0, G_OPTION_ARG_NONE, &is_version, N_("Version"), NULL}, {NULL} }; context = g_option_context_new ("- Dasom Input Method Daemon"); g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); g_option_context_parse (context, &argc, &argv, &error); g_option_context_free (context); if (error != NULL) { g_warning ("%s", error->message); g_error_free (error); return EXIT_FAILURE; } #if ENABLE_NLS bindtextdomain (GETTEXT_PACKAGE, DASOM_LOCALE_DIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #endif if (is_version) { g_print ("%s %s\n", argv[0], VERSION); exit (EXIT_SUCCESS); } if (is_no_daemon == FALSE) { openlog (g_get_prgname (), LOG_PID | LOG_PERROR, LOG_DAEMON); syslog_initialized = TRUE; g_log_set_default_handler ((GLogFunc) dasom_log_default_handler, &is_debug); if (daemon (0, 0) != 0) { g_critical ("Couldn't daemonize."); return EXIT_FAILURE; } } server = dasom_server_new ("unix:abstract=dasom", &error); if (server == NULL) { g_critical ("%s", error->message); g_clear_error (&error); return EXIT_FAILURE; } dasom_server_start (server); loop = g_main_loop_new (NULL, FALSE); g_unix_signal_add (SIGINT, (GSourceFunc) g_main_loop_quit, loop); g_unix_signal_add (SIGTERM, (GSourceFunc) g_main_loop_quit, loop); g_main_loop_run (loop); g_main_loop_unref (loop); g_object_unref (server); if (syslog_initialized) closelog (); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { gboolean print_version = FALSE; gboolean one_shot = FALSE; gchar *output_plugin = NULL; gchar **servers_desc = NULL; gchar **streams_desc = NULL; gchar **input_plugins = NULL; gchar **order = NULL; gchar *config = NULL; int retval = 0; GError *error = NULL; GOptionContext *option_context = NULL; GOptionGroup *option_group; #if DEBUG g_setenv("G_MESSAGES_DEBUG", "all", FALSE); #endif /* ! DEBUG */ setlocale(LC_ALL, ""); #ifdef ENABLE_NLS bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); #endif /* ENABLE_NLS */ #if DEBUG const gchar *debug_log_filename = g_getenv("J4STATUS_DEBUG_LOG_FILENAME"); GDataOutputStream *debug_stream = NULL; if ( debug_log_filename != NULL ) { GFile *debug_log; debug_log = g_file_new_for_path(debug_log_filename); GError *error = NULL; GFileOutputStream *debug_log_stream; debug_log_stream = g_file_append_to(debug_log, G_FILE_CREATE_NONE, NULL, &error); if ( debug_log_stream == NULL ) { g_warning("Couldn't open debug log file: %s", error->message); g_clear_error(&error); } else { debug_stream = g_data_output_stream_new(G_OUTPUT_STREAM(debug_log_stream)); g_object_unref(debug_log_stream); g_log_set_default_handler(_j4status_core_debug_log_handler, debug_stream); } g_object_unref(debug_log); } #endif /* DEBUG */ GOptionEntry entries[] = { { "output", 'o', 0, G_OPTION_ARG_STRING, &output_plugin, "Output plugin to use", "<plugin>" }, { "listen", 'l', 0, G_OPTION_ARG_STRING_ARRAY, &servers_desc, "Socket to listen on, will create a stream on connection (may be specified several times)", "<listen description>" }, { "stream", 't', 0, G_OPTION_ARG_STRING_ARRAY, &streams_desc, "Stream to read from/write to (may be specified several times)", "<stream description>" }, { "input", 'i', 0, G_OPTION_ARG_STRING_ARRAY, &input_plugins, "Input plugins to use (may be specified several times)", "<plugin>" }, { "order", 'O', 0, G_OPTION_ARG_STRING_ARRAY, &order, "Order of sections, specified once a section (see man)", "<section id>" }, { "one-shot", '1', 0, G_OPTION_ARG_NONE, &one_shot, "Tells j4status to stop right after starting", NULL }, { "config", 'c', 0, G_OPTION_ARG_STRING, &config, "Config file to use", "<config>" }, { "version", 'V', 0, G_OPTION_ARG_NONE, &print_version, "Print version", NULL }, { NULL } }; option_context = g_option_context_new("- status line generator"); option_group = g_option_group_new(NULL, NULL, NULL, NULL, NULL); g_option_group_set_translation_domain(option_group, GETTEXT_PACKAGE); g_option_group_add_entries(option_group, entries); g_option_context_set_main_group(option_context, option_group); if ( ! g_option_context_parse(option_context, &argc, &argv, &error) ) { g_warning("Option parsing failed: %s\n", error->message); g_clear_error(&error); retval = 1; goto end; } g_option_context_free(option_context); if ( print_version ) { g_fprintf(stdout, PACKAGE_NAME " " PACKAGE_VERSION "\n"); goto end; } if ( config != NULL ) { g_setenv("J4STATUS_CONFIG_FILE", config, TRUE); g_free(config); } GKeyFile *key_file; key_file = j4status_config_get_key_file("Plugins"); if ( key_file != NULL ) { if ( output_plugin == NULL ) output_plugin = g_key_file_get_string(key_file, "Plugins", "Output", NULL); if ( input_plugins == NULL ) input_plugins = g_key_file_get_string_list(key_file, "Plugins", "Input", NULL, NULL); if ( order == NULL ) order = g_key_file_get_string_list(key_file, "Plugins", "Order", NULL, NULL); g_key_file_free(key_file); } J4statusCoreContext *context; context = g_new0(J4statusCoreContext, 1); J4statusCoreInterface interface = { .context = context, .add_section = _j4status_core_add_section, .remove_section = _j4status_core_remove_section, .trigger_generate = _j4status_core_trigger_generate, .trigger_action = _j4status_core_trigger_action, }; #ifdef G_OS_UNIX g_unix_signal_add(SIGTERM, _j4status_core_source_quit, context); g_unix_signal_add(SIGINT, _j4status_core_source_quit, context); g_unix_signal_add(SIGUSR1, _j4status_core_signal_usr1, context); g_unix_signal_add(SIGUSR2, _j4status_core_signal_usr2, context); /* Ignore SIGPIPE as it is useless */ signal(SIGPIPE, SIG_IGN); #endif /* G_OS_UNIX */ context->output_plugin = j4status_plugins_get_output_plugin(&interface, output_plugin); if ( context->output_plugin == NULL ) { g_warning("No usable output plugin, tried '%s'", output_plugin); retval = 10; goto end; } gchar *header = NULL; if ( context->output_plugin->interface.generate_header != NULL ) header = context->output_plugin->interface.generate_header(context->output_plugin->context); /* Creating input/output stream */ context->io = j4status_io_new(context, header, (const gchar * const *) servers_desc, (const gchar * const *) streams_desc); if ( context->io == NULL ) { g_warning("Couldn't create input/output streams"); retval = 2; goto end; } if ( order != NULL ) { context->order_weights = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); gchar **id; for ( id = order ; *id != NULL ; ++id ) g_hash_table_insert(context->order_weights, *id, GINT_TO_POINTER(1 + id - order)); g_free(order); } context->sections_hash = g_hash_table_new(g_str_hash, g_str_equal); context->input_plugins = j4status_plugins_get_input_plugins(&interface, input_plugins); if ( context->input_plugins == NULL ) { g_warning("No input plugins, will stop early"); one_shot = TRUE; retval = 11; } context->sections = g_list_reverse(context->sections); if ( context->order_weights != NULL ) context->sections = g_list_sort(context->sections, _j4status_core_compare_sections); _j4status_core_start(context); if ( one_shot ) g_idle_add(_j4status_core_source_quit, context); context->loop = g_main_loop_new(NULL, FALSE); g_main_loop_run(context->loop); g_main_loop_unref(context->loop); context->loop = NULL; GList *input_plugin_; J4statusInputPlugin *input_plugin; for ( input_plugin_ = context->input_plugins ; input_plugin_ != NULL ; input_plugin_ = g_list_next(input_plugin_) ) { input_plugin = input_plugin_->data; input_plugin->interface.uninit(input_plugin->context); } if ( context->output_plugin->interface.uninit != NULL ) context->output_plugin->interface.uninit(context->output_plugin->context); j4status_io_free(context->io); if ( context->order_weights != NULL ) g_hash_table_unref(context->order_weights); g_hash_table_unref(context->sections_hash); end: #if DEBUG if ( debug_stream != NULL ) g_object_unref(debug_stream); #endif /* DEBUG */ return retval; }
int main (int argc, char *argv[]) { gboolean res; GError *error; cinnamon_settings_profile_start (NULL); bindtextdomain (GETTEXT_PACKAGE, CINNAMON_SETTINGS_LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); setlocale (LC_ALL, ""); parse_args (&argc, &argv); g_type_init (); cinnamon_settings_profile_start ("opening gtk display"); if (! gtk_init_check (NULL, NULL)) { g_warning ("Unable to initialize GTK+"); exit (EXIT_FAILURE); } cinnamon_settings_profile_end ("opening gtk display"); g_log_set_default_handler (csd_log_default_handler, NULL); notify_init ("cinnamon-settings-daemon"); queue_register_client (); bus_register (); cinnamon_settings_profile_start ("cinnamon_settings_manager_new"); manager = cinnamon_settings_manager_new (); cinnamon_settings_profile_end ("cinnamon_settings_manager_new"); if (manager == NULL) { g_warning ("Unable to register object"); goto out; } error = NULL; res = cinnamon_settings_manager_start (manager, &error); if (! res) { g_warning ("Unable to start: %s", error->message); g_error_free (error); goto out; } if (do_timed_exit) { g_timeout_add_seconds (30, (GSourceFunc) timed_exit_cb, NULL); } gtk_main (); g_debug ("Shutting down"); out: if (name_id > 0) { g_bus_unown_name (name_id); name_id = 0; } if (gnome_name_id > 0) { g_bus_unown_name (gnome_name_id); gnome_name_id = 0; } if (manager != NULL) { g_object_unref (manager); } g_debug ("SettingsDaemon finished"); cinnamon_settings_profile_end (NULL); return 0; }
/** * This is the "real" main which is called both on Windows and UNIX platforms. * For the Windows service case, this will also handle the notifications and set * up the logging support appropriately. */ int main_cmdline(int argc, char **argv) { chassis *srv = NULL; #ifdef HAVE_SIGACTION static struct sigaction sigsegv_sa; #endif /* read the command-line options */ GOptionContext *option_ctx = NULL; GOptionEntry *main_entries = NULL; chassis_frontend_t *frontend = NULL; chassis_options_t *opts = NULL; GError *gerr = NULL; chassis_log *log = NULL; /* a little helper macro to set the src-location that we stepped out at to exit */ #define GOTO_EXIT(status) \ exit_code = status; \ exit_location = G_STRLOC; \ goto exit_nicely; int exit_code = EXIT_SUCCESS; const gchar *exit_location = G_STRLOC; if (chassis_frontend_init_glib()) { /* init the thread, module, ... system */ GOTO_EXIT(EXIT_FAILURE); } /* start the logging ... to stderr */ log = chassis_log_new(); log->min_lvl = G_LOG_LEVEL_MESSAGE; /* display messages while parsing or loading plugins */ g_log_set_default_handler(chassis_log_func, log); #ifdef _WIN32 if (chassis_win32_is_service() && chassis_log_set_event_log(log, g_get_prgname())) { GOTO_EXIT(EXIT_FAILURE); } if (chassis_frontend_init_win32()) { /* setup winsock */ GOTO_EXIT(EXIT_FAILURE); } #endif /* may fail on library mismatch */ if (NULL == (srv = chassis_new())) { GOTO_EXIT(EXIT_FAILURE); } srv->log = log; /* we need the log structure for the log-rotation */ frontend = chassis_frontend_new(); option_ctx = g_option_context_new("- MySQL Proxy"); /** * parse once to get the basic options like --defaults-file and --version * * leave the unknown options in the list */ if (chassis_frontend_init_base_options(option_ctx, &argc, &argv, &(frontend->print_version), &(frontend->default_file), &gerr)) { g_critical("%s: %s", G_STRLOC, gerr->message); g_clear_error(&gerr); GOTO_EXIT(EXIT_FAILURE); } #ifndef _WIN32 signal(SIGPIPE, SIG_IGN); srv->daemon_mode = frontend->daemon_mode; /* add by vinchen/CFR */ srv->auto_restart = frontend->auto_restart; if (frontend->daemon_mode) { chassis_unix_daemonize(); } if (frontend->auto_restart) { int child_exit_status = EXIT_SUCCESS; /* forward the exit-status of the child */ int ret = chassis_unix_proc_keepalive(&child_exit_status); if (ret > 0) { /* the agent stopped */ exit_code = child_exit_status; goto exit_nicely; } else if (ret < 0) { GOTO_EXIT(EXIT_FAILURE); } else { /* we are the child, go on */ } } #endif if (frontend->default_file) { srv->default_file = g_strdup(frontend->default_file); //add by vinchen/CFR if (!(frontend->keyfile = chassis_frontend_open_config_file(frontend->default_file, &gerr))) { g_critical("%s: loading config from '%s' failed: %s", G_STRLOC, frontend->default_file, gerr->message); g_clear_error(&gerr); GOTO_EXIT(EXIT_FAILURE); } } /* print the main version number here, but don't exit * we check for print_version again, after loading the plugins (if any) * and print their version numbers, too. then we exit cleanly. */ if (frontend->print_version) { #ifndef CHASSIS_BUILD_TAG #define CHASSIS_BUILD_TAG PACKAGE_STRING #endif g_print("%s" CHASSIS_NEWLINE, CHASSIS_BUILD_TAG); chassis_frontend_print_version(); } /* add the other options which can also appear in the configfile */ opts = chassis_options_new(); chassis_frontend_set_chassis_options(frontend, opts); main_entries = chassis_options_to_g_option_entries(opts); g_option_context_add_main_entries(option_ctx, main_entries, NULL); /** * parse once to get the basic options * * leave the unknown options in the list */ if (FALSE == g_option_context_parse(option_ctx, &argc, &argv, &gerr)) { g_critical("%s", gerr->message); GOTO_EXIT(EXIT_FAILURE); } if (frontend->keyfile) { if (chassis_keyfile_to_options(frontend->keyfile, "mysql-proxy", main_entries)) { GOTO_EXIT(EXIT_FAILURE); } } //add by vinchen/CFR if (frontend->base_dir != NULL) srv->base_dir_org = g_strdup(frontend->base_dir); if (chassis_frontend_init_basedir(argv[0], &(frontend->base_dir))) { GOTO_EXIT(EXIT_FAILURE); } /* basic setup is done, base-dir is known, ... */ frontend->lua_subdirs = g_new(char *, 2); frontend->lua_subdirs[0] = g_strdup("mysql-proxy"); frontend->lua_subdirs[1] = NULL; if (chassis_frontend_init_lua_path(frontend->lua_path, frontend->base_dir, frontend->lua_subdirs)) { GOTO_EXIT(EXIT_FAILURE); } if (chassis_frontend_init_lua_cpath(frontend->lua_cpath, frontend->base_dir, frontend->lua_subdirs)) { GOTO_EXIT(EXIT_FAILURE); } /* assign the mysqld part to the */ network_mysqld_init(srv); /* starts the also the lua-scope, LUA_PATH and LUA_CPATH have to be set before this being called */ #ifdef HAVE_SIGACTION /* register the sigsegv interceptor */ memset(&sigsegv_sa, 0, sizeof(sigsegv_sa)); sigsegv_sa.sa_handler = sigsegv_handler; sigemptyset(&sigsegv_sa.sa_mask); srv->invoke_dbg_on_crash = frontend->invoke_dbg_on_crash; //add by vinchen/CFR if (frontend->invoke_dbg_on_crash && !(RUNNING_ON_VALGRIND)) { sigaction(SIGSEGV, &sigsegv_sa, NULL); } #endif /* * some plugins cannot see the chassis struct from the point * where they open files, hence we must make it available */ srv->base_dir = g_strdup(frontend->base_dir); if (frontend->plugin_dir) //vinchen/CFR srv->plugin_dir_org = g_strdup(frontend->plugin_dir); if (frontend->pid_file) srv->pid_file_org = g_strdup(frontend->pid_file); if (frontend->log_filename) srv->log_file_name_org = g_strdup(frontend->log_filename); if (frontend->lua_path) srv->lua_path_org = g_strdup(frontend->lua_path); if (frontend->lua_cpath) srv->lua_cpath_org = g_strdup(frontend->lua_cpath); srv->max_files_number = frontend->max_files_number; srv->conn_log = frontend->conn_log; //add by huibohuang srv->query_response_time_stats = frontend->query_response_time_stats; srv->ignore_user = g_strdupv(frontend->ignore_user); chassis_frontend_init_plugin_dir(&frontend->plugin_dir, srv->base_dir); /* * these are used before we gathered all the options * from the plugins, thus we need to fix them up before * dealing with all the rest. */ chassis_resolve_path(srv->base_dir, &frontend->log_filename); chassis_resolve_path(srv->base_dir, &frontend->pid_file); chassis_resolve_path(srv->base_dir, &frontend->plugin_dir); /* * start the logging */ if (frontend->log_filename) { log->log_filename = g_strdup(frontend->log_filename); } log->use_syslog = frontend->use_syslog; if (log->log_filename && log->use_syslog) { g_critical("%s: log-file and log-use-syslog were given, but only one is allowed", G_STRLOC); GOTO_EXIT(EXIT_FAILURE); } if (log->log_filename && FALSE == chassis_log_open(log)) { g_critical("can't open log-file '%s': %s", log->log_filename, g_strerror(errno)); GOTO_EXIT(EXIT_FAILURE); } /* handle log-level after the config-file is read, just in case it is specified in the file */ if (frontend->log_level) { if (0 != chassis_log_set_level(log, frontend->log_level)) { g_critical("--log-level=... failed, level '%s' is unknown ", frontend->log_level); GOTO_EXIT(EXIT_FAILURE); } } else { /* if it is not set, use "critical" as default */ log->min_lvl = G_LOG_LEVEL_CRITICAL; } /* * the MySQL Proxy should load 'admin' and 'proxy' plugins */ if (!frontend->plugin_names) { frontend->plugin_names = g_new(char *, 2); frontend->plugin_names[0] = g_strdup("proxy"); frontend->plugin_names[1] = NULL; }
int main(int argc, char **argv) { const char *sopt = "hVvdm:p:l:f:F::b:s:t:"; const char *method = NULL, *path = NULL; const char *log_filepath = NULL; const char *pid_filepath; #ifdef CONFIG_FSFREEZE const char *fsfreeze_hook = NULL; #endif const char *state_dir; #ifdef _WIN32 const char *service = NULL; #endif const struct option lopt[] = { { "help", 0, NULL, 'h' }, { "version", 0, NULL, 'V' }, { "logfile", 1, NULL, 'l' }, { "pidfile", 1, NULL, 'f' }, #ifdef CONFIG_FSFREEZE { "fsfreeze-hook", 2, NULL, 'F' }, #endif { "verbose", 0, NULL, 'v' }, { "method", 1, NULL, 'm' }, { "path", 1, NULL, 'p' }, { "daemonize", 0, NULL, 'd' }, { "blacklist", 1, NULL, 'b' }, #ifdef _WIN32 { "service", 1, NULL, 's' }, #endif { "statedir", 1, NULL, 't' }, { NULL, 0, NULL, 0 } }; int opt_ind = 0, ch, daemonize = 0, i, j, len; GLogLevelFlags log_level = G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL; GList *blacklist = NULL; GAState *s; module_call_init(MODULE_INIT_QAPI); init_dfl_pathnames(); pid_filepath = dfl_pathnames.pidfile; state_dir = dfl_pathnames.state_dir; while ((ch = getopt_long(argc, argv, sopt, lopt, &opt_ind)) != -1) { switch (ch) { case 'm': method = optarg; break; case 'p': path = optarg; break; case 'l': log_filepath = optarg; break; case 'f': pid_filepath = optarg; break; #ifdef CONFIG_FSFREEZE case 'F': fsfreeze_hook = optarg ? optarg : QGA_FSFREEZE_HOOK_DEFAULT; break; #endif case 't': state_dir = optarg; break; case 'v': /* enable all log levels */ log_level = G_LOG_LEVEL_MASK; break; case 'V': printf("QEMU Guest Agent %s\n", QEMU_VERSION); return 0; case 'd': daemonize = 1; break; case 'b': { if (is_help_option(optarg)) { qmp_for_each_command(ga_print_cmd, NULL); return 0; } for (j = 0, i = 0, len = strlen(optarg); i < len; i++) { if (optarg[i] == ',') { optarg[i] = 0; blacklist = g_list_append(blacklist, &optarg[j]); j = i + 1; } } if (j < i) { blacklist = g_list_append(blacklist, &optarg[j]); } break; } #ifdef _WIN32 case 's': service = optarg; if (strcmp(service, "install") == 0) { const char *fixed_state_dir; /* If the user passed the "-t" option, we save that state dir * in the service. Otherwise we let the service fetch the state * dir from the environment when it starts. */ fixed_state_dir = (state_dir == dfl_pathnames.state_dir) ? NULL : state_dir; if (ga_install_vss_provider()) { return EXIT_FAILURE; } if (ga_install_service(path, log_filepath, fixed_state_dir)) { return EXIT_FAILURE; } return 0; } else if (strcmp(service, "uninstall") == 0) { ga_uninstall_vss_provider(); return ga_uninstall_service(); } else { printf("Unknown service command.\n"); return EXIT_FAILURE; } break; #endif case 'h': usage(argv[0]); return 0; case '?': g_print("Unknown option, try '%s --help' for more information.\n", argv[0]); return EXIT_FAILURE; } } #ifdef _WIN32 /* On win32 the state directory is application specific (be it the default * or a user override). We got past the command line parsing; let's create * the directory (with any intermediate directories). If we run into an * error later on, we won't try to clean up the directory, it is considered * persistent. */ if (g_mkdir_with_parents(state_dir, S_IRWXU) == -1) { g_critical("unable to create (an ancestor of) the state directory" " '%s': %s", state_dir, strerror(errno)); return EXIT_FAILURE; } #endif s = g_malloc0(sizeof(GAState)); s->log_level = log_level; s->log_file = stderr; #ifdef CONFIG_FSFREEZE s->fsfreeze_hook = fsfreeze_hook; #endif g_log_set_default_handler(ga_log, s); g_log_set_fatal_mask(NULL, G_LOG_LEVEL_ERROR); ga_enable_logging(s); s->state_filepath_isfrozen = g_strdup_printf("%s/qga.state.isfrozen", state_dir); s->pstate_filepath = g_strdup_printf("%s/qga.state", state_dir); s->frozen = false; #ifndef _WIN32 /* check if a previous instance of qemu-ga exited with filesystems' state * marked as frozen. this could be a stale value (a non-qemu-ga process * or reboot may have since unfrozen them), but better to require an * uneeded unfreeze than to risk hanging on start-up */ struct stat st; if (stat(s->state_filepath_isfrozen, &st) == -1) { /* it's okay if the file doesn't exist, but if we can't access for * some other reason, such as permissions, there's a configuration * that needs to be addressed. so just bail now before we get into * more trouble later */ if (errno != ENOENT) { g_critical("unable to access state file at path %s: %s", s->state_filepath_isfrozen, strerror(errno)); return EXIT_FAILURE; } } else { g_warning("previous instance appears to have exited with frozen" " filesystems. deferring logging/pidfile creation and" " disabling non-fsfreeze-safe commands until" " guest-fsfreeze-thaw is issued, or filesystems are" " manually unfrozen and the file %s is removed", s->state_filepath_isfrozen); s->frozen = true; } #endif if (ga_is_frozen(s)) { if (daemonize) { /* delay opening/locking of pidfile till filesystems are unfrozen */ s->deferred_options.pid_filepath = pid_filepath; become_daemon(NULL); } if (log_filepath) { /* delay opening the log file till filesystems are unfrozen */ s->deferred_options.log_filepath = log_filepath; } ga_disable_logging(s); qmp_for_each_command(ga_disable_non_whitelisted, NULL); } else { if (daemonize) { become_daemon(pid_filepath); } if (log_filepath) { FILE *log_file = ga_open_logfile(log_filepath); if (!log_file) { g_critical("unable to open specified log file: %s", strerror(errno)); goto out_bad; } s->log_file = log_file; } } /* load persistent state from disk */ if (!read_persistent_state(&s->pstate, s->pstate_filepath, ga_is_frozen(s))) { g_critical("failed to load persistent state"); goto out_bad; } blacklist = ga_command_blacklist_init(blacklist); if (blacklist) { s->blacklist = blacklist; do { g_debug("disabling command: %s", (char *)blacklist->data); qmp_disable_command(blacklist->data); blacklist = g_list_next(blacklist); } while (blacklist); } s->command_state = ga_command_state_new(); ga_command_state_init(s, s->command_state); ga_command_state_init_all(s->command_state); json_message_parser_init(&s->parser, process_event); ga_state = s; #ifndef _WIN32 if (!register_signal_handlers()) { g_critical("failed to register signal handlers"); goto out_bad; } #endif s->main_loop = g_main_loop_new(NULL, false); if (!channel_init(ga_state, method, path)) { g_critical("failed to initialize guest agent channel"); goto out_bad; } #ifndef _WIN32 g_main_loop_run(ga_state->main_loop); #else if (daemonize) { SERVICE_TABLE_ENTRY service_table[] = { { (char *)QGA_SERVICE_NAME, service_main }, { NULL, NULL } }; StartServiceCtrlDispatcher(service_table); } else { g_main_loop_run(ga_state->main_loop); } #endif ga_command_state_cleanup_all(ga_state->command_state); ga_channel_free(ga_state->channel); if (daemonize) { unlink(pid_filepath); } return 0; out_bad: if (daemonize) { unlink(pid_filepath); } return EXIT_FAILURE; }
void cc_shell_log_init (void) { g_log_set_default_handler (cc_shell_log_default_handler, NULL); }
int main (int argc, char**argv) { GLogFunc logger = NULL; GtkWidget* box; GtkWidget* text; GtkWidget* scrolled; GtkWidget* window; logger = g_log_set_default_handler (my_logger, &logger); if (G_UNLIKELY (!logger)) { logger = g_log_default_handler; } gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); box = gtk_vbox_new (FALSE, 6); scrolled = gtk_scrolled_window_new (NULL, NULL); text = gtk_text_view_new (); gtk_window_set_default_size (GTK_WINDOW (window), 400, 300); g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); gtk_widget_modify_font (text, pango_font_description_from_string ("Mono")); gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (text)), "style \"gradients-1\" {\n" " \n" "}\n\n" "style \"gradients-2\" {\n" " \n" "}\n\n" "style \"flat\" {\n" " \n" "}\n\n" "style \"buttons\" {\n" " \n" "}\n\n" "widget \"path-bar-1\" style \"gradients\";\n" "widget \"path-bar-2\" style \"flat\"\n" "widget \"path-bar-3\" style \"flat\"\n" "widget \"path-bar-4\" style \"buttons\";", -1); gtk_box_pack_start (GTK_BOX (box), create_path_bar ("path-bar-1"), FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (box), create_path_bar ("path-bar-2"), FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (box), create_path_bar ("path-bar-3"), FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (box), create_path_bar ("path-bar-4"), FALSE, FALSE, 0); gtk_container_add (GTK_CONTAINER (scrolled), text); gtk_container_add (GTK_CONTAINER (box), scrolled); gtk_container_add (GTK_CONTAINER (window), box); gtk_widget_show_all (window); gtk_main (); return 0; }
void crm_log_deinit(void) { #ifdef HAVE_G_LOG_SET_DEFAULT_HANDLER g_log_set_default_handler(glib_log_default, NULL); #endif }
static void setup_debug_log_glog (void) { default_log_handler = g_log_set_default_handler (log_override_cb, NULL); }
int main (int argc, char *argv[]) { #if HAVE_GEOCLUE EmpathyLocationManager *location_manager = NULL; #endif EmpathyStatusIcon *icon; EmpathyDispatcher *dispatcher; TpAccountManager *account_manager; EmpathyLogManager *log_manager; EmpathyChatroomManager *chatroom_manager; EmpathyCallFactory *call_factory; EmpathyFTFactory *ft_factory; GtkWidget *window; EmpathyIdle *idle; EmpathyConnectivity *connectivity; GError *error = NULL; TpDBusDaemon *dbus_daemon; UniqueApp *unique_app; gboolean chatroom_manager_ready; GOptionContext *optcontext; GOptionEntry options[] = { { "no-connect", 'n', 0, G_OPTION_ARG_NONE, &no_connect, N_("Don't connect on startup"), NULL }, { "start-hidden", 'h', 0, G_OPTION_ARG_NONE, &start_hidden, N_("Don't display the contact list or any other dialogs on startup"), NULL }, { "accounts", 'a', 0, G_OPTION_ARG_NONE, &account_dialog_only, N_("Show the accounts dialog"), NULL }, { "version", 'v', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, show_version_cb, NULL, NULL }, { NULL } }; /* Init */ g_thread_init (NULL); empathy_init (); optcontext = g_option_context_new (N_("- Empathy IM Client")); g_option_context_add_group (optcontext, gst_init_get_option_group ()); g_option_context_add_group (optcontext, gtk_get_option_group (TRUE)); g_option_context_add_main_entries (optcontext, options, GETTEXT_PACKAGE); if (!g_option_context_parse (optcontext, &argc, &argv, &error)) { g_print ("%s\nRun '%s --help' to see a full list of available command line options.\n", error->message, argv[0]); g_warning ("Error in empathy init: %s", error->message); return EXIT_FAILURE; } g_option_context_free (optcontext); empathy_gtk_init (); g_set_application_name (_(PACKAGE_NAME)); g_setenv ("PULSE_PROP_media.role", "phone", TRUE); #if HAVE_LIBCHAMPLAIN gtk_clutter_init (&argc, &argv); #endif gtk_window_set_default_icon_name ("empathy"); textdomain (GETTEXT_PACKAGE); #ifdef ENABLE_DEBUG /* Set up debugger */ g_log_set_default_handler (default_log_handler, NULL); #endif unique_app = unique_app_new_with_commands ("org.gnome.Empathy", NULL, "accounts_dialog", COMMAND_ACCOUNTS_DIALOG, NULL); if (unique_app_is_running (unique_app)) { unique_app_send_message (unique_app, account_dialog_only ? COMMAND_ACCOUNTS_DIALOG : UNIQUE_ACTIVATE, NULL); g_object_unref (unique_app); return EXIT_SUCCESS; } /* Take well-known name */ dbus_daemon = tp_dbus_daemon_dup (&error); if (error == NULL) { if (!tp_dbus_daemon_request_name (dbus_daemon, "org.gnome.Empathy", TRUE, &error)) { DEBUG ("Failed to request well-known name: %s", error ? error->message : "no message"); g_clear_error (&error); } g_object_unref (dbus_daemon); } else { DEBUG ("Failed to dup dbus daemon: %s", error ? error->message : "no message"); g_clear_error (&error); } if (account_dialog_only) { account_manager = tp_account_manager_dup (); show_accounts_ui (NULL, TRUE); gtk_main (); g_object_unref (account_manager); return 0; } notify_init (_(PACKAGE_NAME)); /* Setting up Idle */ idle = empathy_idle_dup_singleton (); empathy_idle_set_auto_away (idle, TRUE); /* Setting up Connectivity */ connectivity = empathy_connectivity_dup_singleton (); use_conn_notify_cb (empathy_conf_get (), EMPATHY_PREFS_USE_CONN, connectivity); empathy_conf_notify_add (empathy_conf_get (), EMPATHY_PREFS_USE_CONN, use_conn_notify_cb, connectivity); /* account management */ account_manager = tp_account_manager_dup (); tp_account_manager_prepare_async (account_manager, NULL, account_manager_ready_cb, NULL); /* Handle channels */ dispatcher = setup_dispatcher (); g_signal_connect (dispatcher, "dispatch", G_CALLBACK (dispatch_cb), NULL); migrate_config_to_xdg_dir (); /* Setting up UI */ window = empathy_main_window_show (); icon = empathy_status_icon_new (GTK_WINDOW (window), start_hidden); g_signal_connect (unique_app, "message-received", G_CALLBACK (unique_app_message_cb), window); /* Logging */ log_manager = empathy_log_manager_dup_singleton (); empathy_log_manager_observe (log_manager, dispatcher); chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL); empathy_chatroom_manager_observe (chatroom_manager, dispatcher); g_object_get (chatroom_manager, "ready", &chatroom_manager_ready, NULL); if (!chatroom_manager_ready) { g_signal_connect (G_OBJECT (chatroom_manager), "notify::ready", G_CALLBACK (chatroom_manager_ready_cb), account_manager); } else { chatroom_manager_ready_cb (chatroom_manager, NULL, account_manager); } /* Create the call factory */ call_factory = empathy_call_factory_initialise (); g_signal_connect (G_OBJECT (call_factory), "new-call-handler", G_CALLBACK (new_call_handler_cb), NULL); /* Create the FT factory */ ft_factory = empathy_ft_factory_dup_singleton (); g_signal_connect (ft_factory, "new-ft-handler", G_CALLBACK (new_ft_handler_cb), NULL); g_signal_connect (ft_factory, "new-incoming-transfer", G_CALLBACK (new_incoming_transfer_cb), NULL); /* Location mananger */ #if HAVE_GEOCLUE location_manager = empathy_location_manager_dup_singleton (); #endif gtk_main (); empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_OFFLINE); g_object_unref (idle); g_object_unref (connectivity); g_object_unref (icon); g_object_unref (account_manager); g_object_unref (log_manager); g_object_unref (dispatcher); g_object_unref (chatroom_manager); #if HAVE_GEOCLUE g_object_unref (location_manager); #endif g_object_unref (ft_factory); g_object_unref (unique_app); notify_uninit (); return EXIT_SUCCESS; }
static void init(int argc, char **argv) { old_logger = g_log_set_default_handler(logger, NULL); }
int main(int argc, char * argv[]) { MPI_Init(&argc, &argv); g_log_set_default_handler(log_handler, NULL); g_set_print_handler(print_handler); mpiu_init(); ROOTONLY { GError * error = NULL; GOptionContext * context = g_option_context_new("paramfile"); g_option_context_add_main_entries(context, entries, NULL); if(!g_option_context_parse(context, &argc, &argv, &error)) { g_print("Option parsing failed: %s", error->message); abort(); } if(g_strv_length(paramfilename) != 1) { g_print(g_option_context_get_help(context, FALSE, NULL)); abort(); } paramfile_read(paramfilename[0]); g_message("Reading param file %s", paramfilename[0]); g_option_context_free(context); } MPI_Barrier(MPI_COMM_WORLD); common_block_sync(); MPI_Barrier(MPI_COMM_WORLD); init_gadget(); g_message("MPI Task: %d of %d, datadir=%s", ThisTask, NTask, CB.datadir); MPI_Barrier(MPI_COMM_WORLD); domain_init(); for(CB.SnapNumMajor = CB.SnapNumMajorBegin; CB.SnapNumMajor < CB.SnapNumMajorEnd; CB.SnapNumMajor ++) { SnapHeader h; snapshot_read(&h); CB.a = h.a; domain_decompose(); domain_build_tree(); for(int color=0; color < NColor; color++) { TAKETURNS { inspect_par(color); inspect_tree(color); } } ROOTONLY { inspect_domain_table(); } domain_cleanup(); } domain_destroy(); MPI_Barrier(MPI_COMM_WORLD); MPI_Finalize(); return 0; }
void gvc_log_init (void) { g_log_set_default_handler (gvc_log_default_handler, NULL); }
int main (int argc, char **argv) { GError *error = NULL; gboolean no_daemon = FALSE; gboolean debug = FALSE; GOptionContext *context; GOptionEntry entries[] = { {"no-daemon", 0, 0, G_OPTION_ARG_NONE, &no_daemon, N_("Do not daemonize"), NULL}, {"debug", 0, 0, G_OPTION_ARG_NONE, &debug, N_("Log debugging message"), NULL}, {NULL} }; context = g_option_context_new ("- dasom daemon"); g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); g_option_context_parse (context, &argc, &argv, &error); g_option_context_free (context); if (error != NULL) { g_warning ("%s", error->message); g_error_free (error); return EXIT_FAILURE; } #ifdef ENABLE_NLS bindtextdomain (GETTEXT_PACKAGE, DASOM_LOCALE_DIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #endif if (no_daemon == FALSE) { openlog (g_get_prgname (), LOG_PID | LOG_PERROR, LOG_DAEMON); syslog_initialized = TRUE; g_log_set_default_handler ((GLogFunc) dasom_log_default_handler, &debug); if (daemon (0, 0) != 0) { g_critical ("Couldn't daemonize."); return EXIT_FAILURE; } } gtk_init (&argc, &argv); AppIndicator *indicator; GtkWidget *menu_shell; GtkWidget *about_menu; GtkWidget *exit_menu; DasomAgent *agent; menu_shell = gtk_menu_new (); about_menu = gtk_menu_item_new_with_label (_("About")); exit_menu = gtk_menu_item_new_with_label (_("Exit")); gtk_widget_show_all (about_menu); gtk_widget_show_all (exit_menu); gtk_menu_shell_append (GTK_MENU_SHELL (menu_shell), about_menu); gtk_menu_shell_append (GTK_MENU_SHELL (menu_shell), exit_menu); gtk_widget_show_all (menu_shell); indicator = app_indicator_new ("dasom-indicator", "input-keyboard", APP_INDICATOR_CATEGORY_APPLICATION_STATUS); app_indicator_set_status (indicator, APP_INDICATOR_STATUS_ACTIVE); app_indicator_set_icon_full (indicator, "dasom-indicator", "Dasom"); app_indicator_set_menu (indicator, GTK_MENU (menu_shell)); agent = dasom_agent_new (); g_signal_connect (agent, "engine-changed", G_CALLBACK (on_engine_changed), indicator); g_signal_connect (agent, "disconnected", G_CALLBACK (on_disconnected), indicator); g_signal_connect (about_menu, "activate", G_CALLBACK (on_about_menu), indicator); g_signal_connect (exit_menu, "activate", G_CALLBACK (on_exit_menu), indicator); gtk_main (); g_object_unref (agent); g_object_unref (indicator); g_object_unref (menu_shell); if (syslog_initialized) closelog (); return EXIT_SUCCESS; }