/* * Exec viewer if found and use session name path. */ static int view_trace(void) { int ret; char *session_name, *trace_path = NULL; struct lttng_session *sessions = NULL; /* * Safety net. If lttng is suid at some point for *any* useless reasons, * this prevent any bad execution of binaries. */ if (getuid() != 0) { if (getuid() != geteuid()) { ERR("UID does not match effective UID."); ret = CMD_ERROR; goto error; } else if (getgid() != getegid()) { ERR("GID does not match effective GID."); ret = CMD_ERROR; goto error; } } /* User define trace path override the session name */ if (opt_trace_path) { session_name = NULL; } else if(opt_session_name == NULL) { session_name = get_session_name(); if (session_name == NULL) { ret = CMD_ERROR; goto error; } } else { session_name = opt_session_name; } DBG("Viewing trace for session %s", session_name); if (session_name) { int i, count, found = 0; /* Getting all sessions */ count = lttng_list_sessions(&sessions); if (count < 0) { ERR("Unable to list sessions. Session name %s not found.", session_name); MSG("Is there a session daemon running?"); ret = CMD_ERROR; goto free_error; } /* Find our session listed by the session daemon */ for (i = 0; i < count; i++) { if (strncmp(sessions[i].name, session_name, NAME_MAX) == 0) { found = 1; break; } } if (!found) { MSG("Session name %s not found", session_name); ret = CMD_ERROR; goto free_sessions; } session_live_mode = sessions[i].live_timer_interval; DBG("Session live mode set to %d", session_live_mode); if (sessions[i].enabled && !session_live_mode) { WARN("Session %s is running. Please stop it before reading it.", session_name); ret = CMD_ERROR; goto free_sessions; } /* If the timer interval is set we are in live mode. */ if (session_live_mode) { trace_path = build_live_path(session_name); if (!trace_path) { ret = CMD_ERROR; goto free_sessions; } } else { /* Get file system session path. */ trace_path = sessions[i].path; } } else { trace_path = opt_trace_path; } MSG("Trace directory: %s\n", trace_path); ret = spawn_viewer(trace_path); if (ret < 0) { /* Don't set ret so lttng can interpret the sessiond error. */ goto free_sessions; } free_sessions: if (session_live_mode) { free(trace_path); } free(sessions); free_error: if (opt_session_name == NULL) { free(session_name); } error: return ret; }
gpointer worker_thread_cb(gpointer data) { UpdaterAppState *app_state; CURL *curl; CURLcode result; FILE *package_file; GError *error = NULL; int fd; //g_return_val_if_fail (data != NULL, NULL); app_state = (UpdaterAppState *) data; try { if(!app_state->url.empty()) { char* tmp_local_filename = NULL; // create temporary file to store the package. fd = g_file_open_tmp ("secondlife-update-XXXXXX", &tmp_local_filename, &error); if (error != NULL) { llerrs << "Unable to create temporary file: " << error->message << llendl; g_error_free(error); throw 0; } if(tmp_local_filename != NULL) { app_state->file = tmp_local_filename; g_free(tmp_local_filename); } package_file = fdopen(fd, "wb"); if (package_file == NULL) { llerrs << "Failed to create temporary file: " << app_state->file.c_str() << llendl; gdk_threads_enter(); display_error(app_state->window, LLTrans::getString("UpdaterFailDownloadTitle"), LLTrans::getString("UpdaterFailUpdateDescriptive")); gdk_threads_leave(); throw 0; } // initialize curl and start downloading the package llinfos << "Downloading package: " << app_state->url << llendl; curl = curl_easy_init(); if (curl == NULL) { llerrs << "Failed to initialize libcurl" << llendl; gdk_threads_enter(); display_error(app_state->window, LLTrans::getString("UpdaterFailDownloadTitle"), LLTrans::getString("UpdaterFailUpdateDescriptive")); gdk_threads_leave(); throw 0; } curl_easy_setopt(curl, CURLOPT_URL, app_state->url.c_str()); curl_easy_setopt(curl, CURLOPT_NOSIGNAL, TRUE); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, TRUE); curl_easy_setopt(curl, CURLOPT_WRITEDATA, package_file); curl_easy_setopt(curl, CURLOPT_NOPROGRESS, FALSE); curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, &download_progress_cb); curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, app_state); result = curl_easy_perform(curl); fclose(package_file); curl_easy_cleanup(curl); if (result) { llerrs << "Failed to download update: " << app_state->url << llendl; gdk_threads_enter(); display_error(app_state->window, LLTrans::getString("UpdaterFailDownloadTitle"), LLTrans::getString("UpdaterFailUpdateDescriptive")); gdk_threads_leave(); throw 0; } } // now pulse the progres bar back and forth while the package is // being unpacked gdk_threads_enter(); std::string installing_msg = LLTrans::getString("UpdaterNowInstalling"); gtk_progress_bar_set_text( GTK_PROGRESS_BAR(app_state->progress_bar), installing_msg.c_str()); app_state->activity_mode = TRUE; gdk_threads_leave(); // *TODO: if the destination is not writable, terminate this // thread and show file chooser? if (!install_package(app_state->file.c_str(), app_state->dest_dir)) { llwarns << "Failed to install package to destination: " << app_state->dest_dir << llendl; gdk_threads_enter(); display_error(app_state->window, LLTrans::getString("UpdaterFailInstallTitle"), LLTrans::getString("UpdaterFailUpdateDescriptive")); //"Failed to update " + app_state->app_name, gdk_threads_leave(); throw 0; } // try to spawn the new viewer if (!spawn_viewer(app_state)) { llwarns << "Viewer was not installed properly in : " << app_state->dest_dir << llendl; gdk_threads_enter(); display_error(app_state->window, LLTrans::getString("UpdaterFailStartTitle"), LLTrans::getString("UpdaterFailUpdateDescriptive")); gdk_threads_leave(); throw 0; } } catch (...) { app_state->failure = TRUE; } gdk_threads_enter(); updater_app_quit(app_state); gdk_threads_leave(); return NULL; }