ubuntu-app-launch-0.5+15.10.20150817/0000755000015300001610000000000012564452317017274 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/cgroup-reap-all.c0000644000015300001610000000347412564452056022442 0ustar pbuserpbgroup00000000000000/* * Copyright © 2014 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include "helpers.h" int kill (pid_t pid, int signal); pid_t getpgid (pid_t); int main (int argc, char * argv[]) { /* Break off a new process group */ setpgid(0, 0); GDBusConnection * cgmanager = cgroup_manager_connection(); g_return_val_if_fail(cgmanager != NULL, -1); GPid selfpid = getpid(); GPid parentpid = getppid(); /* We're gonna try to kill things forever, literally. It's important enough that we can't consider failure an option. */ gboolean killed = TRUE; while (killed) { GList * pidlist = pids_from_cgroup(cgmanager, NULL, NULL); GList * head; killed = FALSE; for (head = pidlist; head != NULL; head = g_list_next(head)) { GPid pid = GPOINTER_TO_INT(head->data); /* We don't want to kill ourselves, or if we're being executed by a script, that script, either. We also don't want things in our process group which we forked at the opening */ if (pid != selfpid && pid != parentpid && getpgid(pid) != selfpid) { g_debug("Killing pid: %d", pid); kill(pid, SIGKILL); killed = TRUE; } } g_list_free(pidlist); } cgroup_manager_unref(cgmanager); return 0; } ubuntu-app-launch-0.5+15.10.20150817/ubuntu-app-test/0000755000015300001610000000000012564452317022351 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/ubuntu-app-test/tests/0000755000015300001610000000000012564452317023513 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/ubuntu-app-test/tests/CMakeLists.txt0000644000015300001610000000003212564452056026246 0ustar pbuserpbgroup00000000000000 message(STATUS "Tests") ubuntu-app-launch-0.5+15.10.20150817/ubuntu-app-test/src/0000755000015300001610000000000012564452317023140 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/ubuntu-app-test/src/ubuntu-app-test.c0000644000015300001610000000613612564452056026367 0ustar pbuserpbgroup00000000000000/* * Copyright © 2015 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include #include "ubuntu-app-launch.h" #include #include #include gboolean timeout (gpointer ploop) { g_main_loop_quit((GMainLoop *)ploop); return G_SOURCE_REMOVE; } void app_failed (const gchar * appid, UbuntuAppLaunchAppFailed failure_type, gpointer ploop) { if (g_strcmp0(appid, "ubuntu-app-test") != 0) { return; } g_warning("Starting 'ubuntu-app-test' failed with error: %d", failure_type); g_main_loop_quit((GMainLoop *)ploop); } void fd_getter (MirPromptSession * session, size_t count, int const * fdsin, void * pfds) { if (count != 1) { g_warning("Didn't get the right number of FDs"); return; } int * fds = (int *)pfds; fds[0] = fdsin[0]; } int main (int argc, char * argv[]) { if (argc == 1) { g_printerr("Usage: %s \n", argv[0]); return -1; } gchar * mirpath = g_build_filename(g_get_user_runtime_dir(), "mir_socket_trusted", NULL); if (!g_file_test(mirpath, G_FILE_TEST_EXISTS)) { g_free(mirpath); g_debug("No Mir detected, exec'ing assuming we're under X11"); return execvp(argv[1], argv + 1); } GMainLoop * loop = g_main_loop_new(NULL, FALSE); ubuntu_app_launch_observer_add_app_failed(app_failed, loop); ubuntu_app_launch_start_application("ubuntu-app-test", NULL); g_timeout_add_seconds(1, timeout, loop); g_main_loop_run(loop); ubuntu_app_launch_observer_delete_app_failed(app_failed, loop); g_main_loop_unref(loop); GPid pid; pid = ubuntu_app_launch_get_primary_pid("ubuntu-app-test"); if (pid == 0) { g_critical("Unable to get PID for 'ubuntu-app-test' application"); return -1; } MirConnection * mir = mir_connect_sync(mirpath, "ubuntu-app-test"); g_free(mirpath); MirPromptSession * session = mir_connection_create_prompt_session_sync(mir, pid, NULL, NULL); int fd = 0; MirWaitHandle * wait = mir_prompt_session_new_fds_for_prompt_providers(session, 1, fd_getter, &fd); mir_wait_for(wait); if (fd == 0) { g_critical("Unable to get FD for prompt session"); return -1; } gchar * sock = g_strdup_printf("fd://%d", fd); g_setenv("MIR_SOCKET", sock, TRUE); g_free(sock); pid_t subpid = 0; int exit_status = -1; if ((subpid = fork()) == 0) { return execvp(argv[1], argv + 1); } waitpid(subpid, &exit_status, 0); mir_prompt_session_release_sync(session); mir_connection_release(mir); return WEXITSTATUS(exit_status); } ubuntu-app-launch-0.5+15.10.20150817/ubuntu-app-test/src/CMakeLists.txt0000644000015300001610000000055112564452056025701 0ustar pbuserpbgroup00000000000000 include_directories("${CMAKE_SOURCE_DIR}/libubuntu-app-launch") add_executable(ubuntu-app-test ubuntu-app-test.c) set_target_properties(ubuntu-app-test PROPERTIES OUTPUT_NAME "ubuntu-app-test") target_link_libraries(ubuntu-app-test ubuntu-launcher ${MIR_LIBRARIES}) install(TARGETS ubuntu-app-test RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}/app-test") ubuntu-app-launch-0.5+15.10.20150817/ubuntu-app-test/CMakeLists.txt0000644000015300001610000000017412564452056025113 0ustar pbuserpbgroup00000000000000add_subdirectory(data) add_subdirectory(src) # testing & coverage if (${enable_tests}) add_subdirectory(tests) endif () ubuntu-app-launch-0.5+15.10.20150817/ubuntu-app-test/data/0000755000015300001610000000000012564452317023262 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/ubuntu-app-test/data/ubuntu-app-test.desktop.in0000644000015300001610000000041012564452056030332 0ustar pbuserpbgroup00000000000000[Desktop Entry] Name=Ubuntu App Test Comment=A shell used to test applications Exec=qmlscene @pkgdatadir@/ubuntu-app-test.qml Type=Application Terminal=false Icon=ubuntu-app-test X-Ayatana-Appmenu-Show-Stubs=false X-Ubuntu-Touch=true X-Ubuntu-Single-Instance=true ubuntu-app-launch-0.5+15.10.20150817/ubuntu-app-test/data/CMakeLists.txt0000644000015300001610000000072612564452056026027 0ustar pbuserpbgroup00000000000000 set(pkgdatadir "${CMAKE_INSTALL_FULL_PKGDATADIR}") configure_file("ubuntu-app-test.desktop.in" "${CMAKE_CURRENT_BINARY_DIR}/ubuntu-app-test.desktop" @ONLY) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/ubuntu-app-test.desktop" DESTINATION "${CMAKE_INSTALL_DATADIR}/applications/") install(FILES "ubuntu-app-test.qml" DESTINATION "${CMAKE_INSTALL_FULL_PKGDATADIR}") install(FILES "ubuntu-app-test.svg" DESTINATION "${CMAKE_INSTALL_DATADIR}/icons/hicolor/scalable/apps") ubuntu-app-launch-0.5+15.10.20150817/ubuntu-app-test/data/ubuntu-app-test.svg0000644000015300001610000004305712564452056027071 0ustar pbuserpbgroup00000000000000 image/svg+xml ubuntu-app-launch-0.5+15.10.20150817/ubuntu-app-test/data/ubuntu-app-test.qml0000644000015300001610000000105612564452056027054 0ustar pbuserpbgroup00000000000000import QtQuick 2.0 import Ubuntu.Components 0.1 MainView { automaticOrientation: true width: parent.width height: parent.height Page { title: i18n.tr("Ubuntu Application Test") TextArea { text: i18n.tr("An application that exists as a dummy so that the application you're wishing to run can be overlayed on top of it. If you're seeing this the application is probably starting, or somehow failed to run.") width: parent.width - units.gu(4) height: parent.height - units.gu(4) x: units.gu(2) y: units.gu(2) readOnly: true } } } ubuntu-app-launch-0.5+15.10.20150817/desktop-hook.c0000644000015300001610000004336312564452056022060 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ /* INTRODUCTION: This is a hook for Click packages. You can find information on Click package hooks in the click documentation: https://click.readthedocs.org/en/latest/ Probably the biggest thing to understand for how this code works is that you need to understand that this hook is run after one, or many packages are installed. A set of symbolic links are made to the desktop files per-application (not per-package) in the directory specified in ubuntu-app-launcher-desktop.click-hook.in. Those desktop files give us the App ID of the packages that are installed and have applications needing desktop files in them. We then operate on each of them ensuring that they are synchronized with the desktop files in ~/.local/share/applications/. The desktop files that we're creating there ARE NOT used for execution by the ubuntu-app-launch Upstart jobs. They are there so that Unity can know which applications are installed for this user and they provide an Exec line to allow compatibility with desktop environments that are not using ubuntu-app-launch for launching applications. You should not modify them and expect any executing under Unity to change. */ #include #include #include #include #include #include "helpers.h" typedef struct _app_state_t app_state_t; struct _app_state_t { gchar * app_id; gboolean has_click; gboolean has_desktop; guint64 click_modified; guint64 desktop_modified; }; /* Desktop Group */ #define DESKTOP_GROUP "Desktop Entry" /* Desktop Keys */ #define APP_ID_KEY "X-Ubuntu-Application-ID" #define PATH_KEY "Path" #define EXEC_KEY "Exec" #define ICON_KEY "Icon" #define SYMBOLIC_ICON_KEY "X-Ubuntu-SymbolicIcon" #define SOURCE_FILE_KEY "X-Ubuntu-UAL-Source-Desktop" /* Other */ #define OLD_KEY_PREFIX "X-Ubuntu-Old-" /* Find an entry in the app array */ app_state_t * find_app_entry (const gchar * name, GArray * app_array) { int i; for (i = 0; i < app_array->len; i++) { app_state_t * state = &g_array_index(app_array, app_state_t, i); if (g_strcmp0(state->app_id, name) == 0) { return state; } } app_state_t newstate; newstate.has_click = FALSE; newstate.has_desktop = FALSE; newstate.click_modified = 0; newstate.desktop_modified = 0; newstate.app_id = g_strdup(name); g_array_append_val(app_array, newstate); /* Note: The pointer needs to be the entry in the array, not the one that we have on the stack. Criticaly important. */ app_state_t * statepntr = &g_array_index(app_array, app_state_t, app_array->len - 1); return statepntr; } /* Looks up the file creation time, which seems harder with GLib than it should be */ guint64 modified_time (const gchar * dir, const gchar * filename) { gchar * path = g_build_filename(dir, filename, NULL); GFile * file = g_file_new_for_path(path); GFileInfo * info = g_file_query_info(file, G_FILE_ATTRIBUTE_TIME_MODIFIED, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, NULL); guint64 time = g_file_info_get_attribute_uint64(info, G_FILE_ATTRIBUTE_TIME_MODIFIED); g_object_unref(info); g_object_unref(file); g_free(path); return time; } /* Look at an click package entry */ void add_click_package (const gchar * dir, const gchar * name, GArray * app_array) { if (!g_str_has_suffix(name, ".desktop")) { return; } gchar * appid = g_strdup(name); g_strstr_len(appid, -1, ".desktop")[0] = '\0'; app_state_t * state = find_app_entry(appid, app_array); state->has_click = TRUE; state->click_modified = modified_time(dir, name); g_free(appid); return; } /* Look at the desktop file and ensure that it was built by us, and if it was that its source still exists */ gboolean desktop_source_exists (const gchar * dir, const gchar * name) { gchar * desktopfile = g_build_filename(dir, name, NULL); GKeyFile * keyfile = g_key_file_new(); g_key_file_load_from_file(keyfile, desktopfile, G_KEY_FILE_NONE, NULL); /* No error */ if (!g_key_file_has_key(keyfile, DESKTOP_GROUP, SOURCE_FILE_KEY, NULL)) { gboolean hasappid = g_key_file_has_key(keyfile, DESKTOP_GROUP, APP_ID_KEY, NULL); g_free(desktopfile); g_key_file_free(keyfile); return hasappid; } /* At this point we know the key exists, so if we can't find the source file we want to delete the file as well. We need to replace it. */ gchar * originalfile = g_key_file_get_string(keyfile, DESKTOP_GROUP, SOURCE_FILE_KEY, NULL); g_key_file_free(keyfile); gboolean found = TRUE; if (!g_file_test(originalfile, G_FILE_TEST_EXISTS)) { g_remove(desktopfile); found = FALSE; } g_free(originalfile); g_free(desktopfile); return found; } /* Look at an desktop file entry */ void add_desktop_file (const gchar * dir, const gchar * name, GArray * app_array) { if (!g_str_has_suffix(name, ".desktop")) { return; } if (!desktop_source_exists(dir, name)) { return; } gchar * appid = g_strdup(name); g_strstr_len(appid, -1, ".desktop")[0] = '\0'; /* We only want valid APP IDs as desktop files */ if (!app_id_to_triplet(appid, NULL, NULL, NULL)) { g_free(appid); return; } app_state_t * state = find_app_entry(appid, app_array); state->has_desktop = TRUE; state->desktop_modified = modified_time(dir, name); g_free(appid); return; } /* Open a directory and look at all the entries */ void dir_for_each (const gchar * dirname, void(*func)(const gchar * dir, const gchar * name, GArray * app_array), GArray * app_array) { GError * error = NULL; GDir * directory = g_dir_open(dirname, 0, &error); if (error != NULL) { g_warning("Unable to read directory '%s': %s", dirname, error->message); g_error_free(error); return; } const gchar * filename = NULL; while ((filename = g_dir_read_name(directory)) != NULL) { func(dirname, filename, app_array); } g_dir_close(directory); return; } /* Helpers to ensure we write nicely */ static void write_string (int fd, const gchar *string) { int res; do res = write (fd, string, strlen (string)); while (G_UNLIKELY (res == -1 && errno == EINTR)); } /* Make NULLs fast and fun! */ static void write_null (int fd) { int res; do res = write (fd, "", 1); while (G_UNLIKELY (res == -1 && errno == EINTR)); } /* Child watcher */ static gboolean apport_child_watch (GPid pid, gint status, gpointer user_data) { g_main_loop_quit((GMainLoop *)user_data); return FALSE; } static gboolean apport_child_timeout (gpointer user_data) { g_warning("Recoverable Error Reporter Timeout"); g_main_loop_quit((GMainLoop *)user_data); return FALSE; } /* Code to report an error, so we can start tracking how important this is */ static void report_recoverable_error (const gchar * app_id, const gchar * iconfield, const gchar * originalicon, const gchar * iconpath) { GError * error = NULL; gint error_stdin = 0; GPid pid = 0; gchar * argv[2] = { "/usr/share/apport/recoverable_problem", NULL }; g_spawn_async_with_pipes(NULL, /* cwd */ argv, NULL, /* envp */ G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL | G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, /* child setup func */ &pid, &error_stdin, NULL, /* stdout */ NULL, /* stderr */ &error); if (error != NULL) { g_warning("Unable to report a recoverable error: %s", error->message); g_error_free(error); } if (error_stdin != 0) { write_string(error_stdin, "IconValue"); write_null(error_stdin); write_string(error_stdin, originalicon); write_null(error_stdin); write_string(error_stdin, "AppID"); write_null(error_stdin); write_string(error_stdin, app_id); write_null(error_stdin); write_string(error_stdin, "IconPath"); write_null(error_stdin); write_string(error_stdin, iconpath); write_null(error_stdin); write_string(error_stdin, "IconField"); write_null(error_stdin); write_string(error_stdin, iconfield); write_null(error_stdin); write_string(error_stdin, "DuplicateSignature"); write_null(error_stdin); write_string(error_stdin, "icon-path-unhandled"); /* write_null(error_stdin); -- No final NULL */ close(error_stdin); } if (pid != 0) { GSource * child_source, * timeout_source; GMainContext * context = g_main_context_new(); GMainLoop * loop = g_main_loop_new(context, FALSE); child_source = g_child_watch_source_new(pid); g_source_attach(child_source, context); g_source_set_callback(child_source, (GSourceFunc)apport_child_watch, loop, NULL); timeout_source = g_timeout_source_new_seconds(5); g_source_attach(timeout_source, context); g_source_set_callback(timeout_source, apport_child_timeout, loop, NULL); g_main_loop_run(loop); g_source_destroy(timeout_source); g_source_destroy(child_source); g_main_loop_unref(loop); g_main_context_unref(context); g_spawn_close_pid(pid); } return; } /* Function to take the source Desktop file and build a new one with similar, but not the same data in it */ static void copy_desktop_file (const gchar * from, const gchar * to, const gchar * appdir, const gchar * app_id) { GError * error = NULL; GKeyFile * keyfile = g_key_file_new(); g_key_file_load_from_file(keyfile, from, G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, &error); if (error != NULL) { g_warning("Unable to read the desktop file '%s' in the application directory: %s", from, error->message); g_error_free(error); g_key_file_unref(keyfile); return; } /* Path Hanlding */ if (g_key_file_has_key(keyfile, DESKTOP_GROUP, PATH_KEY, NULL)) { gchar * oldpath = g_key_file_get_string(keyfile, DESKTOP_GROUP, PATH_KEY, NULL); g_debug("Desktop file '%s' has a Path set to '%s'. Setting as " OLD_KEY_PREFIX PATH_KEY ".", from, oldpath); g_key_file_set_string(keyfile, DESKTOP_GROUP, OLD_KEY_PREFIX PATH_KEY, oldpath); g_free(oldpath); } g_key_file_set_string(keyfile, DESKTOP_GROUP, PATH_KEY, appdir); /* Icon Handling */ if (g_key_file_has_key(keyfile, DESKTOP_GROUP, ICON_KEY, NULL)) { gchar * originalicon = g_key_file_get_string(keyfile, DESKTOP_GROUP, ICON_KEY, NULL); gchar * iconpath = g_build_filename(appdir, originalicon, NULL); /* If the icon in the path exists, let's use that */ if (g_file_test(iconpath, G_FILE_TEST_EXISTS)) { g_key_file_set_string(keyfile, DESKTOP_GROUP, ICON_KEY, iconpath); /* Save the old value, because, debugging */ g_key_file_set_string(keyfile, DESKTOP_GROUP, OLD_KEY_PREFIX ICON_KEY, originalicon); } else { /* So here we are, realizing all is lost. Let's file a bug. */ /* The goal here is to realize how often this case is, so we know how to prioritize fixing it */ report_recoverable_error(app_id, ICON_KEY, originalicon, iconpath); } g_free(iconpath); g_free(originalicon); } /* SymbolicIcon Handling */ if (g_key_file_has_key(keyfile, DESKTOP_GROUP, SYMBOLIC_ICON_KEY, NULL)) { gchar * originalicon = g_key_file_get_string(keyfile, DESKTOP_GROUP, SYMBOLIC_ICON_KEY, NULL); gchar * iconpath = g_build_filename(appdir, originalicon, NULL); /* If the icon in the path exists, let's use that */ if (g_file_test(iconpath, G_FILE_TEST_EXISTS)) { g_key_file_set_string(keyfile, DESKTOP_GROUP, SYMBOLIC_ICON_KEY, iconpath); /* Save the old value, because, debugging */ g_key_file_set_string(keyfile, DESKTOP_GROUP, OLD_KEY_PREFIX SYMBOLIC_ICON_KEY, originalicon); } else { /* So here we are, realizing all is lost. Let's file a bug. */ /* The goal here is to realize how often this case is, so we know how to prioritize fixing it */ report_recoverable_error(app_id, SYMBOLIC_ICON_KEY, originalicon, iconpath); } g_free(iconpath); g_free(originalicon); } /* Exec Handling */ gchar * oldexec = desktop_to_exec(keyfile, from); if (oldexec == NULL) { g_key_file_unref(keyfile); return; } gchar * newexec = g_strdup_printf("aa-exec-click -p %s -- %s", app_id, oldexec); g_key_file_set_string(keyfile, DESKTOP_GROUP, EXEC_KEY, newexec); g_free(newexec); g_free(oldexec); /* Adding an Application ID */ g_key_file_set_string(keyfile, DESKTOP_GROUP, APP_ID_KEY, app_id); /* Adding the source file path */ g_key_file_set_string(keyfile, DESKTOP_GROUP, SOURCE_FILE_KEY, from); /* Output */ gsize datalen = 0; gchar * data = g_key_file_to_data(keyfile, &datalen, &error); g_key_file_unref(keyfile); if (error != NULL) { g_warning("Unable serialize keyfile built from '%s': %s", from, error->message); g_error_free(error); return; } g_file_set_contents(to, data, datalen, &error); g_free(data); if (error != NULL) { g_warning("Unable to write out desktop file to '%s': %s", to, error->message); g_error_free(error); return; } return; } /* Build a desktop file in the user's home directory */ static void build_desktop_file (app_state_t * state, const gchar * symlinkdir, const gchar * desktopdir) { GError * error = NULL; gchar * package = NULL; /* 'Parse' the App ID */ if (!app_id_to_triplet(state->app_id, &package, NULL, NULL)) { return; } /* Read in the database */ ClickDB * db = click_db_new(); click_db_read(db, g_getenv("TEST_CLICK_DB"), &error); if (error != NULL) { g_warning("Unable to read Click database: %s", error->message); g_error_free(error); g_free(package); g_object_unref(db); return; } /* Check click to find out where the files are */ ClickUser * user = click_user_new_for_user(db, g_getenv("TEST_CLICK_USER"), &error); g_object_unref(db); if (error != NULL) { g_warning("Unable to read Click database: %s", error->message); g_error_free(error); g_free(package); return; } gchar * pkgdir = click_user_get_path(user, package, &error); if (error != NULL) { g_warning("Unable to get the Click package directory for %s: %s", package, error->message); g_error_free(error); g_free(package); return; } g_object_unref(user); g_free(package); if (!g_file_test(pkgdir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { g_warning("Directory returned by click '%s' couldn't be found", pkgdir); g_free(pkgdir); return; } gchar * indesktop = manifest_to_desktop(pkgdir, state->app_id); if (indesktop == NULL) { g_free(pkgdir); return; } /* Determine the desktop file name */ gchar * desktopfile = g_strdup_printf("%s.desktop", state->app_id); gchar * desktoppath = g_build_filename(desktopdir, desktopfile, NULL); g_free(desktopfile); copy_desktop_file(indesktop, desktoppath, pkgdir, state->app_id); g_free(desktoppath); g_free(indesktop); g_free(pkgdir); return; } /* Remove the desktop file from the user's home directory */ static gboolean remove_desktop_file (app_state_t * state, const gchar * desktopdir) { gchar * desktopfile = g_strdup_printf("%s.desktop", state->app_id); gchar * desktoppath = g_build_filename(desktopdir, desktopfile, NULL); g_free(desktopfile); GKeyFile * keyfile = g_key_file_new(); g_key_file_load_from_file(keyfile, desktoppath, G_KEY_FILE_NONE, NULL); if (!g_key_file_has_key(keyfile, DESKTOP_GROUP, APP_ID_KEY, NULL)) { g_debug("Desktop file '%s' is not one created by us.", desktoppath); g_key_file_unref(keyfile); g_free(desktoppath); return FALSE; } g_key_file_unref(keyfile); if (g_unlink(desktoppath) != 0) { g_warning("Unable to delete desktop file: %s", desktoppath); } g_free(desktoppath); return TRUE; } /* The main function */ int main (int argc, char * argv[]) { if (argc != 1) { g_error("Shouldn't have arguments"); return 1; } GArray * apparray = g_array_new(FALSE, FALSE, sizeof(app_state_t)); /* Find all the symlinks of desktop files */ gchar * symlinkdir = g_build_filename(g_get_user_cache_dir(), "ubuntu-app-launch", "desktop", NULL); if (!g_file_test(symlinkdir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { g_debug("No installed click packages"); } else { dir_for_each(symlinkdir, add_click_package, apparray); } /* Find all the click desktop files */ gchar * desktopdir = g_build_filename(g_get_user_data_dir(), "applications", NULL); gboolean desktopdirexists = FALSE; if (!g_file_test(desktopdir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { g_debug("No applications defined"); } else { dir_for_each(desktopdir, add_desktop_file, apparray); desktopdirexists = TRUE; } /* Process the merge */ int i; for (i = 0; i < apparray->len; i++) { app_state_t * state = &g_array_index(apparray, app_state_t, i); g_debug("Processing App ID: %s", state->app_id); if (state->has_click && state->has_desktop) { if (state->click_modified > state->desktop_modified) { g_debug("\tClick updated more recently"); g_debug("\tRemoving desktop file"); if (remove_desktop_file(state, desktopdir)) { g_debug("\tBuilding desktop file"); build_desktop_file(state, symlinkdir, desktopdir); } } else { g_debug("\tAlready synchronized"); } } else if (state->has_click) { if (!desktopdirexists) { if (g_mkdir_with_parents(desktopdir, 0755) == 0) { g_debug("\tCreated applications directory"); desktopdirexists = TRUE; } else { g_warning("\tUnable to create applications directory"); } } if (desktopdirexists) { g_debug("\tBuilding desktop file"); build_desktop_file(state, symlinkdir, desktopdir); } } else if (state->has_desktop) { g_debug("\tRemoving desktop file"); remove_desktop_file(state, desktopdir); } g_free(state->app_id); } g_array_free(apparray, TRUE); g_free(desktopdir); g_free(symlinkdir); return 0; } ubuntu-app-launch-0.5+15.10.20150817/zg-report-app.c0000644000015300001610000000612612564452056022154 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include #include "libubuntu-app-launch/ubuntu-app-launch.h" static gboolean watchdog_timeout (gpointer user_data) { g_warning("Watchdog triggered, took too long to submit into Zeitgeist Database!"); g_main_loop_quit((GMainLoop *)user_data); return G_SOURCE_REMOVE; } static void insert_complete (GObject * obj, GAsyncResult * res, gpointer user_data) { GError * error = NULL; GArray * result = NULL; result = zeitgeist_log_insert_event_finish(ZEITGEIST_LOG(obj), res, &error); if (error != NULL) { g_warning("Unable to submit Zeitgeist Event: %s", error->message); g_error_free(error); } g_array_free(result, TRUE); g_main_loop_quit((GMainLoop *)user_data); return; } int main (int argc, char * argv[]) { if (argc != 2 || (g_strcmp0(argv[1], "open") != 0 && g_strcmp0(argv[1], "close") != 0)) { g_printerr("Usage: %s [open|close]\n", argv[0]); return 1; } const gchar * appid = g_getenv("APP_ID"); if (appid == NULL) { g_printerr("No App ID defined"); return 1; } gchar * uri = NULL; gchar * pkg = NULL; gchar * app = NULL; if (ubuntu_app_launch_app_id_parse(appid, &pkg, &app, NULL)) { /* If it's parseable, use the short form */ uri = g_strdup_printf("application://%s_%s.desktop", pkg, app); g_free(pkg); g_free(app); } else { uri = g_strdup_printf("application://%s.desktop", appid); } ZeitgeistLog * log = zeitgeist_log_get_default(); ZeitgeistEvent * event = zeitgeist_event_new(); zeitgeist_event_set_actor(event, "application://ubuntu-app-launch.desktop"); if (g_strcmp0(argv[1], "open") == 0) { zeitgeist_event_set_interpretation(event, ZEITGEIST_ZG_ACCESS_EVENT); } else { zeitgeist_event_set_interpretation(event, ZEITGEIST_ZG_LEAVE_EVENT); } zeitgeist_event_set_manifestation(event, ZEITGEIST_ZG_USER_ACTIVITY); ZeitgeistSubject * subject = zeitgeist_subject_new(); zeitgeist_subject_set_interpretation(subject, ZEITGEIST_NFO_SOFTWARE); zeitgeist_subject_set_manifestation(subject, ZEITGEIST_NFO_SOFTWARE_ITEM); zeitgeist_subject_set_mimetype(subject, "application/x-desktop"); zeitgeist_subject_set_uri(subject, uri); zeitgeist_event_add_subject(event, subject); GMainLoop * main_loop = g_main_loop_new(NULL, FALSE); zeitgeist_log_insert_event(log, event, NULL, insert_complete, main_loop); g_timeout_add_seconds(2, watchdog_timeout, main_loop); g_main_loop_run(main_loop); g_main_loop_unref(main_loop); g_free(uri); return 0; } ubuntu-app-launch-0.5+15.10.20150817/untrusted-helper-type-end.c0000644000015300001610000000367112564452056024504 0ustar pbuserpbgroup00000000000000/* * Copyright © 2014 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include "libubuntu-app-launch/ubuntu-app-launch.h" #include int main (int argc, gchar * argv[]) { const gchar * type = g_getenv("HELPER_TYPE"); g_return_val_if_fail(type != NULL, -1); GDBusConnection * con = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); g_return_val_if_fail(con != NULL, -1); gchar ** appids = ubuntu_app_launch_list_helpers(type); if (appids == NULL) { g_warning("Error getting App IDs for helper type '%s'", argv[1]); return -1; } int i; for (i = 0; appids[i] != NULL; i++) { gchar ** instances = ubuntu_app_launch_list_helper_instances(type, appids[i]); guint instance_cnt = g_strv_length(instances); if (instance_cnt == 0) { g_debug("Stopping %s", appids[i]); if (!ubuntu_app_launch_stop_helper(type, appids[i])) { g_warning("Unable to stop '%s'", appids[i]); } } else { int j; for (j = 0; j < instance_cnt; j++) { g_debug("Stopping %s (%s)", appids[i], instances[j]); if (!ubuntu_app_launch_stop_multiple_helper(type, appids[i], instances[j])) { g_warning("Unable to stop '%s' instance '%s'", appids[i], instances[j]); } } } g_strfreev(instances); } g_strfreev(appids); g_dbus_connection_flush_sync(con, NULL, NULL); g_object_unref(con); return 0; } ubuntu-app-launch-0.5+15.10.20150817/ual-tracepoint.h0000644000015300001610000000256012564452056022377 0ustar pbuserpbgroup00000000000000/* * Copyright © 2014 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #ifndef UAL_TRACEPOINT_H__ #define UAL_TRACEPOINT_H__ 1 #include extern int _ual_tracepoints_env_checked; extern int _ual_tracepoints_enabled; /* Little macro that makes it so we can easily turn off all the tracepoints if they're not needed. Also cleans up the code a bit by removing some common elements */ #define ual_tracepoint(point, ...) \ if (G_UNLIKELY(!_ual_tracepoints_env_checked)) { \ _ual_tracepoints_enabled = getenv("UBUNTU_APP_LAUNCH_LTTNG_ENABLED") != NULL; \ _ual_tracepoints_env_checked = 1; \ } \ if (G_UNLIKELY(_ual_tracepoints_enabled)) { \ tracepoint(ubuntu_app_launch, point, __VA_ARGS__); \ } #endif /* UAL_TRACEPOINT_H__ */ ubuntu-app-launch-0.5+15.10.20150817/tools/0000755000015300001610000000000012564452317020434 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tools/ubuntu-helper-stop.c0000644000015300001610000000242112564452056024361 0ustar pbuserpbgroup00000000000000/* * Copyright © 2014 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include "libubuntu-app-launch/ubuntu-app-launch.h" #include int main (int argc, gchar * argv[]) { if (argc != 3) { g_printerr("Usage: %s \n", argv[0]); return 1; } GDBusConnection * con = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); g_return_val_if_fail(con != NULL, -1); int retval = -1; if (ubuntu_app_launch_stop_helper(argv[1], argv[2])) { retval = 0; } else { g_debug("Unable to stop app id '%s' of type '%s'", argv[2], argv[1]); } g_dbus_connection_flush_sync(con, NULL, NULL); g_object_unref(con); return retval; } ubuntu-app-launch-0.5+15.10.20150817/tools/ubuntu-app-stop.c0000644000015300001610000000171512564452056023667 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include "libubuntu-app-launch/ubuntu-app-launch.h" int main (int argc, gchar * argv[]) { if (argc != 2) { g_printerr("Usage: %s \n", argv[0]); return 1; } if (ubuntu_app_launch_stop_application(argv[1])) { return 0; } else { return 1; } } ubuntu-app-launch-0.5+15.10.20150817/tools/ubuntu-helper-start.c0000644000015300001610000000246212564452056024536 0ustar pbuserpbgroup00000000000000/* * Copyright © 2014 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include "libubuntu-app-launch/ubuntu-app-launch.h" #include int main (int argc, gchar * argv[]) { if (argc != 3) { g_printerr("Usage: %s \n", argv[0]); return 1; } GDBusConnection * con = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); g_return_val_if_fail(con != NULL, -1); int retval = -1; /* TODO: Allow URIs */ if (ubuntu_app_launch_start_helper(argv[1], argv[2], NULL)) { retval = 0; } else { g_debug("Unable to start app id '%s' of type '%s'", argv[2], argv[1]); } g_dbus_connection_flush_sync(con, NULL, NULL); g_object_unref(con); return retval; } ubuntu-app-launch-0.5+15.10.20150817/tools/ubuntu-app-usage.c0000644000015300001610000001270512564452056024007 0ustar pbuserpbgroup00000000000000/* * Copyright © 2014 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include GPtrArray * build_event_templates (void) { GPtrArray * retval = g_ptr_array_new_with_free_func(g_object_unref); ZeitgeistEvent * event; event = zeitgeist_event_new(); zeitgeist_event_set_actor(event, "application://ubuntu-app-launch.desktop"); zeitgeist_event_set_interpretation(event, ZEITGEIST_ZG_ACCESS_EVENT); zeitgeist_event_set_manifestation(event, ZEITGEIST_ZG_USER_ACTIVITY); g_ptr_array_add(retval, event); event = zeitgeist_event_new(); zeitgeist_event_set_actor(event, "application://ubuntu-app-launch.desktop"); zeitgeist_event_set_interpretation(event, ZEITGEIST_ZG_LEAVE_EVENT); zeitgeist_event_set_manifestation(event, ZEITGEIST_ZG_USER_ACTIVITY); g_ptr_array_add(retval, event); return retval; } typedef struct { gchar * name; guint seconds; } usage_t; gint sort_by_usage (gconstpointer a, gconstpointer b) { usage_t * ua = (usage_t *)a; usage_t * ub = (usage_t *)b; return ub->seconds - ua->seconds; } void print_usage (GHashTable * usage) { GArray * sorter = g_array_new(FALSE, FALSE, sizeof(usage_t)); guint maxappname = 0; GHashTableIter iter; g_hash_table_iter_init(&iter, usage); gpointer key, value; while (g_hash_table_iter_next(&iter, &key, &value)) { gchar * appurl = (gchar *)key; appurl += strlen("application://"); gchar * desktop = g_strrstr(appurl, ".desktop"); if (desktop != NULL) desktop[0] = '\0'; usage_t usage = { .name = appurl, .seconds = GPOINTER_TO_UINT(value) }; maxappname = MAX(maxappname, strlen(appurl)); g_array_append_val(sorter, usage); } g_array_sort(sorter, sort_by_usage); int i; for (i = 0; i < sorter->len; i++) { usage_t * usage = &g_array_index(sorter, usage_t, i); gint spaceneeded = maxappname - strlen(usage->name); gchar * space = g_strnfill(spaceneeded, ' '); g_print("%s%s %d seconds\n", usage->name, space, usage->seconds); g_free(space); } g_array_unref(sorter); } void find_events_cb (GObject * obj, GAsyncResult * res, gpointer user_data) { /* No matter what, we want to quit */ g_main_loop_quit((GMainLoop *)user_data); GError * error = NULL; ZeitgeistResultSet * results = NULL; results = zeitgeist_log_find_events_finish(ZEITGEIST_LOG(obj), res, &error); if (error != NULL) { g_error("Unable to get ZG events: %s", error->message); g_error_free(error); return; } GHashTable * laststop = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)g_date_time_unref); GHashTable * usage = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); while (zeitgeist_result_set_has_next(results)) { ZeitgeistEvent * event = zeitgeist_result_set_next_value(results); ZeitgeistSubject * subject = zeitgeist_event_get_subject(event, 0); const gchar * eventtype = "unknown"; const gchar * appurl = zeitgeist_subject_get_uri(subject); if (g_strcmp0(zeitgeist_event_get_interpretation(event), ZEITGEIST_ZG_ACCESS_EVENT) == 0) { eventtype = "started"; GDateTime * stoptime = g_hash_table_lookup(laststop, appurl); if (stoptime != NULL) { GDateTime * starttime = g_date_time_new_from_unix_utc(zeitgeist_event_get_timestamp(event) / 1000); if (starttime != NULL) { GTimeSpan runtime = g_date_time_difference(stoptime, starttime); guint seconds = runtime / G_TIME_SPAN_SECOND; g_date_time_unref(stoptime); /* Update the usage table */ gint previoususage = GPOINTER_TO_UINT(g_hash_table_lookup(usage, appurl)); g_hash_table_insert(usage, g_strdup(appurl), GUINT_TO_POINTER(previoususage + seconds)); } g_hash_table_remove(laststop, appurl); } } else { eventtype = "stopped"; GDateTime * stoptime = g_date_time_new_from_unix_utc(zeitgeist_event_get_timestamp(event) / 1000); if (stoptime != NULL) { g_date_time_ref(stoptime); g_hash_table_insert(laststop, g_strdup(appurl), stoptime); } else { g_debug("Unable to parse start time for: %s", appurl); } } g_debug("Got %s for '%s'" , eventtype, appurl); g_object_unref(subject); g_object_unref(event); } print_usage(usage); g_hash_table_destroy(laststop); g_hash_table_destroy(usage); g_object_unref(results); return; } int main (int argc, char * argv[]) { GMainLoop * main_loop = g_main_loop_new(NULL, FALSE); ZeitgeistLog * log = zeitgeist_log_get_default(); GPtrArray * templates = build_event_templates(); ZeitgeistTimeRange * time = zeitgeist_time_range_new_anytime(); zeitgeist_log_find_events(log, time, /* time range */ templates, ZEITGEIST_STORAGE_STATE_ANY, /* storage state */ 10000, /* num events */ ZEITGEIST_RELEVANT_RESULT_TYPE_RECENT, /* result type */ NULL, /* cancelable */ find_events_cb, main_loop); g_ptr_array_unref(templates); g_object_unref(time); g_main_loop_run(main_loop); g_main_loop_unref(main_loop); g_object_unref(log); return 0; } ubuntu-app-launch-0.5+15.10.20150817/tools/ubuntu-helper-list.c0000644000015300001610000000254312564452056024354 0ustar pbuserpbgroup00000000000000/* * Copyright © 2014 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include "libubuntu-app-launch/ubuntu-app-launch.h" #include int main (int argc, gchar * argv[]) { if (argc != 2) { g_printerr("Usage: %s \n", argv[0]); return 1; } GDBusConnection * con = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); g_return_val_if_fail(con != NULL, -1); gchar ** appids = ubuntu_app_launch_list_helpers(argv[1]); if (appids == NULL) { g_warning("Error getting App IDs for helper type '%s'", argv[1]); return -1; } int i; for (i = 0; appids[i] != NULL; i++) { g_print("%s\n", appids[i]); } g_strfreev(appids); g_dbus_connection_flush_sync(con, NULL, NULL); g_object_unref(con); return 0; } ubuntu-app-launch-0.5+15.10.20150817/tools/ubuntu-app-watch.c0000644000015300001610000000533512564452056024012 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include "libubuntu-app-launch/ubuntu-app-launch.h" void starting (const gchar * appid, gpointer user_data) { g_print("Starting %s\n", appid); return; } void started (const gchar * appid, gpointer user_data) { g_print("Started %s\n", appid); return; } void stopped (const gchar * appid, gpointer user_data) { g_print("Stop %s\n", appid); return; } void resumed (const gchar * appid, GPid * pids, gpointer user_data) { g_print("Resumed %s\n", appid); return; } void paused (const gchar * appid, GPid * pids, gpointer user_data) { g_print("Paused %s\n", appid); return; } void focus (const gchar * appid, gpointer user_data) { g_print("Focus %s\n", appid); return; } void fail (const gchar * appid, UbuntuAppLaunchAppFailed failhow, gpointer user_data) { const gchar * failstr = "unknown"; switch (failhow) { case UBUNTU_APP_LAUNCH_APP_FAILED_CRASH: failstr = "crashed"; break; case UBUNTU_APP_LAUNCH_APP_FAILED_START_FAILURE: failstr = "startup"; break; } g_print("Fail %s (%s)\n", appid, failstr); return; } int main (int argc, gchar * argv[]) { ubuntu_app_launch_observer_add_app_starting(starting, NULL); ubuntu_app_launch_observer_add_app_started(started, NULL); ubuntu_app_launch_observer_add_app_stop(stopped, NULL); ubuntu_app_launch_observer_add_app_focus(focus, NULL); ubuntu_app_launch_observer_add_app_resumed(resumed, NULL); ubuntu_app_launch_observer_add_app_paused(paused, NULL); ubuntu_app_launch_observer_add_app_failed(fail, NULL); GMainLoop * mainloop = g_main_loop_new(NULL, FALSE); g_main_loop_run(mainloop); ubuntu_app_launch_observer_delete_app_starting(starting, NULL); ubuntu_app_launch_observer_delete_app_started(started, NULL); ubuntu_app_launch_observer_delete_app_stop(stopped, NULL); ubuntu_app_launch_observer_delete_app_focus(focus, NULL); ubuntu_app_launch_observer_delete_app_resumed(resumed, NULL); ubuntu_app_launch_observer_delete_app_paused(paused, NULL); ubuntu_app_launch_observer_delete_app_failed(fail, NULL); g_main_loop_unref(mainloop); return 0; } ubuntu-app-launch-0.5+15.10.20150817/tools/ubuntu-app-triplet.c0000644000015300001610000000231412564452056024361 0ustar pbuserpbgroup00000000000000/* * Copyright © 2014 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include "libubuntu-app-launch/ubuntu-app-launch.h" int main (int argc, gchar * argv[]) { if (argc > 4 || argc == 1) { g_printerr("Usage: %s [application] [version]\n", argv[0]); return 1; } gchar * pkg = argv[1]; gchar * app = NULL; gchar * ver = NULL; if (argc > 2) { app = argv[2]; } if (argc > 3) { app = argv[3]; } gchar * appid = ubuntu_app_launch_triplet_to_app_id(pkg, app, ver); if (appid == NULL) { return -1; } g_print("%s\n", appid); g_free(appid); return 0; } ubuntu-app-launch-0.5+15.10.20150817/tools/ubuntu-app-pid.c0000644000015300001610000000176012564452056023456 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include "libubuntu-app-launch/ubuntu-app-launch.h" int main (int argc, gchar * argv[]) { if (argc != 2) { g_printerr("Usage: %s \n", argv[0]); return 1; } GPid pid = ubuntu_app_launch_get_primary_pid(argv[1]); if (pid == 0) { return 1; } g_print("%d\n", pid); return 0; } ubuntu-app-launch-0.5+15.10.20150817/tools/ubuntu-app-launch.c0000644000015300001610000000447312564452056024160 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include #include "libubuntu-app-launch/ubuntu-app-launch.h" const gchar * global_appid = NULL; int retval = 0; static void good_observer (const gchar * appid, gpointer user_data) { if (g_strcmp0(appid, global_appid) != 0) { return; } g_debug("Application '%s' running", appid); g_main_loop_quit((GMainLoop *)user_data); } static void bad_observer (const gchar * appid, UbuntuAppLaunchAppFailed failure_type, gpointer user_data) { if (g_strcmp0(appid, global_appid) != 0) { return; } g_debug("Application '%s' failed: %s", appid, failure_type == UBUNTU_APP_LAUNCH_APP_FAILED_CRASH ? "crash" : "startup failure"); retval = -1; g_main_loop_quit((GMainLoop *)user_data); } int main (int argc, gchar * argv[]) { if (argc < 2) { g_printerr("Usage: %s [uris]\n", argv[0]); return 1; } global_appid = argv[1]; GMainLoop * mainloop = g_main_loop_new(NULL, FALSE); gchar ** uris = NULL; if (argc > 2) { int i; uris = g_new0(gchar *, argc - 1); for (i = 2; i < argc; i++) { uris[i - 2] = argv[i]; } } ubuntu_app_launch_observer_add_app_started(good_observer, mainloop); ubuntu_app_launch_observer_add_app_focus(good_observer, mainloop); ubuntu_app_launch_observer_add_app_failed(bad_observer, mainloop); ubuntu_app_launch_start_application(global_appid, (const gchar * const *)uris); g_main_loop_run(mainloop); ubuntu_app_launch_observer_delete_app_started(good_observer, mainloop); ubuntu_app_launch_observer_delete_app_focus(good_observer, mainloop); ubuntu_app_launch_observer_delete_app_failed(bad_observer, mainloop); g_main_loop_unref(mainloop); g_free(uris); return retval; } ubuntu-app-launch-0.5+15.10.20150817/tools/ubuntu-app-list.c0000644000015300001610000000171712564452056023657 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include "libubuntu-app-launch/ubuntu-app-launch.h" int main (int argc, char * argv[]) { gchar ** apps; apps = ubuntu_app_launch_list_running_apps(); int i; for (i = 0; apps[i] != NULL; i++) { g_print("%s\n", apps[i]); } g_strfreev(apps); return 0; } ubuntu-app-launch-0.5+15.10.20150817/tools/CMakeLists.txt0000644000015300001610000000665712564452056023212 0ustar pbuserpbgroup00000000000000 ######################## # ubuntu-app-list ######################## add_executable(ubuntu-app-list ubuntu-app-list.c) set_target_properties(ubuntu-app-list PROPERTIES OUTPUT_NAME "ubuntu-app-list") target_link_libraries(ubuntu-app-list ubuntu-launcher) install(TARGETS ubuntu-app-list RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}") ######################## # ubuntu-app-launch ######################## add_executable(ubuntu-app-launch ubuntu-app-launch.c) set_target_properties(ubuntu-app-launch PROPERTIES OUTPUT_NAME "ubuntu-app-launch") target_link_libraries(ubuntu-app-launch ubuntu-launcher) install(TARGETS ubuntu-app-launch RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}") ######################## # ubuntu-app-watch ######################## add_executable(ubuntu-app-watch ubuntu-app-watch.c) set_target_properties(ubuntu-app-watch PROPERTIES OUTPUT_NAME "ubuntu-app-watch") target_link_libraries(ubuntu-app-watch ubuntu-launcher) install(TARGETS ubuntu-app-watch RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}") ######################## # ubuntu-app-pid ######################## add_executable(ubuntu-app-pid ubuntu-app-pid.c) set_target_properties(ubuntu-app-pid PROPERTIES OUTPUT_NAME "ubuntu-app-pid") target_link_libraries(ubuntu-app-pid ubuntu-launcher) install(TARGETS ubuntu-app-pid RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}") ######################## # ubuntu-app-stop ######################## add_executable(ubuntu-app-stop ubuntu-app-stop.c) set_target_properties(ubuntu-app-stop PROPERTIES OUTPUT_NAME "ubuntu-app-stop") target_link_libraries(ubuntu-app-stop ubuntu-launcher) install(TARGETS ubuntu-app-stop RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}") ######################## # ubuntu-app-triplet ######################## add_executable(ubuntu-app-triplet ubuntu-app-triplet.c) set_target_properties(ubuntu-app-triplet PROPERTIES OUTPUT_NAME "ubuntu-app-triplet") target_link_libraries(ubuntu-app-triplet ubuntu-launcher) install(TARGETS ubuntu-app-triplet RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}") ######################## # ubuntu-helper-start ######################## add_executable(ubuntu-helper-start ubuntu-helper-start.c) set_target_properties(ubuntu-helper-start PROPERTIES OUTPUT_NAME "ubuntu-helper-start") target_link_libraries(ubuntu-helper-start ubuntu-launcher) install(TARGETS ubuntu-helper-start RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}") ######################## # ubuntu-helper-stop ######################## add_executable(ubuntu-helper-stop ubuntu-helper-stop.c) set_target_properties(ubuntu-helper-stop PROPERTIES OUTPUT_NAME "ubuntu-helper-stop") target_link_libraries(ubuntu-helper-stop ubuntu-launcher) install(TARGETS ubuntu-helper-stop RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}") ######################## # ubuntu-helper-list ######################## add_executable(ubuntu-helper-list ubuntu-helper-list.c) set_target_properties(ubuntu-helper-list PROPERTIES OUTPUT_NAME "ubuntu-helper-list") target_link_libraries(ubuntu-helper-list ubuntu-launcher) install(TARGETS ubuntu-helper-list RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}") ######################## # ubuntu-app-usage ######################## add_executable(ubuntu-app-usage ubuntu-app-usage.c) set_target_properties(ubuntu-app-usage PROPERTIES OUTPUT_NAME "ubuntu-app-usage") target_link_libraries(ubuntu-app-usage ubuntu-launcher) install(TARGETS ubuntu-app-usage RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}") ubuntu-app-launch-0.5+15.10.20150817/ubuntu-app-launch-desktop.click-hook.in0000644000015300001610000000020612564452056026663 0ustar pbuserpbgroup00000000000000Pattern: ${home}/.cache/ubuntu-app-launch/desktop/${id}.desktop Exec: @pkglibexecdir@/desktop-hook User-Level: yes Hook-Name: desktop ubuntu-app-launch-0.5+15.10.20150817/helpers.h0000644000015300001610000000505012564452117021105 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include typedef struct _EnvHandle EnvHandle; gboolean app_id_to_triplet (const gchar * app_id, gchar ** package, gchar ** application, gchar ** version); gchar * manifest_to_desktop (const gchar * app_dir, const gchar * app_id); gchar * desktop_to_exec (GKeyFile * desktop_file, const gchar * from); GArray * desktop_exec_parse (const gchar * execline, const gchar * uri_list); GKeyFile * keyfile_for_appid (const gchar * appid, gchar * * desktopfile); void set_confined_envvars (EnvHandle * handle, const gchar * package, const gchar * app_dir); /* A handle to group environment setting */ EnvHandle * env_handle_start (void); void env_handle_add (EnvHandle * handle, const gchar * variable, const gchar * value); void env_handle_finish (EnvHandle * handle); typedef struct _handshake_t handshake_t; handshake_t * starting_handshake_start (const gchar * app_id); void starting_handshake_wait (handshake_t * handshake); GDBusConnection * cgroup_manager_connection (void); void cgroup_manager_unref (GDBusConnection * cgroup_manager); GList * pids_from_cgroup (GDBusConnection * cgmanager, const gchar * jobname, const gchar * instancename); gboolean verify_keyfile (GKeyFile * inkeyfile, const gchar * desktop); ubuntu-app-launch-0.5+15.10.20150817/xmir-helper.c0000644000015300001610000000550112564452110021664 0ustar pbuserpbgroup00000000000000/* * Copyright © 2014 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #define _POSIX_C_SOURCE 200212L #include #include #include #include #include #include void sigchild_handler (int signal) { fprintf(stderr, "XMir has closed unexpectedly\n"); exit(1); } struct sigaction sigchild_action = { .sa_handler = sigchild_handler, .sa_flags = SA_NOCLDWAIT }; int main (int argc, char * argv[]) { if (argc < 3) { fprintf(stderr, "xmir-helper needs more arguments: xmir-helper $(appid) $(thing to exec) ... \n"); return 1; } /* Make nice variables for the things we need */ char * appid = argv[1]; char * xmir = getenv("UBUNTU_APP_LAUNCH_XMIR_PATH"); if (xmir == NULL) { xmir = "/usr/bin/Xmir"; } /* Build a socket pair to get the connection back from XMir */ int sockets[2]; if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sockets) != 0) { fprintf(stderr, "Unable to create socketpair for communicating with XMir\n"); return 1; } /* Give them nice names, the compiler will optimize out */ int xmirsocket = sockets[0]; int helpersocket = sockets[1]; /* Watch for the child dying */ if (sigaction(SIGCHLD, &sigchild_action, NULL) != 0) { fprintf(stderr, "Unable to setup child signal handler\n"); return 1; } /* Start XMir */ if (fork() == 0) { /* XMir start here */ /* GOAL: XMir -displayfd ${xmirsocket} -mir ${appid} */ char socketbuf[16] = {0}; snprintf(socketbuf, 16, "%d", xmirsocket); char * xmirexec[6] = { xmir, "-displayfd", socketbuf, "-mir", appid, NULL }; return execv(xmir, xmirexec); } /* Wait to get the display number from XMir */ char readbuf[16] = {0}; if (read(helpersocket, readbuf, 16) == 0) { fprintf(stderr, "Not reading anything from XMir\n"); return 1; } int i; for (i = 0; i < sizeof(readbuf); i++) { if (readbuf[i] == '\n') { readbuf[i] = '\0'; break; } } char displaynumber[16] = {0}; snprintf(displaynumber, 16, ":%s", readbuf); /* Set up the display variable */ setenv("DISPLAY", displaynumber, 1); /* Now that we have everything setup, we can execute */ char ** nargv = &argv[2]; int execret = execvp(nargv[0], nargv); return execret; } ubuntu-app-launch-0.5+15.10.20150817/cmake/0000755000015300001610000000000012564452317020354 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/cmake/UseGdbusCodegen.cmake0000644000015300001610000000246512564452056024373 0ustar pbuserpbgroup00000000000000cmake_minimum_required(VERSION 2.6) if(POLICY CMP0011) cmake_policy(SET CMP0011 NEW) endif(POLICY CMP0011) find_program(GDBUS_CODEGEN NAMES gdbus-codegen DOC "gdbus-codegen executable") if(NOT GDBUS_CODEGEN) message(FATAL_ERROR "Excutable gdbus-codegen not found") endif() macro(add_gdbus_codegen outfiles name prefix service_xml) add_custom_command( OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${name}.h" "${CMAKE_CURRENT_BINARY_DIR}/${name}.c" COMMAND "${GDBUS_CODEGEN}" --interface-prefix "${prefix}" --generate-c-code "${name}" "${service_xml}" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} DEPENDS ${ARGN} "${service_xml}" ) list(APPEND ${outfiles} "${CMAKE_CURRENT_BINARY_DIR}/${name}.c") endmacro(add_gdbus_codegen) macro(add_gdbus_codegen_with_namespace outfiles name prefix namespace service_xml) add_custom_command( OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${name}.h" "${CMAKE_CURRENT_BINARY_DIR}/${name}.c" COMMAND "${GDBUS_CODEGEN}" --interface-prefix "${prefix}" --generate-c-code "${name}" --c-namespace "${namespace}" "${service_xml}" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} DEPENDS ${ARGN} "${service_xml}" ) list(APPEND ${outfiles} "${CMAKE_CURRENT_BINARY_DIR}/${name}.c") endmacro(add_gdbus_codegen_with_namespace) ubuntu-app-launch-0.5+15.10.20150817/cmake/UseConstantBuilder.cmake0000644000015300001610000000123212564452056025131 0ustar pbuserpbgroup00000000000000cmake_minimum_required(VERSION 2.6) if(POLICY CMP0011) cmake_policy(SET CMP0011 NEW) endif(POLICY CMP0011) macro(add_constant_template outfiles name const_name input) set(file_target "${CMAKE_CURRENT_BINARY_DIR}/${name}.c") add_custom_command( OUTPUT ${file_target} COMMAND ${CMAKE_COMMAND} "-Dname=${name}" "-Dfile_target=${file_target}" "-Dconst_name=${const_name}" "-Dinput=${input}" -P "${CMAKE_SOURCE_DIR}/cmake/ConstantBuilderTemplates.cmake" DEPENDS "${CMAKE_SOURCE_DIR}/cmake/ConstantBuilderTemplates.cmake" "${input}" ) list(APPEND ${outfiles} "${file_target}") endmacro(add_constant_template) ubuntu-app-launch-0.5+15.10.20150817/cmake/ListOperations.cmake0000644000015300001610000000073512564452056024342 0ustar pbuserpbgroup00000000000000 macro(list_prefix _outvar _listvar _prefix) set(${_outvar}) foreach(_item IN LISTS ${_listvar}) list(APPEND ${_outvar} ${_prefix}${_item}) endforeach() endmacro(list_prefix) macro(list_make_absolute _outvar _listvar _prefix) set(${_outvar}) foreach(_item IN LISTS ${_listvar}) if(IS_ABSOLUTE ${_item}) list(APPEND ${_outvar} ${_item}) else() list(APPEND ${_outvar} ${_prefix}${_item}) endif() endforeach() endmacro(list_make_absolute) ubuntu-app-launch-0.5+15.10.20150817/cmake/UseGSettings.cmake0000644000015300001610000000371512564452056023750 0ustar pbuserpbgroup00000000000000# GSettings.cmake, CMake macros written for Marlin, feel free to re-use them. option (GSETTINGS_LOCALINSTALL "Install GSettings Schemas locally instead of to the GLib prefix" ${LOCAL_INSTALL}) option (GSETTINGS_COMPILE "Compile GSettings Schemas after installation" ${GSETTINGS_LOCALINSTALL}) if(GSETTINGS_LOCALINSTALL) message(STATUS "GSettings schemas will be installed locally.") endif() if(GSETTINGS_COMPILE) message(STATUS "GSettings shemas will be compiled.") endif() macro(add_schema SCHEMA_NAME) set(PKG_CONFIG_EXECUTABLE pkg-config) # Have an option to not install the schema into where GLib is if (GSETTINGS_LOCALINSTALL) SET (GSETTINGS_DIR "${CMAKE_INSTALL_PREFIX}/share/glib-2.0/schemas/") else (GSETTINGS_LOCALINSTALL) execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} glib-2.0 --variable prefix OUTPUT_VARIABLE _glib_prefix OUTPUT_STRIP_TRAILING_WHITESPACE) SET (GSETTINGS_DIR "${_glib_prefix}/share/glib-2.0/schemas/") endif (GSETTINGS_LOCALINSTALL) # Run the validator and error if it fails execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} gio-2.0 --variable glib_compile_schemas OUTPUT_VARIABLE _glib_comple_schemas OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process (COMMAND ${_glib_comple_schemas} --dry-run --schema-file=${CMAKE_CURRENT_SOURCE_DIR}/${SCHEMA_NAME} ERROR_VARIABLE _schemas_invalid OUTPUT_STRIP_TRAILING_WHITESPACE) if (_schemas_invalid) message (SEND_ERROR "Schema validation error: ${_schemas_invalid}") endif (_schemas_invalid) # Actually install and recomple schemas message (STATUS "GSettings schemas will be installed into ${GSETTINGS_DIR}") install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/${SCHEMA_NAME} DESTINATION ${GSETTINGS_DIR} OPTIONAL) if (GSETTINGS_COMPILE) install (CODE "message (STATUS \"Compiling GSettings schemas\")") install (CODE "execute_process (COMMAND ${_glib_comple_schemas} ${GSETTINGS_DIR})") endif () endmacro() ubuntu-app-launch-0.5+15.10.20150817/cmake/UseGObjectIntrospection.cmake0000644000015300001610000000751612564452056026142 0ustar pbuserpbgroup00000000000000# Copyright (C) 2010, Pino Toscano, # # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. include(ListOperations) macro(_gir_list_prefix _outvar _listvar _prefix) set(${_outvar}) foreach(_item IN LISTS ${_listvar}) list(APPEND ${_outvar} ${_prefix}${_item}) endforeach() endmacro(_gir_list_prefix) macro(gir_add_introspections introspections_girs) foreach(gir IN LISTS ${introspections_girs}) set(_gir_name "${gir}") ## Transform the gir filename to something which can reference through a variable ## without automake/make complaining, eg Gtk-2.0.gir -> Gtk_2_0_gir string(REPLACE "-" "_" _gir_name "${_gir_name}") string(REPLACE "." "_" _gir_name "${_gir_name}") # Namespace and Version is either fetched from the gir filename # or the _NAMESPACE/_VERSION variable combo set(_gir_namespace "${${_gir_name}_NAMESPACE}") if (_gir_namespace STREQUAL "") string(REGEX REPLACE "([^-]+)-.*" "\\1" _gir_namespace "${gir}") endif () set(_gir_version "${${_gir_name}_VERSION}") if (_gir_version STREQUAL "") string(REGEX REPLACE ".*-([^-]+).gir" "\\1" _gir_version "${gir}") endif () # _PROGRAM is an optional variable which needs it's own --program argument set(_gir_program "${${_gir_name}_PROGRAM}") if (NOT _gir_program STREQUAL "") set(_gir_program "--program=${_gir_program}") endif () # Variables which provides a list of things _gir_list_prefix(_gir_libraries ${_gir_name}_LIBS "--library=") _gir_list_prefix(_gir_packages ${_gir_name}_PACKAGES "--pkg=") _gir_list_prefix(_gir_includes ${_gir_name}_INCLUDES "--include=") _gir_list_prefix(_gir_export_packages ${_gir_name}_EXPORT_PACKAGES "--pkg-export=") # Reuse the LIBTOOL variable from by automake if it's set set(_gir_libtool "--no-libtool") add_custom_command( COMMAND ${INTROSPECTION_SCANNER} ${INTROSPECTION_SCANNER_ARGS} --quiet --warn-all --namespace=${_gir_namespace} --nsversion=${_gir_version} ${_gir_libtool} ${_gir_program} ${_gir_libraries} ${_gir_packages} ${_gir_includes} ${_gir_export_packages} ${${_gir_name}_SCANNERFLAGS} ${${_gir_name}_CFLAGS} ${${_gir_name}_FILES} --output ${CMAKE_CURRENT_BINARY_DIR}/${gir} DEPENDS ${${_gir_name}_FILES} ${${_gir_name}_LIBS} OUTPUT ${gir} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} VERBATIM ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${gir} DESTINATION share/gir-1.0) string(REPLACE ".gir" ".typelib" _typelib "${gir}") add_custom_command( COMMAND ${INTROSPECTION_COMPILER} ${INTROSPECTION_COMPILER_ARGS} --includedir=. ${CMAKE_CURRENT_BINARY_DIR}/${gir} -o ${CMAKE_CURRENT_BINARY_DIR}/${_typelib} DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${gir} OUTPUT ${_typelib} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${_typelib} DESTINATION ${CMAKE_INSTALL_LIBDIR}/girepository-1.0) add_custom_target(gir-${gir} ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${gir}) add_custom_target(gir-typelibs-${_typelib} ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_typelib}) endforeach() endmacro(gir_add_introspections) macro(gir_get_cflags _output) get_directory_property(_tmp_includes INCLUDE_DIRECTORIES) list_prefix(_includes _tmp_includes "-I") get_directory_property(_tmp_compile_definitions COMPILE_DEFINITIONS) list_prefix(_compile_definitions _tmp_compile_definitions "-D") set(${_output} ${_includes} ${_compile_definitions}) endmacro(gir_get_cflags) ubuntu-app-launch-0.5+15.10.20150817/cmake/UseGlibGeneration.cmake0000644000015300001610000000544512564452056024734 0ustar pbuserpbgroup00000000000000cmake_minimum_required(VERSION 2.6) if(POLICY CMP0011) cmake_policy(SET CMP0011 NEW) endif(POLICY CMP0011) find_program(GLIB_MKENUMS glib-mkenums) find_program(GLIB_GENMARSHAL glib-genmarshal) macro(add_glib_marshal outfiles name prefix otherinclude) add_custom_command( OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${name}.h" COMMAND ${GLIB_GENMARSHAL} --header "--prefix=${prefix}" "${CMAKE_CURRENT_SOURCE_DIR}/${name}.list" > "${CMAKE_CURRENT_BINARY_DIR}/${name}.h" DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${name}.list" ) add_custom_command( OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${name}.c" COMMAND echo "\\#include \\\"${otherinclude}\\\"" > "${CMAKE_CURRENT_BINARY_DIR}/${name}.c" COMMAND echo "\\#include \\\"glib-object.h\\\"" >> "${CMAKE_CURRENT_BINARY_DIR}/${name}.c" COMMAND echo "\\#include \\\"${name}.h\\\"" >> "${CMAKE_CURRENT_BINARY_DIR}/${name}.c" COMMAND ${GLIB_GENMARSHAL} --body "--prefix=${prefix}" "${CMAKE_CURRENT_SOURCE_DIR}/${name}.list" >> "${CMAKE_CURRENT_BINARY_DIR}/${name}.c" DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${name}.list" "${CMAKE_CURRENT_BINARY_DIR}/${name}.h" ) list(APPEND ${outfiles} "${CMAKE_CURRENT_BINARY_DIR}/${name}.c") endmacro(add_glib_marshal) macro(add_glib_enumtypes_t outfiles name htemplate ctemplate) add_custom_command( OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${name}.h" COMMAND ${GLIB_MKENUMS} --template "${htemplate}" ${ARGN} > "${CMAKE_CURRENT_BINARY_DIR}/${name}.h" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DEPENDS ${ARGN} "${htemplate}" ) add_custom_command( OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${name}.c" COMMAND ${GLIB_MKENUMS} --template "${ctemplate}" ${ARGN} > "${CMAKE_CURRENT_BINARY_DIR}/${name}.c" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DEPENDS ${ARGN} ${ctemplate} "${CMAKE_CURRENT_BINARY_DIR}/${name}.h" ) list(APPEND ${outfiles} "${CMAKE_CURRENT_BINARY_DIR}/${name}.c") endmacro(add_glib_enumtypes_t) macro(add_glib_enumtypes outfiles name namespace includeguard) set(htemplate "${CMAKE_CURRENT_BINARY_DIR}/${name}.h.template") set(ctemplate "${CMAKE_CURRENT_BINARY_DIR}/${name}.c.template") # Write the .h template add_custom_command( OUTPUT ${htemplate} ${ctemplate} COMMAND ${CMAKE_COMMAND} "-Dctemplate=${ctemplate}" "-Dhtemplate=${htemplate}" "-Dname=${name}" "-Dnamespace=${namespace}" "-Dincludeguard=${includeguard}" "\"-Dheaders=${ARGN}\"" -P "${CMAKE_SOURCE_DIR}/cmake/GlibGenerationTemplates.cmake" DEPENDS "${CMAKE_SOURCE_DIR}/cmake/GlibGenerationTemplates.cmake" ${headers} ) add_glib_enumtypes_t(${outfiles} ${name} ${htemplate} ${ctemplate} ${ARGN}) endmacro(add_glib_enumtypes) ubuntu-app-launch-0.5+15.10.20150817/cmake/UseLttngGenTp.cmake0000644000015300001610000000133212564452056024060 0ustar pbuserpbgroup00000000000000cmake_minimum_required(VERSION 2.6) if(POLICY CMP0011) cmake_policy(SET CMP0011 NEW) endif(POLICY CMP0011) find_program(LTTNG_GEN_TP NAMES lttng-gen-tp DOC "lttng-gen-tp executable") if(NOT LTTNG_GEN_TP) message(FATAL_ERROR "Excutable lttng-gen-top not found") endif() function(add_lttng_gen_tp) set(_one_value NAME) cmake_parse_arguments (arg "" "${_one_value}" "" ${ARGN}) add_custom_command( OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${arg_NAME}.h" "${CMAKE_CURRENT_BINARY_DIR}/${arg_NAME}.c" COMMAND "${LTTNG_GEN_TP}" -o "${arg_NAME}.h" -o "${arg_NAME}.c" "${CMAKE_CURRENT_SOURCE_DIR}/${arg_NAME}.tp" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} DEPENDS "${arg_NAME}.tp" ) endfunction(add_lttng_gen_tp) ubuntu-app-launch-0.5+15.10.20150817/cmake/Coverage.cmake0000644000015300001610000000414612564452056023116 0ustar pbuserpbgroup00000000000000if (CMAKE_BUILD_TYPE MATCHES coverage) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage") set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} --coverage") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage") find_program(GCOVR_EXECUTABLE gcovr HINTS ${GCOVR_ROOT} "${GCOVR_ROOT}/bin") if (NOT GCOVR_EXECUTABLE) message(STATUS "Gcovr binary was not found, can not generate XML coverage info.") else () message(STATUS "Gcovr found, can generate XML coverage info.") add_custom_target (coverage-xml WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND "${GCOVR_EXECUTABLE}" --exclude="test.*" --exclude="obj.*" -x -r "${CMAKE_SOURCE_DIR}" --object-directory=${CMAKE_BINARY_DIR} -o coverage.xml) endif() find_program(LCOV_EXECUTABLE lcov HINTS ${LCOV_ROOT} "${GCOVR_ROOT}/bin") find_program(GENHTML_EXECUTABLE genhtml HINTS ${GENHTML_ROOT}) if (NOT LCOV_EXECUTABLE) message(STATUS "Lcov binary was not found, can not generate HTML coverage info.") else () if(NOT GENHTML_EXECUTABLE) message(STATUS "Genthml binary not found, can not generate HTML coverage info.") else() message(STATUS "Lcov and genhtml found, can generate HTML coverage info.") add_custom_target (coverage-html WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND "${LCOV_EXECUTABLE}" --directory ${CMAKE_BINARY_DIR} --capture --output-file coverage.info --no-checksum COMMAND "${LCOV_EXECUTABLE}" --remove "${CMAKE_BINARY_DIR}/coverage.info" '/usr/*' --output-file "${CMAKE_BINARY_DIR}/coverage.info" COMMAND "${LCOV_EXECUTABLE}" --remove "${CMAKE_BINARY_DIR}/coverage.info" '${CMAKE_BINARY_DIR}/*' --output-file "${CMAKE_BINARY_DIR}/coverage.info" COMMAND "${LCOV_EXECUTABLE}" --remove "${CMAKE_BINARY_DIR}/coverage.info" '${CMAKE_SOURCE_DIR}/tests/*' --output-file "${CMAKE_BINARY_DIR}/coverage.info" COMMAND "${GENHTML_EXECUTABLE}" --prefix ${CMAKE_BINARY_DIR} --output-directory coveragereport --title "Code Coverage" --legend --show-details coverage.info ) endif() endif() endif() ubuntu-app-launch-0.5+15.10.20150817/cmake/FindGObjectIntrospection.cmake0000644000015300001610000000376512564452056026270 0ustar pbuserpbgroup00000000000000# - try to find gobject-introspection # # Once done this will define # # INTROSPECTION_FOUND - system has gobject-introspection # INTROSPECTION_SCANNER - the gobject-introspection scanner, g-ir-scanner # INTROSPECTION_COMPILER - the gobject-introspection compiler, g-ir-compiler # INTROSPECTION_GENERATE - the gobject-introspection generate, g-ir-generate # INTROSPECTION_GIRDIR # INTROSPECTION_TYPELIBDIR # INTROSPECTION_CFLAGS # INTROSPECTION_LIBS # # Copyright (C) 2010, Pino Toscano, # # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. macro(_GIR_GET_PKGCONFIG_VAR _outvar _varname) execute_process( COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=${_varname} gobject-introspection-1.0 OUTPUT_VARIABLE _result RESULT_VARIABLE _null ) if (_null) else() string(REGEX REPLACE "[\r\n]" " " _result "${_result}") string(REGEX REPLACE " +$" "" _result "${_result}") separate_arguments(_result) set(${_outvar} ${_result} CACHE INTERNAL "") endif() endmacro(_GIR_GET_PKGCONFIG_VAR) find_package(PkgConfig) if(PKG_CONFIG_FOUND) if(PACKAGE_FIND_VERSION_COUNT GREATER 0) set(_gir_version_cmp ">=${PACKAGE_FIND_VERSION}") endif() pkg_check_modules(_pc_gir gobject-introspection-1.0${_gir_version_cmp}) if(_pc_gir_FOUND) set(INTROSPECTION_FOUND TRUE) _gir_get_pkgconfig_var(INTROSPECTION_SCANNER "g_ir_scanner") _gir_get_pkgconfig_var(INTROSPECTION_COMPILER "g_ir_compiler") _gir_get_pkgconfig_var(INTROSPECTION_GENERATE "g_ir_generate") _gir_get_pkgconfig_var(INTROSPECTION_GIRDIR "girdir") _gir_get_pkgconfig_var(INTROSPECTION_TYPELIBDIR "typelibdir") set(INTROSPECTION_CFLAGS "${_pc_gir_CFLAGS}") set(INTROSPECTION_LIBS "${_pc_gir_LIBS}") endif() endif() mark_as_advanced( INTROSPECTION_SCANNER INTROSPECTION_COMPILER INTROSPECTION_GENERATE INTROSPECTION_GIRDIR INTROSPECTION_TYPELIBDIR INTROSPECTION_CFLAGS INTROSPECTION_LIBS ) ubuntu-app-launch-0.5+15.10.20150817/upstart-jobs/0000755000015300001610000000000012564452317021731 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/upstart-jobs/untrusted-helper-logrotate.conf0000644000015300001610000000047112564452056030112 0ustar pbuserpbgroup00000000000000description "Untrusted Helper Logs need a shorter lifecycle" # Run after log rotate start on stopped logrotate script logdir=${XDG_CACHE_HOME:-$HOME/.cache}/upstart # # If a log is older than two days we're clearing it # find ${logdir} -mtime +2 -name "untrusted-helper-*.log.[1-9].gz" -delete end script ubuntu-app-launch-0.5+15.10.20150817/upstart-jobs/untrusted-helper-type-end.conf.in0000644000015300001610000000034512564452056030244 0ustar pbuserpbgroup00000000000000description "End all untrusted helpers of a particular type, usually when the manager ends" start on untrusted-helper-type-end instance ${HELPER_TYPE} emits untrusted-helper-end exec @pkglibexecdir@/untrusted-helper-type-end ubuntu-app-launch-0.5+15.10.20150817/upstart-jobs/application-legacy.conf.in0000644000015300001610000000175312564452110026747 0ustar pbuserpbgroup00000000000000description "Application Launching for Legacy Applications" author "Ted Gould " instance ${APP_ID}-${INSTANCE_ID} start on application-legacy-start stop on application-end or desktop-end env APP_ID env APP_EXEC env APP_EXEC_POLICY="" env APP_URIS env APP_DESKTOP_FILE_PATH env APP_XMIR_ENABLE # This will be set to "unconfined" by desktop-exec if there is no confinement defined apparmor switch $APP_EXEC_POLICY cgroup freezer # Initial OOM Score oom score 110 # This could be confined exec @pkglibexecdir@/exec-line-exec post-start exec @pkglibexecdir@/zg-report-app open post-stop script @pkglibexecdir@/zg-report-app close @pkglibexecdir@/cgroup-reap-all DEVELOPER_MODE=`gdbus call --system --dest com.canonical.PropertyService --object-path /com/canonical/PropertyService --method com.canonical.PropertyService.GetProperty adb` if [ "$DEVELOPER_MODE" != "(true,)" ] ; then rm -f ${HOME}/.cache/upstart/application-legacy-${APP_ID}-${INSTANCE_ID}.log* fi end script ubuntu-app-launch-0.5+15.10.20150817/upstart-jobs/application.conf.in0000644000015300001610000000052312564452056025510 0ustar pbuserpbgroup00000000000000description "Application Launching Wrapper" author "Ted Gould " start on application-start task # Events aren't emitted directly, but start is used to create them emits application-legacy-start emits application-click-start env APP_ID export APP_ID env APP_URIS export APP_URIS exec @pkglibexecdir@/application-job ubuntu-app-launch-0.5+15.10.20150817/upstart-jobs/application-failed.conf.in0000644000015300001610000000025612564452056026735 0ustar pbuserpbgroup00000000000000description "Application Failing" start on stopped application-legacy RESULT=failed or stopped application-click RESULT=failed task exec @pkglibexecdir@/application-failed ubuntu-app-launch-0.5+15.10.20150817/upstart-jobs/application-logrotate.conf0000644000015300001610000000060112564452056027076 0ustar pbuserpbgroup00000000000000description "Application Logs need a shorter lifecycle" # Run after log rotate start on stopped logrotate script logdir=${XDG_CACHE_HOME:-$HOME/.cache}/upstart # # If a log is older than two days we're clearing it # find ${logdir} -mtime +2 -name "application-click-*.log.[1-9].gz" -delete find ${logdir} -mtime +2 -name "application-legacy-*.log.[1-9].gz" -delete end script ubuntu-app-launch-0.5+15.10.20150817/upstart-jobs/application-click.conf.in0000644000015300001610000000167312564452110026571 0ustar pbuserpbgroup00000000000000description "Application Launching for Click Applications" author "Ted Gould " instance ${APP_ID} start on application-click-start stop on application-end or desktop-end env APP_ID env APP_EXEC env APP_URIS env APP_DIR env APP_DESKTOP_FILE_PATH env APP_XMIR_ENABLE env UBUNTU_APP_LAUNCH_ARCH="@ubuntu_app_launch_arch@" export UBUNTU_APP_LAUNCH_ARCH apparmor switch ${APP_ID} cgroup freezer # Initial OOM Score oom score 100 # Remember, this is confined exec @pkglibexecdir@/exec-line-exec post-start exec @pkglibexecdir@/zg-report-app open post-stop script @pkglibexecdir@/zg-report-app close @pkglibexecdir@/cgroup-reap-all DEVELOPER_MODE=`gdbus call --system --dest com.canonical.PropertyService --object-path /com/canonical/PropertyService --method com.canonical.PropertyService.GetProperty adb` if [ "$DEVELOPER_MODE" != "(true,)" ] ; then rm -f ${HOME}/.cache/upstart/application-click-${APP_ID}.log* fi end script ubuntu-app-launch-0.5+15.10.20150817/upstart-jobs/CMakeLists.txt0000644000015300001610000000632112564452056024473 0ustar pbuserpbgroup00000000000000 #################### # application.conf #################### configure_file("application.conf.in" "${CMAKE_CURRENT_BINARY_DIR}/application.conf" @ONLY) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/application.conf" DESTINATION "${CMAKE_INSTALL_DATADIR}/upstart/sessions") add_test(application.conf.test "${CMAKE_CURRENT_SOURCE_DIR}/test-conffile.sh" "${CMAKE_CURRENT_BINARY_DIR}/application.conf") #################### # application-legacy.conf #################### configure_file("application-legacy.conf.in" "${CMAKE_CURRENT_BINARY_DIR}/application-legacy.conf" @ONLY) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/application-legacy.conf" DESTINATION "${CMAKE_INSTALL_DATADIR}/upstart/sessions") add_test(application-legacy.conf.test "${CMAKE_CURRENT_SOURCE_DIR}/test-conffile.sh" "${CMAKE_CURRENT_BINARY_DIR}/application-legacy.conf") #################### # application-click.conf #################### configure_file("application-click.conf.in" "${CMAKE_CURRENT_BINARY_DIR}/application-click.conf" @ONLY) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/application-click.conf" DESTINATION "${CMAKE_INSTALL_DATADIR}/upstart/sessions") add_test(application-click.conf.test "${CMAKE_CURRENT_SOURCE_DIR}/test-conffile.sh" "${CMAKE_CURRENT_BINARY_DIR}/application-click.conf") #################### # application-failed.conf #################### configure_file("application-failed.conf.in" "${CMAKE_CURRENT_BINARY_DIR}/application-failed.conf" @ONLY) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/application-failed.conf" DESTINATION "${CMAKE_INSTALL_DATADIR}/upstart/sessions") add_test(application-failed.conf.test "${CMAKE_CURRENT_SOURCE_DIR}/test-conffile.sh" "${CMAKE_CURRENT_BINARY_DIR}/application-failed.conf") #################### # application-logrotate.conf #################### install(FILES "application-logrotate.conf" DESTINATION "${CMAKE_INSTALL_DATADIR}/upstart/sessions") add_test(application-logrotate.conf.test "${CMAKE_CURRENT_SOURCE_DIR}/test-conffile.sh" "${CMAKE_CURRENT_SOURCE_DIR}/application-logrotate.conf") #################### # untrusted-helper.conf #################### configure_file("untrusted-helper.conf.in" "${CMAKE_CURRENT_BINARY_DIR}/untrusted-helper.conf" @ONLY) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/untrusted-helper.conf" DESTINATION "${CMAKE_INSTALL_DATADIR}/upstart/sessions") add_test(untrusted-helper.conf.test "${CMAKE_CURRENT_SOURCE_DIR}/test-conffile.sh" "${CMAKE_CURRENT_BINARY_DIR}/untrusted-helper.conf") #################### # untrusted-helper-type-end.conf #################### configure_file("untrusted-helper-type-end.conf.in" "${CMAKE_CURRENT_BINARY_DIR}/untrusted-helper-type-end.conf" @ONLY) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/untrusted-helper-type-end.conf" DESTINATION "${CMAKE_INSTALL_DATADIR}/upstart/sessions") add_test(untrusted-helper-type-end.conf.test "${CMAKE_CURRENT_SOURCE_DIR}/test-conffile.sh" "${CMAKE_CURRENT_BINARY_DIR}/untrusted-helper-type-end.conf") #################### # untrusted-helper-logrotate.conf #################### install(FILES "untrusted-helper-logrotate.conf" DESTINATION "${CMAKE_INSTALL_DATADIR}/upstart/sessions") add_test(untrusted-helper-logrotate.conf.test "${CMAKE_CURRENT_SOURCE_DIR}/test-conffile.sh" "${CMAKE_CURRENT_SOURCE_DIR}/untrusted-helper-logrotate.conf") ubuntu-app-launch-0.5+15.10.20150817/upstart-jobs/untrusted-helper.conf.in0000644000015300001610000000136512564452056026524 0ustar pbuserpbgroup00000000000000description "Untrusted Helpers installed from Click Packages" start on untrusted-helper-start stop on untrusted-helper-end or desktop-end instance ${HELPER_TYPE}:${INSTANCE_ID}:${APP_ID} env APP_ID env APP_EXEC="echo Error" env HELPER_TYPE env INSTANCE_ID="" env APP_URIS env UBUNTU_APP_LAUNCH_ARCH="@ubuntu_app_launch_arch@" export UBUNTU_APP_LAUNCH_ARCH apparmor switch ${APP_ID} cgroup freezer oom score 800 # This is unconfined pre-start script if [ -x "@pkglibexecdir@/${HELPER_TYPE}/exec-tool" ] ; then @pkglibexecdir@/${HELPER_TYPE}/exec-tool else echo "Unable to find exec tool for ${HELPER_TYPE}" exit -1 fi end script # Remember, this is confined exec @pkglibexecdir@/exec-line-exec post-stop exec @pkglibexecdir@/cgroup-reap-all ubuntu-app-launch-0.5+15.10.20150817/upstart-jobs/test-conffile.sh0000755000015300001610000000063612564452056025037 0ustar pbuserpbgroup00000000000000#!/bin/bash UPSTARTVERSION=`initctl version | sed 's/[[:alpha:]\)|(|[:space:]]//g' | awk -F- '{print $1}' | awk -F. '{print $2}'` # Only test on newer versions of Upstart, like not the # versions on the builders if [ ${UPSTARTVERSION} -gt 7 ] ; then dbus-test-runner --task init-checkconf --parameter "$1" --task-name init-checkconf else echo "Upstart Version: $UPSTARTVERSION" echo " ....Skipping Tests" fi ubuntu-app-launch-0.5+15.10.20150817/application-job.c0000644000015300001610000000642012564452056022515 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include #include "libubuntu-app-launch/ubuntu-app-launch.h" int retval = 0; const gchar * global_appid; static void app_started (const gchar * appid, gpointer user_data) { if (g_strcmp0(appid, global_appid) != 0) return; g_debug("Application Started: %s", appid); g_main_loop_quit((GMainLoop *)user_data); } static void app_focus (const gchar * appid, gpointer user_data) { if (g_strcmp0(appid, global_appid) != 0) return; g_debug("Application Focused"); g_main_loop_quit((GMainLoop *)user_data); } static void app_failed (const gchar * appid, UbuntuAppLaunchAppFailed failure_type, gpointer user_data) { if (g_strcmp0(appid, global_appid) != 0) return; g_warning("Application Startup Failed"); retval = 1; g_main_loop_quit((GMainLoop *)user_data); } /* A fallback so that we can see what is going on. The job can not always signal that it has been started, and thus we wouldn't quit. Which would be a bad thing. */ static gboolean timeout_check (gpointer user_data) { g_debug("Timeout reached"); g_main_loop_quit((GMainLoop *)user_data); return TRUE; /* Keep the source connected to avoid the disconnect error */ } int main (int argc, char * argv[]) { GDBusConnection * con = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); g_return_val_if_fail(con != NULL, 1); global_appid = g_getenv("APP_ID"); g_return_val_if_fail(global_appid != NULL, 1); const gchar * uris_str = g_getenv("APP_URIS"); gchar ** uris = NULL; if (uris_str != NULL) { GError * error = NULL; gint uri_count = 0; g_shell_parse_argv(uris_str, &uri_count, &uris, &error); if (error != NULL) { g_warning("Unable to parse uris '%s': %s", uris_str, error->message); g_error_free(error); } else { g_debug("Got %d URIs", uri_count); } } GMainLoop * mainloop = g_main_loop_new(NULL, FALSE); ubuntu_app_launch_observer_add_app_started(app_started, mainloop); ubuntu_app_launch_observer_add_app_focus(app_focus, mainloop); ubuntu_app_launch_observer_add_app_failed(app_failed, mainloop); guint timer = g_timeout_add_seconds(1, timeout_check, mainloop); g_debug("Start Application: %s", global_appid); g_return_val_if_fail(ubuntu_app_launch_start_application(global_appid, (const gchar * const *)uris), -1); g_strfreev(uris); g_debug("Wait for results"); g_main_loop_run(mainloop); g_source_remove(timer); ubuntu_app_launch_observer_delete_app_started(app_started, mainloop); ubuntu_app_launch_observer_delete_app_focus(app_focus, mainloop); ubuntu_app_launch_observer_delete_app_failed(app_failed, mainloop); g_main_loop_unref(mainloop); g_object_unref(con); return retval; } ubuntu-app-launch-0.5+15.10.20150817/COPYING0000644000015300001610000010451312564452056020333 0ustar pbuserpbgroup00000000000000 GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . ubuntu-app-launch-0.5+15.10.20150817/helpers.c0000644000015300001610000004356112564452056021113 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include #include #include #include "helpers.h" /* Take an app ID and validate it and then break it up and spit it out. These are newly allocated strings */ gboolean app_id_to_triplet (const gchar * app_id, gchar ** package, gchar ** application, gchar ** version) { /* 'Parse' the App ID */ gchar ** app_id_segments = g_strsplit(app_id, "_", 4); if (g_strv_length(app_id_segments) != 3) { g_debug("Unable to parse Application ID: %s", app_id); g_strfreev(app_id_segments); return FALSE; } if (package != NULL) { *package = app_id_segments[0]; } else { g_free(app_id_segments[0]); } if (application != NULL) { *application = app_id_segments[1]; } else { g_free(app_id_segments[1]); } if (version != NULL) { *version = app_id_segments[2]; } else { g_free(app_id_segments[2]); } g_free(app_id_segments); return TRUE; } /* Take a manifest, parse it, find the application and and then return the path to the desktop file */ gchar * manifest_to_desktop (const gchar * app_dir, const gchar * app_id) { gchar * package = NULL; gchar * application = NULL; gchar * version = NULL; ClickDB * db = NULL; ClickUser * user = NULL; JsonObject * manifest = NULL; gchar * desktoppath = NULL; GError * error = NULL; if (!app_id_to_triplet(app_id, &package, &application, &version)) { g_warning("Unable to parse triplet: %s", app_id); return NULL; } db = click_db_new(); /* If TEST_CLICK_DB is unset, this reads the system database. */ click_db_read(db, g_getenv("TEST_CLICK_DB"), &error); if (error != NULL) { g_warning("Unable to read Click database: %s", error->message); goto manifest_out; } /* If TEST_CLICK_USER is unset, this uses the current user name. */ user = click_user_new_for_user(db, g_getenv("TEST_CLICK_USER"), &error); if (error != NULL) { g_warning("Unable to read Click database: %s", error->message); goto manifest_out; } manifest = click_user_get_manifest(user, package, &error); if (error != NULL) { g_warning("Unable to get manifest for '%s': %s", package, error->message); goto manifest_out; } if (!json_object_has_member(manifest, "version")) { g_warning("Manifest '%s' doesn't have a version", package); goto manifest_out; } if (g_strcmp0(json_object_get_string_member(manifest, "version"), version) != 0) { g_warning("Manifest '%s' version '%s' doesn't match AppID version '%s'", package, json_object_get_string_member(manifest, "version"), version); goto manifest_out; } if (!json_object_has_member(manifest, "hooks")) { g_warning("Manifest '%s' doesn't have an hooks section", package); goto manifest_out; } JsonObject * appsobj = json_object_get_object_member(manifest, "hooks"); if (appsobj == NULL) { g_warning("Manifest '%s' has an hooks section that is not a JSON object", package); goto manifest_out; } if (!json_object_has_member(appsobj, application)) { g_warning("Manifest '%s' doesn't have the application '%s' defined", package, application); goto manifest_out; } JsonObject * appobj = json_object_get_object_member(appsobj, application); if (appobj == NULL) { g_warning("Manifest '%s' has a definition for application '%s' that is not an object", package, application); goto manifest_out; } gchar * filename = NULL; if (json_object_has_member(appobj, "desktop")) { filename = g_strdup(json_object_get_string_member(appobj, "desktop")); } else { filename = g_strdup_printf("%s.desktop", application); } desktoppath = g_build_filename(app_dir, filename, NULL); g_free(filename); if (!g_file_test(desktoppath, G_FILE_TEST_EXISTS)) { g_warning("Application desktop file '%s' doesn't exist", desktoppath); g_free(desktoppath); desktoppath = NULL; } manifest_out: if (error != NULL) g_error_free(error); if (manifest != NULL) json_object_unref(manifest); g_clear_object(&user); g_clear_object(&db); g_free(package); g_free(application); g_free(version); return desktoppath; } /* Take a desktop file, make sure that it makes sense and then return the exec line */ gchar * desktop_to_exec (GKeyFile * desktop_file, const gchar * from) { GError * error = NULL; if (!g_key_file_has_group(desktop_file, "Desktop Entry")) { g_warning("Desktop file '%s' does not have a 'Desktop Entry' group", from); return NULL; } gchar * type = g_key_file_get_string(desktop_file, "Desktop Entry", "Type", &error); if (error != NULL) { g_warning("Desktop file '%s' unable to get type: %s", from, error->message); g_error_free(error); g_free(type); return NULL; } if (g_strcmp0(type, "Application") != 0) { g_warning("Desktop file '%s' has a type of '%s' instead of 'Application'", from, type); g_free(type); return NULL; } g_free(type); if (g_key_file_has_key(desktop_file, "Desktop Entry", "NoDisplay", NULL)) { gboolean nodisplay = g_key_file_get_boolean(desktop_file, "Desktop Entry", "NoDisplay", NULL); if (nodisplay) { g_warning("Desktop file '%s' is set to not display, not copying", from); return NULL; } } if (g_key_file_has_key(desktop_file, "Desktop Entry", "Hidden", NULL)) { gboolean hidden = g_key_file_get_boolean(desktop_file, "Desktop Entry", "Hidden", NULL); if (hidden) { g_warning("Desktop file '%s' is set to be hidden, not copying", from); return NULL; } } if (g_key_file_has_key(desktop_file, "Desktop Entry", "Terminal", NULL)) { gboolean terminal = g_key_file_get_boolean(desktop_file, "Desktop Entry", "Terminal", NULL); if (terminal) { g_warning("Desktop file '%s' is set to run in a terminal, not copying", from); return NULL; } } if (!g_key_file_has_key(desktop_file, "Desktop Entry", "Exec", NULL)) { g_warning("Desktop file '%s' has no 'Exec' key", from); return NULL; } gchar * exec = g_key_file_get_string(desktop_file, "Desktop Entry", "Exec", NULL); return exec; } /* Convert a URI into a file */ static gchar * uri2file (const gchar * uri) { GError * error = NULL; gchar * retval = g_filename_from_uri(uri, NULL, &error); if (error != NULL) { g_warning("Unable to resolve '%s' to a filename: %s", uri, error->message); g_error_free(error); } if (retval == NULL) { retval = g_strdup(""); } g_debug("Converting URI '%s' to file '%s'", uri, retval); return retval; } /* Put the list of files into the argument array */ static inline void file_list_handling (GArray * outarray, gchar ** list, gchar * (*dup_func) (const gchar * in)) { /* No URLs, cool, this is a noop */ if (list == NULL || list[0] == NULL) { return; } int i; for (i = 0; list[i] != NULL; i++) { gchar * entry = dup_func(list[i]); /* No NULLs */ if (entry != NULL && entry[0] != '\0') { g_array_append_val(outarray, entry); } else { g_free(entry); } } } /* Parse a desktop exec line and return the next string */ static void desktop_exec_segment_parse (GArray * finalarray, const gchar * execsegment, gchar ** uri_list) { /* No NULL strings */ if (execsegment == NULL || execsegment[0] == '\0') return; /* Handle %F and %U as an argument on their own as per the spec */ if (g_strcmp0(execsegment, "%U") == 0) { return file_list_handling(finalarray, uri_list, g_strdup); } if (g_strcmp0(execsegment, "%F") == 0) { return file_list_handling(finalarray, uri_list, uri2file); } /* Start looking at individual codes */ gchar ** execsplit = g_strsplit(execsegment, "%", 0); /* If we didn't have any codes, just exit here */ if (execsplit[1] == NULL) { g_strfreev(execsplit); gchar * dup = g_strdup(execsegment); g_array_append_val(finalarray, dup); return; } int i; gboolean previous_percent = FALSE; GArray * outarray = g_array_new(TRUE, FALSE, sizeof(const gchar *)); g_array_append_val(outarray, execsplit[0]); gchar * single_file = NULL; /* The variables allowed in an exec line from the Freedesktop.org Desktop File specification: http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#exec-variables */ for (i = 1; execsplit[i] != NULL; i++) { const gchar * skipchar = &(execsplit[i][1]); /* Handle the case of %%F printing "%F" */ if (previous_percent) { g_array_append_val(outarray, execsplit[i]); previous_percent = FALSE; continue; } switch (execsplit[i][0]) { case '\0': { const gchar * percent = "%"; g_array_append_val(outarray, percent); /* %% is the literal */ previous_percent = TRUE; break; } case 'd': case 'D': case 'n': case 'N': case 'v': case 'm': /* Deprecated */ g_array_append_val(outarray, skipchar); break; case 'f': if (uri_list != NULL && uri_list[0] != NULL) { if (single_file == NULL) single_file = uri2file(uri_list[0]); g_array_append_val(outarray, single_file); } g_array_append_val(outarray, skipchar); break; case 'F': g_warning("Exec line segment has a '%%F' that isn't its own argument '%s', ignoring.", execsegment); g_array_append_val(outarray, skipchar); break; case 'i': case 'c': case 'k': /* Perhaps? Not sure anyone uses these */ g_array_append_val(outarray, skipchar); break; case 'U': g_warning("Exec line segment has a '%%U' that isn't its own argument '%s', ignoring.", execsegment); g_array_append_val(outarray, skipchar); break; case 'u': if (uri_list != NULL && uri_list[0] != NULL) { g_array_append_val(outarray, uri_list[0]); } g_array_append_val(outarray, skipchar); break; default: g_warning("Desktop Exec line code '%%%c' unknown, skipping.", execsplit[i][0]); g_array_append_val(outarray, skipchar); break; } } gchar * output = g_strjoinv(NULL, (gchar **)outarray->data); g_array_free(outarray, TRUE); if (output != NULL && output[0] != '\0') { g_array_append_val(finalarray, output); } else { g_free(output); } g_free(single_file); g_strfreev(execsplit); } /* Take a full exec line, split it out, parse the segments and return it to the caller */ GArray * desktop_exec_parse (const gchar * execline, const gchar * urilist) { GError * error = NULL; gchar ** splitexec = NULL; gchar ** splituris = NULL; gint execitems = 0; /* This returns from desktop file style quoting to straight strings with the appropriate characters split by the spaces that were meant for splitting. Trickier than it sounds. But now we should be able to assume that each string in the array is expected to be its own parameter. */ g_shell_parse_argv(execline, &execitems, &splitexec, &error); if (error != NULL) { g_warning("Unable to parse exec line '%s': %s", execline, error->message); g_error_free(error); return NULL; } if (urilist != NULL && urilist[0] != '\0') { g_shell_parse_argv(urilist, NULL, &splituris, &error); if (error != NULL) { g_warning("Unable to parse URIs '%s': %s", urilist, error->message); g_error_free(error); /* Continuing without URIs */ splituris = NULL; } } GArray * newargv = g_array_new(TRUE, FALSE, sizeof(gchar *)); int i; for (i = 0; i < execitems; i++) { desktop_exec_segment_parse(newargv, splitexec[i], splituris); } g_strfreev(splitexec); if (splituris != NULL) { g_strfreev(splituris); } /* Each string here should be its own param */ return newargv; } /* Set environment various variables to make apps work under * confinement according to: * https://wiki.ubuntu.com/SecurityTeam/Specifications/ApplicationConfinement */ void set_confined_envvars (EnvHandle * handle, const gchar * package, const gchar * app_dir) { g_return_if_fail(package != NULL); g_return_if_fail(app_dir != NULL); g_debug("Setting 'UBUNTU_APPLICATION_ISOLATION' to '1'"); env_handle_add(handle, "UBUNTU_APPLICATION_ISOLATION", "1"); /* Make sure the XDG base dirs are set for the application using * the user's current values/system defaults. We could set these to * what is expected in the AppArmor profile, but that might be too * brittle if someone uses different base dirs. */ g_debug("Setting 'XDG_CACHE_HOME' using g_get_user_cache_dir()"); env_handle_add(handle, "XDG_CACHE_HOME", g_get_user_cache_dir()); g_debug("Setting 'XDG_CONFIG_HOME' using g_get_user_config_dir()"); env_handle_add(handle, "XDG_CONFIG_HOME", g_get_user_config_dir()); g_debug("Setting 'XDG_DATA_HOME' using g_get_user_data_dir()"); env_handle_add(handle, "XDG_DATA_HOME", g_get_user_data_dir()); g_debug("Setting 'XDG_RUNTIME_DIR' using g_get_user_runtime_dir()"); env_handle_add(handle, "XDG_RUNTIME_DIR", g_get_user_runtime_dir()); /* Add the application's dir to the list of sources for data */ gchar * datadirs = g_strjoin(":", app_dir, g_getenv("XDG_DATA_DIRS"), NULL); env_handle_add(handle, "XDG_DATA_DIRS", datadirs); g_free(datadirs); /* Set TMPDIR to something sane and application-specific */ gchar * tmpdir = g_strdup_printf("%s/confined/%s", g_get_user_runtime_dir(), package); g_debug("Setting 'TMPDIR' to '%s'", tmpdir); env_handle_add(handle, "TMPDIR", tmpdir); g_debug("Creating '%s'", tmpdir); g_mkdir_with_parents(tmpdir, 0700); g_free(tmpdir); /* Do the same for nvidia */ gchar * nv_shader_cachedir = g_strdup_printf("%s/%s", g_get_user_cache_dir(), package); g_debug("Setting '__GL_SHADER_DISK_CACHE_PATH' to '%s'", nv_shader_cachedir); env_handle_add(handle, "__GL_SHADER_DISK_CACHE_PATH", nv_shader_cachedir); g_free(nv_shader_cachedir); return; } static void unity_signal_cb (GDBusConnection * con, const gchar * sender, const gchar * path, const gchar * interface, const gchar * signal, GVariant * params, gpointer user_data) { GMainLoop * mainloop = (GMainLoop *)user_data; g_main_loop_quit(mainloop); } struct _handshake_t { GDBusConnection * con; GMainLoop * mainloop; guint signal_subscribe; guint timeout; }; static gboolean unity_too_slow_cb (gpointer user_data) { handshake_t * handshake = (handshake_t *)user_data; g_main_loop_quit(handshake->mainloop); handshake->timeout = 0; return G_SOURCE_REMOVE; } handshake_t * starting_handshake_start (const gchar * app_id) { GError * error = NULL; handshake_t * handshake = g_new0(handshake_t, 1); handshake->mainloop = g_main_loop_new(NULL, FALSE); handshake->con = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error); if (error != NULL) { g_critical("Unable to connect to session bus: %s", error->message); g_error_free(error); g_free(handshake); return NULL; } /* Set up listening for the unfrozen signal from Unity */ handshake->signal_subscribe = g_dbus_connection_signal_subscribe(handshake->con, NULL, /* sender */ "com.canonical.UbuntuAppLaunch", /* interface */ "UnityStartingSignal", /* signal */ "/", /* path */ app_id, /* arg0 */ G_DBUS_SIGNAL_FLAGS_NONE, unity_signal_cb, handshake->mainloop, NULL); /* user data destroy */ /* Send unfreeze to to Unity */ g_dbus_connection_emit_signal(handshake->con, NULL, /* destination */ "/", /* path */ "com.canonical.UbuntuAppLaunch", /* interface */ "UnityStartingBroadcast", /* signal */ g_variant_new("(s)", app_id), &error); /* Really, Unity? */ handshake->timeout = g_timeout_add_seconds(1, unity_too_slow_cb, handshake); return handshake; } void starting_handshake_wait (handshake_t * handshake) { if (handshake == NULL) return; g_main_loop_run(handshake->mainloop); if (handshake->timeout != 0) g_source_remove(handshake->timeout); g_main_loop_unref(handshake->mainloop); g_dbus_connection_signal_unsubscribe(handshake->con, handshake->signal_subscribe); g_object_unref(handshake->con); g_free(handshake); } EnvHandle * env_handle_start (void) { GVariantBuilder * builder = g_variant_builder_new(G_VARIANT_TYPE_ARRAY); return (EnvHandle *)builder; } void env_handle_add (EnvHandle * handle, const gchar * variable, const gchar * value) { g_return_if_fail(handle != NULL); gchar * combinedstr = g_strdup_printf("%s=%s", variable, value); GVariant * env = g_variant_new_take_string(combinedstr); g_variant_builder_add_value((GVariantBuilder*)handle, env); } void env_handle_finish (EnvHandle * handle) { g_return_if_fail(handle != NULL); /* Check to see if we can get the job environment */ const gchar * job_name = g_getenv("UPSTART_JOB"); const gchar * instance_name = g_getenv("UPSTART_INSTANCE"); g_return_if_fail(job_name != NULL); /* Get a bus, let's go! */ GDBusConnection * bus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); g_return_if_fail(bus != NULL); GVariantBuilder builder; /* Target: (assb) */ g_variant_builder_init(&builder, G_VARIANT_TYPE_TUPLE); /* Setup the job properties */ g_variant_builder_open(&builder, G_VARIANT_TYPE_ARRAY); g_variant_builder_add_value(&builder, g_variant_new_string(job_name)); if (instance_name != NULL) g_variant_builder_add_value(&builder, g_variant_new_string(instance_name)); g_variant_builder_close(&builder); /* The value itself */ g_variant_builder_add_value(&builder, g_variant_builder_end((GVariantBuilder*)handle)); /* Do we want to replace? Yes, we do! */ g_variant_builder_add_value(&builder, g_variant_new_boolean(TRUE)); GError * error = NULL; GVariant * reply = g_dbus_connection_call_sync(bus, DBUS_SERVICE_UPSTART, DBUS_PATH_UPSTART, DBUS_INTERFACE_UPSTART, "SetEnvList", g_variant_builder_end(&builder), NULL, /* reply */ G_DBUS_CALL_FLAGS_NONE, -1, /* timeout */ NULL, /* cancelable */ &error); /* error */ if (reply != NULL) { g_variant_unref(reply); } if (error != NULL) { g_warning("Unable to set environment variables: %s", error->message); g_error_free(error); } g_object_unref(bus); } ubuntu-app-launch-0.5+15.10.20150817/tests/0000755000015300001610000000000012564452317020436 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/exec-test-full.sh0000755000015300001610000000063612564452056023643 0ustar pbuserpbgroup00000000000000#!/bin/bash -e if [ "$PATH" != "$APP_DIR/lib/64bit-amazing/bin:$APP_DIR:/path" ] ; then echo "Bad PATH: $PATH" exit 1 fi if [ "$LD_LIBRARY_PATH" != "$APP_DIR/lib/64bit-amazing:$APP_DIR/lib:/lib" ] ; then echo "Bad LD_LIBRARY_PATH: $LD_LIBRARY_PATH" exit 1 fi if [ "$QML2_IMPORT_PATH" != "/bar/qml/import:$APP_DIR/lib/64bit-amazing" ] ; then echo "Bad QML import path: $QML2_IMPORT_PATH" exit 1 fi exit 0 ubuntu-app-launch-0.5+15.10.20150817/tests/exec-test.sh.in0000755000015300001610000000335512564452056023311 0ustar pbuserpbgroup00000000000000#!/bin/bash -e export PATH=/path export LD_LIBRARY_PATH=/lib export APP_EXEC=@CMAKE_CURRENT_SOURCE_DIR@/exec-test-full.sh export APP_DIR=@CMAKE_CURRENT_BINARY_DIR@ export QML2_IMPORT_PATH=/bar/qml/import export UBUNTU_APP_LAUNCH_ARCH=64bit-amazing echo "Testing Full Test" @CMAKE_BINARY_DIR@/exec-line-exec export PATH=/path export LD_LIBRARY_PATH=/lib export APP_EXEC=@CMAKE_CURRENT_SOURCE_DIR@/exec-test-noarch.sh export APP_DIR=@CMAKE_CURRENT_BINARY_DIR@ export QML2_IMPORT_PATH=/bar/qml/import unset UBUNTU_APP_LAUNCH_ARCH echo "Testing Noarch Test" @CMAKE_BINARY_DIR@/exec-line-exec unset PATH unset LD_LIBRARY_PATH export APP_EXEC=@CMAKE_CURRENT_SOURCE_DIR@/exec-test-noinit.sh export APP_DIR=@CMAKE_CURRENT_BINARY_DIR@ unset QML2_IMPORT_PATH export UBUNTU_APP_LAUNCH_ARCH=64bit-amazing echo "Testing Uninitialized Test" @CMAKE_BINARY_DIR@/exec-line-exec export PATH=/path export LD_LIBRARY_PATH=/lib export APP_EXEC=@CMAKE_CURRENT_SOURCE_DIR@/exec-test-colon.sh export APP_DIR=@CMAKE_CURRENT_BINARY_DIR@/foo:bar export QML2_IMPORT_PATH=/bar/qml/import export UBUNTU_APP_LAUNCH_ARCH=64bit-amazing echo "Testing Colon Test" @CMAKE_BINARY_DIR@/exec-line-exec export PATH=/path export LD_LIBRARY_PATH=/lib export APP_EXEC=@CMAKE_CURRENT_SOURCE_DIR@/exec-test-archcolon.sh export APP_DIR=@CMAKE_CURRENT_BINARY_DIR@ export QML2_IMPORT_PATH=/bar/qml/import export UBUNTU_APP_LAUNCH_ARCH=64bit-amazing:amazinger echo "Testing Arch Colon Test" @CMAKE_BINARY_DIR@/exec-line-exec export PATH="" export LD_LIBRARY_PATH="" export APP_EXEC=@CMAKE_CURRENT_SOURCE_DIR@/exec-test-nullstr.sh export APP_DIR=@CMAKE_CURRENT_BINARY_DIR@ export QML2_IMPORT_PATH="" export UBUNTU_APP_LAUNCH_ARCH=64bit-amazing echo "Testing Null string Test" @CMAKE_BINARY_DIR@/exec-line-exec ubuntu-app-launch-0.5+15.10.20150817/tests/link-farm/0000755000015300001610000000000012564452317022316 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/link-farm/com.test.multiple_first_1.2.3.desktop0000644000015300001610000000001712564452056031225 0ustar pbuserpbgroup00000000000000Needs to exist ubuntu-app-launch-0.5+15.10.20150817/tests/link-farm/com.test.mir_nomir_1.desktop0000644000015300001610000000001712564452110027644 0ustar pbuserpbgroup00000000000000Needs to exist ubuntu-app-launch-0.5+15.10.20150817/tests/link-farm/com.test.good_application_1.2.3.desktop0000644000015300001610000000001712564452056031476 0ustar pbuserpbgroup00000000000000Needs to exist ubuntu-app-launch-0.5+15.10.20150817/tests/link-farm/README0000644000015300001610000000026012564452056023174 0ustar pbuserpbgroup00000000000000This directory is setup as our testing link farm. Anything that has a desktop in here will be detected as a click package, something without will be seen as a legacy package. ubuntu-app-launch-0.5+15.10.20150817/tests/link-farm/com.test.mir_mir_1.desktop0000644000015300001610000000001712564452110027307 0ustar pbuserpbgroup00000000000000Needs to exist ubuntu-app-launch-0.5+15.10.20150817/tests/helper-handshake-test.cc0000644000015300001610000000612012564452056025124 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include #include #include extern "C" { #include "../helpers.h" } class HelperHandshakeTest : public ::testing::Test { private: GTestDBus * testbus = NULL; protected: GMainLoop * mainloop = NULL; virtual void SetUp() { mainloop = g_main_loop_new(NULL, FALSE); testbus = g_test_dbus_new(G_TEST_DBUS_NONE); g_test_dbus_up(testbus); } virtual void TearDown() { g_test_dbus_down(testbus); g_clear_object(&testbus); g_main_loop_unref(mainloop); mainloop = NULL; return; } public: GDBusMessage * FilterFunc (GDBusConnection * conn, GDBusMessage * message, gboolean incomming) { if (g_strcmp0(g_dbus_message_get_member(message), "UnityStartingBroadcast") == 0) { GVariant * body = g_dbus_message_get_body(message); GVariant * correct_body = g_variant_new("(s)", "fooapp"); g_variant_ref_sink(correct_body); [body, correct_body]() { ASSERT_TRUE(g_variant_equal(body, correct_body)); }(); g_variant_unref(correct_body); g_main_loop_quit(mainloop); } return message; } }; static GDBusMessage * filter_func (GDBusConnection * conn, GDBusMessage * message, gboolean incomming, gpointer user_data) { return static_cast(user_data)->FilterFunc(conn, message, incomming); } TEST_F(HelperHandshakeTest, BaseHandshake) { GDBusConnection * con = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); guint filter = g_dbus_connection_add_filter(con, filter_func, this, NULL); handshake_t * handshake = starting_handshake_start("fooapp"); g_main_loop_run(mainloop); g_dbus_connection_remove_filter(con, filter); g_dbus_connection_emit_signal(con, g_dbus_connection_get_unique_name(con), /* destination */ "/", /* path */ "com.canonical.UbuntuAppLaunch", /* interface */ "UnityStartingSignal", /* signal */ g_variant_new("(s)", "fooapp"), /* params, the same */ NULL); starting_handshake_wait(handshake); g_object_unref(con); return; } static gboolean two_second_reached (gpointer user_data) { bool * reached = static_cast(user_data); *reached = true; } TEST_F(HelperHandshakeTest, HandshakeTimeout) { bool timeout_reached = false; handshake_t * handshake = starting_handshake_start("fooapp"); guint outertimeout = g_timeout_add_seconds(2, two_second_reached, &timeout_reached); starting_handshake_wait(handshake); ASSERT_FALSE(timeout_reached); return; } ubuntu-app-launch-0.5+15.10.20150817/tests/exec-util-test.cc0000644000015300001610000002343112564452117023622 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include #include #include #include #include #include class ExecUtil : public ::testing::Test { protected: DbusTestService * service = NULL; DbusTestDbusMock * mock = NULL; GDBusConnection * bus = NULL; protected: static void starting_cb (const gchar * appid, gpointer user_data) { g_debug("I'm too sexy to callback"); } virtual void SetUp() { g_setenv("UPSTART_JOB", "made-up-job", TRUE); g_setenv("XDG_DATA_DIRS", CMAKE_SOURCE_DIR, TRUE); g_setenv("XDG_CACHE_HOME", CMAKE_SOURCE_DIR "/libertine-data", TRUE); g_setenv("XDG_DATA_HOME", CMAKE_SOURCE_DIR "/libertine-home", TRUE); g_setenv("UBUNTU_APP_LAUNCH_LIBERTINE_LAUNCH", "libertine-launch", TRUE); service = dbus_test_service_new(NULL); mock = dbus_test_dbus_mock_new("com.ubuntu.Upstart"); DbusTestDbusMockObject * obj = dbus_test_dbus_mock_get_object(mock, "/com/ubuntu/Upstart", "com.ubuntu.Upstart0_6", NULL); dbus_test_dbus_mock_object_add_method(mock, obj, "GetJobByName", G_VARIANT_TYPE("s"), G_VARIANT_TYPE("o"), "ret = dbus.ObjectPath('/com/test/job')", NULL); DbusTestDbusMockObject * jobobj = dbus_test_dbus_mock_get_object(mock, "/com/test/job", "com.ubuntu.Upstart0_6.Job", NULL); dbus_test_dbus_mock_object_add_method(mock, jobobj, "Start", G_VARIANT_TYPE("(asb)"), NULL, "", NULL); dbus_test_service_add_task(service, DBUS_TEST_TASK(mock)); dbus_test_service_start_tasks(service); bus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); g_dbus_connection_set_exit_on_close(bus, FALSE); g_object_add_weak_pointer(G_OBJECT(bus), (gpointer *)&bus); /* Make the handshake clear faster */ ubuntu_app_launch_observer_add_app_starting(starting_cb, NULL); } virtual void TearDown() { ubuntu_app_launch_observer_delete_app_starting(starting_cb, NULL); g_clear_object(&mock); g_clear_object(&service); g_object_unref(bus); unsigned int cleartry = 0; while (bus != NULL && cleartry < 100) { g_usleep(100000); while (g_main_pending()) { g_main_iteration(TRUE); } cleartry++; } } inline void StartCheckEnv (const std::string& appid, std::map> enums) { std::map env_found; DbusTestDbusMockObject * obj = dbus_test_dbus_mock_get_object(mock, "/com/test/job", "com.ubuntu.Upstart0_6.Job", nullptr); g_setenv("TEST_CLICK_DB", "click-db-dir", TRUE); g_setenv("TEST_CLICK_USER", "test-user", TRUE); g_setenv("UBUNTU_APP_LAUNCH_LINK_FARM", CMAKE_SOURCE_DIR "/link-farm", TRUE); ASSERT_TRUE(ubuntu_app_launch_start_application(appid.c_str(), nullptr)); guint len = 0; const DbusTestDbusMockCall * calls = dbus_test_dbus_mock_object_get_method_calls(mock, obj, "Start", &len, nullptr); ASSERT_EQ(1, len); ASSERT_NE(nullptr, calls); ASSERT_STREQ("Start", calls[0].name); GVariant * envarray = g_variant_get_child_value(calls[0].params, 0); GVariantIter iter; g_variant_iter_init(&iter, envarray); gchar * envvar = NULL; while (g_variant_iter_loop(&iter, "s", &envvar)) { g_debug("Looking at variable: %s", envvar); gchar * var = g_strdup(envvar); gchar * equal = g_strstr_len(var, -1, "="); ASSERT_NE(equal, nullptr); equal[0] = '\0'; gchar * value = &(equal[1]); /* Test the variable */ auto varfunc = enums[var]; EXPECT_NE(nullptr, varfunc); if (varfunc) varfunc(value); /* Mark it as found */ env_found[var] = true; g_free(var); } g_variant_unref(envarray); for(auto enumval : enums) { EXPECT_TRUE(env_found[enumval.first]); } } }; static void nocheck (const gchar *) { } TEST_F(ExecUtil, ClickExec) { #define APP_DIR CMAKE_SOURCE_DIR "/click-root-dir/.click/users/test-user/com.test.good" StartCheckEnv("com.test.good_application_1.2.3", { {"UBUNTU_APPLICATION_ISOLATION", [](const gchar * value) { EXPECT_STREQ("1", value); }}, {"XDG_CACHE_HOME", nocheck}, {"XDG_CONFIG_HOME", nocheck}, {"XDG_DATA_HOME", nocheck}, {"XDG_RUNTIME_DIR", nocheck}, {"XDG_DATA_DIRS", [](const gchar * value) { EXPECT_TRUE(g_str_has_prefix(value, APP_DIR ":")); }}, {"TMPDIR", [](const gchar * value) { EXPECT_TRUE(g_str_has_suffix(value, "com.test.good")); }}, {"__GL_SHADER_DISK_CACHE_PATH", [](const gchar * value) { EXPECT_TRUE(g_str_has_suffix(value, "com.test.good")); }}, {"APP_DIR", [](const gchar * value) { EXPECT_STREQ(APP_DIR, value); }}, {"APP_EXEC", [](const gchar * value) { EXPECT_STREQ("foo", value); }}, {"APP_ID", [](const gchar * value) { EXPECT_STREQ("com.test.good_application_1.2.3", value); }}, {"APP_LAUNCHER_PID", [](const gchar * value) { EXPECT_EQ(getpid(), atoi(value)); }}, {"APP_DESKTOP_FILE_PATH", [](const gchar * value) { EXPECT_STREQ(APP_DIR "/application.desktop", value); }}, }); #undef APP_DIR } TEST_F(ExecUtil, DesktopExec) { StartCheckEnv("foo", { {"APP_EXEC", [](const gchar * value) { EXPECT_STREQ("foo", value); }}, {"APP_DESKTOP_FILE_PATH", [](const gchar * value) { EXPECT_STREQ(CMAKE_SOURCE_DIR "/applications/foo.desktop", value); }}, {"APP_EXEC_POLICY", [](const gchar * value) { EXPECT_STREQ("unconfined", value); }}, {"APP_ID", [](const gchar * value) { EXPECT_STREQ("foo", value); }}, {"INSTANCE_ID", nocheck}, {"APP_LAUNCHER_PID", [](const gchar * value) { EXPECT_EQ(getpid(), atoi(value)); }}, }); } TEST_F(ExecUtil, DesktopMir) { StartCheckEnv("xmir", { {"APP_EXEC", [](const gchar * value) { EXPECT_STREQ("xfoo", value); }}, {"APP_DESKTOP_FILE_PATH", [](const gchar * value) { EXPECT_STREQ(CMAKE_SOURCE_DIR "/applications/xmir.desktop", value); }}, {"APP_EXEC_POLICY", [](const gchar * value) { EXPECT_STREQ("unconfined", value); }}, {"APP_ID", [](const gchar * value) { EXPECT_STREQ("xmir", value); }}, {"INSTANCE_ID", nocheck}, {"APP_LAUNCHER_PID", [](const gchar * value) { EXPECT_EQ(getpid(), atoi(value)); }}, {"APP_XMIR_ENABLE", [](const gchar * value) { EXPECT_STREQ("1", value); }}, }); } TEST_F(ExecUtil, DesktopNoMir) { StartCheckEnv("noxmir", { {"APP_EXEC", [](const gchar * value) { EXPECT_STREQ("noxmir", value); }}, {"APP_DESKTOP_FILE_PATH", [](const gchar * value) { EXPECT_STREQ(CMAKE_SOURCE_DIR "/applications/noxmir.desktop", value); }}, {"APP_EXEC_POLICY", [](const gchar * value) { EXPECT_STREQ("unconfined", value); }}, {"APP_ID", [](const gchar * value) { EXPECT_STREQ("noxmir", value); }}, {"INSTANCE_ID", nocheck}, {"APP_LAUNCHER_PID", [](const gchar * value) { EXPECT_EQ(getpid(), atoi(value)); }}, {"APP_XMIR_ENABLE", [](const gchar * value) { EXPECT_STREQ("0", value); }}, }); } TEST_F(ExecUtil, ClickMir) { StartCheckEnv("com.test.mir_mir_1", { {"UBUNTU_APPLICATION_ISOLATION", nocheck}, {"XDG_CACHE_HOME", nocheck}, {"XDG_CONFIG_HOME", nocheck}, {"XDG_DATA_HOME", nocheck}, {"XDG_RUNTIME_DIR", nocheck}, {"XDG_DATA_DIRS", nocheck}, {"TMPDIR", nocheck}, {"__GL_SHADER_DISK_CACHE_PATH", nocheck}, {"APP_DIR", nocheck}, {"APP_EXEC", nocheck}, {"APP_ID", [](const gchar * value) { EXPECT_STREQ("com.test.mir_mir_1", value); }}, {"APP_LAUNCHER_PID", nocheck}, {"APP_DESKTOP_FILE_PATH", nocheck}, {"APP_XMIR_ENABLE", [](const gchar * value) { EXPECT_STREQ("1", value); }}, }); } TEST_F(ExecUtil, ClickNoMir) { StartCheckEnv("com.test.mir_nomir_1", { {"UBUNTU_APPLICATION_ISOLATION", nocheck}, {"XDG_CACHE_HOME", nocheck}, {"XDG_CONFIG_HOME", nocheck}, {"XDG_DATA_HOME", nocheck}, {"XDG_RUNTIME_DIR", nocheck}, {"XDG_DATA_DIRS", nocheck}, {"TMPDIR", nocheck}, {"__GL_SHADER_DISK_CACHE_PATH", nocheck}, {"APP_DIR", nocheck}, {"APP_EXEC", nocheck}, {"APP_ID", [](const gchar * value) { EXPECT_STREQ("com.test.mir_nomir_1", value); }}, {"APP_LAUNCHER_PID", nocheck}, {"APP_DESKTOP_FILE_PATH", nocheck}, {"APP_XMIR_ENABLE", [](const gchar * value) { EXPECT_STREQ("0", value); }}, }); } TEST_F(ExecUtil, LibertineExec) { StartCheckEnv("container-name_test_0.0", { {"APP_EXEC", [](const gchar * value) { EXPECT_STREQ("libertine-launch \"container-name\" test", value); }}, {"APP_EXEC_POLICY", [](const gchar * value) { EXPECT_STREQ("unconfined", value); }}, {"APP_ID", [](const gchar * value) { EXPECT_STREQ("container-name_test_0.0", value); }}, {"APP_LAUNCHER_PID", [](const gchar * value) { EXPECT_EQ(getpid(), atoi(value)); }}, {"INSTANCE_ID", nocheck}, {"APP_XMIR_ENABLE", [](const gchar * value) { EXPECT_STREQ("1", value); }}, }); } TEST_F(ExecUtil, LibertineExecUser) { StartCheckEnv("container-name_user-app_0.0", { {"APP_EXEC", [](const gchar * value) { EXPECT_STREQ("libertine-launch \"container-name\" user-app", value); }}, {"APP_EXEC_POLICY", [](const gchar * value) { EXPECT_STREQ("unconfined", value); }}, {"APP_ID", [](const gchar * value) { EXPECT_STREQ("container-name_user-app_0.0", value); }}, {"APP_LAUNCHER_PID", [](const gchar * value) { EXPECT_EQ(getpid(), atoi(value)); }}, {"INSTANCE_ID", nocheck}, {"APP_XMIR_ENABLE", [](const gchar * value) { EXPECT_STREQ("1", value); }}, }); } ubuntu-app-launch-0.5+15.10.20150817/tests/libual-test.cc0000644000015300001610000015425112564452125023177 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include #include #include #include #include #include "mir-mock.h" extern "C" { #include "ubuntu-app-launch.h" #include "libdbustest/dbus-test.h" #include } class LibUAL : public ::testing::Test { protected: DbusTestService * service = NULL; DbusTestDbusMock * mock = NULL; DbusTestDbusMock * cgmock = NULL; GDBusConnection * bus = NULL; std::string last_focus_appid; std::string last_resume_appid; guint resume_timeout = 0; private: static void focus_cb (const gchar * appid, gpointer user_data) { g_debug("Focus Callback: %s", appid); LibUAL * _this = static_cast(user_data); _this->last_focus_appid = appid; } static void resume_cb (const gchar * appid, gpointer user_data) { g_debug("Resume Callback: %s", appid); LibUAL * _this = static_cast(user_data); _this->last_resume_appid = appid; if (_this->resume_timeout > 0) { _this->pause(_this->resume_timeout); } } protected: /* Useful debugging stuff, but not on by default. You really want to not get all this noise typically */ void debugConnection() { if (true) return; DbusTestBustle * bustle = dbus_test_bustle_new("test.bustle"); dbus_test_service_add_task(service, DBUS_TEST_TASK(bustle)); g_object_unref(bustle); DbusTestProcess * monitor = dbus_test_process_new("dbus-monitor"); dbus_test_service_add_task(service, DBUS_TEST_TASK(monitor)); g_object_unref(monitor); } virtual void SetUp() { /* Click DB test mode */ g_setenv("TEST_CLICK_DB", "click-db-dir", TRUE); g_setenv("TEST_CLICK_USER", "test-user", TRUE); gchar * linkfarmpath = g_build_filename(CMAKE_SOURCE_DIR, "link-farm", NULL); g_setenv("UBUNTU_APP_LAUNCH_LINK_FARM", linkfarmpath, TRUE); g_free(linkfarmpath); g_setenv("XDG_DATA_DIRS", CMAKE_SOURCE_DIR, TRUE); g_setenv("XDG_CACHE_HOME", CMAKE_SOURCE_DIR "/libertine-data", TRUE); g_setenv("XDG_DATA_HOME", CMAKE_SOURCE_DIR "/libertine-home", TRUE); service = dbus_test_service_new(NULL); debugConnection(); mock = dbus_test_dbus_mock_new("com.ubuntu.Upstart"); DbusTestDbusMockObject * obj = dbus_test_dbus_mock_get_object(mock, "/com/ubuntu/Upstart", "com.ubuntu.Upstart0_6", NULL); dbus_test_dbus_mock_object_add_method(mock, obj, "EmitEvent", G_VARIANT_TYPE("(sasb)"), NULL, "", NULL); dbus_test_dbus_mock_object_add_method(mock, obj, "GetJobByName", G_VARIANT_TYPE("s"), G_VARIANT_TYPE("o"), "if args[0] == 'application-click':\n" " ret = dbus.ObjectPath('/com/test/application_click')\n" "elif args[0] == 'application-legacy':\n" " ret = dbus.ObjectPath('/com/test/application_legacy')\n" "elif args[0] == 'untrusted-helper':\n" " ret = dbus.ObjectPath('/com/test/untrusted/helper')\n", NULL); dbus_test_dbus_mock_object_add_method(mock, obj, "SetEnv", G_VARIANT_TYPE("(assb)"), NULL, "", NULL); /* Click App */ DbusTestDbusMockObject * jobobj = dbus_test_dbus_mock_get_object(mock, "/com/test/application_click", "com.ubuntu.Upstart0_6.Job", NULL); dbus_test_dbus_mock_object_add_method(mock, jobobj, "Start", G_VARIANT_TYPE("(asb)"), NULL, "if args[0][0] == 'APP_ID=com.test.good_application_1.2.3':" " raise dbus.exceptions.DBusException('Foo running', name='com.ubuntu.Upstart0_6.Error.AlreadyStarted')", NULL); dbus_test_dbus_mock_object_add_method(mock, jobobj, "Stop", G_VARIANT_TYPE("(asb)"), NULL, "", NULL); dbus_test_dbus_mock_object_add_method(mock, jobobj, "GetAllInstances", NULL, G_VARIANT_TYPE("ao"), "ret = [ dbus.ObjectPath('/com/test/app_instance') ]", NULL); DbusTestDbusMockObject * instobj = dbus_test_dbus_mock_get_object(mock, "/com/test/app_instance", "com.ubuntu.Upstart0_6.Instance", NULL); dbus_test_dbus_mock_object_add_property(mock, instobj, "name", G_VARIANT_TYPE_STRING, g_variant_new_string("com.test.good_application_1.2.3"), NULL); gchar * process_var = g_strdup_printf("[('main', %d)]", getpid()); dbus_test_dbus_mock_object_add_property(mock, instobj, "processes", G_VARIANT_TYPE("a(si)"), g_variant_new_parsed(process_var), NULL); g_free(process_var); /* Legacy App */ DbusTestDbusMockObject * ljobobj = dbus_test_dbus_mock_get_object(mock, "/com/test/application_legacy", "com.ubuntu.Upstart0_6.Job", NULL); dbus_test_dbus_mock_object_add_method(mock, ljobobj, "Start", G_VARIANT_TYPE("(asb)"), NULL, "", NULL); dbus_test_dbus_mock_object_add_method(mock, ljobobj, "Stop", G_VARIANT_TYPE("(asb)"), NULL, "", NULL); dbus_test_dbus_mock_object_add_method(mock, ljobobj, "GetAllInstances", NULL, G_VARIANT_TYPE("ao"), "ret = [ dbus.ObjectPath('/com/test/legacy_app_instance') ]", NULL); DbusTestDbusMockObject * linstobj = dbus_test_dbus_mock_get_object(mock, "/com/test/legacy_app_instance", "com.ubuntu.Upstart0_6.Instance", NULL); dbus_test_dbus_mock_object_add_property(mock, linstobj, "name", G_VARIANT_TYPE_STRING, g_variant_new_string("bar-2342345"), NULL); dbus_test_dbus_mock_object_add_property(mock, linstobj, "processes", G_VARIANT_TYPE("a(si)"), g_variant_new_parsed("[('main', 5678)]"), NULL); /* Untrusted Helper */ DbusTestDbusMockObject * uhelperobj = dbus_test_dbus_mock_get_object(mock, "/com/test/untrusted/helper", "com.ubuntu.Upstart0_6.Job", NULL); dbus_test_dbus_mock_object_add_method(mock, uhelperobj, "Start", G_VARIANT_TYPE("(asb)"), NULL, "", NULL); dbus_test_dbus_mock_object_add_method(mock, uhelperobj, "Stop", G_VARIANT_TYPE("(asb)"), NULL, "", NULL); dbus_test_dbus_mock_object_add_method(mock, uhelperobj, "GetAllInstances", NULL, G_VARIANT_TYPE("ao"), "ret = [ dbus.ObjectPath('/com/test/untrusted/helper/instance'), dbus.ObjectPath('/com/test/untrusted/helper/multi_instance') ]", NULL); DbusTestDbusMockObject * uhelperinstance = dbus_test_dbus_mock_get_object(mock, "/com/test/untrusted/helper/instance", "com.ubuntu.Upstart0_6.Instance", NULL); dbus_test_dbus_mock_object_add_property(mock, uhelperinstance, "name", G_VARIANT_TYPE_STRING, g_variant_new_string("untrusted-type::com.foo_bar_43.23.12"), NULL); DbusTestDbusMockObject * unhelpermulti = dbus_test_dbus_mock_get_object(mock, "/com/test/untrusted/helper/multi_instance", "com.ubuntu.Upstart0_6.Instance", NULL); dbus_test_dbus_mock_object_add_property(mock, unhelpermulti, "name", G_VARIANT_TYPE_STRING, g_variant_new_string("untrusted-type:24034582324132:com.bar_foo_8432.13.1"), NULL); /* Create the cgroup manager mock */ cgmock = dbus_test_dbus_mock_new("org.test.cgmock"); g_setenv("UBUNTU_APP_LAUNCH_CG_MANAGER_NAME", "org.test.cgmock", TRUE); DbusTestDbusMockObject * cgobject = dbus_test_dbus_mock_get_object(cgmock, "/org/linuxcontainers/cgmanager", "org.linuxcontainers.cgmanager0_0", NULL); dbus_test_dbus_mock_object_add_method(cgmock, cgobject, "GetTasksRecursive", G_VARIANT_TYPE("(ss)"), G_VARIANT_TYPE("ai"), "ret = [100, 200, 300]", NULL); /* Put it together */ dbus_test_service_add_task(service, DBUS_TEST_TASK(mock)); dbus_test_service_add_task(service, DBUS_TEST_TASK(cgmock)); dbus_test_service_start_tasks(service); bus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); g_dbus_connection_set_exit_on_close(bus, FALSE); g_object_add_weak_pointer(G_OBJECT(bus), (gpointer *)&bus); /* Make sure we pretend the CG manager is just on our bus */ g_setenv("UBUNTU_APP_LAUNCH_CG_MANAGER_SESSION_BUS", "YES", TRUE); ASSERT_TRUE(ubuntu_app_launch_observer_add_app_focus(focus_cb, this)); ASSERT_TRUE(ubuntu_app_launch_observer_add_app_resume(resume_cb, this)); } virtual void TearDown() { ubuntu_app_launch_observer_delete_app_focus(focus_cb, this); ubuntu_app_launch_observer_delete_app_resume(resume_cb, this); g_clear_object(&mock); g_clear_object(&cgmock); g_clear_object(&service); g_object_unref(bus); unsigned int cleartry = 0; while (bus != NULL && cleartry < 100) { pause(100); cleartry++; } ASSERT_EQ(nullptr, bus); } GVariant * find_env (GVariant * env_array, const gchar * var) { int i; gchar * envvar = NULL; GVariant * retval = nullptr; for (i = 0; i < g_variant_n_children(env_array); i++) { GVariant * child = g_variant_get_child_value(env_array, i); const gchar * envvar = g_variant_get_string(child, nullptr); if (g_str_has_prefix(envvar, var)) { if (retval != nullptr) { g_warning("Found the env var more than once!"); g_variant_unref(retval); return nullptr; } retval = child; } else { g_variant_unref(child); } } if (!retval) { gchar * envstr = g_variant_print(env_array, FALSE); g_warning("Unable to find '%s' in '%s'", var, envstr); g_free(envstr); } return retval; } bool check_env (GVariant * env_array, const gchar * var, const gchar * value) { bool found = false; GVariant * val = find_env(env_array, var); if (val == nullptr) return false; const gchar * envvar = g_variant_get_string(val, nullptr); gchar * combined = g_strdup_printf("%s=%s", var, value); if (g_strcmp0(envvar, combined) == 0) { found = true; } g_variant_unref(val); return found; } void pause (guint time = 0) { if (time > 0) { GMainLoop * mainloop = g_main_loop_new(NULL, FALSE); g_timeout_add(time, [](gpointer pmainloop) -> gboolean { g_main_loop_quit(static_cast(pmainloop)); return G_SOURCE_REMOVE; }, mainloop); g_main_loop_run(mainloop); g_main_loop_unref(mainloop); } while (g_main_pending()) { g_main_iteration(TRUE); } } }; TEST_F(LibUAL, StartApplication) { DbusTestDbusMockObject * obj = dbus_test_dbus_mock_get_object(mock, "/com/test/application_click", "com.ubuntu.Upstart0_6.Job", NULL); /* Basic make sure we can send the event */ ASSERT_TRUE(ubuntu_app_launch_start_application("com.test.multiple_first_1.2.3", NULL)); EXPECT_EQ(1, dbus_test_dbus_mock_object_check_method_call(mock, obj, "Start", NULL, NULL)); ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(mock, obj, NULL)); /* Now look at the details of the call */ ASSERT_TRUE(ubuntu_app_launch_start_application("com.test.multiple_first_1.2.3", NULL)); guint len = 0; const DbusTestDbusMockCall * calls = dbus_test_dbus_mock_object_get_method_calls(mock, obj, "Start", &len, NULL); EXPECT_NE(nullptr, calls); EXPECT_EQ(1, len); EXPECT_STREQ("Start", calls->name); EXPECT_EQ(2, g_variant_n_children(calls->params)); GVariant * block = g_variant_get_child_value(calls->params, 1); EXPECT_TRUE(g_variant_get_boolean(block)); g_variant_unref(block); GVariant * env = g_variant_get_child_value(calls->params, 0); EXPECT_TRUE(check_env(env, "APP_ID", "com.test.multiple_first_1.2.3")); g_variant_unref(env); ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(mock, obj, NULL)); /* Let's pass some URLs */ const gchar * urls[] = { "http://ubuntu.com/", "https://ubuntu.com/", "file:///home/phablet/test.txt", NULL }; ASSERT_TRUE(ubuntu_app_launch_start_application("com.test.multiple_first_1.2.3", urls)); len = 0; calls = dbus_test_dbus_mock_object_get_method_calls(mock, obj, "Start", &len, NULL); EXPECT_NE(nullptr, calls); EXPECT_EQ(1, len); env = g_variant_get_child_value(calls->params, 0); EXPECT_TRUE(check_env(env, "APP_ID", "com.test.multiple_first_1.2.3")); EXPECT_TRUE(check_env(env, "APP_URIS", "'http://ubuntu.com/' 'https://ubuntu.com/' 'file:///home/phablet/test.txt'")); g_variant_unref(env); return; } TEST_F(LibUAL, StartApplicationTest) { DbusTestDbusMockObject * obj = dbus_test_dbus_mock_get_object(mock, "/com/test/application_click", "com.ubuntu.Upstart0_6.Job", NULL); ASSERT_TRUE(ubuntu_app_launch_start_application_test("com.test.multiple_first_1.2.3", NULL)); guint len = 0; const DbusTestDbusMockCall * calls = dbus_test_dbus_mock_object_get_method_calls(mock, obj, "Start", &len, NULL); EXPECT_NE(nullptr, calls); EXPECT_EQ(1, len); EXPECT_STREQ("Start", calls->name); EXPECT_EQ(2, g_variant_n_children(calls->params)); GVariant * block = g_variant_get_child_value(calls->params, 1); EXPECT_TRUE(g_variant_get_boolean(block)); g_variant_unref(block); GVariant * env = g_variant_get_child_value(calls->params, 0); EXPECT_TRUE(check_env(env, "APP_ID", "com.test.multiple_first_1.2.3")); EXPECT_TRUE(check_env(env, "QT_LOAD_TESTABILITY", "1")); g_variant_unref(env); } TEST_F(LibUAL, StopApplication) { DbusTestDbusMockObject * obj = dbus_test_dbus_mock_get_object(mock, "/com/test/application_click", "com.ubuntu.Upstart0_6.Job", NULL); ASSERT_TRUE(ubuntu_app_launch_stop_application("com.test.good_application_1.2.3")); ASSERT_EQ(dbus_test_dbus_mock_object_check_method_call(mock, obj, "Stop", NULL, NULL), 1); } /* NOTE: The fact that there is 'libertine-data' in these strings is because we're using one CACHE_HOME for this test suite and the libertine functions need to pull things from there, where these are only comparisons. It's just what value is in the environment variable */ TEST_F(LibUAL, ApplicationLog) { gchar * click_log = ubuntu_app_launch_application_log_path("com.test.good_application_1.2.3"); EXPECT_STREQ(CMAKE_SOURCE_DIR "/libertine-data/upstart/application-click-com.test.good_application_1.2.3.log", click_log); g_free(click_log); gchar * legacy_single = ubuntu_app_launch_application_log_path("single"); EXPECT_STREQ(CMAKE_SOURCE_DIR "/libertine-data/upstart/application-legacy-single-.log", legacy_single); g_free(legacy_single); gchar * legacy_multiple = ubuntu_app_launch_application_log_path("bar"); EXPECT_STREQ(CMAKE_SOURCE_DIR "/libertine-data/upstart/application-legacy-bar-2342345.log", legacy_multiple); g_free(legacy_multiple); } TEST_F(LibUAL, ApplicationPid) { /* Check bad params */ EXPECT_EQ(0, ubuntu_app_launch_get_primary_pid(NULL)); EXPECT_FALSE(ubuntu_app_launch_pid_in_app_id(0, "com.test.good_application_1.2.3")); EXPECT_FALSE(ubuntu_app_launch_pid_in_app_id(100, NULL)); /* Check primary pid, which comes from Upstart */ EXPECT_EQ(ubuntu_app_launch_get_primary_pid("com.test.good_application_1.2.3"), getpid()); EXPECT_EQ(ubuntu_app_launch_get_primary_pid("bar"), 5678); /* Look at the full PID list from CG Manager */ DbusTestDbusMockObject * cgobject = dbus_test_dbus_mock_get_object(cgmock, "/org/linuxcontainers/cgmanager", "org.linuxcontainers.cgmanager0_0", NULL); const DbusTestDbusMockCall * calls = NULL; guint len = 0; /* Click in the set */ EXPECT_TRUE(ubuntu_app_launch_pid_in_app_id(100, "com.test.good_application_1.2.3")); calls = dbus_test_dbus_mock_object_get_method_calls(cgmock, cgobject, "GetTasksRecursive", &len, NULL); EXPECT_EQ(1, len); EXPECT_STREQ("GetTasksRecursive", calls->name); EXPECT_TRUE(g_variant_equal(calls->params, g_variant_new("(ss)", "freezer", "upstart/application-click-com.test.good_application_1.2.3"))); ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(cgmock, cgobject, NULL)); /* Click out of the set */ EXPECT_FALSE(ubuntu_app_launch_pid_in_app_id(101, "com.test.good_application_1.2.3")); calls = dbus_test_dbus_mock_object_get_method_calls(cgmock, cgobject, "GetTasksRecursive", &len, NULL); EXPECT_EQ(1, len); EXPECT_STREQ("GetTasksRecursive", calls->name); EXPECT_TRUE(g_variant_equal(calls->params, g_variant_new("(ss)", "freezer", "upstart/application-click-com.test.good_application_1.2.3"))); ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(cgmock, cgobject, NULL)); /* Legacy Single Instance */ EXPECT_TRUE(ubuntu_app_launch_pid_in_app_id(100, "single")); calls = dbus_test_dbus_mock_object_get_method_calls(cgmock, cgobject, "GetTasksRecursive", &len, NULL); EXPECT_EQ(1, len); EXPECT_STREQ("GetTasksRecursive", calls->name); EXPECT_TRUE(g_variant_equal(calls->params, g_variant_new("(ss)", "freezer", "upstart/application-legacy-single-"))); ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(cgmock, cgobject, NULL)); /* Legacy Multi Instance */ EXPECT_TRUE(ubuntu_app_launch_pid_in_app_id(100, "bar")); calls = dbus_test_dbus_mock_object_get_method_calls(cgmock, cgobject, "GetTasksRecursive", &len, NULL); EXPECT_EQ(1, len); EXPECT_STREQ("GetTasksRecursive", calls->name); EXPECT_TRUE(g_variant_equal(calls->params, g_variant_new("(ss)", "freezer", "upstart/application-legacy-bar-2342345"))); ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(cgmock, cgobject, NULL)); } TEST_F(LibUAL, ApplicationId) { g_setenv("TEST_CLICK_DB", "click-db-dir", TRUE); g_setenv("TEST_CLICK_USER", "test-user", TRUE); /* Test with current-user-version, should return the version in the manifest */ EXPECT_STREQ("com.test.good_application_1.2.3", ubuntu_app_launch_triplet_to_app_id("com.test.good", "application", "current-user-version")); /* Test with version specified, shouldn't even read the manifest */ EXPECT_STREQ("com.test.good_application_1.2.4", ubuntu_app_launch_triplet_to_app_id("com.test.good", "application", "1.2.4")); /* Test with out a version or app, should return the version in the manifest */ EXPECT_STREQ("com.test.good_application_1.2.3", ubuntu_app_launch_triplet_to_app_id("com.test.good", "first-listed-app", "current-user-version")); /* Test with a version or but wildcard app, should return the version in the manifest */ EXPECT_STREQ("com.test.good_application_1.2.4", ubuntu_app_launch_triplet_to_app_id("com.test.good", "last-listed-app", "1.2.4")); /* Make sure we can select the app from a list correctly */ EXPECT_STREQ("com.test.multiple_first_1.2.3", ubuntu_app_launch_triplet_to_app_id("com.test.multiple", "first-listed-app", NULL)); EXPECT_STREQ("com.test.multiple_first_1.2.3", ubuntu_app_launch_triplet_to_app_id("com.test.multiple", NULL, NULL)); EXPECT_STREQ("com.test.multiple_fifth_1.2.3", ubuntu_app_launch_triplet_to_app_id("com.test.multiple", "last-listed-app", NULL)); EXPECT_EQ(nullptr, ubuntu_app_launch_triplet_to_app_id("com.test.multiple", "only-listed-app", NULL)); EXPECT_STREQ("com.test.good_application_1.2.3", ubuntu_app_launch_triplet_to_app_id("com.test.good", "only-listed-app", NULL)); /* A bunch that should be NULL */ EXPECT_EQ(nullptr, ubuntu_app_launch_triplet_to_app_id("com.test.no-hooks", NULL, NULL)); EXPECT_EQ(nullptr, ubuntu_app_launch_triplet_to_app_id("com.test.no-json", NULL, NULL)); EXPECT_EQ(nullptr, ubuntu_app_launch_triplet_to_app_id("com.test.no-object", NULL, NULL)); EXPECT_EQ(nullptr, ubuntu_app_launch_triplet_to_app_id("com.test.no-version", NULL, NULL)); /* Libertine tests */ EXPECT_EQ(nullptr, ubuntu_app_launch_triplet_to_app_id("container-name", NULL, NULL)); EXPECT_EQ(nullptr, ubuntu_app_launch_triplet_to_app_id("container-name", "not-exist", NULL)); EXPECT_STREQ("container-name_test_0.0", ubuntu_app_launch_triplet_to_app_id("container-name", "test", NULL)); EXPECT_STREQ("container-name_user-app_0.0", ubuntu_app_launch_triplet_to_app_id("container-name", "user-app", NULL)); } TEST_F(LibUAL, AppIdParse) { EXPECT_TRUE(ubuntu_app_launch_app_id_parse("com.ubuntu.test_test_123", NULL, NULL, NULL)); EXPECT_FALSE(ubuntu_app_launch_app_id_parse("inkscape", NULL, NULL, NULL)); EXPECT_FALSE(ubuntu_app_launch_app_id_parse("music-app", NULL, NULL, NULL)); gchar * pkg; gchar * app; gchar * version; ASSERT_TRUE(ubuntu_app_launch_app_id_parse("com.ubuntu.test_test_123", &pkg, &app, &version)); EXPECT_STREQ("com.ubuntu.test", pkg); EXPECT_STREQ("test", app); EXPECT_STREQ("123", version); g_free(pkg); g_free(app); g_free(version); return; } TEST_F(LibUAL, ApplicationList) { gchar ** apps = ubuntu_app_launch_list_running_apps(); ASSERT_NE(apps, nullptr); ASSERT_EQ(g_strv_length(apps), 2); /* Not enforcing order, but wanting to use the GTest functions for "actually testing" so the errors look right. */ if (g_strcmp0(apps[0], "com.test.good_application_1.2.3") == 0) { ASSERT_STREQ("com.test.good_application_1.2.3", apps[0]); ASSERT_STREQ("bar", apps[1]); } else { ASSERT_STREQ("bar", apps[0]); ASSERT_STREQ("com.test.good_application_1.2.3", apps[1]); } g_strfreev(apps); } typedef struct { unsigned int count; const gchar * name; } observer_data_t; static void observer_cb (const gchar * appid, gpointer user_data) { observer_data_t * data = (observer_data_t *)user_data; if (data->name == NULL) { data->count++; } else if (g_strcmp0(data->name, appid) == 0) { data->count++; } } TEST_F(LibUAL, StartStopObserver) { observer_data_t start_data = { .count = 0, .name = nullptr }; observer_data_t stop_data = { .count = 0, .name = nullptr }; ASSERT_TRUE(ubuntu_app_launch_observer_add_app_started(observer_cb, &start_data)); ASSERT_TRUE(ubuntu_app_launch_observer_add_app_stop(observer_cb, &stop_data)); DbusTestDbusMockObject * obj = dbus_test_dbus_mock_get_object(mock, "/com/ubuntu/Upstart", "com.ubuntu.Upstart0_6", NULL); /* Basic start */ dbus_test_dbus_mock_object_emit_signal(mock, obj, "EventEmitted", G_VARIANT_TYPE("(sas)"), g_variant_new_parsed("('started', ['JOB=application-click', 'INSTANCE=com.test.good_application_1.2.3'])"), NULL ); g_usleep(100000); while (g_main_pending()) g_main_iteration(TRUE); ASSERT_EQ(start_data.count, 1); /* Basic stop */ dbus_test_dbus_mock_object_emit_signal(mock, obj, "EventEmitted", G_VARIANT_TYPE("(sas)"), g_variant_new_parsed("('stopped', ['JOB=application-click', 'INSTANCE=com.test.good_application_1.2.3'])"), NULL ); g_usleep(100000); while (g_main_pending()) g_main_iteration(TRUE); ASSERT_EQ(stop_data.count, 1); /* Start legacy */ start_data.count = 0; start_data.name = "bar"; dbus_test_dbus_mock_object_emit_signal(mock, obj, "EventEmitted", G_VARIANT_TYPE("(sas)"), g_variant_new_parsed("('started', ['JOB=application-legacy', 'INSTANCE=bar-234235'])"), NULL ); g_usleep(100000); while (g_main_pending()) g_main_iteration(TRUE); ASSERT_EQ(start_data.count, 1); /* Legacy stop */ stop_data.count = 0; stop_data.name = "bar"; dbus_test_dbus_mock_object_emit_signal(mock, obj, "EventEmitted", G_VARIANT_TYPE("(sas)"), g_variant_new_parsed("('stopped', ['JOB=application-legacy', 'INSTANCE=bar-9344321'])"), NULL ); g_usleep(100000); while (g_main_pending()) g_main_iteration(TRUE); ASSERT_EQ(stop_data.count, 1); /* Test Noise Start */ start_data.count = 0; start_data.name = "com.test.good_application_1.2.3"; stop_data.count = 0; stop_data.name = "com.test.good_application_1.2.3"; /* A full lifecycle */ dbus_test_dbus_mock_object_emit_signal(mock, obj, "EventEmitted", G_VARIANT_TYPE("(sas)"), g_variant_new_parsed("('starting', ['JOB=application-click', 'INSTANCE=com.test.good_application_1.2.3'])"), NULL ); dbus_test_dbus_mock_object_emit_signal(mock, obj, "EventEmitted", G_VARIANT_TYPE("(sas)"), g_variant_new_parsed("('started', ['JOB=application-click', 'INSTANCE=com.test.good_application_1.2.3'])"), NULL ); dbus_test_dbus_mock_object_emit_signal(mock, obj, "EventEmitted", G_VARIANT_TYPE("(sas)"), g_variant_new_parsed("('stopping', ['JOB=application-click', 'INSTANCE=com.test.good_application_1.2.3'])"), NULL ); dbus_test_dbus_mock_object_emit_signal(mock, obj, "EventEmitted", G_VARIANT_TYPE("(sas)"), g_variant_new_parsed("('stopped', ['JOB=application-click', 'INSTANCE=com.test.good_application_1.2.3'])"), NULL ); g_usleep(100000); while (g_main_pending()) g_main_iteration(TRUE); /* Ensure we just signaled once for each */ ASSERT_EQ(start_data.count, 1); ASSERT_EQ(stop_data.count, 1); /* Remove */ ASSERT_TRUE(ubuntu_app_launch_observer_delete_app_started(observer_cb, &start_data)); ASSERT_TRUE(ubuntu_app_launch_observer_delete_app_stop(observer_cb, &stop_data)); } static GDBusMessage * filter_starting (GDBusConnection * conn, GDBusMessage * message, gboolean incomming, gpointer user_data) { if (g_strcmp0(g_dbus_message_get_member(message), "UnityStartingSignal") == 0) { unsigned int * count = static_cast(user_data); (*count)++; g_object_unref(message); return NULL; } return message; } static void starting_observer (const gchar * appid, gpointer user_data) { std::string * last = static_cast(user_data); *last = appid; return; } TEST_F(LibUAL, StartingResponses) { std::string last_observer; unsigned int starting_count = 0; GDBusConnection * session = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); guint filter = g_dbus_connection_add_filter(session, filter_starting, &starting_count, NULL); EXPECT_TRUE(ubuntu_app_launch_observer_add_app_starting(starting_observer, &last_observer)); g_dbus_connection_emit_signal(session, NULL, /* destination */ "/", /* path */ "com.canonical.UbuntuAppLaunch", /* interface */ "UnityStartingBroadcast", /* signal */ g_variant_new("(s)", "com.test.good_application_1.2.3"), /* params, the same */ NULL); pause(100); EXPECT_EQ("com.test.good_application_1.2.3", last_observer); EXPECT_EQ(1, starting_count); EXPECT_TRUE(ubuntu_app_launch_observer_delete_app_starting(starting_observer, &last_observer)); g_dbus_connection_remove_filter(session, filter); g_object_unref(session); } TEST_F(LibUAL, AppIdTest) { ASSERT_TRUE(ubuntu_app_launch_start_application("com.test.good_application_1.2.3", NULL)); pause(50); /* Ensure all the events come through */ EXPECT_EQ("com.test.good_application_1.2.3", this->last_focus_appid); EXPECT_EQ("com.test.good_application_1.2.3", this->last_resume_appid); } GDBusMessage * filter_func_good (GDBusConnection * conn, GDBusMessage * message, gboolean incomming, gpointer user_data) { if (!incomming) { return message; } if (g_strcmp0(g_dbus_message_get_path(message), (gchar *)user_data) == 0) { GDBusMessage * reply = g_dbus_message_new_method_reply(message); g_dbus_connection_send_message(conn, reply, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); g_object_unref(message); return NULL; } return message; } TEST_F(LibUAL, UrlSendTest) { GDBusConnection * session = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); guint filter = g_dbus_connection_add_filter(session, filter_func_good, (gpointer)"/com_2etest_2egood_5fapplication_5f1_2e2_2e3", NULL); const gchar * uris[] = { "http://www.test.com", NULL }; ASSERT_TRUE(ubuntu_app_launch_start_application("com.test.good_application_1.2.3", uris)); pause(100); /* Ensure all the events come through */ EXPECT_EQ("com.test.good_application_1.2.3", this->last_focus_appid); EXPECT_EQ("com.test.good_application_1.2.3", this->last_resume_appid); g_dbus_connection_remove_filter(session, filter); /* Send multiple resume responses to ensure we unsubscribe */ /* Multiple to increase our chance of hitting a bad free in the middle, fun with async! */ int i; for (i = 0; i < 5; i++) { g_dbus_connection_emit_signal(session, NULL, /* destination */ "/", /* path */ "com.canonical.UbuntuAppLaunch", /* interface */ "UnityResumeResponse", /* signal */ g_variant_new("(s)", "com.test.good_application_1.2.3"), /* params, the same */ NULL); pause(50); /* Ensure all the events come through */ } g_object_unref(session); } TEST_F(LibUAL, UrlSendNoObjectTest) { const gchar * uris[] = { "http://www.test.com", NULL }; ASSERT_TRUE(ubuntu_app_launch_start_application("com.test.good_application_1.2.3", uris)); pause(100); /* Ensure all the events come through */ EXPECT_EQ("com.test.good_application_1.2.3", this->last_focus_appid); EXPECT_EQ("com.test.good_application_1.2.3", this->last_resume_appid); } TEST_F(LibUAL, UnityTimeoutTest) { this->resume_timeout = 100; ASSERT_TRUE(ubuntu_app_launch_start_application("com.test.good_application_1.2.3", NULL)); pause(1000); /* Ensure all the events come through */ EXPECT_EQ("com.test.good_application_1.2.3", this->last_focus_appid); EXPECT_EQ("com.test.good_application_1.2.3", this->last_resume_appid); } TEST_F(LibUAL, UnityTimeoutUriTest) { this->resume_timeout = 200; const gchar * uris[] = { "http://www.test.com", NULL }; ASSERT_TRUE(ubuntu_app_launch_start_application("com.test.good_application_1.2.3", uris)); pause(1000); /* Ensure all the events come through */ EXPECT_EQ("com.test.good_application_1.2.3", this->last_focus_appid); EXPECT_EQ("com.test.good_application_1.2.3", this->last_resume_appid); } GDBusMessage * filter_respawn (GDBusConnection * conn, GDBusMessage * message, gboolean incomming, gpointer user_data) { if (g_strcmp0(g_dbus_message_get_member(message), "UnityResumeResponse") == 0) { g_object_unref(message); return NULL; } return message; } TEST_F(LibUAL, UnityLostTest) { GDBusConnection * session = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); guint filter = g_dbus_connection_add_filter(session, filter_respawn, NULL, NULL); guint start = g_get_monotonic_time(); const gchar * uris[] = { "http://www.test.com", NULL }; ASSERT_TRUE(ubuntu_app_launch_start_application("com.test.good_application_1.2.3", uris)); guint end = g_get_monotonic_time(); g_debug("Start call time: %d ms", (end - start) / 1000); EXPECT_LT(end - start, 2000 * 1000); pause(1000); /* Ensure all the events come through */ EXPECT_EQ("com.test.good_application_1.2.3", this->last_focus_appid); EXPECT_EQ("com.test.good_application_1.2.3", this->last_resume_appid); g_dbus_connection_remove_filter(session, filter); g_object_unref(session); } TEST_F(LibUAL, LegacySingleInstance) { DbusTestDbusMockObject * obj = dbus_test_dbus_mock_get_object(mock, "/com/test/application_legacy", "com.ubuntu.Upstart0_6.Job", NULL); /* Check for a single-instance app */ ASSERT_TRUE(ubuntu_app_launch_start_application("single", NULL)); guint len = 0; const DbusTestDbusMockCall * calls = dbus_test_dbus_mock_object_get_method_calls(mock, obj, "Start", &len, NULL); EXPECT_NE(nullptr, calls); EXPECT_EQ(1, len); EXPECT_STREQ("Start", calls->name); EXPECT_EQ(2, g_variant_n_children(calls->params)); GVariant * block = g_variant_get_child_value(calls->params, 1); EXPECT_TRUE(g_variant_get_boolean(block)); g_variant_unref(block); GVariant * env = g_variant_get_child_value(calls->params, 0); EXPECT_TRUE(check_env(env, "APP_ID", "single")); EXPECT_TRUE(check_env(env, "INSTANCE_ID", "")); g_variant_unref(env); ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(mock, obj, NULL)); /* Check for a multi-instance app */ ASSERT_TRUE(ubuntu_app_launch_start_application("multiple", NULL)); len = 0; calls = dbus_test_dbus_mock_object_get_method_calls(mock, obj, "Start", &len, NULL); EXPECT_NE(nullptr, calls); EXPECT_EQ(1, len); EXPECT_STREQ("Start", calls->name); EXPECT_EQ(2, g_variant_n_children(calls->params)); block = g_variant_get_child_value(calls->params, 1); EXPECT_TRUE(g_variant_get_boolean(block)); g_variant_unref(block); env = g_variant_get_child_value(calls->params, 0); EXPECT_TRUE(check_env(env, "APP_ID", "multiple")); EXPECT_FALSE(check_env(env, "INSTANCE_ID", "")); g_variant_unref(env); } static void failed_observer (const gchar * appid, UbuntuAppLaunchAppFailed reason, gpointer user_data) { if (reason == UBUNTU_APP_LAUNCH_APP_FAILED_CRASH) { std::string * last = static_cast(user_data); *last = appid; } return; } TEST_F(LibUAL, FailingObserver) { std::string last_observer; GDBusConnection * session = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); EXPECT_TRUE(ubuntu_app_launch_observer_add_app_failed(failed_observer, &last_observer)); g_dbus_connection_emit_signal(session, NULL, /* destination */ "/", /* path */ "com.canonical.UbuntuAppLaunch", /* interface */ "ApplicationFailed", /* signal */ g_variant_new("(ss)", "com.test.good_application_1.2.3", "crash"), /* params, the same */ NULL); pause(100); EXPECT_EQ("com.test.good_application_1.2.3", last_observer); last_observer.clear(); g_dbus_connection_emit_signal(session, NULL, /* destination */ "/", /* path */ "com.canonical.UbuntuAppLaunch", /* interface */ "ApplicationFailed", /* signal */ g_variant_new("(ss)", "com.test.good_application_1.2.3", "blahblah"), /* params, the same */ NULL); pause(100); EXPECT_EQ("com.test.good_application_1.2.3", last_observer); last_observer.clear(); g_dbus_connection_emit_signal(session, NULL, /* destination */ "/", /* path */ "com.canonical.UbuntuAppLaunch", /* interface */ "ApplicationFailed", /* signal */ g_variant_new("(ss)", "com.test.good_application_1.2.3", "start-failure"), /* params, the same */ NULL); pause(100); EXPECT_TRUE(last_observer.empty()); EXPECT_TRUE(ubuntu_app_launch_observer_delete_app_failed(failed_observer, &last_observer)); g_object_unref(session); } TEST_F(LibUAL, StartHelper) { DbusTestDbusMockObject * obj = dbus_test_dbus_mock_get_object(mock, "/com/test/untrusted/helper", "com.ubuntu.Upstart0_6.Job", NULL); /* Basic make sure we can send the event */ ASSERT_TRUE(ubuntu_app_launch_start_helper("untrusted-type", "com.test.multiple_first_1.2.3", NULL)); EXPECT_EQ(1, dbus_test_dbus_mock_object_check_method_call(mock, obj, "Start", NULL, NULL)); ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(mock, obj, NULL)); /* Now look at the details of the call */ ASSERT_TRUE(ubuntu_app_launch_start_helper("untrusted-type", "com.test.multiple_first_1.2.3", NULL)); guint len = 0; const DbusTestDbusMockCall * calls = dbus_test_dbus_mock_object_get_method_calls(mock, obj, "Start", &len, NULL); EXPECT_NE(nullptr, calls); EXPECT_EQ(1, len); EXPECT_STREQ("Start", calls->name); EXPECT_EQ(2, g_variant_n_children(calls->params)); GVariant * block = g_variant_get_child_value(calls->params, 1); EXPECT_TRUE(g_variant_get_boolean(block)); g_variant_unref(block); GVariant * env = g_variant_get_child_value(calls->params, 0); EXPECT_TRUE(check_env(env, "APP_ID", "com.test.multiple_first_1.2.3")); EXPECT_TRUE(check_env(env, "HELPER_TYPE", "untrusted-type")); EXPECT_FALSE(check_env(env, "INSTANCE_ID", NULL)); g_variant_unref(env); ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(mock, obj, NULL)); /* Now check a multi out */ gchar * instance_id = ubuntu_app_launch_start_multiple_helper("untrusted-type", "com.test.multiple_first_1.2.3", NULL); ASSERT_NE(nullptr, instance_id); g_debug("Multi-instance ID: %s", instance_id); len = 0; calls = dbus_test_dbus_mock_object_get_method_calls(mock, obj, "Start", &len, NULL); EXPECT_NE(nullptr, calls); EXPECT_EQ(1, len); EXPECT_STREQ("Start", calls->name); EXPECT_EQ(2, g_variant_n_children(calls->params)); block = g_variant_get_child_value(calls->params, 1); EXPECT_TRUE(g_variant_get_boolean(block)); g_variant_unref(block); env = g_variant_get_child_value(calls->params, 0); EXPECT_TRUE(check_env(env, "APP_ID", "com.test.multiple_first_1.2.3")); EXPECT_TRUE(check_env(env, "HELPER_TYPE", "untrusted-type")); EXPECT_TRUE(check_env(env, "INSTANCE_ID", instance_id)); g_variant_unref(env); g_free(instance_id); ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(mock, obj, NULL)); /* Let's pass some URLs */ const gchar * urls[] = { "http://ubuntu.com/", "https://ubuntu.com/", "file:///home/phablet/test.txt", NULL }; ASSERT_TRUE(ubuntu_app_launch_start_helper("untrusted-type", "com.test.multiple_first_1.2.3", urls)); len = 0; calls = dbus_test_dbus_mock_object_get_method_calls(mock, obj, "Start", &len, NULL); EXPECT_NE(nullptr, calls); EXPECT_EQ(1, len); env = g_variant_get_child_value(calls->params, 0); EXPECT_TRUE(check_env(env, "APP_ID", "com.test.multiple_first_1.2.3")); EXPECT_TRUE(check_env(env, "APP_URIS", "'http://ubuntu.com/' 'https://ubuntu.com/' 'file:///home/phablet/test.txt'")); EXPECT_TRUE(check_env(env, "HELPER_TYPE", "untrusted-type")); EXPECT_FALSE(check_env(env, "INSTANCE_ID", NULL)); g_variant_unref(env); return; } TEST_F(LibUAL, StopHelper) { DbusTestDbusMockObject * obj = dbus_test_dbus_mock_get_object(mock, "/com/test/untrusted/helper", "com.ubuntu.Upstart0_6.Job", NULL); /* Basic helper */ ASSERT_TRUE(ubuntu_app_launch_stop_helper("untrusted-type", "com.test.good_application_1.2.3")); ASSERT_EQ(dbus_test_dbus_mock_object_check_method_call(mock, obj, "Stop", NULL, NULL), 1); guint len = 0; const DbusTestDbusMockCall * calls = dbus_test_dbus_mock_object_get_method_calls(mock, obj, "Stop", &len, NULL); EXPECT_NE(nullptr, calls); EXPECT_EQ(1, len); EXPECT_STREQ("Stop", calls->name); EXPECT_EQ(2, g_variant_n_children(calls->params)); GVariant * block = g_variant_get_child_value(calls->params, 1); EXPECT_TRUE(g_variant_get_boolean(block)); g_variant_unref(block); GVariant * env = g_variant_get_child_value(calls->params, 0); EXPECT_TRUE(check_env(env, "APP_ID", "com.test.good_application_1.2.3")); EXPECT_TRUE(check_env(env, "HELPER_TYPE", "untrusted-type")); EXPECT_FALSE(check_env(env, "INSTANCE_ID", NULL)); g_variant_unref(env); ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(mock, obj, NULL)); /* Multi helper */ ASSERT_TRUE(ubuntu_app_launch_stop_multiple_helper("untrusted-type", "com.test.good_application_1.2.3", "instance-me")); ASSERT_EQ(dbus_test_dbus_mock_object_check_method_call(mock, obj, "Stop", NULL, NULL), 1); len = 0; calls = dbus_test_dbus_mock_object_get_method_calls(mock, obj, "Stop", &len, NULL); EXPECT_NE(nullptr, calls); EXPECT_EQ(1, len); EXPECT_STREQ("Stop", calls->name); EXPECT_EQ(2, g_variant_n_children(calls->params)); block = g_variant_get_child_value(calls->params, 1); EXPECT_TRUE(g_variant_get_boolean(block)); g_variant_unref(block); env = g_variant_get_child_value(calls->params, 0); EXPECT_TRUE(check_env(env, "APP_ID", "com.test.good_application_1.2.3")); EXPECT_TRUE(check_env(env, "HELPER_TYPE", "untrusted-type")); EXPECT_TRUE(check_env(env, "INSTANCE_ID", "instance-me")); g_variant_unref(env); ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(mock, obj, NULL)); return; } TEST_F(LibUAL, HelperList) { gchar ** blanktype = ubuntu_app_launch_list_helpers("not-a-type"); EXPECT_NE(nullptr, blanktype); EXPECT_EQ(0, g_strv_length(blanktype)); g_strfreev(blanktype); gchar ** goodtype = ubuntu_app_launch_list_helpers("untrusted-type"); EXPECT_NE(nullptr, goodtype); EXPECT_EQ(2, g_strv_length(goodtype)); if (g_strcmp0(goodtype[0], "com.foo_bar_43.23.12") == 0) { EXPECT_STREQ("com.foo_bar_43.23.12", goodtype[0]); EXPECT_STREQ("com.bar_foo_8432.13.1", goodtype[1]); } else { EXPECT_STREQ("com.foo_bar_43.23.12", goodtype[1]); EXPECT_STREQ("com.bar_foo_8432.13.1", goodtype[0]); } g_strfreev(goodtype); } TEST_F(LibUAL, HelperInstanceList) { gchar ** blanktype = ubuntu_app_launch_list_helper_instances("not-a-type", "com.bar_foo_8432.13.1"); EXPECT_NE(nullptr, blanktype); EXPECT_EQ(0, g_strv_length(blanktype)); g_strfreev(blanktype); gchar ** goodtype = ubuntu_app_launch_list_helper_instances("untrusted-type", "com.bar_foo_8432.13.1"); EXPECT_NE(nullptr, goodtype); EXPECT_EQ(1, g_strv_length(goodtype)); EXPECT_STREQ("24034582324132", goodtype[0]); g_strfreev(goodtype); } typedef struct { unsigned int count; const gchar * appid; const gchar * type; const gchar * instance; } helper_observer_data_t; static void helper_observer_cb (const gchar * appid, const gchar * instance, const gchar * type, gpointer user_data) { helper_observer_data_t * data = (helper_observer_data_t *)user_data; if (g_strcmp0(data->appid, appid) == 0 && g_strcmp0(data->type, type) == 0 && g_strcmp0(data->instance, instance) == 0) { data->count++; } } TEST_F(LibUAL, StartStopHelperObserver) { helper_observer_data_t start_data = { .count = 0, .appid = "com.foo_foo_1.2.3", .type = "my-type-is-scorpio", .instance = nullptr }; helper_observer_data_t stop_data = { .count = 0, .appid = "com.bar_bar_44.32", .type = "my-type-is-libra", .instance = "1234" }; ASSERT_TRUE(ubuntu_app_launch_observer_add_helper_started(helper_observer_cb, "my-type-is-scorpio", &start_data)); ASSERT_TRUE(ubuntu_app_launch_observer_add_helper_stop(helper_observer_cb, "my-type-is-libra", &stop_data)); DbusTestDbusMockObject * obj = dbus_test_dbus_mock_get_object(mock, "/com/ubuntu/Upstart", "com.ubuntu.Upstart0_6", NULL); /* Basic start */ dbus_test_dbus_mock_object_emit_signal(mock, obj, "EventEmitted", G_VARIANT_TYPE("(sas)"), g_variant_new_parsed("('started', ['JOB=untrusted-helper', 'INSTANCE=my-type-is-scorpio::com.foo_foo_1.2.3'])"), NULL ); g_usleep(100000); while (g_main_pending()) g_main_iteration(TRUE); ASSERT_EQ(start_data.count, 1); /* Basic stop */ dbus_test_dbus_mock_object_emit_signal(mock, obj, "EventEmitted", G_VARIANT_TYPE("(sas)"), g_variant_new_parsed("('stopped', ['JOB=untrusted-helper', 'INSTANCE=my-type-is-libra:1234:com.bar_bar_44.32'])"), NULL ); g_usleep(100000); while (g_main_pending()) g_main_iteration(TRUE); ASSERT_EQ(stop_data.count, 1); /* Remove */ ASSERT_TRUE(ubuntu_app_launch_observer_delete_helper_started(helper_observer_cb, "my-type-is-scorpio", &start_data)); ASSERT_TRUE(ubuntu_app_launch_observer_delete_helper_stop(helper_observer_cb, "my-type-is-libra", &stop_data)); } gboolean datain (GIOChannel * source, GIOCondition cond, gpointer data) { gsize * datacnt = static_cast(data); gchar * str = NULL; gsize len = 0; GError * error = NULL; g_io_channel_read_line(source, &str, &len, NULL, &error); g_free(str); if (error != NULL) { g_warning("Unable to read from channel: %s", error->message); g_error_free(error); } *datacnt += len; return TRUE; } static void signal_increment (GDBusConnection * connection, const gchar * sender, const gchar * path, const gchar * interface, const gchar * signal, GVariant * params, gpointer user_data) { guint * count = (guint *)user_data; g_debug("Count incremented to: %d", *count + 1); *count = *count + 1; } TEST_F(LibUAL, PauseResume) { g_setenv("UBUNTU_APP_LAUNCH_OOM_PROC_PATH", CMAKE_BINARY_DIR "/libual-proc" , 1); /* Setup some spew */ GPid spewpid = 0; gint spewstdout = 0; const gchar * spewline[] = { SPEW_UTILITY, NULL }; ASSERT_TRUE(g_spawn_async_with_pipes(NULL, (gchar **)spewline, NULL, /* environment */ G_SPAWN_DEFAULT, NULL, NULL, /* child setup */ &spewpid, NULL, /* stdin */ &spewstdout, NULL, /* stderr */ NULL)); /* error */ gsize datacnt = 0; GIOChannel * spewoutchan = g_io_channel_unix_new(spewstdout); g_io_channel_set_flags(spewoutchan, G_IO_FLAG_NONBLOCK, NULL); g_io_add_watch(spewoutchan, G_IO_IN, datain, &datacnt); /* Setup our OOM adjust file */ gchar * procdir = g_strdup_printf(CMAKE_BINARY_DIR "/libual-proc/%d", spewpid); ASSERT_EQ(0, g_mkdir_with_parents(procdir, 0700)); gchar * oomadjfile = g_strdup_printf("%s/oom_score_adj", procdir); g_free(procdir); ASSERT_TRUE(g_file_set_contents(oomadjfile, "0", -1, NULL)); /* Setup the cgroup */ g_setenv("UBUNTU_APP_LAUNCH_CG_MANAGER_NAME", "org.test.cgmock2", TRUE); DbusTestDbusMock * cgmock2 = dbus_test_dbus_mock_new("org.test.cgmock2"); DbusTestDbusMockObject * cgobject = dbus_test_dbus_mock_get_object(cgmock2, "/org/linuxcontainers/cgmanager", "org.linuxcontainers.cgmanager0_0", NULL); gchar * pypids = g_strdup_printf("ret = [%d]", spewpid); dbus_test_dbus_mock_object_add_method(cgmock, cgobject, "GetTasksRecursive", G_VARIANT_TYPE("(ss)"), G_VARIANT_TYPE("ai"), pypids, NULL); g_free(pypids); dbus_test_service_add_task(service, DBUS_TEST_TASK(cgmock2)); dbus_test_task_run(DBUS_TEST_TASK(cgmock2)); g_object_unref(G_OBJECT(cgmock2)); /* Setup ZG Mock */ DbusTestDbusMock * zgmock = dbus_test_dbus_mock_new("org.gnome.zeitgeist.Engine"); DbusTestDbusMockObject * zgobj = dbus_test_dbus_mock_get_object(zgmock, "/org/gnome/zeitgeist/log/activity", "org.gnome.zeitgeist.Log", NULL); dbus_test_dbus_mock_object_add_method(zgmock, zgobj, "InsertEvents", G_VARIANT_TYPE("a(asaasay)"), G_VARIANT_TYPE("au"), "ret = [ 0 ]", NULL); dbus_test_service_add_task(service, DBUS_TEST_TASK(zgmock)); dbus_test_task_run(DBUS_TEST_TASK(zgmock)); g_object_unref(G_OBJECT(zgmock)); /* Give things a chance to start */ do { g_debug("Giving mocks a chance to start"); pause(200); } while (dbus_test_task_get_state(DBUS_TEST_TASK(cgmock2)) != DBUS_TEST_TASK_STATE_RUNNING && dbus_test_task_get_state(DBUS_TEST_TASK(zgmock)) != DBUS_TEST_TASK_STATE_RUNNING); /* Setup signal handling */ guint paused_count = 0; guint resumed_count = 0; guint paused_signal = g_dbus_connection_signal_subscribe(bus, nullptr, "com.canonical.UbuntuAppLaunch", "ApplicationPaused", "/", nullptr, G_DBUS_SIGNAL_FLAGS_NONE, signal_increment, &paused_count, nullptr); guint resumed_signal = g_dbus_connection_signal_subscribe(bus, nullptr, "com.canonical.UbuntuAppLaunch", "ApplicationResumed", "/", nullptr, G_DBUS_SIGNAL_FLAGS_NONE, signal_increment, &resumed_count, nullptr); /* Test it */ EXPECT_NE(0, datacnt); paused_count = 0; /* Pause the app */ EXPECT_TRUE(ubuntu_app_launch_pause_application("com.test.good_application_1.2.3")); pause(0); /* Flush queued events */ datacnt = 0; /* clear it */ pause(200); /* Check data coming out */ EXPECT_EQ(1, paused_count); EXPECT_EQ(0, datacnt); /* Check to make sure we sent the event to ZG */ guint numcalls = 0; const DbusTestDbusMockCall * calls = dbus_test_dbus_mock_object_get_method_calls(zgmock, zgobj, "InsertEvents", &numcalls, NULL); EXPECT_NE(nullptr, calls); EXPECT_EQ(1, numcalls); dbus_test_dbus_mock_object_clear_method_calls(zgmock, zgobj, NULL); /* Check to ensure we set the OOM score */ gchar * pauseoomscore = NULL; ASSERT_TRUE(g_file_get_contents(oomadjfile, &pauseoomscore, NULL, NULL)); EXPECT_STREQ("900", pauseoomscore); g_free(pauseoomscore); resumed_count = 0; /* Now Resume the App */ EXPECT_TRUE(ubuntu_app_launch_resume_application("com.test.good_application_1.2.3")); pause(200); EXPECT_NE(0, datacnt); EXPECT_EQ(1, resumed_count); /* Check to make sure we sent the event to ZG */ numcalls = 0; calls = dbus_test_dbus_mock_object_get_method_calls(zgmock, zgobj, "InsertEvents", &numcalls, NULL); EXPECT_NE(nullptr, calls); EXPECT_EQ(1, numcalls); /* Check to ensure we set the OOM score */ gchar * resumeoomscore = NULL; ASSERT_TRUE(g_file_get_contents(oomadjfile, &resumeoomscore, NULL, NULL)); EXPECT_STREQ("100", resumeoomscore); g_free(resumeoomscore); /* Clean up */ gchar * killstr = g_strdup_printf("kill -9 %d", spewpid); ASSERT_TRUE(g_spawn_command_line_sync(killstr, NULL, NULL, NULL, NULL)); g_free(killstr); g_io_channel_unref(spewoutchan); g_spawn_command_line_sync("rm -rf " CMAKE_BINARY_DIR "/libual-proc", NULL, NULL, NULL, NULL); g_dbus_connection_signal_unsubscribe(bus, paused_signal); g_dbus_connection_signal_unsubscribe(bus, resumed_signal); /* Kill ZG default instance :-( */ ZeitgeistLog * log = zeitgeist_log_get_default(); g_object_unref(log); g_object_unref(log); g_free(oomadjfile); } TEST_F(LibUAL, StartSessionHelper) { DbusTestDbusMockObject * obj = dbus_test_dbus_mock_get_object(mock, "/com/test/untrusted/helper", "com.ubuntu.Upstart0_6.Job", NULL); MirConnection * conn = mir_connect_sync("libual-test", "start-session-helper"); // Mocked, doesn't need cleaning up MirPromptSession * msession = mir_connection_create_prompt_session_sync(conn, 5, nullptr, nullptr); /* Building a temporary file and making an FD for it */ const char * filedata = "This is some data that we should get on the other side\n"; ASSERT_TRUE(g_file_set_contents(SESSION_TEMP_FILE, filedata, strlen(filedata), nullptr) == TRUE); int mirfd = open(SESSION_TEMP_FILE, 0); mir_mock_set_trusted_fd(mirfd); /* Basic make sure we can send the event */ gchar * instance_id = ubuntu_app_launch_start_session_helper("untrusted-type", msession, "com.test.multiple_first_1.2.3", NULL); ASSERT_NE(nullptr, instance_id); guint len = 0; const DbusTestDbusMockCall * calls = dbus_test_dbus_mock_object_get_method_calls(mock, obj, "Start", &len, NULL); EXPECT_NE(nullptr, calls); EXPECT_EQ(1, len); EXPECT_STREQ("Start", calls->name); EXPECT_EQ(2, g_variant_n_children(calls->params)); GVariant * block = g_variant_get_child_value(calls->params, 1); EXPECT_TRUE(g_variant_get_boolean(block)); g_variant_unref(block); /* Check the environment */ GVariant * env = g_variant_get_child_value(calls->params, 0); EXPECT_TRUE(check_env(env, "APP_ID", "com.test.multiple_first_1.2.3")); EXPECT_TRUE(check_env(env, "HELPER_TYPE", "untrusted-type")); EXPECT_TRUE(check_env(env, "INSTANCE_ID", instance_id)); GVariant * mnamev = find_env(env, "UBUNTU_APP_LAUNCH_DEMANGLE_NAME"); ASSERT_NE(nullptr, mnamev); /* Have to assert because, eh, GVariant */ EXPECT_STREQ(g_dbus_connection_get_unique_name(bus), g_variant_get_string(mnamev, nullptr) + strlen("UBUNTU_APP_LAUNCH_DEMANGLE_NAME=")); GVariant * mpathv = find_env(env, "UBUNTU_APP_LAUNCH_DEMANGLE_PATH"); ASSERT_NE(nullptr, mpathv); /* Have to assert because, eh, GVariant */ g_variant_unref(env); /* Setup environment for call */ const gchar * mname = g_variant_get_string(mnamev, nullptr); mname += strlen("UBUNTU_APP_LAUNCH_DEMANGLE_NAME="); g_setenv("UBUNTU_APP_LAUNCH_DEMANGLE_NAME", mname, TRUE); g_variant_unref(mnamev); const gchar * mpath = g_variant_get_string(mpathv, nullptr); mpath += strlen("UBUNTU_APP_LAUNCH_DEMANGLE_PATH="); g_setenv("UBUNTU_APP_LAUNCH_DEMANGLE_PATH", mpath, TRUE); g_variant_unref(mpathv); /* Exec our tool */ std::promise outputpromise; std::thread t([&outputpromise]() { gchar * socketstdout = nullptr; GError * error = nullptr; g_unsetenv("G_MESSAGES_DEBUG"); g_spawn_command_line_sync( SOCKET_DEMANGLER " " SOCKET_TOOL, &socketstdout, nullptr, nullptr, &error); if (error != nullptr) { fprintf(stderr, "Unable to spawn '" SOCKET_DEMANGLER " " SOCKET_TOOL "': %s\n", error->message); g_error_free(error); outputpromise.set_value(std::string("")); } else { outputpromise.set_value(std::string(socketstdout)); g_free(socketstdout); } }); t.detach(); auto outputfuture = outputpromise.get_future(); while (outputfuture.wait_for(std::chrono::milliseconds{1}) != std::future_status::ready) { pause(); } ASSERT_STREQ(filedata, outputfuture.get().c_str()); ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(mock, obj, NULL)); return; } TEST_F(LibUAL, SetExec) { DbusTestDbusMockObject * obj = dbus_test_dbus_mock_get_object(mock, "/com/ubuntu/Upstart", "com.ubuntu.Upstart0_6", NULL); const char * exec = "lets exec this"; g_setenv("UPSTART_JOB", "fubar", TRUE); g_unsetenv("UBUNTU_APP_LAUNCH_DEMANGLE_NAME"); EXPECT_TRUE(ubuntu_app_launch_helper_set_exec(exec, NULL)); guint len = 0; const DbusTestDbusMockCall * calls = dbus_test_dbus_mock_object_get_method_calls(mock, obj, "SetEnv", &len, NULL); ASSERT_NE(nullptr, calls); EXPECT_EQ(1, len); gchar * appexecstr = g_strdup_printf("APP_EXEC=%s", exec); GVariant * appexecenv = g_variant_get_child_value(calls[0].params, 1); EXPECT_STREQ(appexecstr, g_variant_get_string(appexecenv, nullptr)); g_variant_unref(appexecenv); g_free(appexecstr); ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(mock, obj, NULL)); /* Now check for the demangler */ g_setenv("UBUNTU_APP_LAUNCH_DEMANGLE_NAME", g_dbus_connection_get_unique_name(bus), TRUE); EXPECT_TRUE(ubuntu_app_launch_helper_set_exec(exec, NULL)); calls = dbus_test_dbus_mock_object_get_method_calls(mock, obj, "SetEnv", &len, NULL); ASSERT_NE(nullptr, calls); EXPECT_EQ(1, len); gchar * demangleexecstr = g_strdup_printf("APP_EXEC=%s %s", SOCKET_DEMANGLER_INSTALL, exec); appexecenv = g_variant_get_child_value(calls[0].params, 1); EXPECT_STREQ(demangleexecstr, g_variant_get_string(appexecenv, nullptr)); g_variant_unref(appexecenv); g_free(demangleexecstr); ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(mock, obj, NULL)); /* Now check for the directory */ g_setenv("UBUNTU_APP_LAUNCH_DEMANGLE_NAME", g_dbus_connection_get_unique_name(bus), TRUE); EXPECT_TRUE(ubuntu_app_launch_helper_set_exec(exec, "/not/a/real/directory")); calls = dbus_test_dbus_mock_object_get_method_calls(mock, obj, "SetEnv", &len, NULL); ASSERT_NE(nullptr, calls); EXPECT_EQ(2, len); appexecenv = g_variant_get_child_value(calls[1].params, 1); EXPECT_STREQ("APP_DIR=/not/a/real/directory", g_variant_get_string(appexecenv, nullptr)); g_variant_unref(appexecenv); ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(mock, obj, NULL)); } TEST_F(LibUAL, AppInfo) { g_setenv("TEST_CLICK_DB", "click-db-dir", TRUE); g_setenv("TEST_CLICK_USER", "test-user", TRUE); char * dir = nullptr; char * file = nullptr; /* Basics */ EXPECT_TRUE(ubuntu_app_launch_application_info("com.test.good_application_1.2.3", nullptr, nullptr)); EXPECT_FALSE(ubuntu_app_launch_application_info("com.test.bad_not-app_1.3.3.7", nullptr, nullptr)); EXPECT_FALSE(ubuntu_app_launch_application_info(nullptr, nullptr, nullptr)); /* Ensure false doesn't set the values */ EXPECT_FALSE(ubuntu_app_launch_application_info("com.test.bad_not-app_1.3.3.7", &dir, &file)); EXPECT_EQ(nullptr, dir); EXPECT_EQ(nullptr, file); g_clear_pointer(&dir, g_free); g_clear_pointer(&file, g_free); /* Correct values from a click */ EXPECT_TRUE(ubuntu_app_launch_application_info("com.test.good_application_1.2.3", &dir, &file)); EXPECT_STREQ(CMAKE_SOURCE_DIR "/click-root-dir/.click/users/test-user/com.test.good", dir); EXPECT_STREQ("application.desktop", file); g_clear_pointer(&dir, g_free); g_clear_pointer(&file, g_free); /* Correct values from a legacy */ EXPECT_TRUE(ubuntu_app_launch_application_info("bar", &dir, &file)); EXPECT_STREQ(CMAKE_SOURCE_DIR, dir); EXPECT_STREQ("applications/bar.desktop", file); g_clear_pointer(&dir, g_free); g_clear_pointer(&file, g_free); /* Correct values for libertine */ EXPECT_TRUE(ubuntu_app_launch_application_info("container-name_test_0.0", &dir, &file)); EXPECT_STREQ(CMAKE_SOURCE_DIR "/libertine-data/libertine-container/container-name/rootfs/usr/share", dir); EXPECT_STREQ("applications/test.desktop", file); g_clear_pointer(&dir, g_free); g_clear_pointer(&file, g_free); } ubuntu-app-launch-0.5+15.10.20150817/tests/socket-tool.c0000644000015300001610000000072312564452056023047 0ustar pbuserpbgroup00000000000000 #include #include #include int main (int argc, char * argv[]) { const char * fdstr = getenv("MIR_SOCKET"); if (!fdstr) { fprintf(stderr, "No MIR_SOCKET defined\n"); return 1; } int fdnum = 0; sscanf(fdstr, "fd://%d", &fdnum); if (fdnum == 0) { fprintf(stderr, "Unable to get FD number\n"); return 1; } char inchar; while (read(fdnum, &inchar, 1) == 1) fwrite(&inchar, 1, 1, stdout); close(fdnum); return 0; } ubuntu-app-launch-0.5+15.10.20150817/tests/click-app-dir/0000755000015300001610000000000012564452317023055 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-app-dir/.click/0000755000015300001610000000000012564452317024220 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-app-dir/.click/info/0000755000015300001610000000000012564452317025153 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-app-dir/.click/info/com.test.multiple.manifest0000644000015300001610000000046712564452056032300 0ustar pbuserpbgroup00000000000000{ "version": "1.2.3", "hooks": { "first": { "desktop": "application.desktop" }, "second": { "desktop": "application.desktop" }, "third": { "desktop": "application.desktop" }, "fourth": { "desktop": "application.desktop" }, "fifth": { "desktop": "application.desktop" } } } ubuntu-app-launch-0.5+15.10.20150817/tests/click-app-dir/.click/info/com.test.no-json.manifest0000644000015300001610000000010112564452056032011 0ustar pbuserpbgroup00000000000000 Lovin' some data ubuntu-app-launch-0.5+15.10.20150817/tests/click-app-dir/.click/info/com.test.good.manifest0000644000015300001610000000014312564452056031364 0ustar pbuserpbgroup00000000000000{ "version": "1.2.3", "hooks": { "application": { "desktop": "application.desktop" } } } ubuntu-app-launch-0.5+15.10.20150817/tests/click-app-dir/.click/info/com.test.no-app.manifest0000644000015300001610000000014612564452056031631 0ustar pbuserpbgroup00000000000000{ "version": "1.2.3", "hooks": { "no-application": { "desktop": "application.desktop" } } } ubuntu-app-launch-0.5+15.10.20150817/tests/click-app-dir/.click/info/com.test.no-version.manifest0000644000015300001610000000013712564452056032536 0ustar pbuserpbgroup00000000000000{ "ver": "1.2.3", "hooks": { "application": { "desktop": "application.desktop" } } } ubuntu-app-launch-0.5+15.10.20150817/tests/click-app-dir/.click/info/com.test.no-object.manifest0000644000015300001610000000003312564452056032312 0ustar pbuserpbgroup00000000000000[ "foo", "bar", 5, 6 ] ubuntu-app-launch-0.5+15.10.20150817/tests/click-app-dir/.click/info/com.test.no-hooks.manifest0000644000015300001610000000014412564452056032172 0ustar pbuserpbgroup00000000000000{ "version": "1.2.3", "hookie": { "application": { "desktop": "application.desktop" } } } ubuntu-app-launch-0.5+15.10.20150817/tests/click-app-dir/.click/info/com.test.bad-version.manifest0000644000015300001610000000014312564452056032645 0ustar pbuserpbgroup00000000000000{ "version": "4.5.6", "hooks": { "application": { "desktop": "application.desktop" } } } ubuntu-app-launch-0.5+15.10.20150817/tests/click-app-dir/.click/info/com.test.mir.manifest0000644000015300001610000000020112564452110031205 0ustar pbuserpbgroup00000000000000{ "version": "1", "hooks": { "mir": { "desktop": "xmir.desktop" }, "nomir": { "desktop": "noxmir.desktop" } } } ubuntu-app-launch-0.5+15.10.20150817/tests/click-app-dir/application.desktop0000644000015300001610000000007312564452056026753 0ustar pbuserpbgroup00000000000000[Desktop Entry] Name=Application Type=Application Exec=foo ubuntu-app-launch-0.5+15.10.20150817/tests/click-app-dir/noxmir.desktop0000644000015300001610000000021012564452110025744 0ustar pbuserpbgroup00000000000000[Desktop Entry] Name=No XMir Needed Type=Application Exec=noxmir NoDisplay=false Hidden=false Terminal=false X-Ubuntu-XMir-Enable=false ubuntu-app-launch-0.5+15.10.20150817/tests/click-app-dir/xmir.desktop0000644000015300001610000000020412564452110025412 0ustar pbuserpbgroup00000000000000[Desktop Entry] Name=X Application Type=Application Exec=xfoo NoDisplay=false Hidden=false Terminal=false X-Ubuntu-XMir-Enable=true ubuntu-app-launch-0.5+15.10.20150817/tests/ubuntu-app-launch-mock.h0000644000015300001610000000130412564452056025104 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ void ubuntu_app_launch_mock_set_primary_pid (GPid pid); ubuntu-app-launch-0.5+15.10.20150817/tests/mir-mock.h0000644000015300001610000000041012564452056022320 0ustar pbuserpbgroup00000000000000 #ifndef MIR_MOCK_H #define MIR_MOCK_H 1 #include #include void mir_mock_connect_return_valid (bool valid); std::pair mir_mock_connect_last_connect (void); void mir_mock_set_trusted_fd (int fd); #endif // MIR_MOCK_H ubuntu-app-launch-0.5+15.10.20150817/tests/ubuntu-app-launch-mock.c0000644000015300001610000000210112564452056025073 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include "ubuntu-app-launch.h" #include "ubuntu-app-launch-mock.h" static GPid primary_pid = 0; static gchar * primary_pid_appid = NULL; GPid ubuntu_app_launch_get_primary_pid (const gchar * appid) { g_free(primary_pid_appid); primary_pid_appid = g_strdup(appid); return primary_pid; } void ubuntu_app_launch_mock_set_primary_pid (GPid pid) { primary_pid = pid; return; } ubuntu-app-launch-0.5+15.10.20150817/tests/failure-test.cc0000644000015300001610000000753012564452056023356 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include #include #include #include class FailureTest : public ::testing::Test { private: GTestDBus * testbus = NULL; protected: virtual void SetUp() { testbus = g_test_dbus_new(G_TEST_DBUS_NONE); g_test_dbus_up(testbus); } virtual void TearDown() { g_test_dbus_down(testbus); g_clear_object(&testbus); return; } static gboolean pause_helper (gpointer pmainloop) { g_main_loop_quit(static_cast(pmainloop)); return G_SOURCE_REMOVE; } void pause (guint time) { if (time > 0) { GMainLoop * mainloop = g_main_loop_new(NULL, FALSE); g_timeout_add(time, pause_helper, mainloop); g_main_loop_run(mainloop); g_main_loop_unref(mainloop); } while (g_main_pending()) { g_main_iteration(TRUE); } } }; static void failed_observer (const gchar * appid, UbuntuAppLaunchAppFailed reason, gpointer user_data) { if (reason == UBUNTU_APP_LAUNCH_APP_FAILED_CRASH) { std::string * last = static_cast(user_data); *last = appid; } return; } TEST_F(FailureTest, CrashTest) { g_setenv("EXIT_STATUS", "-100", TRUE); g_setenv("JOB", "application-click", TRUE); g_setenv("INSTANCE", "foo", TRUE); std::string last_observer; ASSERT_TRUE(ubuntu_app_launch_observer_add_app_failed(failed_observer, &last_observer)); /* Status based */ ASSERT_TRUE(g_spawn_command_line_sync(APP_FAILED_TOOL, NULL, NULL, NULL, NULL)); pause(100); EXPECT_EQ("foo", last_observer); last_observer.clear(); g_unsetenv("EXIT_STATUS"); g_setenv("EXIT_SIGNAL", "KILL", TRUE); /* Signal based */ ASSERT_TRUE(g_spawn_command_line_sync(APP_FAILED_TOOL, NULL, NULL, NULL, NULL)); pause(100); EXPECT_EQ("foo", last_observer); ASSERT_TRUE(ubuntu_app_launch_observer_delete_app_failed(failed_observer, &last_observer)); return; } TEST_F(FailureTest, LegacyTest) { g_setenv("EXIT_STATUS", "-100", TRUE); g_setenv("JOB", "application-legacy", TRUE); g_setenv("INSTANCE", "foo-1234", TRUE); std::string last_observer; ASSERT_TRUE(ubuntu_app_launch_observer_add_app_failed(failed_observer, &last_observer)); /* Status based */ ASSERT_TRUE(g_spawn_command_line_sync(APP_FAILED_TOOL, NULL, NULL, NULL, NULL)); pause(100); EXPECT_EQ("foo", last_observer); ASSERT_TRUE(ubuntu_app_launch_observer_delete_app_failed(failed_observer, &last_observer)); return; } static void failed_start_observer (const gchar * appid, UbuntuAppLaunchAppFailed reason, gpointer user_data) { if (reason == UBUNTU_APP_LAUNCH_APP_FAILED_START_FAILURE) { std::string * last = static_cast(user_data); *last = appid; } return; } TEST_F(FailureTest, StartTest) { g_setenv("JOB", "application-click", TRUE); g_setenv("INSTANCE", "foo", TRUE); g_unsetenv("EXIT_STATUS"); g_unsetenv("EXIT_SIGNAL"); std::string last_observer; ASSERT_TRUE(ubuntu_app_launch_observer_add_app_failed(failed_start_observer, &last_observer)); ASSERT_TRUE(g_spawn_command_line_sync(APP_FAILED_TOOL, NULL, NULL, NULL, NULL)); pause(100); EXPECT_EQ("foo", last_observer); ASSERT_TRUE(ubuntu_app_launch_observer_delete_app_failed(failed_start_observer, &last_observer)); return; } ubuntu-app-launch-0.5+15.10.20150817/tests/libertine-data/0000755000015300001610000000000012564452317023322 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/libertine-data/libertine-container/0000755000015300001610000000000012564452317027257 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/libertine-data/libertine-container/container-name/0000755000015300001610000000000012564452317032157 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/libertine-data/libertine-container/container-name/rootfs/0000755000015300001610000000000012564452317033473 5ustar pbuserpbgroup00000000000000././@LongLink0000000000000000000000000000015100000000000011212 Lustar 00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/libertine-data/libertine-container/container-name/rootfs/usr/ubuntu-app-launch-0.5+15.10.20150817/tests/libertine-data/libertine-container/container-name/rootfs/0000755000015300001610000000000012564452317033473 5ustar pbuserpbgroup00000000000000././@LongLink0000000000000000000000000000015700000000000011220 Lustar 00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/libertine-data/libertine-container/container-name/rootfs/usr/share/ubuntu-app-launch-0.5+15.10.20150817/tests/libertine-data/libertine-container/container-name/rootfs/0000755000015300001610000000000012564452317033473 5ustar pbuserpbgroup00000000000000././@LongLink0000000000000000000000000000017400000000000011217 Lustar 00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/libertine-data/libertine-container/container-name/rootfs/usr/share/applications/ubuntu-app-launch-0.5+15.10.20150817/tests/libertine-data/libertine-container/container-name/rootfs/0000755000015300001610000000000012564452317033473 5ustar pbuserpbgroup00000000000000././@LongLink0000000000000000000000000000021000000000000011206 Lustar 00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/libertine-data/libertine-container/container-name/rootfs/usr/share/applications/test.desktopubuntu-app-launch-0.5+15.10.20150817/tests/libertine-data/libertine-container/container-name/rootfs/0000644000015300001610000000006512564452117033474 0ustar pbuserpbgroup00000000000000[Desktop Entry] Name=Test Type=Application Exec=test ubuntu-app-launch-0.5+15.10.20150817/tests/libertine-home/0000755000015300001610000000000012564452317023341 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/libertine-home/libertine-container/0000755000015300001610000000000012564452317027276 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/libertine-home/libertine-container/user-data/0000755000015300001610000000000012564452317031163 5ustar pbuserpbgroup00000000000000././@LongLink0000000000000000000000000000015000000000000011211 Lustar 00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/libertine-home/libertine-container/user-data/container-name/ubuntu-app-launch-0.5+15.10.20150817/tests/libertine-home/libertine-container/user-data/container-na0000755000015300001610000000000012564452317033462 5ustar pbuserpbgroup00000000000000././@LongLink0000000000000000000000000000015700000000000011220 Lustar 00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/libertine-home/libertine-container/user-data/container-name/.local/ubuntu-app-launch-0.5+15.10.20150817/tests/libertine-home/libertine-container/user-data/container-na0000755000015300001610000000000012564452317033462 5ustar pbuserpbgroup00000000000000././@LongLink0000000000000000000000000000016500000000000011217 Lustar 00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/libertine-home/libertine-container/user-data/container-name/.local/share/ubuntu-app-launch-0.5+15.10.20150817/tests/libertine-home/libertine-container/user-data/container-na0000755000015300001610000000000012564452317033462 5ustar pbuserpbgroup00000000000000././@LongLink0000000000000000000000000000020200000000000011207 Lustar 00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/libertine-home/libertine-container/user-data/container-name/.local/share/applications/ubuntu-app-launch-0.5+15.10.20150817/tests/libertine-home/libertine-container/user-data/container-na0000755000015300001610000000000012564452317033462 5ustar pbuserpbgroup00000000000000././@LongLink0000000000000000000000000000022200000000000011211 Lustar 00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/libertine-home/libertine-container/user-data/container-name/.local/share/applications/user-app.desktopubuntu-app-launch-0.5+15.10.20150817/tests/libertine-home/libertine-container/user-data/container-na0000644000015300001610000000007512564452117033464 0ustar pbuserpbgroup00000000000000[Desktop Entry] Name=User App Type=Application Exec=user-app ubuntu-app-launch-0.5+15.10.20150817/tests/helper-test.cc0000644000015300001610000003626512564452056023215 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include #include #include #include extern "C" { #include "../helpers.h" } class HelperTest : public ::testing::Test { private: protected: virtual void SetUp() { g_setenv("XDG_DATA_DIRS", CMAKE_SOURCE_DIR, TRUE); g_setenv("DATA_WRITE_DIR", CMAKE_BINARY_DIR, TRUE); g_setenv("UPSTART_JOB", "made-up-job", TRUE); return; } }; TEST_F(HelperTest, AppIdTest) { ASSERT_TRUE(app_id_to_triplet("com.ubuntu.test_test_123", NULL, NULL, NULL)); ASSERT_FALSE(app_id_to_triplet("inkscape", NULL, NULL, NULL)); ASSERT_FALSE(app_id_to_triplet("music-app", NULL, NULL, NULL)); gchar * pkg; gchar * app; gchar * version; ASSERT_TRUE(app_id_to_triplet("com.ubuntu.test_test_123", &pkg, &app, &version)); ASSERT_STREQ(pkg, "com.ubuntu.test"); ASSERT_STREQ(app, "test"); ASSERT_STREQ(version, "123"); g_free(pkg); g_free(app); g_free(version); return; } TEST_F(HelperTest, DesktopExecParse) { GArray * output; /* No %s and no URLs */ output = desktop_exec_parse("foo", NULL); ASSERT_EQ(output->len, 1); ASSERT_STREQ(g_array_index(output, gchar *, 0), "foo"); g_array_free(output, TRUE); /* URL without any % items */ output = desktop_exec_parse("foo", "http://ubuntu.com"); ASSERT_EQ(output->len, 1); ASSERT_STREQ(g_array_index(output, gchar *, 0), "foo"); g_array_free(output, TRUE); /* Little u with a single URL */ output = desktop_exec_parse("foo %u", "http://ubuntu.com"); ASSERT_EQ(output->len, 2); ASSERT_STREQ(g_array_index(output, gchar *, 0), "foo"); ASSERT_STREQ(g_array_index(output, gchar *, 1), "http://ubuntu.com"); g_array_free(output, TRUE); /* Little u with a NULL string */ output = desktop_exec_parse("foo %u", ""); ASSERT_EQ(output->len, 1); ASSERT_STREQ(g_array_index(output, gchar *, 0), "foo"); g_array_free(output, TRUE); /* Big %U with a single URL */ output = desktop_exec_parse("foo %U", "http://ubuntu.com"); ASSERT_EQ(output->len, 2); ASSERT_STREQ(g_array_index(output, gchar *, 0), "foo"); ASSERT_STREQ(g_array_index(output, gchar *, 1), "http://ubuntu.com"); g_array_free(output, TRUE); /* Little %u by itself */ output = desktop_exec_parse("foo %u", "http://ubuntu.com http://slashdot.org"); ASSERT_EQ(output->len, 2); ASSERT_STREQ(g_array_index(output, gchar *, 0), "foo"); ASSERT_STREQ(g_array_index(output, gchar *, 1), "http://ubuntu.com"); g_array_free(output, TRUE); /* Little %u in quotes */ output = desktop_exec_parse("foo %u \"%u\" %u%u", "http://ubuntu.com"); ASSERT_EQ(output->len, 4); ASSERT_STREQ(g_array_index(output, gchar *, 0), "foo"); ASSERT_STREQ(g_array_index(output, gchar *, 1), "http://ubuntu.com"); ASSERT_STREQ(g_array_index(output, gchar *, 2), "http://ubuntu.com"); ASSERT_STREQ(g_array_index(output, gchar *, 3), "http://ubuntu.comhttp://ubuntu.com"); g_array_free(output, TRUE); /* Single escaped " before the URL as a second param */ output = desktop_exec_parse("foo \\\"%u", "http://ubuntu.com"); ASSERT_EQ(output->len, 2); ASSERT_STREQ(g_array_index(output, gchar *, 0), "foo"); ASSERT_STREQ(g_array_index(output, gchar *, 1), "\"http://ubuntu.com"); g_array_free(output, TRUE); /* URL is a quote, make sure we handle the error */ output = desktop_exec_parse("foo %u", "\""); ASSERT_EQ(output->len, 1); ASSERT_STREQ(g_array_index(output, gchar *, 0), "foo"); g_array_free(output, TRUE); /* Lots of quotes, escaped and not */ output = desktop_exec_parse("foo \\\"\"%u\"", "'\"'"); ASSERT_EQ(output->len, 2); ASSERT_STREQ(g_array_index(output, gchar *, 0), "foo"); ASSERT_STREQ(g_array_index(output, gchar *, 1), "\"\""); g_array_free(output, TRUE); /* Let's have no params, but a little %u */ output = desktop_exec_parse("foo\\ %u", "bar"); ASSERT_EQ(output->len, 1); ASSERT_STREQ(g_array_index(output, gchar *, 0), "foo bar"); g_array_free(output, TRUE); /* Big U with two URLs */ output = desktop_exec_parse("foo %U", "http://ubuntu.com http://slashdot.org"); ASSERT_EQ(output->len, 3); ASSERT_STREQ(g_array_index(output, gchar *, 0), "foo"); ASSERT_STREQ(g_array_index(output, gchar *, 1), "http://ubuntu.com"); ASSERT_STREQ(g_array_index(output, gchar *, 2), "http://slashdot.org"); g_array_free(output, TRUE); /* Big U with no URLs */ output = desktop_exec_parse("foo %U", NULL); ASSERT_EQ(output->len, 1); ASSERT_STREQ(g_array_index(output, gchar *, 0), "foo"); g_array_free(output, TRUE); /* Big U with quoted URL */ output = desktop_exec_parse("foo %U", "'http://ubuntu.com'"); ASSERT_EQ(output->len, 2); ASSERT_STREQ(g_array_index(output, gchar *, 0), "foo"); ASSERT_STREQ(g_array_index(output, gchar *, 1), "http://ubuntu.com"); g_array_free(output, TRUE); /* Big U with URLs that have spaces */ output = desktop_exec_parse("foo %u", "'http://bob.com/foo bar/' http://slashdot.org"); ASSERT_EQ(output->len, 2); ASSERT_STREQ(g_array_index(output, gchar *, 0), "foo"); ASSERT_STREQ(g_array_index(output, gchar *, 1), "http://bob.com/foo bar/"); g_array_free(output, TRUE); /* %f with a valid file */ output = desktop_exec_parse("foo %f", "file:///proc/version"); ASSERT_EQ(output->len, 2); ASSERT_STREQ(g_array_index(output, gchar *, 0), "foo"); ASSERT_STREQ(g_array_index(output, gchar *, 1), "/proc/version"); g_array_free(output, TRUE); /* A %f with a NULL string */ output = desktop_exec_parse("foo %f", ""); ASSERT_EQ(output->len, 1); ASSERT_STREQ(g_array_index(output, gchar *, 0), "foo"); g_array_free(output, TRUE); /* %f with a URL that isn't a file */ output = desktop_exec_parse("foo %f", "torrent://moviephone.com/hot-new-movie"); ASSERT_EQ(output->len, 1); ASSERT_STREQ(g_array_index(output, gchar *, 0), "foo"); g_array_free(output, TRUE); /* Lots of %f combinations */ output = desktop_exec_parse("foo %f \"%f\" %f%f %f\\ %f", "file:///proc/version"); ASSERT_EQ(output->len, 5); ASSERT_STREQ(g_array_index(output, gchar *, 0), "foo"); ASSERT_STREQ(g_array_index(output, gchar *, 1), "/proc/version"); ASSERT_STREQ(g_array_index(output, gchar *, 2), "/proc/version"); ASSERT_STREQ(g_array_index(output, gchar *, 3), "/proc/version/proc/version"); ASSERT_STREQ(g_array_index(output, gchar *, 4), "/proc/version /proc/version"); g_array_free(output, TRUE); /* Little f with two files */ output = desktop_exec_parse("foo %f", "file:///proc/version file:///proc/uptime"); ASSERT_EQ(output->len, 2); ASSERT_STREQ(g_array_index(output, gchar *, 0), "foo"); ASSERT_STREQ(g_array_index(output, gchar *, 1), "/proc/version"); g_array_free(output, TRUE); /* Big F with two files */ output = desktop_exec_parse("foo %F", "file:///proc/version file:///proc/uptime"); ASSERT_EQ(output->len, 3); ASSERT_STREQ(g_array_index(output, gchar *, 0), "foo"); ASSERT_STREQ(g_array_index(output, gchar *, 1), "/proc/version"); ASSERT_STREQ(g_array_index(output, gchar *, 2), "/proc/uptime"); g_array_free(output, TRUE); /* Big F with no files */ output = desktop_exec_parse("foo %F", NULL); ASSERT_EQ(output->len, 1); ASSERT_STREQ(g_array_index(output, gchar *, 0), "foo"); g_array_free(output, TRUE); /* Groups of percents */ output = desktop_exec_parse("foo %% \"%%\" %%%%", NULL); ASSERT_EQ(output->len, 4); ASSERT_STREQ(g_array_index(output, gchar *, 0), "foo"); ASSERT_STREQ(g_array_index(output, gchar *, 1), "%"); ASSERT_STREQ(g_array_index(output, gchar *, 2), "%"); ASSERT_STREQ(g_array_index(output, gchar *, 3), "%%"); g_array_free(output, TRUE); /* All the % sequences we don't support */ output = desktop_exec_parse("foo %d %D %n %N %v %m %i %c %k", "file:///proc/version"); ASSERT_EQ(output->len, 1); ASSERT_STREQ(g_array_index(output, gchar *, 0), "foo"); g_array_free(output, TRUE); return; } TEST_F(HelperTest, KeyfileForAppid) { GKeyFile * keyfile = NULL; gchar * desktop = NULL; g_debug("XDG_DATA_DIRS=%s", g_getenv("XDG_DATA_DIRS")); keyfile = keyfile_for_appid("bar", &desktop); ASSERT_TRUE(keyfile == NULL); ASSERT_TRUE(desktop == NULL); keyfile = keyfile_for_appid("foo", &desktop); ASSERT_TRUE(keyfile != NULL); ASSERT_TRUE(desktop != NULL); g_key_file_free(keyfile); g_free(desktop); desktop = NULL; keyfile = keyfile_for_appid("no-exec", &desktop); ASSERT_TRUE(keyfile == NULL); ASSERT_TRUE(desktop == NULL); keyfile = keyfile_for_appid("no-entry", &desktop); ASSERT_TRUE(keyfile == NULL); ASSERT_TRUE(desktop == NULL); return; } TEST_F(HelperTest, SetConfinedEnvvars) { DbusTestService * service = dbus_test_service_new(NULL); DbusTestDbusMock * mock = dbus_test_dbus_mock_new("com.ubuntu.Upstart"); DbusTestDbusMockObject * obj = dbus_test_dbus_mock_get_object(mock, "/com/ubuntu/Upstart", "com.ubuntu.Upstart0_6", NULL); dbus_test_dbus_mock_object_add_method(mock, obj, "SetEnvList", G_VARIANT_TYPE("(asasb)"), NULL, "", NULL); dbus_test_service_add_task(service, DBUS_TEST_TASK(mock)); dbus_test_service_start_tasks(service); GDBusConnection * bus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); g_dbus_connection_set_exit_on_close(bus, FALSE); g_object_add_weak_pointer(G_OBJECT(bus), (gpointer *)&bus); /* Not a test other than "don't crash" */ EnvHandle * handle = env_handle_start(); set_confined_envvars(handle, "foo-app-pkg", "/foo/bar"); env_handle_finish(handle); guint len = 0; const DbusTestDbusMockCall * calls = dbus_test_dbus_mock_object_get_method_calls(mock, obj, "SetEnvList", &len, NULL); ASSERT_EQ(len, 1); ASSERT_NE(calls, nullptr); ASSERT_STREQ("SetEnvList", calls[0].name); unsigned int i; bool got_app_isolation = false; bool got_cache_home = false; bool got_config_home = false; bool got_data_home = false; bool got_runtime_dir = false; bool got_data_dirs = false; bool got_temp_dir = false; bool got_shader_dir = false; GVariant * envarray = g_variant_get_child_value(calls[0].params, 1); GVariantIter iter; g_variant_iter_init(&iter, envarray); gchar * envvar = NULL; while (g_variant_iter_loop(&iter, "s", &envvar)) { gchar * var = g_strdup(envvar); gchar * equal = g_strstr_len(var, -1, "="); ASSERT_NE(equal, nullptr); equal[0] = '\0'; gchar * value = &(equal[1]); if (g_strcmp0(var, "UBUNTU_APPLICATION_ISOLATION") == 0) { ASSERT_STREQ(value, "1"); got_app_isolation = true; } else if (g_strcmp0(var, "XDG_CACHE_HOME") == 0) { got_cache_home = true; } else if (g_strcmp0(var, "XDG_CONFIG_HOME") == 0) { got_config_home = true; } else if (g_strcmp0(var, "XDG_DATA_HOME") == 0) { got_data_home = true; } else if (g_strcmp0(var, "XDG_RUNTIME_DIR") == 0) { got_runtime_dir = true; } else if (g_strcmp0(var, "XDG_DATA_DIRS") == 0) { ASSERT_TRUE(g_str_has_prefix(value, "/foo/bar:")); got_data_dirs = true; } else if (g_strcmp0(var, "TMPDIR") == 0) { ASSERT_TRUE(g_str_has_suffix(value, "foo-app-pkg")); got_temp_dir = true; } else if (g_strcmp0(var, "__GL_SHADER_DISK_CACHE_PATH") == 0) { ASSERT_TRUE(g_str_has_suffix(value, "foo-app-pkg")); got_shader_dir = true; } else { g_warning("Unknown variable! %s", var); ASSERT_TRUE(false); } g_free(var); } g_variant_unref(envarray); ASSERT_TRUE(got_app_isolation); ASSERT_TRUE(got_cache_home); ASSERT_TRUE(got_config_home); ASSERT_TRUE(got_data_home); ASSERT_TRUE(got_runtime_dir); ASSERT_TRUE(got_data_dirs); ASSERT_TRUE(got_temp_dir); ASSERT_TRUE(got_shader_dir); g_object_unref(bus); g_object_unref(mock); g_object_unref(service); return; } TEST_F(HelperTest, DesktopToExec) { GKeyFile * keyfile = NULL; gchar * exec = NULL; keyfile = g_key_file_new(); ASSERT_TRUE(g_key_file_load_from_file(keyfile, CMAKE_SOURCE_DIR "/applications/foo.desktop", G_KEY_FILE_NONE, NULL)); exec = desktop_to_exec(keyfile, ""); ASSERT_TRUE(exec != NULL); ASSERT_STREQ(exec, "foo"); g_free(exec); g_key_file_free(keyfile); keyfile = g_key_file_new(); ASSERT_TRUE(g_key_file_load_from_file(keyfile, CMAKE_SOURCE_DIR "/applications/hidden.desktop", G_KEY_FILE_NONE, NULL)); exec = desktop_to_exec(keyfile, ""); ASSERT_TRUE(exec == NULL); g_key_file_free(keyfile); keyfile = g_key_file_new(); ASSERT_TRUE(g_key_file_load_from_file(keyfile, CMAKE_SOURCE_DIR "/applications/nodisplay.desktop", G_KEY_FILE_NONE, NULL)); exec = desktop_to_exec(keyfile, ""); ASSERT_TRUE(exec == NULL); g_key_file_free(keyfile); keyfile = g_key_file_new(); ASSERT_TRUE(g_key_file_load_from_file(keyfile, CMAKE_SOURCE_DIR "/applications/no-entry.desktop", G_KEY_FILE_NONE, NULL)); exec = desktop_to_exec(keyfile, ""); ASSERT_TRUE(exec == NULL); g_key_file_free(keyfile); keyfile = g_key_file_new(); ASSERT_TRUE(g_key_file_load_from_file(keyfile, CMAKE_SOURCE_DIR "/applications/no-exec.desktop", G_KEY_FILE_NONE, NULL)); exec = desktop_to_exec(keyfile, ""); ASSERT_TRUE(exec == NULL); g_key_file_free(keyfile); keyfile = g_key_file_new(); ASSERT_TRUE(g_key_file_load_from_file(keyfile, CMAKE_SOURCE_DIR "/applications/scope.desktop", G_KEY_FILE_NONE, NULL)); exec = desktop_to_exec(keyfile, ""); ASSERT_TRUE(exec == NULL); g_key_file_free(keyfile); keyfile = g_key_file_new(); ASSERT_TRUE(g_key_file_load_from_file(keyfile, CMAKE_SOURCE_DIR "/applications/terminal.desktop", G_KEY_FILE_NONE, NULL)); exec = desktop_to_exec(keyfile, ""); ASSERT_TRUE(exec == NULL); g_key_file_free(keyfile); return; } TEST_F(HelperTest, ManifestToDesktop) { gchar * desktop = NULL; g_setenv("TEST_CLICK_DB", "click-db-dir", TRUE); g_setenv("TEST_CLICK_USER", "test-user", TRUE); desktop = manifest_to_desktop(CMAKE_SOURCE_DIR "/click-app-dir/", "com.test.good_application_1.2.3"); ASSERT_STREQ(CMAKE_SOURCE_DIR "/click-app-dir/application.desktop", desktop); g_free(desktop); desktop = NULL; desktop = manifest_to_desktop(CMAKE_SOURCE_DIR "/click-app-dir/", "com.test.bad-version_application_1.2.3"); ASSERT_TRUE(desktop == NULL); desktop = manifest_to_desktop(CMAKE_SOURCE_DIR "/click-app-dir/", "com.test.no-app_application_1.2.3"); ASSERT_TRUE(desktop == NULL); desktop = manifest_to_desktop(CMAKE_SOURCE_DIR "/click-app-dir/", "com.test.no-hooks_application_1.2.3"); ASSERT_TRUE(desktop == NULL); desktop = manifest_to_desktop(CMAKE_SOURCE_DIR "/click-app-dir/", "com.test.no-version_application_1.2.3"); ASSERT_TRUE(desktop == NULL); desktop = manifest_to_desktop(CMAKE_SOURCE_DIR "/click-app-dir/", "com.test.no-exist_application_1.2.3"); ASSERT_TRUE(desktop == NULL); desktop = manifest_to_desktop(CMAKE_SOURCE_DIR "/click-app-dir/", "com.test.no-json_application_1.2.3"); ASSERT_TRUE(desktop == NULL); desktop = manifest_to_desktop(CMAKE_SOURCE_DIR "/click-app-dir/", "com.test.no-object_application_1.2.3"); ASSERT_TRUE(desktop == NULL); /* Bad App ID */ desktop = manifest_to_desktop(CMAKE_SOURCE_DIR "/click-app-dir/", "com.test.good_application-1.2.3"); ASSERT_TRUE(desktop == NULL); return; } ubuntu-app-launch-0.5+15.10.20150817/tests/zg-test.cc0000644000015300001610000000761212564452056022350 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include #include #include TEST(ZGEvent, OpenTest) { DbusTestService * service = dbus_test_service_new(NULL); DbusTestDbusMock * mock = dbus_test_dbus_mock_new("org.gnome.zeitgeist.Engine"); DbusTestDbusMockObject * obj = dbus_test_dbus_mock_get_object(mock, "/org/gnome/zeitgeist/log/activity", "org.gnome.zeitgeist.Log", NULL); dbus_test_dbus_mock_object_add_method(mock, obj, "InsertEvents", G_VARIANT_TYPE("a(asaasay)"), G_VARIANT_TYPE("au"), "ret = [ 0 ]", NULL); dbus_test_service_add_task(service, DBUS_TEST_TASK(mock)); DbusTestProcess * zgevent = dbus_test_process_new(ZG_EVENT_TOOL); dbus_test_process_append_param(zgevent, "open"); g_setenv("APP_ID", "foo", 1); dbus_test_task_set_wait_for(DBUS_TEST_TASK(zgevent), "org.gnome.zeitgeist.Engine"); dbus_test_task_set_name(DBUS_TEST_TASK(zgevent), "ZGEvent"); dbus_test_service_add_task(service, DBUS_TEST_TASK(zgevent)); dbus_test_service_start_tasks(service); /* Give it time to send the event and exit */ g_usleep(150000); while (g_main_pending()) { g_main_iteration(TRUE); } ASSERT_EQ(dbus_test_task_get_state(DBUS_TEST_TASK(zgevent)), DBUS_TEST_TASK_STATE_FINISHED); ASSERT_TRUE(dbus_test_task_passed(DBUS_TEST_TASK(zgevent))); guint numcalls = 0; const DbusTestDbusMockCall * calls = dbus_test_dbus_mock_object_get_method_calls(mock, obj, "InsertEvents", &numcalls, NULL); ASSERT_NE(calls, nullptr); ASSERT_EQ(numcalls, 1); g_object_unref(zgevent); g_object_unref(mock); g_object_unref(service); } static void zg_state_changed (DbusTestTask * task, DbusTestTaskState state, gpointer user_data) { if (state != DBUS_TEST_TASK_STATE_FINISHED) return; g_debug("ZG Event Task Finished"); GMainLoop * mainloop = static_cast(user_data); g_main_loop_quit(mainloop); } TEST(ZGEvent, TimeoutTest) { GMainLoop * mainloop = g_main_loop_new(NULL, FALSE); DbusTestService * service = dbus_test_service_new(NULL); DbusTestDbusMock * mock = dbus_test_dbus_mock_new("org.gnome.zeitgeist.Engine"); DbusTestDbusMockObject * obj = dbus_test_dbus_mock_get_object(mock, "/org/gnome/zeitgeist/log/activity", "org.gnome.zeitgeist.Log", NULL); dbus_test_dbus_mock_object_add_method(mock, obj, "InsertEvents", G_VARIANT_TYPE("a(asaasay)"), G_VARIANT_TYPE("au"), "time.sleep(6)\n" "ret = [ 0 ]", NULL); dbus_test_service_add_task(service, DBUS_TEST_TASK(mock)); DbusTestProcess * zgevent = dbus_test_process_new(ZG_EVENT_TOOL); dbus_test_process_append_param(zgevent, "close"); g_setenv("APP_ID", "foo", 1); dbus_test_task_set_wait_for(DBUS_TEST_TASK(zgevent), "org.gnome.zeitgeist.Engine"); dbus_test_task_set_name(DBUS_TEST_TASK(zgevent), "ZGEvent"); g_signal_connect(G_OBJECT(zgevent), DBUS_TEST_TASK_SIGNAL_STATE_CHANGED, G_CALLBACK(zg_state_changed), mainloop); dbus_test_service_add_task(service, DBUS_TEST_TASK(zgevent)); guint64 start = g_get_monotonic_time(); dbus_test_service_start_tasks(service); g_main_loop_run(mainloop); guint64 end = g_get_monotonic_time(); /* Fourteen seconds to do a two second op -- Jenkins is slow */ EXPECT_LT(end - start, 14 * 1000 * 1000); g_object_unref(zgevent); g_object_unref(service); g_main_loop_unref(mainloop); } ubuntu-app-launch-0.5+15.10.20150817/tests/click-desktop-hook-db/0000755000015300001610000000000012564452317024513 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-desktop-hook-db/test.conf.in0000644000015300001610000000011312564452056026741 0ustar pbuserpbgroup00000000000000[Click Database] root = @CMAKE_CURRENT_BINARY_DIR@/click-root-desktop-hook ubuntu-app-launch-0.5+15.10.20150817/tests/exec-test-noinit.sh0000755000015300001610000000060312564452056024173 0ustar pbuserpbgroup00000000000000#!/bin/bash -e if [ "$PATH" != "$APP_DIR/lib/64bit-amazing/bin:$APP_DIR" ] ; then echo "Bad PATH: $PATH" exit 1 fi if [ "$LD_LIBRARY_PATH" != "$APP_DIR/lib/64bit-amazing:$APP_DIR/lib" ] ; then echo "Bad LD_LIBRARY_PATH: $LD_LIBRARY_PATH" exit 1 fi if [ "$QML2_IMPORT_PATH" != "$APP_DIR/lib/64bit-amazing" ] ; then echo "Bad QML import path: $QML2_IMPORT_PATH" exit 1 fi exit 0 ubuntu-app-launch-0.5+15.10.20150817/tests/exec-test-archcolon.sh0000755000015300001610000000051112564452056024641 0ustar pbuserpbgroup00000000000000#!/bin/bash -e if [ "$PATH" != "$APP_DIR:/path" ] ; then echo "Bad PATH: $PATH" exit 1 fi if [ "$LD_LIBRARY_PATH" != "$APP_DIR/lib:/lib" ] ; then echo "Bad LD_LIBRARY_PATH: $LD_LIBRARY_PATH" exit 1 fi if [ "$QML2_IMPORT_PATH" != "/bar/qml/import" ] ; then echo "Bad QML import path: $QML2_IMPORT_PATH" exit 1 fi exit 0 ubuntu-app-launch-0.5+15.10.20150817/tests/exec-test-nullstr.sh0000755000015300001610000000060312564452056024376 0ustar pbuserpbgroup00000000000000#!/bin/bash -e if [ "$PATH" != "$APP_DIR/lib/64bit-amazing/bin:$APP_DIR" ] ; then echo "Bad PATH: $PATH" exit 1 fi if [ "$LD_LIBRARY_PATH" != "$APP_DIR/lib/64bit-amazing:$APP_DIR/lib" ] ; then echo "Bad LD_LIBRARY_PATH: $LD_LIBRARY_PATH" exit 1 fi if [ "$QML2_IMPORT_PATH" != "$APP_DIR/lib/64bit-amazing" ] ; then echo "Bad QML import path: $QML2_IMPORT_PATH" exit 1 fi exit 0 ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/0000755000015300001610000000000012564452317023260 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/com.test.no-app/0000755000015300001610000000000012564452317026205 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/com.test.no-app/1.2.30000777000015300001610000000000012564452317031556 2../../click-app-dirustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/.click/0000755000015300001610000000000012564452317024423 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/.click/users/0000755000015300001610000000000012564452317025564 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/.click/users/test-user-4/0000755000015300001610000000000012564452317027660 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/.click/users/test-user-4/com.test.good0000777000015300001610000000000012564452317036253 2../../../com.test.good/1.2.4/ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/.click/users/test-user/0000755000015300001610000000000012564452317027517 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/.click/users/test-user/com.test.no-app0000777000015300001610000000000012564452317036536 2../../../com.test.no-app/1.2.3ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/.click/users/test-user/com.test.mir0000777000015300001610000000000012564452317035306 2../../../com.test.mir/1/ustar pbuserpbgroup00000000000000././@LongLink0000000000000000000000000000014600000000000011216 Lustar 00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/.click/users/test-user/com.test.bad-versionubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/.click/users/test-user/com.test.bad-versio0000777000015300001610000000000012564452317040416 2../../../com.test.bad-version/1.2.3ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/.click/users/test-user/com.test.no-hooks0000777000015300001610000000000012564452317037444 2../../../com.test.no-hooks/1.2.3ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/.click/users/test-user/com.test.good0000777000015300001610000000000012564452317036032 2../../../com.test.good/1.2.3ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/.click/users/test-user/com.test.multiple0000777000015300001610000000000012564452317037640 2../../../com.test.multiple/1.2.3ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/.click/users/test-user/com.test.no-version0000777000015300001610000000000012564452317040350 2../../../com.test.no-version/1.2.3ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/.click/users/test-user/com.test.no-object0000777000015300001610000000000012564452317037712 2../../../com.test.no-object/1.2.3ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/.click/users/test-user/com.test.no-json0000777000015300001610000000000012564452317037120 2../../../com.test.no-json/1.2.3ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/.click/users/test-user-5/0000755000015300001610000000000012564452317027661 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/.click/users/test-user-5/com.test.good0000777000015300001610000000000012564452317036255 2../../../com.test.good/1.2.5/ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/com.test.mir/0000755000015300001610000000000012564452317025602 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/com.test.mir/10000777000015300001610000000000012564452317030731 2../../click-app-dir/ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/com.test.bad-version/0000755000015300001610000000000012564452317027224 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/com.test.bad-version/1.2.30000777000015300001610000000000012564452317032575 2../../click-app-dirustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/com.test.no-hooks/0000755000015300001610000000000012564452317026550 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/com.test.no-hooks/1.2.30000777000015300001610000000000012564452317032121 2../../click-app-dirustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/com.test.good/0000755000015300001610000000000012564452317025743 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/com.test.good/1.2.30000777000015300001610000000000012564452317031314 2../../click-app-dirustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/com.test.good/1.2.4/0000755000015300001610000000000012564452317026405 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/com.test.good/1.2.4/.click/0000755000015300001610000000000012564452317027550 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/com.test.good/1.2.4/.click/info/0000755000015300001610000000000012564452317030503 5ustar pbuserpbgroup00000000000000././@LongLink0000000000000000000000000000016100000000000011213 Lustar 00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/com.test.good/1.2.4/.click/info/com.test.good.manifestubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/com.test.good/1.2.4/.click/info/com.test.g0000644000015300001610000000014312564452056032405 0ustar pbuserpbgroup00000000000000{ "version": "1.2.4", "hooks": { "application": { "desktop": "application.desktop" } } } ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/com.test.good/1.2.4/application.desktop0000777000015300001610000000000012564452317041456 2../../../click-app-dir/application.desktopustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/com.test.good/1.2.5/0000755000015300001610000000000012564452317026406 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/com.test.good/1.2.5/.click/0000755000015300001610000000000012564452317027551 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/com.test.good/1.2.5/.click/info/0000755000015300001610000000000012564452317030504 5ustar pbuserpbgroup00000000000000././@LongLink0000000000000000000000000000016100000000000011213 Lustar 00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/com.test.good/1.2.5/.click/info/com.test.good.manifestubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/com.test.good/1.2.5/.click/info/com.test.g0000644000015300001610000000014312564452056032406 0ustar pbuserpbgroup00000000000000{ "version": "1.2.5", "hooks": { "application": { "desktop": "application.desktop" } } } ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/com.test.good/1.2.5/application.desktop0000777000015300001610000000000012564452317041457 2../../../click-app-dir/application.desktopustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/com.test.multiple/0000755000015300001610000000000012564452317026646 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/com.test.multiple/1.2.30000777000015300001610000000000012564452317032217 2../../click-app-dirustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/com.test.no-version/0000755000015300001610000000000012564452317027112 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/com.test.no-version/1.2.30000777000015300001610000000000012564452317032463 2../../click-app-dirustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/com.test.no-object/0000755000015300001610000000000012564452317026673 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/com.test.no-object/1.2.30000777000015300001610000000000012564452317032244 2../../click-app-dirustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/com.test.no-json/0000755000015300001610000000000012564452317026376 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-root-dir/com.test.no-json/1.2.30000777000015300001610000000000012564452317031747 2../../click-app-dirustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/exec-test-noarch.sh0000755000015300001610000000051112564452056024143 0ustar pbuserpbgroup00000000000000#!/bin/bash -e if [ "$PATH" != "$APP_DIR:/path" ] ; then echo "Bad PATH: $PATH" exit 1 fi if [ "$LD_LIBRARY_PATH" != "$APP_DIR/lib:/lib" ] ; then echo "Bad LD_LIBRARY_PATH: $LD_LIBRARY_PATH" exit 1 fi if [ "$QML2_IMPORT_PATH" != "/bar/qml/import" ] ; then echo "Bad QML import path: $QML2_IMPORT_PATH" exit 1 fi exit 0 ubuntu-app-launch-0.5+15.10.20150817/tests/manual0000644000015300001610000001027712564452056021645 0ustar pbuserpbgroup00000000000000Test-case ubuntu-app-launch/click-app
Ensure the clock is installed via click by running: click list
com.ubuntu.clock should be listed. Note the version for later
Ensure the clock app is not currently running: ubuntu-app-list
Clock application shouldn't be listed
Launch the clock application: ubuntu-app-launch com.ubuntu.clock_clock_$(version from click list)
The clock application should be brought to focus and shown to the user
Test-case ubuntu-app-launch/legacy-app
Ensure that the system-settings is installed: apt-cache policy ubuntu-system-settings
One of the versions in the version table should a *** next to it
Ensure the settings app is not currently running: ubuntu-app-list
Settings shouldn't be listed
Launch the settings application: ubuntu-app-launch ubuntu-system-settings
The settings application should be brought to focus and shown to the user
Test-case ubuntu-app-launch/secondary-activation
Run test case: ubuntu-app-launch/legacy-app
Everything behaves as expected
Use the launcher to return to the home screen
The settings app is no longer shown
Send a URL to the service: ubuntu-app-launch ubuntu-system-settings settings:///system/battery
The settings application should come back into focus and be on the power settings pane
Test-case ubuntu-app-launch/helper-run
NOTE: Test is theoretical today, needs other components to be written
Get a device that supports sending SMS
Typically this is a phone
Note the SMS sent count visible on the lock screen infographic for this user
Start the messaging app
Send an SMS
SMS should report as being sent successfully
Wait approximately 1 minute
Screen should lock
Look at the lock screen infographic for the SMS sent count
Count should have incremented by 1
Test-case ubuntu-app-launch/security-app-launch
Setup the security tests: https://wiki.ubuntu.com/Touch/Testing#Running_Security_tests
Execute the click-apparmor test to start and stop several confined applications
Ensure that all applications start and stop correctly
Test-case ubuntu-app-launch/cgroup-containment
Install the Terminal app if not already installed
It can be found in the Application Store if not currently installed
Launch the Terminal app
A new application should open with a terminal prompt where you can type commands
Ensure the Terminal is in a terminal specific cgroup
Type the command cat /proc/self/cgroup on the Terminal app.
Under the "freeze" cgroup the end of the path should include the AppID of the terminal. An example would be (the version many change): 4:freezer:/user.slice/user-32011.slice/session-c2.scope/upstart/application-click-com.ubuntu.terminal_terminal_0.5.106
Test-case ubuntu-app-launch/correct-job-type
Launch the settings application: ubuntu-app-launch ubuntu-system-settings
The settings application should be brought to focus and shown to the user
Launch the clock application: ubuntu-app-launch `ubuntu-app-triplet com.ubuntu.clock`
The clock application should be brought to focus and shown to the user
Verify the settings app is running under the application-legacy upstart job
Running initctl list | grep application-legacy | grep ubuntu-system-settings should return a single entry
Verify the clock app is running under the application-click upstart job
Running initctl list | grep application-click | grep com.ubuntu.clock should return a single entry
ubuntu-app-launch-0.5+15.10.20150817/tests/data-spew.c0000644000015300001610000000174512564452056022476 0ustar pbuserpbgroup00000000000000/* * Copyright © 2014 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include gboolean timeout (gpointer user_data) { g_print("Data\n"); return TRUE; } int main (int argc, char * argv[]) { GMainLoop * loop = g_main_loop_new(NULL, FALSE); g_timeout_add(100, timeout, NULL); g_main_loop_run(loop); g_main_loop_unref(loop); return 0; } ubuntu-app-launch-0.5+15.10.20150817/tests/xmir-helper-exec.sh0000755000015300001610000000003312564452110024136 0ustar pbuserpbgroup00000000000000#!/bin/bash echo $DISPLAY ubuntu-app-launch-0.5+15.10.20150817/tests/cgroup-reap-test.cc0000644000015300001610000001057612564452056024157 0ustar pbuserpbgroup00000000000000/* * Copyright 2014 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include #include #include class CGroupReap : public ::testing::Test { protected: DbusTestService * service = NULL; DbusTestDbusMock * cgmock = NULL; GDBusConnection * bus = NULL; GPid sleeppid = 0; virtual void SetUp() { const gchar * argv[] = { "sleep", "30", NULL }; g_spawn_async(NULL, (gchar **)argv, NULL, /* env */ G_SPAWN_SEARCH_PATH, NULL, NULL, /* child setup */ &sleeppid, NULL); /* error */ ASSERT_NE(0, sleeppid); service = dbus_test_service_new(NULL); /* Create the cgroup manager mock */ cgmock = dbus_test_dbus_mock_new("org.test.cgmock"); g_setenv("UBUNTU_APP_LAUNCH_CG_MANAGER_NAME", "org.test.cgmock", TRUE); DbusTestDbusMockObject * cgobject = dbus_test_dbus_mock_get_object(cgmock, "/org/linuxcontainers/cgmanager", "org.linuxcontainers.cgmanager0_0", NULL); /* This Python code executes in dbusmock and checks to see if the sleeping process is running. If it is, it returns its PID in the list of PIDs, if not it doesn't return any PIDs. */ gchar * pythoncode = g_strdup_printf( "if os.spawnlp(os.P_WAIT, 'ps', 'ps', '%d') == 0 :\n" " ret = [ %d ]\n" "else:\n" " ret = [ ]", sleeppid, sleeppid); dbus_test_dbus_mock_object_add_method(cgmock, cgobject, "GetTasksRecursive", G_VARIANT_TYPE("(ss)"), G_VARIANT_TYPE("ai"), pythoncode, NULL); g_free(pythoncode); /* Put it together */ dbus_test_service_add_task(service, DBUS_TEST_TASK(cgmock)); dbus_test_service_start_tasks(service); bus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); g_dbus_connection_set_exit_on_close(bus, FALSE); g_object_add_weak_pointer(G_OBJECT(bus), (gpointer *)&bus); /* Make sure we pretend the CG manager is just on our bus */ g_setenv("UBUNTU_APP_LAUNCH_CG_MANAGER_SESSION_BUS", "YES", TRUE); } virtual void TearDown() { g_clear_object(&cgmock); g_clear_object(&service); g_object_unref(bus); unsigned int cleartry = 0; while (bus != NULL && cleartry < 100) { pause(100); cleartry++; } ASSERT_EQ(bus, nullptr); g_debug("Killing the sleeper: %d", sleeppid); kill(sleeppid, SIGKILL); } static gboolean pause_helper (gpointer pmainloop) { g_main_loop_quit(static_cast(pmainloop)); return G_SOURCE_REMOVE; } void pause (guint time) { if (time > 0) { GMainLoop * mainloop = g_main_loop_new(NULL, FALSE); g_timeout_add(time, pause_helper, mainloop); g_main_loop_run(mainloop); g_main_loop_unref(mainloop); } while (g_main_pending()) { g_main_iteration(TRUE); } } bool sleepRunning (void) { gint status = 1; gchar * cmdline = g_strdup_printf("ps %d", sleeppid); g_spawn_command_line_sync(cmdline, NULL, NULL, &status, NULL); g_free(cmdline); return status == 0; } }; TEST_F(CGroupReap, KillSleep) { g_setenv("UPSTART_JOB", "foo", TRUE); g_setenv("UPSTART_INSTANCE", "bar", TRUE); ASSERT_TRUE(g_spawn_command_line_sync(CG_REAP_TOOL, NULL, NULL, NULL, NULL)); EXPECT_FALSE(sleepRunning()); DbusTestDbusMockObject * cgobject = dbus_test_dbus_mock_get_object(cgmock, "/org/linuxcontainers/cgmanager", "org.linuxcontainers.cgmanager0_0", NULL); const DbusTestDbusMockCall * calls = NULL; guint len = 0; calls = dbus_test_dbus_mock_object_get_method_calls(cgmock, cgobject, "GetTasksRecursive", &len, NULL); EXPECT_EQ(2, len); EXPECT_STREQ("GetTasksRecursive", calls->name); EXPECT_TRUE(g_variant_equal(calls->params, g_variant_new("(ss)", "freezer", ""))); ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(cgmock, cgobject, NULL)); } ubuntu-app-launch-0.5+15.10.20150817/tests/xmir-helper-test.in0000755000015300001610000000114412564452110024171 0ustar pbuserpbgroup00000000000000#!/bin/bash echo -n "Testing XMir Helper… " export UBUNTU_APP_LAUNCH_XMIR_PATH="@CMAKE_CURRENT_SOURCE_DIR@/xmir-mock.sh" TESTVALUE=`@CMAKE_BINARY_DIR@/xmir-helper com.mir.test_mirtest_1.2.3 @CMAKE_CURRENT_SOURCE_DIR@/xmir-helper-exec.sh` if [ $TESTVALUE == ":42" ]; then echo "PASSED" else echo "FAILED" exit 1 fi echo -n "Testing an evil XMir helper… " export UBUNTU_APP_LAUNCH_XMIR_PATH="@CMAKE_CURRENT_SOURCE_DIR@/xmir-mock-evil.sh" if @CMAKE_BINARY_DIR@/xmir-helper com.mir.test_mirtest_1.2.3 @CMAKE_CURRENT_SOURCE_DIR@/xmir-helper-exec.sh ; then echo "FAILED" exit 1 else echo "PASSED" fi ubuntu-app-launch-0.5+15.10.20150817/tests/CMakeLists.txt0000644000015300001610000000663412564452110023176 0ustar pbuserpbgroup00000000000000 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") configure_file ("click-db-dir/test.conf.in" "${CMAKE_CURRENT_BINARY_DIR}/click-db-dir/test.conf" @ONLY) set_directory_properties (PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${CMAKE_CURRENT_BINARY_DIR}/click-db-dir/test.conf") # Google Test include_directories(${GTEST_INCLUDE_DIR}) add_library (gtest STATIC ${GTEST_SOURCE_DIR}/gtest-all.cc ${GTEST_SOURCE_DIR}/gtest_main.cc) # Helper test add_executable (helper-test helper-test.cc) add_definitions ( -DCMAKE_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}" ) add_definitions ( -DCMAKE_BINARY_DIR="${CMAKE_CURRENT_BINARY_DIR}" ) target_link_libraries (helper-test helpers gtest ${GTEST_LIBS} ${DBUSTEST_LIBRARIES}) add_test (helper-test helper-test) # Helper test add_executable (helper-handshake-test helper-handshake-test.cc) target_link_libraries (helper-handshake-test helpers gtest ${GTEST_LIBS}) add_test (helper-handshake-test helper-handshake-test) # libUAL Test include_directories("${CMAKE_SOURCE_DIR}/libubuntu-app-launch") add_definitions ( -DSPEW_UTILITY="${CMAKE_CURRENT_BINARY_DIR}/data-spew" ) add_definitions ( -DSESSION_TEMP_FILE="${CMAKE_CURRENT_BINARY_DIR}/libual-test-session-start-temp" ) add_definitions ( -DSOCKET_DEMANGLER="${CMAKE_BINARY_DIR}/socket-demangler" ) add_definitions ( -DSOCKET_DEMANGLER_INSTALL="${pkglibexecdir}/socket-demangler" ) add_definitions ( -DSOCKET_TOOL="${CMAKE_CURRENT_BINARY_DIR}/socket-tool" ) add_executable (libual-test libual-test.cc mir-mock.cpp) target_link_libraries (libual-test gtest ${GTEST_LIBS} ${LIBUPSTART_LIBRARIES} ${DBUSTEST_LIBRARIES} ubuntu-launcher) add_executable (data-spew data-spew.c) target_link_libraries (data-spew ${GLIB2_LIBRARIES}) add_executable (socket-tool socket-tool.c) add_test (NAME libual-test COMMAND libual-test) # Failure Test add_definitions ( -DAPP_FAILED_TOOL="${CMAKE_BINARY_DIR}/application-failed" ) add_executable (failure-test failure-test.cc) target_link_libraries (failure-test gtest ${GTEST_LIBS} ubuntu-launcher) add_test (failure-test failure-test) # ZG Test add_definitions ( -DZG_EVENT_TOOL="${CMAKE_BINARY_DIR}/zg-report-app" ) add_executable (zg-test zg-test.cc) target_link_libraries (zg-test gtest ${GTEST_LIBS} ${DBUSTEST_LIBRARIES} ${GIO2_LIBRARIES}) add_test (zg-test zg-test) # Exec Line Exec Test configure_file("exec-test.sh.in" "${CMAKE_CURRENT_BINARY_DIR}/exec-test.sh" @ONLY) add_test (exec-test "${CMAKE_CURRENT_BINARY_DIR}/exec-test.sh") # Exec Utils add_executable (exec-util-test exec-util-test.cc) target_link_libraries (exec-util-test gtest ubuntu-launcher ${GTEST_LIBS} ${DBUSTEST_LIBRARIES} ${GIO2_LIBRARIES}) add_test (exec-util-test exec-util-test) # CGroup Reap Test add_definitions ( -DCG_REAP_TOOL="${CMAKE_BINARY_DIR}/cgroup-reap-all" ) add_executable (cgroup-reap-test cgroup-reap-test.cc) target_link_libraries (cgroup-reap-test gtest ${GTEST_LIBS} ${DBUSTEST_LIBRARIES} ${GIO2_LIBRARIES}) add_test (cgroup-reap-test cgroup-reap-test) # Desktop Hook Test configure_file ("click-desktop-hook-db/test.conf.in" "${CMAKE_CURRENT_BINARY_DIR}/click-desktop-hook-db/test.conf" @ONLY) configure_file ("desktop-hook-test.sh.in" "${CMAKE_CURRENT_BINARY_DIR}/desktop-hook-test.sh" @ONLY) add_test (desktop-hook-test desktop-hook-test.sh) # XMir helper Test configure_file ("xmir-helper-test.in" "${CMAKE_CURRENT_BINARY_DIR}/xmir-helper-test" @ONLY) add_test (xmir-helper-test xmir-helper-test) ubuntu-app-launch-0.5+15.10.20150817/tests/desktop-hook-test.sh.in0000755000015300001610000001064012564452056024767 0ustar pbuserpbgroup00000000000000#!/bin/bash -e TEST_DIR=@CMAKE_CURRENT_BINARY_DIR@ SRC_DIR=@CMAKE_CURRENT_SOURCE_DIR@ CACHE_DIR=${TEST_DIR}/desktop-hook-test-click-dir CLICK_DIR=${CACHE_DIR}/ubuntu-app-launch/desktop/ DATA_DIR=${TEST_DIR}/desktop-hook-test-apps-dir APPS_DIR=${DATA_DIR}/applications/ # Remove the old directories rm -rf ${CACHE_DIR} rm -rf ${DATA_DIR} rm -f @CMAKE_CURRENT_BINARY_DIR@/click-root-desktop-hook # Copy our source applications mkdir -p ${CLICK_DIR} cp ${SRC_DIR}/link-farm/* ${CLICK_DIR} # Build our root dir ln -s @CMAKE_CURRENT_SOURCE_DIR@/click-root-dir @CMAKE_CURRENT_BINARY_DIR@/click-root-desktop-hook # Setup the environment export XDG_CACHE_HOME=${CACHE_DIR} export XDG_DATA_HOME=${DATA_DIR} export TEST_CLICK_DB=@CMAKE_CURRENT_BINARY_DIR@/click-desktop-hook-db export TEST_CLICK_USER=test-user # Run the tool @CMAKE_BINARY_DIR@/desktop-hook # Check that the files exist if [ ! -e ${APPS_DIR}/com.test.good_application_1.2.3.desktop ] ; then echo "Desktop file not created for: com.test.good_application_1.2.3" exit 1 fi if [ ! -e ${APPS_DIR}/com.test.multiple_first_1.2.3.desktop ] ; then echo "Desktop file not created for: com.test.multiple_first_1.2.3" exit 1 fi # Verify we're adding containment to them grep "^Exec=aa-exec-click -p com.test.good_application_1.2.3 --" ${APPS_DIR}/com.test.good_application_1.2.3.desktop > /dev/null grep "^Exec=aa-exec-click -p com.test.multiple_first_1.2.3 --" ${APPS_DIR}/com.test.multiple_first_1.2.3.desktop > /dev/null # Make sure they have the AppID (people started using it) :-/ grep "^X-Ubuntu-Application-ID=com.test.good_application_1.2.3" ${APPS_DIR}/com.test.good_application_1.2.3.desktop > /dev/null grep "^X-Ubuntu-Application-ID=com.test.multiple_first_1.2.3" ${APPS_DIR}/com.test.multiple_first_1.2.3.desktop > /dev/null # Remove a file and ensure it gets recreated rm -f ${APPS_DIR}/com.test.good_application_1.2.3.desktop @CMAKE_BINARY_DIR@/desktop-hook if [ ! -e ${APPS_DIR}/com.test.good_application_1.2.3.desktop ] ; then echo "Desktop file not recreated for: com.test.good_application_1.2.3" exit 1 fi # Remove a source file and make sure it goes rm -f ${CLICK_DIR}/com.test.multiple_first_1.2.3.desktop @CMAKE_BINARY_DIR@/desktop-hook if [ -e ${APPS_DIR}/com.test.multiple_first_1.2.3.desktop ] ; then echo "Not cleaning up deleted files" exit 1 fi # Verify the good file is in the desktop hook root grep "^X-Ubuntu-UAL-Source-Desktop=@CMAKE_CURRENT_BINARY_DIR@/click-root-desktop-hook" ${APPS_DIR}/com.test.good_application_1.2.3.desktop > /dev/null # Remove our root rm -f @CMAKE_CURRENT_BINARY_DIR@/click-root-desktop-hook # Point to the new db and run export TEST_CLICK_DB=@CMAKE_CURRENT_BINARY_DIR@/click-db-dir @CMAKE_BINARY_DIR@/desktop-hook # Verify that we have the file and it's in the new root if [ ! -e ${APPS_DIR}/com.test.good_application_1.2.3.desktop ] ; then echo "Desktop file not created for: com.test.good_application_1.2.3" exit 1 fi grep "^X-Ubuntu-UAL-Source-Desktop=@CMAKE_CURRENT_SOURCE_DIR@/click-root-dir" ${APPS_DIR}/com.test.good_application_1.2.3.desktop > /dev/null # Upgrade the good application mv ${CLICK_DIR}/com.test.good_application_1.2.3.desktop ${CLICK_DIR}/com.test.good_application_1.2.4.desktop export TEST_CLICK_USER=test-user-4 @CMAKE_BINARY_DIR@/desktop-hook if [ -e ${APPS_DIR}/com.test.good_application_1.2.3.desktop ] ; then echo "Desktop file not removed for: com.test.good_application_1.2.3" exit 1 fi if [ ! -e ${APPS_DIR}/com.test.good_application_1.2.4.desktop ] ; then echo "Desktop file not created for: com.test.good_application_1.2.4" exit 1 fi # Upgrade the good application, but don't have a Source line like in an upgrade scenario mv ${CLICK_DIR}/com.test.good_application_1.2.4.desktop ${CLICK_DIR}/com.test.good_application_1.2.5.desktop cat ${APPS_DIR}/com.test.good_application_1.2.4.desktop | grep -v "^X-Ubuntu-UAL-Source-Desktop" > ${APPS_DIR}/com.test.good_application_1.2.4.desktop.tmp rm ${APPS_DIR}/com.test.good_application_1.2.4.desktop mv ${APPS_DIR}/com.test.good_application_1.2.4.desktop.tmp ${APPS_DIR}/com.test.good_application_1.2.4.desktop export TEST_CLICK_USER=test-user-5 @CMAKE_BINARY_DIR@/desktop-hook if [ -e ${APPS_DIR}/com.test.good_application_1.2.4.desktop ] ; then echo "Desktop file not removed for: com.test.good_application_1.2.4" exit 1 fi if [ ! -e ${APPS_DIR}/com.test.good_application_1.2.5.desktop ] ; then echo "Desktop file not created for: com.test.good_application_1.2.5" exit 1 fi ubuntu-app-launch-0.5+15.10.20150817/tests/click-db-dir/0000755000015300001610000000000012564452317022662 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/click-db-dir/test.conf.in0000644000015300001610000000010212564452056025106 0ustar pbuserpbgroup00000000000000[Click Database] root = @CMAKE_CURRENT_SOURCE_DIR@/click-root-dir ubuntu-app-launch-0.5+15.10.20150817/tests/exec-test-colon.sh0000755000015300001610000000046312564452056024011 0ustar pbuserpbgroup00000000000000#!/bin/bash -e if [ "$PATH" != "/path" ] ; then echo "Bad PATH: $PATH" exit 1 fi if [ "$LD_LIBRARY_PATH" != "/lib" ] ; then echo "Bad LD_LIBRARY_PATH: $LD_LIBRARY_PATH" exit 1 fi if [ "$QML2_IMPORT_PATH" != "/bar/qml/import" ] ; then echo "Bad QML import path: $QML2_IMPORT_PATH" exit 1 fi exit 0 ubuntu-app-launch-0.5+15.10.20150817/tests/xmir-mock.sh0000755000015300001610000000052012564452110022667 0ustar pbuserpbgroup00000000000000#!/bin/bash if [ $1 != "-displayfd" ]; then echo "-displayfd missing" exit 1 fi if [ $3 != "-mir" ]; then echo "-mir missing" exit 1 fi if [ $4 != "com.mir.test_mirtest_1.2.3" ]; then echo "AppID wrong" exit 1 fi echo "42" >&$2 # Ensure that our "XMir" runs longer than # the test, if it exits first that's a failure sleep 1 ubuntu-app-launch-0.5+15.10.20150817/tests/applications/0000755000015300001610000000000012564452317023124 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/tests/applications/bar.desktop0000644000015300001610000000015612564452056025265 0ustar pbuserpbgroup00000000000000 "But still valid XML" ubuntu-app-launch-0.5+15.10.20150817/tests/applications/multiple.desktop0000644000015300001610000000021012564452056026343 0ustar pbuserpbgroup00000000000000[Desktop Entry] Name=Multiple Type=Application Exec=multiple NoDisplay=false Hidden=false Terminal=false X-Ubuntu-Single-Instance=false ubuntu-app-launch-0.5+15.10.20150817/tests/applications/single.desktop0000644000015300001610000000020312564452056025773 0ustar pbuserpbgroup00000000000000[Desktop Entry] Name=Single Type=Application Exec=single NoDisplay=false Hidden=false Terminal=false X-Ubuntu-Single-Instance=true ubuntu-app-launch-0.5+15.10.20150817/tests/applications/nodisplay.desktop0000644000015300001610000000013612564452056026521 0ustar pbuserpbgroup00000000000000[Desktop Entry] Name=Foo Type=Application Exec=foo NoDisplay=true Hidden=false Terminal=false ubuntu-app-launch-0.5+15.10.20150817/tests/applications/no-entry.desktop0000644000015300001610000000014312564452056026270 0ustar pbuserpbgroup00000000000000[Desktop Non-Entry] Name=Foo Type=Application Exec=foo NoDisplay=false Hidden=false Terminal=false ubuntu-app-launch-0.5+15.10.20150817/tests/applications/scope.desktop0000644000015300001610000000013112564452056025623 0ustar pbuserpbgroup00000000000000[Desktop Entry] Name=Foo Type=Scope Exec=foo NoDisplay=false Hidden=false Terminal=false ubuntu-app-launch-0.5+15.10.20150817/tests/applications/terminal.desktop0000644000015300001610000000013612564452056026332 0ustar pbuserpbgroup00000000000000[Desktop Entry] Name=Foo Type=Application Exec=foo NoDisplay=false Hidden=false Terminal=true ubuntu-app-launch-0.5+15.10.20150817/tests/applications/hidden.desktop0000644000015300001610000000013612564452056025752 0ustar pbuserpbgroup00000000000000[Desktop Entry] Name=Foo Type=Application Exec=foo NoDisplay=false Hidden=true Terminal=false ubuntu-app-launch-0.5+15.10.20150817/tests/applications/noxmir.desktop0000644000015300001610000000021012564452110026013 0ustar pbuserpbgroup00000000000000[Desktop Entry] Name=No XMir Needed Type=Application Exec=noxmir NoDisplay=false Hidden=false Terminal=false X-Ubuntu-XMir-Enable=false ubuntu-app-launch-0.5+15.10.20150817/tests/applications/no-exec.desktop0000644000015300001610000000012612564452056026054 0ustar pbuserpbgroup00000000000000[Desktop Entry] Name=Foo Type=Application NoDisplay=false Hidden=false Terminal=false ubuntu-app-launch-0.5+15.10.20150817/tests/applications/xmir.desktop0000644000015300001610000000020412564452110025461 0ustar pbuserpbgroup00000000000000[Desktop Entry] Name=X Application Type=Application Exec=xfoo NoDisplay=false Hidden=false Terminal=false X-Ubuntu-XMir-Enable=true ubuntu-app-launch-0.5+15.10.20150817/tests/applications/foo.desktop0000644000015300001610000000013712564452056025303 0ustar pbuserpbgroup00000000000000[Desktop Entry] Name=Foo Type=Application Exec=foo NoDisplay=false Hidden=false Terminal=false ubuntu-app-launch-0.5+15.10.20150817/tests/mir-mock.cpp0000644000015300001610000000475012564452056022666 0ustar pbuserpbgroup00000000000000 #include "mir-mock.h" #include #include #include #include static const char * valid_trust_session = "In the circle of trust"; static bool valid_trust_connection = true; static pid_t last_trust_pid = 0; static int trusted_fd = 1234; MirPromptSession * mir_connection_create_prompt_session_sync(MirConnection * connection, pid_t pid, void (*)(MirPromptSession *, MirPromptSessionState, void*data), void * context) { last_trust_pid = pid; if (valid_trust_connection) { return (MirPromptSession *)valid_trust_session; } else { return nullptr; } } void mir_prompt_session_release_sync (MirPromptSession * session) { if (reinterpret_cast(session) != valid_trust_session) { std::cerr << "Releasing a Mir Trusted Prompt that isn't valid" << std::endl; exit(1); } } MirWaitHandle * mir_prompt_session_new_fds_for_prompt_providers (MirPromptSession * session, unsigned int numfds, mir_client_fd_callback cb, void * data) { if (reinterpret_cast(session) != valid_trust_session) { std::cerr << "Releasing a Mir Trusted Prompt that isn't valid" << std::endl; exit(1); } /* TODO: Put in another thread to be more mir like */ std::thread * thread = new std::thread([session, numfds, cb, data]() { int fdlist[numfds]; for (int i = 0; i < numfds; i++) fdlist[i] = trusted_fd; cb(session, numfds, fdlist, data); }); return reinterpret_cast(thread); } void mir_wait_for (MirWaitHandle * wait) { auto thread = reinterpret_cast(wait); if (thread->joinable()) thread->join(); delete thread; } static const char * valid_connection_str = "Valid Mir Connection"; static std::pair last_connection; static bool valid_connection = true; void mir_mock_connect_return_valid (bool valid) { valid_connection = valid; } std::pair mir_mock_connect_last_connect (void) { return last_connection; } MirConnection * mir_connect_sync (char const * server, char const * appname) { last_connection = std::pair(server, appname); if (valid_connection) { return (MirConnection *)(valid_connection_str); } else { return nullptr; } } void mir_connection_release (MirConnection * con) { if (reinterpret_cast(con) != valid_connection_str) { std::cerr << "Releasing a Mir Connection that isn't valid" << std::endl; exit(1); } } void mir_mock_set_trusted_fd (int fd) { trusted_fd = fd; } ubuntu-app-launch-0.5+15.10.20150817/exec-line-exec.c0000644000015300001610000001200512564452110022220 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include #include #include #include #include #include "exec-line-exec-trace.h" #include "helpers.h" #include "ual-tracepoint.h" int main (int argc, char * argv[]) { /* Make sure we have work to do */ /* This string is quoted using desktop file quoting: http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#exec-variables */ const gchar * app_exec = g_getenv("APP_EXEC"); if (app_exec == NULL) { /* There should be no reason for this, a g_error() so that it gets picked up by Apport and we can track it */ g_error("No exec line given, nothing to do except fail"); return 1; } /* For the tracepoints */ const gchar * app_id = g_getenv("APP_ID"); ual_tracepoint(exec_start, app_id); /* URIs */ const gchar * app_uris = g_getenv("APP_URIS"); /* Look to see if we have a directory defined that we should be using for everything. If so, change to it and add it to the path */ const gchar * appdir = g_getenv("APP_DIR"); if (appdir != NULL) { if (g_chdir(appdir) != 0) { g_warning("Unable to change directory to '%s'", appdir); } } /* Protect against app directories that have ':' in them */ if (appdir != NULL && strchr(appdir, ':') == NULL) { const gchar * path_path = g_getenv("PATH"); if (path_path != NULL && path_path[0] == '\0') path_path = NULL; gchar * path_libpath = NULL; const gchar * path_joinable[4] = { 0 }; const gchar * lib_path = g_getenv("LD_LIBRARY_PATH"); if (lib_path != NULL && lib_path[0] == '\0') lib_path = NULL; gchar * lib_libpath = g_build_filename(appdir, "lib", NULL); const gchar * lib_joinable[4] = { 0 }; const gchar * import_path = g_getenv("QML2_IMPORT_PATH"); if (import_path != NULL && import_path[0] == '\0') import_path = NULL; gchar * import_libpath = NULL; const gchar * import_joinable[4] = { 0 }; /* If we've got an architecture set insert that into the path before everything else */ const gchar * archdir = g_getenv("UBUNTU_APP_LAUNCH_ARCH"); if (archdir != NULL && strchr(archdir, ':') == NULL) { path_libpath = g_build_filename(appdir, "lib", archdir, "bin", NULL); import_libpath = g_build_filename(appdir, "lib", archdir, NULL); path_joinable[0] = path_libpath; path_joinable[1] = appdir; path_joinable[2] = path_path; lib_joinable[0] = import_libpath; lib_joinable[1] = lib_libpath; lib_joinable[2] = lib_path; /* Need to check whether the original is NULL because we're appending instead of prepending */ if (import_path == NULL) { import_joinable[0] = import_libpath; } else { import_joinable[0] = import_path; import_joinable[1] = import_libpath; } } else { path_joinable[0] = appdir; path_joinable[1] = path_path; lib_joinable[0] = lib_libpath; lib_joinable[1] = lib_path; import_joinable[0] = import_path; } gchar * newpath = g_strjoinv(":", (gchar**)path_joinable); g_setenv("PATH", newpath, TRUE); g_free(path_libpath); g_free(newpath); gchar * newlib = g_strjoinv(":", (gchar**)lib_joinable); g_setenv("LD_LIBRARY_PATH", newlib, TRUE); g_free(lib_libpath); g_free(newlib); if (import_joinable[0] != NULL) { gchar * newimport = g_strjoinv(":", (gchar**)import_joinable); g_setenv("QML2_IMPORT_PATH", newimport, TRUE); g_free(newimport); } g_free(import_libpath); } /* Parse the execiness of it all */ GArray * newargv = desktop_exec_parse(app_exec, app_uris); if (newargv == NULL) { g_warning("Unable to parse exec line '%s'", app_exec); return 1; } ual_tracepoint(exec_parse_complete, app_id); if (g_getenv("MIR_SOCKET") != NULL && g_strcmp0(g_getenv("APP_XMIR_ENABLE"), "1") == 0) { g_debug("XMir Helper being used"); /* xmir-helper $(APP_ID) $(COMMAND) */ const gchar * appid = g_getenv("APP_ID"); g_array_prepend_val(newargv, appid); /* Pulling into the heap instead of the code page */ char * xmir_helper = g_strdup(XMIR_HELPER); g_array_prepend_val(newargv, xmir_helper); } /* Now exec */ gchar ** nargv = (gchar**)g_array_free(newargv, FALSE); ual_tracepoint(exec_pre_exec, app_id); int execret = execvp(nargv[0], nargv); if (execret != 0) { gchar * execprint = g_strjoinv(" ", nargv); g_warning("Unable to exec '%s' in '%s': %s", execprint, appdir, strerror(errno)); g_free(execprint); } return execret; } ubuntu-app-launch-0.5+15.10.20150817/exec-line-exec-trace.tp0000644000015300001610000000057612564452110023527 0ustar pbuserpbgroup00000000000000 TRACEPOINT_EVENT(ubuntu_app_launch, exec_start, TP_ARGS(const char *, appid), TP_FIELDS( ctf_string(appid, appid) ) ) TRACEPOINT_EVENT(ubuntu_app_launch, exec_parse_complete, TP_ARGS(const char *, appid), TP_FIELDS( ctf_string(appid, appid) ) ) TRACEPOINT_EVENT(ubuntu_app_launch, exec_pre_exec, TP_ARGS(const char *, appid), TP_FIELDS( ctf_string(appid, appid) ) ) ubuntu-app-launch-0.5+15.10.20150817/libubuntu-app-launch/0000755000015300001610000000000012564452317023333 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/libubuntu-app-launch/ubuntu-app-launch-trace.tp0000644000015300001610000001500412564452117030342 0ustar pbuserpbgroup00000000000000 #include #define BYTE_ORDER __BYTE_ORDER /******************************* LibUAL start function *******************************/ TRACEPOINT_EVENT(ubuntu_app_launch, libual_start, TP_ARGS(const char *, appid), TP_FIELDS( ctf_string(appid, appid) ) ) TRACEPOINT_EVENT(ubuntu_app_launch, libual_determine_type, TP_ARGS(const char *, appid, const char *, type), TP_FIELDS( ctf_string(appid, appid) ctf_string(type, type) ) ) TRACEPOINT_EVENT(ubuntu_app_launch, libual_determine_libertine, TP_ARGS(const char *, appid, const char *, executionenv), TP_FIELDS( ctf_string(appid, appid) ctf_string(executionenv, executionenv) ) ) TRACEPOINT_EVENT(ubuntu_app_launch, libual_job_path_determined, TP_ARGS(const char *, appid, const char *, job_path), TP_FIELDS( ctf_string(appid, appid) ctf_string(job_path, job_path) ) ) TRACEPOINT_EVENT(ubuntu_app_launch, libual_start_message_sent, TP_ARGS(const char *, appid), TP_FIELDS( ctf_string(appid, appid) ) ) TRACEPOINT_EVENT(ubuntu_app_launch, libual_start_message_callback, TP_ARGS(const char *, appid), TP_FIELDS( ctf_string(appid, appid) ) ) /******************************* LibUAL observers *******************************/ TRACEPOINT_EVENT(ubuntu_app_launch, observer_start, TP_ARGS(const char *, type), TP_FIELDS( ctf_string(type, type) ) ) TRACEPOINT_EVENT(ubuntu_app_launch, observer_finish, TP_ARGS(const char *, type), TP_FIELDS( ctf_string(type, type) ) ) /******************************* Second Exec tracking *******************************/ TRACEPOINT_EVENT(ubuntu_app_launch, second_exec_start, TP_ARGS(const char *, appid, const char *, appuris), TP_FIELDS( ctf_string(appid, appid) ctf_string(appuris, appuris) ) ) TRACEPOINT_EVENT(ubuntu_app_launch, second_exec_emit_resume, TP_ARGS(const char *, appid), TP_FIELDS( ctf_string(appid, appid) ) ) TRACEPOINT_EVENT(ubuntu_app_launch, second_exec_resume_complete, TP_ARGS(const char *, appid), TP_FIELDS( ctf_string(appid, appid) ) ) TRACEPOINT_EVENT(ubuntu_app_launch, second_exec_resume_timeout, TP_ARGS(const char *, appid), TP_FIELDS( ctf_string(appid, appid) ) ) TRACEPOINT_EVENT(ubuntu_app_launch, second_exec_emit_focus, TP_ARGS(const char *, appid), TP_FIELDS( ctf_string(appid, appid) ) ) TRACEPOINT_EVENT(ubuntu_app_launch, second_exec_finish, TP_ARGS(const char *, appid), TP_FIELDS( ctf_string(appid, appid) ) ) TRACEPOINT_EVENT(ubuntu_app_launch, second_exec_got_dbus_names, TP_ARGS(const char *, appid), TP_FIELDS( ctf_string(appid, appid) ) ) TRACEPOINT_EVENT(ubuntu_app_launch, second_exec_got_primary_pid, TP_ARGS(const char *, appid), TP_FIELDS( ctf_string(appid, appid) ) ) TRACEPOINT_EVENT(ubuntu_app_launch, second_exec_request_pid, TP_ARGS(const char *, appid, const char *, dbus_name), TP_FIELDS( ctf_string(appid, appid) ctf_string(dbus_name, dbus_name) ) ) TRACEPOINT_EVENT(ubuntu_app_launch, second_exec_got_pid, TP_ARGS(const char *, appid, const char *, dbus_name), TP_FIELDS( ctf_string(appid, appid) ctf_string(dbus_name, dbus_name) ) ) TRACEPOINT_EVENT(ubuntu_app_launch, second_exec_contact_app, TP_ARGS(const char *, appid, const char *, dbus_name), TP_FIELDS( ctf_string(appid, appid) ctf_string(dbus_name, dbus_name) ) ) TRACEPOINT_EVENT(ubuntu_app_launch, second_exec_app_contacted, TP_ARGS(const char *, appid), TP_FIELDS( ctf_string(appid, appid) ) ) TRACEPOINT_EVENT(ubuntu_app_launch, second_exec_app_error, TP_ARGS(const char *, appid), TP_FIELDS( ctf_string(appid, appid) ) ) TRACEPOINT_EVENT(ubuntu_app_launch, second_exec_connection_complete, TP_ARGS(const char *, appid), TP_FIELDS( ctf_string(appid, appid) ) ) /******************************* Desktop File Single Instance *******************************/ TRACEPOINT_EVENT(ubuntu_app_launch, desktop_single_start, TP_ARGS(const char *, appid), TP_FIELDS( ctf_string(appid, appid) ) ) TRACEPOINT_EVENT(ubuntu_app_launch, desktop_single_found, TP_ARGS(const char *, appid), TP_FIELDS( ctf_string(appid, appid) ) ) TRACEPOINT_EVENT(ubuntu_app_launch, desktop_single_finished, TP_ARGS(const char *, appid, const char *, apptype), TP_FIELDS( ctf_string(appid, appid) ctf_string(apptype, apptype) ) ) /******************************* CGroup Manager PID listing *******************************/ TRACEPOINT_EVENT(ubuntu_app_launch, pids_list_start, TP_ARGS(const char *, appid), TP_FIELDS( ctf_string(appid, appid) ) ) TRACEPOINT_EVENT(ubuntu_app_launch, pids_list_connected, TP_ARGS(const char *, appid), TP_FIELDS( ctf_string(appid, appid) ) ) TRACEPOINT_EVENT(ubuntu_app_launch, pids_list_finished, TP_ARGS(const char *, appid, int, numpids), TP_FIELDS( ctf_string(appid, appid) ctf_integer(int, numpids, numpids) ) ) /******************************* Click Exec *******************************/ TRACEPOINT_EVENT(ubuntu_app_launch, click_start, TP_ARGS(const char *, appid), TP_FIELDS( ctf_string(appid, appid) ) ) TRACEPOINT_EVENT(ubuntu_app_launch, click_starting_sent, TP_ARGS(const char *, appid), TP_FIELDS( ctf_string(appid, appid) ) ) TRACEPOINT_EVENT(ubuntu_app_launch, click_found_pkgdir, TP_ARGS(const char *, appid), TP_FIELDS( ctf_string(appid, appid) ) ) TRACEPOINT_EVENT(ubuntu_app_launch, click_configured_env, TP_ARGS(const char *, appid), TP_FIELDS( ctf_string(appid, appid) ) ) TRACEPOINT_EVENT(ubuntu_app_launch, click_read_manifest, TP_ARGS(const char *, appid), TP_FIELDS( ctf_string(appid, appid) ) ) TRACEPOINT_EVENT(ubuntu_app_launch, click_read_desktop, TP_ARGS(const char *, appid), TP_FIELDS( ctf_string(appid, appid) ) ) TRACEPOINT_EVENT(ubuntu_app_launch, click_send_env_vars, TP_ARGS(const char *, appid), TP_FIELDS( ctf_string(appid, appid) ) ) TRACEPOINT_EVENT(ubuntu_app_launch, handshake_wait, TP_ARGS(const char *, appid), TP_FIELDS( ctf_string(appid, appid) ) ) TRACEPOINT_EVENT(ubuntu_app_launch, handshake_complete, TP_ARGS(const char *, appid), TP_FIELDS( ctf_string(appid, appid) ) ) /******************************* Desktop Exec *******************************/ TRACEPOINT_EVENT(ubuntu_app_launch, desktop_start, TP_ARGS(const char *, appid), TP_FIELDS( ctf_string(appid, appid) ) ) TRACEPOINT_EVENT(ubuntu_app_launch, desktop_starting_sent, TP_ARGS(const char *, appid), TP_FIELDS( ctf_string(appid, appid) ) ) TRACEPOINT_EVENT(ubuntu_app_launch, desktop_found, TP_ARGS(const char *, appid), TP_FIELDS( ctf_string(appid, appid) ) ) TRACEPOINT_EVENT(ubuntu_app_launch, desktop_send_env_vars, TP_ARGS(const char *, appid), TP_FIELDS( ctf_string(appid, appid) ) ) ubuntu-app-launch-0.5+15.10.20150817/libubuntu-app-launch/app-info.h0000644000015300001610000000225012564452125025211 0ustar pbuserpbgroup00000000000000/* * Copyright © 2015 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #pragma once #include gboolean app_info_legacy (const gchar * appid, gchar ** appdir, gchar ** appdesktop); gboolean app_info_libertine (const gchar * appid, gchar ** appdir, gchar ** appdesktop); gboolean app_info_click (const gchar * appid, gchar ** appdir, gchar ** appdesktop); gchar * click_triplet_to_app_id (const gchar * pkg, const gchar * app, const gchar * ver); gchar * libertine_triplet_to_app_id (const gchar * pkg, const gchar * app, const gchar * ver); ubuntu-app-launch-0.5+15.10.20150817/libubuntu-app-launch/click-exec.h0000644000015300001610000000152212564452056025513 0ustar pbuserpbgroup00000000000000/* * Copyright © 2014 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include #include "helpers.h" gboolean click_task_setup (GDBusConnection * bus, const gchar * app_id, EnvHandle * envhandle); ubuntu-app-launch-0.5+15.10.20150817/libubuntu-app-launch/desktop-exec.c0000644000015300001610000001442012564452125026070 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include #include #include #include #include #include "helpers.h" #include "ubuntu-app-launch-trace.h" #include "recoverable-problem.h" #include "ual-tracepoint.h" #include "ubuntu-app-launch.h" #include "app-info.h" /* Reports an error on the caller of UAL so that we can track who is trying to launch bad AppIDs, and then fix their bug so that we get better reporting upstream. */ void report_error_on_caller (const gchar * app_id) { g_warning("Unable to find keyfile for application '%s'", app_id); const gchar * props[3] = { "AppId", NULL, NULL }; props[1] = app_id; GPid pid = getpid(); /* Checking to see if we're using the command line tool to create the appid. Chances are in that case it's a user error, and we don't need to automatically record it, the user mistyped. */ gboolean debugtool = FALSE; if (pid != 0) { const gchar * cmdpath = "/proc/self/cmdline"; gchar * cmdline = NULL; if (g_file_get_contents(cmdpath, &cmdline, NULL, NULL)) { if (g_strstr_len(cmdline, -1, "ubuntu-app-launch") != NULL) { debugtool = TRUE; } g_free(cmdline); } else { /* The caller has already exited, probably a debug tool */ debugtool = TRUE; } } if (!debugtool) { report_recoverable_problem("ubuntu-app-launch-invalid-appid", pid, TRUE, props); } else { g_debug("Suppressing appid recoverable error for debug tool"); } } /* Get the keyfile object for a libertine container based application. Look into the container's filesystem on disk and find it in /usr/share/applications in there. Those are currently the only apps that we look at today. We're not ensuring anything about the file other than it has basic sanity. */ GKeyFile * keyfile_for_libertine (const gchar * appid, gchar ** outcontainer) { gchar * desktopfile = NULL; gchar * desktopdir = NULL; if (!app_info_libertine(appid, &desktopdir, &desktopfile)) { return NULL; } gchar * desktopfull = g_build_filename(desktopdir, desktopfile, NULL); g_debug("Desktop full: %s", desktopfull); g_free(desktopdir); g_free(desktopfile); /* We now think we have a valid 'desktopfile' path */ GKeyFile * keyfile = g_key_file_new(); gboolean loaded = g_key_file_load_from_file(keyfile, desktopfull, G_KEY_FILE_NONE, NULL); if (!loaded) { g_free(desktopfull); g_key_file_free(keyfile); return NULL; } if (!verify_keyfile(keyfile, desktopfull)) { g_free(desktopfull); g_key_file_free(keyfile); return NULL; } g_free(desktopfull); if (outcontainer != NULL) { ubuntu_app_launch_app_id_parse(appid, outcontainer, NULL, NULL); } return keyfile; } gboolean desktop_task_setup (GDBusConnection * bus, const gchar * app_id, EnvHandle * handle, gboolean is_libertine) { if (app_id == NULL) { g_error("No APP_ID environment variable defined"); return FALSE; } ual_tracepoint(desktop_start, app_id); handshake_t * handshake = starting_handshake_start(app_id); if (handshake == NULL) { g_warning("Unable to setup starting handshake"); } ual_tracepoint(desktop_starting_sent, app_id); gchar * desktopfilename = NULL; GKeyFile * keyfile = NULL; gchar * libertinecontainer = NULL; if (is_libertine) { /* desktopfilename not set, not useful in this context */ keyfile = keyfile_for_libertine(app_id, &libertinecontainer); } else { keyfile = keyfile_for_appid(app_id, &desktopfilename); } if (keyfile == NULL) { report_error_on_caller(app_id); g_free(libertinecontainer); return FALSE; } ual_tracepoint(desktop_found, app_id); /* Desktop file name so that libs can get other info from it */ if (desktopfilename != NULL) { env_handle_add(handle, "APP_DESKTOP_FILE_PATH", desktopfilename); g_free(desktopfilename); } if (g_key_file_has_key(keyfile, "Desktop Entry", "Path", NULL)) { gchar * path = g_key_file_get_string(keyfile, "Desktop Entry", "Path", NULL); env_handle_add(handle, "APP_DIR", path); g_free(path); } gchar * apparmor = g_key_file_get_string(keyfile, "Desktop Entry", "X-Ubuntu-AppArmor-Profile", NULL); if (apparmor != NULL) { env_handle_add(handle, "APP_EXEC_POLICY", apparmor); set_confined_envvars(handle, app_id, "/usr/share"); g_free(apparmor); } else { env_handle_add(handle, "APP_EXEC_POLICY", "unconfined"); } if (g_key_file_has_key(keyfile, "Desktop Entry", "X-Ubuntu-XMir-Enable", NULL)) { if (g_key_file_get_boolean(keyfile, "Desktop Entry", "X-Ubuntu-XMir-Enable", NULL)) { env_handle_add(handle, "APP_XMIR_ENABLE", "1"); } else { env_handle_add(handle, "APP_XMIR_ENABLE", "0"); } } else if (is_libertine) { /* Default to X for libertine stuff */ env_handle_add(handle, "APP_XMIR_ENABLE", "1"); } /* This string is quoted using desktop file quoting: http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#exec-variables */ gchar * execline = desktop_to_exec(keyfile, app_id); g_return_val_if_fail(execline != NULL, 1); if (is_libertine) { static const gchar * libertine_launch = NULL; if (G_UNLIKELY(libertine_launch == NULL)) { libertine_launch = g_getenv("UBUNTU_APP_LAUNCH_LIBERTINE_LAUNCH"); if (libertine_launch == NULL) { libertine_launch = LIBERTINE_LAUNCH; } } gchar * libexec = g_strdup_printf("%s \"%s\" %s", libertine_launch, libertinecontainer, execline); g_free(execline); execline = libexec; } g_free(libertinecontainer); /* Handles NULL, let's be sure it goes away */ env_handle_add(handle, "APP_EXEC", execline); g_free(execline); g_key_file_free(keyfile); ual_tracepoint(handshake_wait, app_id); starting_handshake_wait(handshake); ual_tracepoint(handshake_complete, app_id); return TRUE; } ubuntu-app-launch-0.5+15.10.20150817/libubuntu-app-launch/desktop-exec.h0000644000015300001610000000156712564452117026106 0ustar pbuserpbgroup00000000000000/* * Copyright © 2014 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #pragma once #include #include "helpers.h" gboolean desktop_task_setup (GDBusConnection * bus, const gchar * appid, EnvHandle * envhandle, gboolean is_libertine); ubuntu-app-launch-0.5+15.10.20150817/libubuntu-app-launch/recoverable-problem.h0000644000015300001610000000175712564452056027445 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include void report_recoverable_problem (const gchar * signature, GPid report_pid, gboolean wait, const gchar * additional_properties[]); ubuntu-app-launch-0.5+15.10.20150817/libubuntu-app-launch/ubuntu-app-launch.pc.in0000644000015300001610000000044112564452056027633 0ustar pbuserpbgroup00000000000000libdir=@libdir@ includedir=@includedir@ Cflags: -I${includedir}/libubuntu-app-launch-@apiversion@ Requires: glib-2.0 mirclient Libs: -L${libdir} -lubuntu-app-launch Name: libubuntu-app-launch Description: A library to manage and watch applications under session init Version: @VERSION@ ubuntu-app-launch-0.5+15.10.20150817/libubuntu-app-launch/ubuntu-app-launch.c0000644000015300001610000021265312564452125027055 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include "ubuntu-app-launch.h" #include #include #include #include #include #include #include #include "ubuntu-app-launch-trace.h" #include "second-exec-core.h" #include "helpers.h" #include "ual-tracepoint.h" #include "click-exec.h" #include "desktop-exec.h" #include "recoverable-problem.h" #include "proxy-socket-demangler.h" #include "app-info.h" static void apps_for_job (GDBusConnection * con, const gchar * name, GArray * apps, gboolean truncate_legacy); static void free_helper (gpointer value); static GList * pids_for_appid (const gchar * appid); int kill (pid_t pid, int signal); static gchar * escape_dbus_string (const gchar * input); G_DEFINE_QUARK(UBUNTU_APP_LAUNCH_PROXY_PATH, proxy_path); G_DEFINE_QUARK(UBUNTU_APP_LAUNCH_MIR_FD, mir_fd); /* Function to take the urls and escape them so that they can be parsed on the other side correctly. */ static gchar * app_uris_string (const gchar * const * uris) { guint i = 0; GArray * array = g_array_new(TRUE, TRUE, sizeof(gchar *)); g_array_set_clear_func(array, free_helper); for (i = 0; i < g_strv_length((gchar**)uris); i++) { gchar * escaped = g_shell_quote(uris[i]); g_array_append_val(array, escaped); } gchar * urisjoin = g_strjoinv(" ", (gchar**)array->data); g_array_unref(array); return urisjoin; } typedef struct { gchar * appid; gchar * uris; } app_start_t; static void application_start_cb (GObject * obj, GAsyncResult * res, gpointer user_data) { app_start_t * data = (app_start_t *)user_data; GError * error = NULL; GVariant * result = NULL; ual_tracepoint(libual_start_message_callback, data->appid); g_debug("Started Message Callback: %s", data->appid); result = g_dbus_connection_call_finish(G_DBUS_CONNECTION(obj), res, &error); if (result != NULL) g_variant_unref(result); if (error != NULL) { if (g_dbus_error_is_remote_error(error)) { gchar * remote_error = g_dbus_error_get_remote_error(error); g_debug("Remote error: %s", remote_error); if (g_strcmp0(remote_error, "com.ubuntu.Upstart0_6.Error.AlreadyStarted") == 0) { second_exec(data->appid, data->uris); } g_free(remote_error); } else { g_warning("Unable to emit event to start application: %s", error->message); } g_error_free(error); } g_free(data->appid); g_free(data->uris); g_free(data); } /* Get the path of the job from Upstart, if we've got it already, we'll just use the cache of the value */ static const gchar * get_jobpath (GDBusConnection * con, const gchar * jobname) { gchar * cachepath = g_strdup_printf("ubuntu-app-lauch-job-path-cache-%s", jobname); gpointer cachedata = g_object_get_data(G_OBJECT(con), cachepath); if (cachedata != NULL) { g_free(cachepath); return cachedata; } GError * error = NULL; GVariant * job_path_variant = g_dbus_connection_call_sync(con, DBUS_SERVICE_UPSTART, DBUS_PATH_UPSTART, DBUS_INTERFACE_UPSTART, "GetJobByName", g_variant_new("(s)", jobname), G_VARIANT_TYPE("(o)"), G_DBUS_CALL_FLAGS_NONE, -1, /* timeout: default */ NULL, /* cancelable */ &error); if (error != NULL) { g_warning("Unable to find job '%s': %s", jobname, error->message); g_error_free(error); g_free(cachepath); return NULL; } gchar * job_path = NULL; g_variant_get(job_path_variant, "(o)", &job_path); g_variant_unref(job_path_variant); g_object_set_data_full(G_OBJECT(con), cachepath, job_path, g_free); g_free(cachepath); return job_path; } /* Check to see if a legacy app wants us to manage whether they're single instance or not */ static gboolean legacy_single_instance (const gchar * appid) { ual_tracepoint(desktop_single_start, appid); GKeyFile * keyfile = keyfile_for_appid(appid, NULL); if (keyfile == NULL) { g_warning("Unable to find keyfile for application '%s'", appid); return FALSE; } ual_tracepoint(desktop_single_found, appid); gboolean singleinstance = FALSE; if (g_key_file_has_key(keyfile, "Desktop Entry", "X-Ubuntu-Single-Instance", NULL)) { GError * error = NULL; singleinstance = g_key_file_get_boolean(keyfile, "Desktop Entry", "X-Ubuntu-Single-Instance", &error); if (error != NULL) { g_warning("Unable to get single instance key for app '%s': %s", appid, error->message); g_error_free(error); /* Ensure that if we got an error, we assume standard case */ singleinstance = FALSE; } } g_key_file_free(keyfile); ual_tracepoint(desktop_single_finished, appid, singleinstance ? "single" : "unmanaged"); return singleinstance; } /* Determine whether it's a click package by looking for the symlink that is created by the desktop hook */ static gboolean is_click (const gchar * appid) { gchar * appiddesktop = g_strdup_printf("%s.desktop", appid); gchar * click_link = NULL; const gchar * link_farm_dir = g_getenv("UBUNTU_APP_LAUNCH_LINK_FARM"); if (G_LIKELY(link_farm_dir == NULL)) { click_link = g_build_filename(g_get_home_dir(), ".cache", "ubuntu-app-launch", "desktop", appiddesktop, NULL); } else { click_link = g_build_filename(link_farm_dir, appiddesktop, NULL); } g_free(appiddesktop); gboolean click = g_file_test(click_link, G_FILE_TEST_EXISTS); g_free(click_link); return click; } /* Determine whether an AppId is realated to a Libertine container by checking the container and program name. */ static gboolean is_libertine (const gchar * appid) { if (app_info_libertine(appid, NULL, NULL)) { g_debug("Libertine application detected: %s", appid); return TRUE; } else { return FALSE; } } static gboolean start_application_core (const gchar * appid, const gchar * const * uris, gboolean test) { ual_tracepoint(libual_start, appid); g_return_val_if_fail(appid != NULL, FALSE); GDBusConnection * con = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); g_return_val_if_fail(con != NULL, FALSE); gboolean click = is_click(appid); ual_tracepoint(libual_determine_type, appid, click ? "click" : "legacy"); /* Figure out if it is libertine */ gboolean libertine = FALSE; if (!click) { libertine = is_libertine(appid); } ual_tracepoint(libual_determine_libertine, appid, libertine ? "container" : "host"); /* Figure out the DBus path for the job */ const gchar * jobpath = NULL; if (click) { jobpath = get_jobpath(con, "application-click"); } else { jobpath = get_jobpath(con, "application-legacy"); } if (jobpath == NULL) { g_object_unref(con); g_warning("Unable to get job path"); return FALSE; } ual_tracepoint(libual_job_path_determined, appid, jobpath); /* Callback data */ app_start_t * app_start_data = g_new0(app_start_t, 1); app_start_data->appid = g_strdup(appid); /* Build up our environment */ GVariantBuilder builder; g_variant_builder_init(&builder, G_VARIANT_TYPE_TUPLE); g_variant_builder_open(&builder, G_VARIANT_TYPE_ARRAY); g_variant_builder_add_value(&builder, g_variant_new_take_string(g_strdup_printf("APP_ID=%s", appid))); g_variant_builder_add_value(&builder, g_variant_new_take_string(g_strdup_printf("APP_LAUNCHER_PID=%d", getpid()))); if (uris != NULL) { gchar * urisjoin = app_uris_string(uris); gchar * urienv = g_strdup_printf("APP_URIS=%s", urisjoin); app_start_data->uris = urisjoin; g_variant_builder_add_value(&builder, g_variant_new_take_string(urienv)); } if (!click) { if (libertine || legacy_single_instance(appid)) { g_variant_builder_add_value(&builder, g_variant_new_string("INSTANCE_ID=")); } else { gchar * instanceid = g_strdup_printf("INSTANCE_ID=%" G_GUINT64_FORMAT, g_get_real_time()); g_variant_builder_add_value(&builder, g_variant_new_take_string(instanceid)); } } if (test) { g_variant_builder_add_value(&builder, g_variant_new_string("QT_LOAD_TESTABILITY=1")); } gboolean setup_complete = FALSE; if (click) { setup_complete = click_task_setup(con, appid, (EnvHandle*)&builder); } else { setup_complete = desktop_task_setup(con, appid, (EnvHandle*)&builder, libertine); } if (setup_complete) { g_variant_builder_close(&builder); g_variant_builder_add_value(&builder, g_variant_new_boolean(TRUE)); /* Call the job start function */ g_dbus_connection_call(con, DBUS_SERVICE_UPSTART, jobpath, DBUS_INTERFACE_UPSTART_JOB, "Start", g_variant_builder_end(&builder), NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, /* cancelable */ application_start_cb, app_start_data); ual_tracepoint(libual_start_message_sent, appid); } else { g_variant_builder_clear(&builder); } g_object_unref(con); return setup_complete; } gboolean ubuntu_app_launch_start_application (const gchar * appid, const gchar * const * uris) { return start_application_core(appid, uris, FALSE); } gboolean ubuntu_app_launch_start_application_test (const gchar * appid, const gchar * const * uris) { return start_application_core(appid, uris, TRUE); } static void stop_job (GDBusConnection * con, const gchar * jobname, const gchar * appname, const gchar * instanceid) { g_debug("Stopping job %s app_id %s instance_id %s", jobname, appname, instanceid); const gchar * job_path = get_jobpath(con, jobname); if (job_path == NULL) return; GVariantBuilder builder; g_variant_builder_init(&builder, G_VARIANT_TYPE_TUPLE); g_variant_builder_open(&builder, G_VARIANT_TYPE_ARRAY); g_variant_builder_add_value(&builder, g_variant_new_take_string(g_strdup_printf("APP_ID=%s", appname))); if (instanceid != NULL) { g_variant_builder_add_value(&builder, g_variant_new_take_string(g_strdup_printf("INSTANCE_ID=%s", instanceid))); } g_variant_builder_close(&builder); g_variant_builder_add_value(&builder, g_variant_new_boolean(FALSE)); /* wait */ GError * error = NULL; GVariant * stop_variant = g_dbus_connection_call_sync(con, DBUS_SERVICE_UPSTART, job_path, DBUS_INTERFACE_UPSTART_JOB, "Stop", g_variant_builder_end(&builder), NULL, G_DBUS_CALL_FLAGS_NONE, -1, /* timeout: default */ NULL, /* cancelable */ &error); if (error != NULL) { g_warning("Unable to stop job %s app_id %s instance_id %s: %s", jobname, appname, instanceid, error->message); g_error_free(error); } g_variant_unref(stop_variant); } static void free_helper (gpointer value) { gchar ** strp = (gchar **)value; g_free(*strp); } gboolean ubuntu_app_launch_stop_application (const gchar * appid) { g_return_val_if_fail(appid != NULL, FALSE); GDBusConnection * con = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); g_return_val_if_fail(con != NULL, FALSE); gboolean found = FALSE; int i; GArray * apps = g_array_new(TRUE, TRUE, sizeof(gchar *)); g_array_set_clear_func(apps, free_helper); /* Look through the click jobs and see if any match. There can only be one instance for each ID in the click world */ apps_for_job(con, "application-click", apps, FALSE); for (i = 0; i < apps->len; i++) { const gchar * array_id = g_array_index(apps, const gchar *, i); if (g_strcmp0(array_id, appid) == 0) { stop_job(con, "application-click", appid, NULL); found = TRUE; break; /* There can be only one with click */ } } if (apps->len > 0) g_array_remove_range(apps, 0, apps->len); /* Look through the legacy apps. Trickier because we know that there can be many instances of the legacy jobs out there, so we might have to kill more than one of them. */ apps_for_job(con, "application-legacy", apps, FALSE); gchar * appiddash = g_strdup_printf("%s-", appid); /* Probably could go RegEx here, but let's start with just a prefix lookup */ for (i = 0; i < apps->len; i++) { const gchar * array_id = g_array_index(apps, const gchar *, i); if (g_str_has_prefix(array_id, appiddash)) { gchar * instanceid = g_strrstr(array_id, "-"); stop_job(con, "application-legacy", appid, &(instanceid[1])); found = TRUE; } } g_free(appiddash); g_array_free(apps, TRUE); g_object_unref(con); return found; } /* Set the OOM value using the helper as an async task */ static gboolean use_oom_helper (GPid pid, const gchar * oomscore) { GError * error = NULL; const gchar * args[4] = { OOM_HELPER, NULL, /* pid */ oomscore, NULL }; gchar * pidstr = g_strdup_printf("%d", pid); args[1] = pidstr; g_spawn_async(NULL, /* working dir */ (gchar **)args, NULL, /* env */ G_SPAWN_DEFAULT, NULL, NULL, /* child setup */ NULL, /* pid */ &error); /* error */ g_free(pidstr); if (error != NULL) { g_warning("Unable to launch OOM helper '" OOM_HELPER "' on PID '%d': %s", pid, error->message); g_error_free(error); return FALSE; } return TRUE; } /* Sets the OOM score to a particular value, returns true on NULL */ static gboolean set_oom_value (GPid pid, const gchar * oomscore) { static const gchar * procpath = NULL; if (G_UNLIKELY(procpath == NULL)) { /* Set by the test suite, probably not anyone else */ procpath = g_getenv("UBUNTU_APP_LAUNCH_OOM_PROC_PATH"); if (G_LIKELY(procpath == NULL)) { procpath = "/proc"; } } gchar * path = g_strdup_printf("%s/%d/oom_score_adj", procpath, pid); FILE * adj = fopen(path, "w"); int openerr = errno; g_free(path); if (adj == NULL) { switch (openerr) { case ENOENT: /* ENOENT happens a fair amount because of races, so it's not worth printing a warning about */ return TRUE; case EACCES: { /* We can get this error when trying to set the OOM value on Oxide renderers because they're started by the sandbox and don't have their adjustment value available for us to write. We have a helper to deal with this, but it's kinda expensive so we only use it when we have to. */ return use_oom_helper(pid, oomscore); } default: g_warning("Unable to set OOM value for '%d' to '%s': %s", pid, oomscore, strerror(openerr)); return FALSE; } } size_t writesize = fwrite(oomscore, 1, strlen(oomscore), adj); int writeerr = errno; fclose(adj); if (writesize == strlen(oomscore)) return TRUE; if (writeerr != 0) g_warning("Unable to set OOM value for '%d' to '%s': %s", pid, oomscore, strerror(writeerr)); else /* No error, but yet, wrong size. Not sure, what could cause this. */ g_debug("Unable to set OOM value for '%d' to '%s': Wrote %d bytes", pid, oomscore, (int)writesize); return FALSE; } /* Throw out a DBus signal that we've signalled all of these processes. This is the fun GVariant building part. */ static void notify_signalling (GList * pids, const gchar * appid, const gchar * signal_name) { GDBusConnection * conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); if (conn == NULL) { return; } /* Pull together a PID array */ GVariant *pidarray = NULL; if (pids == NULL) { pidarray = g_variant_new_array(G_VARIANT_TYPE_UINT64, NULL, 0); } else { GList * i; GVariantBuilder builder; g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY); for (i = pids; i != NULL; i = g_list_next(i)) g_variant_builder_add_value(&builder, g_variant_new_uint64(GPOINTER_TO_INT(i->data))); pidarray = g_variant_builder_end(&builder); } /* Combine into the wrapping tuple */ GVariantBuilder btuple; g_variant_builder_init(&btuple, G_VARIANT_TYPE_TUPLE); g_variant_builder_add_value(&btuple, g_variant_new_string(appid)); g_variant_builder_add_value(&btuple, pidarray); /* Emit !!! */ GError * error = NULL; g_dbus_connection_emit_signal(conn, NULL, /* destination */ "/", /* path */ "com.canonical.UbuntuAppLaunch", /* interface */ signal_name, /* signal */ g_variant_builder_end(&btuple), /* params, the same */ &error); if (error != NULL) { g_warning("Unable to emit signal '%s' for appid '%s': %s", signal_name, appid, error->message); g_error_free(error); } else { g_debug("Emmitted '%s' to DBus", signal_name); } g_object_unref(conn); } /* Gets all the pids for an appid and sends a signal to all of them. This also loops to ensure no new pids are added while we're signaling */ static gboolean signal_to_cgroup (const gchar * appid, int signal, const gchar * oomscore, const gchar * signal_name) { GHashTable * pidssignaled = g_hash_table_new(g_direct_hash, g_direct_equal); guint hash_table_size = 0; gboolean retval = TRUE; do { hash_table_size = g_hash_table_size(pidssignaled); GList * pidlist = pids_for_appid(appid); GList * iter; if (pidlist == NULL) { g_warning("Unable to get pids for '%s' to send signal %d", appid, signal); retval = FALSE; break; } for (iter = pidlist; iter != NULL; iter = g_list_next(iter)) { if (g_hash_table_contains(pidssignaled, iter->data)) { continue; } /* We've got a PID that we've not previously signaled */ GPid pid = GPOINTER_TO_INT(iter->data); if (-1 == kill(pid, signal)) { /* While that didn't work, we still want to try as many as we can */ g_warning("Unable to send signal %d to pid %d", signal, pid); retval = FALSE; } if (!set_oom_value(pid, oomscore)) { retval = FALSE; } g_hash_table_add(pidssignaled, iter->data); } g_list_free(pidlist); /* If it grew, then try again */ } while (hash_table_size != g_hash_table_size(pidssignaled)); notify_signalling(g_hash_table_get_keys(pidssignaled), appid, signal_name); g_hash_table_destroy(pidssignaled); return retval; } /* Mostly here to just print a warning if we can't submit the event, they're not critical to have */ static void zg_insert_complete (GObject * obj, GAsyncResult * res, gpointer user_data) { GError * error = NULL; GArray * result = NULL; result = zeitgeist_log_insert_event_finish(ZEITGEIST_LOG(obj), res, &error); if (error != NULL) { g_warning("Unable to submit Zeitgeist Event: %s", error->message); g_error_free(error); } g_array_free(result, TRUE); return; } /* Function to report the access and leaving events to Zeitgeist so we can track application usage */ static void report_zg_event (const gchar * appid, const gchar * eventtype) { gchar * uri = NULL; gchar * pkg = NULL; gchar * app = NULL; if (ubuntu_app_launch_app_id_parse(appid, &pkg, &app, NULL)) { /* If it's parseable, use the short form */ uri = g_strdup_printf("application://%s_%s.desktop", pkg, app); g_free(pkg); g_free(app); } else { uri = g_strdup_printf("application://%s.desktop", appid); } ZeitgeistLog * log = zeitgeist_log_get_default(); ZeitgeistEvent * event = zeitgeist_event_new(); zeitgeist_event_set_actor(event, "application://ubuntu-app-launch.desktop"); zeitgeist_event_set_interpretation(event, eventtype); zeitgeist_event_set_manifestation(event, ZEITGEIST_ZG_USER_ACTIVITY); ZeitgeistSubject * subject = zeitgeist_subject_new(); zeitgeist_subject_set_interpretation(subject, ZEITGEIST_NFO_SOFTWARE); zeitgeist_subject_set_manifestation(subject, ZEITGEIST_NFO_SOFTWARE_ITEM); zeitgeist_subject_set_mimetype(subject, "application/x-desktop"); zeitgeist_subject_set_uri(subject, uri); zeitgeist_event_add_subject(event, subject); zeitgeist_log_insert_event(log, event, NULL, zg_insert_complete, NULL); g_free(uri); g_object_unref(log); g_object_unref(event); g_object_unref(subject); } gboolean ubuntu_app_launch_pause_application (const gchar * appid) { report_zg_event(appid, ZEITGEIST_ZG_LEAVE_EVENT); return signal_to_cgroup(appid, SIGSTOP, "900", "ApplicationPaused"); } gboolean ubuntu_app_launch_resume_application (const gchar * appid) { report_zg_event(appid, ZEITGEIST_ZG_ACCESS_EVENT); return signal_to_cgroup(appid, SIGCONT, "100", "ApplicationResumed"); } gchar * ubuntu_app_launch_application_log_path (const gchar * appid) { gchar * path = NULL; g_return_val_if_fail(appid != NULL, NULL); if (is_click(appid)) { gchar * appfile = g_strdup_printf("application-click-%s.log", appid); path = g_build_filename(g_get_user_cache_dir(), "upstart", appfile, NULL); g_free(appfile); return path; } if (!is_libertine(appid) && legacy_single_instance(appid)) { gchar * appfile = g_strdup_printf("application-legacy-%s-.log", appid); path = g_build_filename(g_get_user_cache_dir(), "upstart", appfile, NULL); g_free(appfile); return path; } /* If we're not single instance, we can't recreate the instance ID but if it's running we can grab it. */ unsigned int i; GDBusConnection * con = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); g_return_val_if_fail(con != NULL, NULL); GArray * apps = g_array_new(TRUE, TRUE, sizeof(gchar *)); g_array_set_clear_func(apps, free_helper); apps_for_job(con, "application-legacy", apps, FALSE); gchar * appiddash = g_strdup_printf("%s-", appid); /* Probably could go RegEx here, but let's start with just a prefix lookup */ for (i = 0; i < apps->len && path == NULL; i++) { const gchar * array_id = g_array_index(apps, const gchar *, i); if (g_str_has_prefix(array_id, appiddash)) { gchar * appfile = g_strdup_printf("application-legacy-%s.log", array_id); path = g_build_filename(g_get_user_cache_dir(), "upstart", appfile, NULL); g_free(appfile); } } g_free(appiddash); g_array_free(apps, TRUE); g_object_unref(con); return path; } gboolean ubuntu_app_launch_application_info (const gchar * appid, gchar ** appdir, gchar ** appdesktop) { if (is_click(appid)) { return app_info_click(appid, appdir, appdesktop); } else if (is_libertine(appid)) { return app_info_libertine(appid, appdir, appdesktop); } else { return app_info_legacy(appid, appdir, appdesktop); } } static GDBusConnection * gdbus_upstart_ref (void) { static GDBusConnection * gdbus_upstart = NULL; if (gdbus_upstart != NULL) { return g_object_ref(gdbus_upstart); } GError * error = NULL; gdbus_upstart = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error); if (error != NULL) { g_warning("Unable to connect to Upstart bus: %s", error->message); g_error_free(error); return NULL; } g_object_add_weak_pointer(G_OBJECT(gdbus_upstart), (gpointer)&gdbus_upstart); return gdbus_upstart; } /* The data we keep for each observer */ typedef struct _observer_t observer_t; struct _observer_t { GDBusConnection * conn; guint sighandle; UbuntuAppLaunchAppObserver func; gpointer user_data; }; /* The data we keep for each failed observer */ typedef struct _failed_observer_t failed_observer_t; struct _failed_observer_t { GDBusConnection * conn; guint sighandle; UbuntuAppLaunchAppFailedObserver func; gpointer user_data; }; /* The data we keep for each failed observer */ typedef struct _paused_resumed_observer_t paused_resumed_observer_t; struct _paused_resumed_observer_t { GDBusConnection * conn; guint sighandle; UbuntuAppLaunchAppPausedResumedObserver func; gpointer user_data; const gchar * lttng_signal; }; /* The lists of Observers */ static GList * starting_array = NULL; static GList * started_array = NULL; static GList * stop_array = NULL; static GList * focus_array = NULL; static GList * resume_array = NULL; static GList * failed_array = NULL; static GList * paused_array = NULL; static GList * resumed_array = NULL; static void observer_cb (GDBusConnection * conn, const gchar * sender, const gchar * object, const gchar * interface, const gchar * signal, GVariant * params, gpointer user_data) { observer_t * observer = (observer_t *)user_data; const gchar * signalname = NULL; g_variant_get_child(params, 0, "&s", &signalname); ual_tracepoint(observer_start, signalname); gchar * env = NULL; GVariant * envs = g_variant_get_child_value(params, 1); GVariantIter iter; g_variant_iter_init(&iter, envs); gboolean job_found = FALSE; gboolean job_legacy = FALSE; gchar * instance = NULL; while (g_variant_iter_loop(&iter, "s", &env)) { if (g_strcmp0(env, "JOB=application-click") == 0) { job_found = TRUE; } else if (g_strcmp0(env, "JOB=application-legacy") == 0) { job_found = TRUE; job_legacy = TRUE; } else if (g_str_has_prefix(env, "INSTANCE=")) { instance = g_strdup(env + strlen("INSTANCE=")); } } g_variant_unref(envs); if (job_legacy && instance != NULL) { gchar * dash = g_strrstr(instance, "-"); if (dash != NULL) { dash[0] = '\0'; } } if (job_found && instance != NULL) { observer->func(instance, observer->user_data); } ual_tracepoint(observer_finish, signalname); g_free(instance); } /* Creates the observer structure and registers for the signal with GDBus so that we can get a callback */ static gboolean add_app_generic (UbuntuAppLaunchAppObserver observer, gpointer user_data, const gchar * signal, GList ** list) { GDBusConnection * conn = gdbus_upstart_ref(); if (conn == NULL) { return FALSE; } observer_t * observert = g_new0(observer_t, 1); observert->conn = conn; observert->func = observer; observert->user_data = user_data; *list = g_list_prepend(*list, observert); observert->sighandle = g_dbus_connection_signal_subscribe(conn, NULL, /* sender */ DBUS_INTERFACE_UPSTART, /* interface */ "EventEmitted", /* signal */ DBUS_PATH_UPSTART, /* path */ signal, /* arg0 */ G_DBUS_SIGNAL_FLAGS_NONE, observer_cb, observert, NULL); /* user data destroy */ return TRUE; } gboolean ubuntu_app_launch_observer_add_app_started (UbuntuAppLaunchAppObserver observer, gpointer user_data) { return add_app_generic(observer, user_data, "started", &started_array); } gboolean ubuntu_app_launch_observer_add_app_stop (UbuntuAppLaunchAppObserver observer, gpointer user_data) { return add_app_generic(observer, user_data, "stopped", &stop_array); } /* Creates the observer structure and registers for the signal with GDBus so that we can get a callback */ static gboolean add_session_generic (UbuntuAppLaunchAppObserver observer, gpointer user_data, const gchar * signal, GList ** list, GDBusSignalCallback session_cb) { GDBusConnection * conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); if (conn == NULL) { return FALSE; } observer_t * observert = g_new0(observer_t, 1); observert->conn = conn; observert->func = observer; observert->user_data = user_data; *list = g_list_prepend(*list, observert); observert->sighandle = g_dbus_connection_signal_subscribe(conn, NULL, /* sender */ "com.canonical.UbuntuAppLaunch", /* interface */ signal, /* signal */ "/", /* path */ NULL, /* arg0 */ G_DBUS_SIGNAL_FLAGS_NONE, session_cb, observert, NULL); /* user data destroy */ return TRUE; } /* Generic handler for a bunch of our signals */ static inline void generic_signal_cb (GDBusConnection * conn, const gchar * sender, const gchar * object, const gchar * interface, const gchar * signal, GVariant * params, gpointer user_data) { observer_t * observer = (observer_t *)user_data; const gchar * appid = NULL; if (observer->func != NULL) { g_variant_get(params, "(&s)", &appid); observer->func(appid, observer->user_data); } } /* Handle the focus signal when it occurs, call the observer */ static void focus_signal_cb (GDBusConnection * conn, const gchar * sender, const gchar * object, const gchar * interface, const gchar * signal, GVariant * params, gpointer user_data) { ual_tracepoint(observer_start, "focus"); generic_signal_cb(conn, sender, object, interface, signal, params, user_data); ual_tracepoint(observer_finish, "focus"); } gboolean ubuntu_app_launch_observer_add_app_focus (UbuntuAppLaunchAppObserver observer, gpointer user_data) { return add_session_generic(observer, user_data, "UnityFocusRequest", &focus_array, focus_signal_cb); } /* Handle the resume signal when it occurs, call the observer, then send a signal back when we're done */ static void resume_signal_cb (GDBusConnection * conn, const gchar * sender, const gchar * object, const gchar * interface, const gchar * signal, GVariant * params, gpointer user_data) { ual_tracepoint(observer_start, "resume"); generic_signal_cb(conn, sender, object, interface, signal, params, user_data); GError * error = NULL; g_dbus_connection_emit_signal(conn, sender, /* destination */ "/", /* path */ "com.canonical.UbuntuAppLaunch", /* interface */ "UnityResumeResponse", /* signal */ params, /* params, the same */ &error); if (error != NULL) { g_warning("Unable to emit response signal: %s", error->message); g_error_free(error); } ual_tracepoint(observer_finish, "resume"); } gboolean ubuntu_app_launch_observer_add_app_resume (UbuntuAppLaunchAppObserver observer, gpointer user_data) { return add_session_generic(observer, user_data, "UnityResumeRequest", &resume_array, resume_signal_cb); } /* Handle the starting signal when it occurs, call the observer, then send a signal back when we're done */ static void starting_signal_cb (GDBusConnection * conn, const gchar * sender, const gchar * object, const gchar * interface, const gchar * signal, GVariant * params, gpointer user_data) { ual_tracepoint(observer_start, "starting"); generic_signal_cb(conn, sender, object, interface, signal, params, user_data); GError * error = NULL; g_dbus_connection_emit_signal(conn, sender, /* destination */ "/", /* path */ "com.canonical.UbuntuAppLaunch", /* interface */ "UnityStartingSignal", /* signal */ params, /* params, the same */ &error); if (error != NULL) { g_warning("Unable to emit response signal: %s", error->message); g_error_free(error); } ual_tracepoint(observer_finish, "starting"); } gboolean ubuntu_app_launch_observer_add_app_starting (UbuntuAppLaunchAppObserver observer, gpointer user_data) { return add_session_generic(observer, user_data, "UnityStartingBroadcast", &starting_array, starting_signal_cb); } /* Handle the failed signal when it occurs, call the observer */ static void failed_signal_cb (GDBusConnection * conn, const gchar * sender, const gchar * object, const gchar * interface, const gchar * signal, GVariant * params, gpointer user_data) { failed_observer_t * observer = (failed_observer_t *)user_data; const gchar * appid = NULL; const gchar * typestr = NULL; ual_tracepoint(observer_start, "failed"); if (observer->func != NULL) { UbuntuAppLaunchAppFailed type = UBUNTU_APP_LAUNCH_APP_FAILED_CRASH; g_variant_get(params, "(&s&s)", &appid, &typestr); if (g_strcmp0("crash", typestr) == 0) { type = UBUNTU_APP_LAUNCH_APP_FAILED_CRASH; } else if (g_strcmp0("start-failure", typestr) == 0) { type = UBUNTU_APP_LAUNCH_APP_FAILED_START_FAILURE; } else { g_warning("Application failure type '%s' unknown, reporting as a crash", typestr); } observer->func(appid, type, observer->user_data); } ual_tracepoint(observer_finish, "failed"); } gboolean ubuntu_app_launch_observer_add_app_failed (UbuntuAppLaunchAppFailedObserver observer, gpointer user_data) { GDBusConnection * conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); if (conn == NULL) { return FALSE; } failed_observer_t * observert = g_new0(failed_observer_t, 1); observert->conn = conn; observert->func = observer; observert->user_data = user_data; failed_array = g_list_prepend(failed_array, observert); observert->sighandle = g_dbus_connection_signal_subscribe(conn, NULL, /* sender */ "com.canonical.UbuntuAppLaunch", /* interface */ "ApplicationFailed", /* signal */ "/", /* path */ NULL, /* arg0 */ G_DBUS_SIGNAL_FLAGS_NONE, failed_signal_cb, observert, NULL); /* user data destroy */ return TRUE; } /* Handle the paused signal when it occurs, call the observer */ static void paused_signal_cb (GDBusConnection * conn, const gchar * sender, const gchar * object, const gchar * interface, const gchar * signal, GVariant * params, gpointer user_data) { paused_resumed_observer_t * observer = (paused_resumed_observer_t *)user_data; ual_tracepoint(observer_start, observer->lttng_signal); if (observer->func != NULL) { GArray * pidarray = g_array_new(TRUE, TRUE, sizeof(GPid)); GVariant * appid = g_variant_get_child_value(params, 0); GVariant * pids = g_variant_get_child_value(params, 1); guint64 pid; GVariantIter thispid; g_variant_iter_init(&thispid, pids); while (g_variant_iter_loop(&thispid, "t", &pid)) { GPid gpid = (GPid)pid; /* Should be a no-op for most architectures, but just in case */ g_array_append_val(pidarray, gpid); } observer->func(g_variant_get_string(appid, NULL), (GPid *)pidarray->data, observer->user_data); g_array_free(pidarray, TRUE); g_variant_unref(appid); g_variant_unref(pids); } ual_tracepoint(observer_finish, observer->lttng_signal); } static gboolean paused_resumed_generic (UbuntuAppLaunchAppPausedResumedObserver observer, gpointer user_data, GList ** queue, const gchar * signal_name, const gchar * lttng_signal) { GDBusConnection * conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); if (conn == NULL) { return FALSE; } paused_resumed_observer_t * observert = g_new0(paused_resumed_observer_t, 1); observert->conn = conn; observert->func = observer; observert->user_data = user_data; observert->lttng_signal = lttng_signal; *queue = g_list_prepend(*queue, observert); observert->sighandle = g_dbus_connection_signal_subscribe(conn, NULL, /* sender */ "com.canonical.UbuntuAppLaunch", /* interface */ signal_name, /* signal */ "/", /* path */ NULL, /* arg0 */ G_DBUS_SIGNAL_FLAGS_NONE, paused_signal_cb, observert, NULL); /* user data destroy */ return TRUE; } gboolean ubuntu_app_launch_observer_add_app_paused (UbuntuAppLaunchAppPausedResumedObserver observer, gpointer user_data) { return paused_resumed_generic(observer, user_data, &paused_array, "ApplicationPaused", "paused"); } gboolean ubuntu_app_launch_observer_add_app_resumed (UbuntuAppLaunchAppPausedResumedObserver observer, gpointer user_data) { return paused_resumed_generic(observer, user_data, &resumed_array, "ApplicationResumed", "resumed"); } static gboolean delete_app_generic (UbuntuAppLaunchAppObserver observer, gpointer user_data, GList ** list) { observer_t * observert = NULL; GList * look; for (look = *list; look != NULL; look = g_list_next(look)) { observert = (observer_t *)look->data; if (observert->func == observer && observert->user_data == user_data) { break; } } if (look == NULL) { return FALSE; } g_dbus_connection_signal_unsubscribe(observert->conn, observert->sighandle); g_object_unref(observert->conn); g_free(observert); *list = g_list_delete_link(*list, look); return TRUE; } gboolean ubuntu_app_launch_observer_delete_app_started (UbuntuAppLaunchAppObserver observer, gpointer user_data) { return delete_app_generic(observer, user_data, &started_array); } gboolean ubuntu_app_launch_observer_delete_app_stop (UbuntuAppLaunchAppObserver observer, gpointer user_data) { return delete_app_generic(observer, user_data, &stop_array); } gboolean ubuntu_app_launch_observer_delete_app_resume (UbuntuAppLaunchAppObserver observer, gpointer user_data) { return delete_app_generic(observer, user_data, &resume_array); } gboolean ubuntu_app_launch_observer_delete_app_focus (UbuntuAppLaunchAppObserver observer, gpointer user_data) { return delete_app_generic(observer, user_data, &focus_array); } gboolean ubuntu_app_launch_observer_delete_app_starting (UbuntuAppLaunchAppObserver observer, gpointer user_data) { return delete_app_generic(observer, user_data, &starting_array); } gboolean ubuntu_app_launch_observer_delete_app_failed (UbuntuAppLaunchAppFailedObserver observer, gpointer user_data) { failed_observer_t * observert = NULL; GList * look; for (look = failed_array; look != NULL; look = g_list_next(look)) { observert = (failed_observer_t *)look->data; if (observert->func == observer && observert->user_data == user_data) { break; } } if (look == NULL) { return FALSE; } g_dbus_connection_signal_unsubscribe(observert->conn, observert->sighandle); g_object_unref(observert->conn); g_free(observert); failed_array = g_list_delete_link(failed_array, look); return TRUE; } static gboolean paused_resumed_delete (UbuntuAppLaunchAppPausedResumedObserver observer, gpointer user_data, GList ** list) { paused_resumed_observer_t * observert = NULL; GList * look; for (look = *list; look != NULL; look = g_list_next(look)) { observert = (paused_resumed_observer_t *)look->data; if (observert->func == observer && observert->user_data == user_data) { break; } } if (look == NULL) { return FALSE; } g_dbus_connection_signal_unsubscribe(observert->conn, observert->sighandle); g_object_unref(observert->conn); g_free(observert); *list = g_list_delete_link(*list, look); return TRUE; } gboolean ubuntu_app_launch_observer_delete_app_paused (UbuntuAppLaunchAppPausedResumedObserver observer, gpointer user_data) { return paused_resumed_delete(observer, user_data, &paused_array); } gboolean ubuntu_app_launch_observer_delete_app_resumed (UbuntuAppLaunchAppPausedResumedObserver observer, gpointer user_data) { return paused_resumed_delete(observer, user_data, &resumed_array); } typedef void (*per_instance_func_t) (GDBusConnection * con, GVariant * prop_dict, gpointer user_data); static void foreach_job_instance (GDBusConnection * con, const gchar * jobname, per_instance_func_t func, gpointer user_data) { const gchar * job_path = get_jobpath(con, jobname); if (job_path == NULL) return; GError * error = NULL; GVariant * instance_tuple = g_dbus_connection_call_sync(con, DBUS_SERVICE_UPSTART, job_path, DBUS_INTERFACE_UPSTART_JOB, "GetAllInstances", NULL, G_VARIANT_TYPE("(ao)"), G_DBUS_CALL_FLAGS_NONE, -1, /* timeout: default */ NULL, /* cancelable */ &error); if (error != NULL) { g_warning("Unable to get instances of job '%s': %s", jobname, error->message); g_error_free(error); return; } GVariant * instance_list = g_variant_get_child_value(instance_tuple, 0); g_variant_unref(instance_tuple); GVariantIter instance_iter; g_variant_iter_init(&instance_iter, instance_list); const gchar * instance_path = NULL; while (g_variant_iter_loop(&instance_iter, "&o", &instance_path)) { GVariant * props_tuple = g_dbus_connection_call_sync(con, DBUS_SERVICE_UPSTART, instance_path, "org.freedesktop.DBus.Properties", "GetAll", g_variant_new("(s)", DBUS_INTERFACE_UPSTART_INSTANCE), G_VARIANT_TYPE("(a{sv})"), G_DBUS_CALL_FLAGS_NONE, -1, /* timeout: default */ NULL, /* cancelable */ &error); if (error != NULL) { g_warning("Unable to name of instance '%s': %s", instance_path, error->message); g_error_free(error); error = NULL; continue; } GVariant * props_dict = g_variant_get_child_value(props_tuple, 0); func(con, props_dict, user_data); g_variant_unref(props_dict); g_variant_unref(props_tuple); } g_variant_unref(instance_list); } typedef struct { GArray * apps; gboolean truncate_legacy; const gchar * jobname; } apps_for_job_t; static void apps_for_job_instance (GDBusConnection * con, GVariant * props_dict, gpointer user_data) { GVariant * namev = g_variant_lookup_value(props_dict, "name", G_VARIANT_TYPE_STRING); if (namev == NULL) { return; } apps_for_job_t * data = (apps_for_job_t *)user_data; gchar * instance_name = g_variant_dup_string(namev, NULL); g_variant_unref(namev); if (data->truncate_legacy && g_strcmp0(data->jobname, "application-legacy") == 0) { gchar * last_dash = g_strrstr(instance_name, "-"); if (last_dash != NULL) { last_dash[0] = '\0'; } } g_array_append_val(data->apps, instance_name); } /* Get all the instances for a given job name */ static void apps_for_job (GDBusConnection * con, const gchar * jobname, GArray * apps, gboolean truncate_legacy) { apps_for_job_t data = { .jobname = jobname, .apps = apps, .truncate_legacy = truncate_legacy }; foreach_job_instance(con, jobname, apps_for_job_instance, &data); } gchar ** ubuntu_app_launch_list_running_apps (void) { GDBusConnection * con = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); g_return_val_if_fail(con != NULL, g_new0(gchar *, 1)); GArray * apps = g_array_new(TRUE, TRUE, sizeof(gchar *)); apps_for_job(con, "application-legacy", apps, TRUE); apps_for_job(con, "application-click", apps, FALSE); g_object_unref(con); return (gchar **)g_array_free(apps, FALSE); } typedef struct { GPid pid; const gchar * appid; const gchar * jobname; } pid_for_job_t; static void pid_for_job_instance (GDBusConnection * con, GVariant * props_dict, gpointer user_data) { GVariant * namev = g_variant_lookup_value(props_dict, "name", G_VARIANT_TYPE_STRING); if (namev == NULL) { return; } pid_for_job_t * data = (pid_for_job_t *)user_data; gchar * instance_name = g_variant_dup_string(namev, NULL); g_variant_unref(namev); if (g_strcmp0(data->jobname, "application-legacy") == 0) { gchar * last_dash = g_strrstr(instance_name, "-"); if (last_dash != NULL) { last_dash[0] = '\0'; } } if (g_strcmp0(instance_name, data->appid) == 0) { GVariant * processv = g_variant_lookup_value(props_dict, "processes", G_VARIANT_TYPE("a(si)")); if (processv != NULL) { if (g_variant_n_children(processv) > 0) { GVariant * first_entry = g_variant_get_child_value(processv, 0); GVariant * pidv = g_variant_get_child_value(first_entry, 1); data->pid = g_variant_get_int32(pidv); g_variant_unref(pidv); g_variant_unref(first_entry); } g_variant_unref(processv); } } g_free(instance_name); } /* Look for the app for a job */ static GPid pid_for_job (GDBusConnection * con, const gchar * jobname, const gchar * appid) { pid_for_job_t data = { .jobname = jobname, .appid = appid, .pid = 0 }; foreach_job_instance(con, jobname, pid_for_job_instance, &data); return data.pid; } GPid ubuntu_app_launch_get_primary_pid (const gchar * appid) { g_return_val_if_fail(appid != NULL, 0); GDBusConnection * con = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); g_return_val_if_fail(con != NULL, 0); GPid pid = 0; if (pid == 0) { pid = pid_for_job(con, "application-legacy", appid); } if (pid == 0) { pid = pid_for_job(con, "application-click", appid); } g_object_unref(con); return pid; } /* Get the PIDs for an AppID. If it's click or legacy single instance that's a simple call to the helper. But if it's not, we have to make a call for each instance of the app that we have running. */ static GList * pids_for_appid (const gchar * appid) { ual_tracepoint(pids_list_start, appid); GDBusConnection * cgmanager = cgroup_manager_connection(); g_return_val_if_fail(cgmanager != NULL, NULL); ual_tracepoint(pids_list_connected, appid); if (is_click(appid)) { GList * pids = pids_from_cgroup(cgmanager, "application-click", appid); cgroup_manager_unref(cgmanager); ual_tracepoint(pids_list_finished, appid, g_list_length(pids)); return pids; } else if (!is_libertine(appid) && legacy_single_instance(appid)) { gchar * jobname = g_strdup_printf("%s-", appid); GList * pids = pids_from_cgroup(cgmanager, "application-legacy", jobname); g_free(jobname); cgroup_manager_unref(cgmanager); ual_tracepoint(pids_list_finished, appid, g_list_length(pids)); return pids; } /* If we're not single instance, we need to find all the pids for all the instances of the app */ unsigned int i; GDBusConnection * con = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); g_return_val_if_fail(con != NULL, NULL); GList * pids = NULL; GArray * apps = g_array_new(TRUE, TRUE, sizeof(gchar *)); g_array_set_clear_func(apps, free_helper); apps_for_job(con, "application-legacy", apps, FALSE); gchar * appiddash = g_strdup_printf("%s-", appid); /* Probably could go RegEx here, but let's start with just a prefix lookup */ for (i = 0; i < apps->len; i++) { const gchar * array_id = g_array_index(apps, const gchar *, i); if (g_str_has_prefix(array_id, appiddash)) { GList * morepids = pids_from_cgroup(cgmanager, "application-legacy", array_id); pids = g_list_concat(pids, morepids); } } g_free(appiddash); g_array_free(apps, TRUE); g_object_unref(con); cgroup_manager_unref(cgmanager); ual_tracepoint(pids_list_finished, appid, g_list_length(pids)); return pids; } gboolean ubuntu_app_launch_pid_in_app_id (GPid pid, const gchar * appid) { g_return_val_if_fail(appid != NULL, FALSE); if (pid == 0) { return FALSE; } GList * pidlist = pids_for_appid(appid); GList * head; for (head = pidlist; head != NULL; head = g_list_next(head)) { GPid checkpid = GPOINTER_TO_INT(head->data); if (checkpid == pid) { g_list_free(pidlist); return TRUE; } } g_list_free(pidlist); return FALSE; } gboolean ubuntu_app_launch_app_id_parse (const gchar * appid, gchar ** package, gchar ** application, gchar ** version) { g_return_val_if_fail(appid != NULL, FALSE); /* 'Parse' the App ID */ gchar ** app_id_segments = g_strsplit(appid, "_", 4); if (g_strv_length(app_id_segments) != 3) { g_debug("Unable to parse Application ID: %s", appid); g_strfreev(app_id_segments); return FALSE; } if (package != NULL) { *package = app_id_segments[0]; } else { g_free(app_id_segments[0]); } if (application != NULL) { *application = app_id_segments[1]; } else { g_free(app_id_segments[1]); } if (version != NULL) { *version = app_id_segments[2]; } else { g_free(app_id_segments[2]); } g_free(app_id_segments); return TRUE; } /* Figure out whether we're a libertine container app or a click and then choose which function to use */ gchar * ubuntu_app_launch_triplet_to_app_id (const gchar * pkg, const gchar * app, const gchar * ver) { g_return_val_if_fail(pkg != NULL, NULL); /* Check if is a libertine container */ gchar * libertinepath = g_build_filename(g_get_user_cache_dir(), "libertine-container", pkg, NULL); gboolean libcontainer = g_file_test(libertinepath, G_FILE_TEST_EXISTS); g_free(libertinepath); if (libcontainer) { return libertine_triplet_to_app_id(pkg, app, ver); } else { return click_triplet_to_app_id(pkg, app, ver); } } /* Print an error if we couldn't start it */ static void start_helper_callback (GObject * obj, GAsyncResult * res, gpointer user_data) { GError * error = NULL; GVariant * result = NULL; result = g_dbus_connection_call_finish(G_DBUS_CONNECTION(obj), res, &error); if (result != NULL) g_variant_unref(result); if (error != NULL) { g_warning("Unable to start helper: %s", error->message); g_error_free(error); } } /* Implements sending the "start" command to Upstart for the untrusted helper job with the various configuration options to define the instance. In the end there's only one job with an array of instances. */ static gboolean start_helper_core (const gchar * type, const gchar * appid, const gchar * const * uris, const gchar * instance, const gchar * mirsocketpath) { GDBusConnection * con = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); g_return_val_if_fail(con != NULL, FALSE); const gchar * jobpath = get_jobpath(con, "untrusted-helper"); /* Build up our environment */ GVariantBuilder builder; g_variant_builder_init(&builder, G_VARIANT_TYPE_TUPLE); g_variant_builder_open(&builder, G_VARIANT_TYPE_ARRAY); g_variant_builder_add_value(&builder, g_variant_new_take_string(g_strdup_printf("APP_ID=%s", appid))); g_variant_builder_add_value(&builder, g_variant_new_take_string(g_strdup_printf("HELPER_TYPE=%s", type))); if (uris != NULL) { gchar * urisjoin = app_uris_string(uris); g_variant_builder_add_value(&builder, g_variant_new_take_string(g_strdup_printf("APP_URIS=%s", urisjoin))); g_free(urisjoin); } if (instance != NULL) { g_variant_builder_add_value(&builder, g_variant_new_take_string(g_strdup_printf("INSTANCE_ID=%s", instance))); } if (mirsocketpath != NULL) { g_variant_builder_add_value(&builder, g_variant_new_take_string(g_strdup_printf("UBUNTU_APP_LAUNCH_DEMANGLE_PATH=%s", mirsocketpath))); g_variant_builder_add_value(&builder, g_variant_new_take_string(g_strdup_printf("UBUNTU_APP_LAUNCH_DEMANGLE_NAME=%s", g_dbus_connection_get_unique_name(con)))); } g_variant_builder_close(&builder); g_variant_builder_add_value(&builder, g_variant_new_boolean(TRUE)); /* Call the job start function */ g_dbus_connection_call(con, DBUS_SERVICE_UPSTART, jobpath, DBUS_INTERFACE_UPSTART_JOB, "Start", g_variant_builder_end(&builder), NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, /* cancelable */ start_helper_callback, NULL); g_object_unref(con); return TRUE; } gboolean ubuntu_app_launch_start_helper (const gchar * type, const gchar * appid, const gchar * const * uris) { g_return_val_if_fail(type != NULL, FALSE); g_return_val_if_fail(appid != NULL, FALSE); g_return_val_if_fail(g_strstr_len(type, -1, ":") == NULL, FALSE); return start_helper_core(type, appid, uris, NULL, NULL); } gchar * ubuntu_app_launch_start_multiple_helper (const gchar * type, const gchar * appid, const gchar * const * uris) { g_return_val_if_fail(type != NULL, NULL); g_return_val_if_fail(appid != NULL, NULL); g_return_val_if_fail(g_strstr_len(type, -1, ":") == NULL, NULL); gchar * instanceid = g_strdup_printf("%" G_GUINT64_FORMAT, g_get_real_time()); if (start_helper_core(type, appid, uris, instanceid, NULL)) { return instanceid; } g_free(instanceid); return NULL; } /* Transfer from Mir's data structure to ours */ static void get_mir_session_fd_helper (MirPromptSession * session, size_t count, int const * fdin, void * user_data) { if (count != 1) { g_warning("Mir trusted session returned %d FDs instead of one", (int)count); return; } int * retfd = (int *)user_data; *retfd = fdin[0]; } /* Setup to get the FD from Mir, blocking */ static int get_mir_session_fd (MirPromptSession * session) { int retfd = 0; MirWaitHandle * wait = mir_prompt_session_new_fds_for_prompt_providers(session, 1, get_mir_session_fd_helper, &retfd); mir_wait_for(wait); return retfd; } static GList * open_proxies = NULL; static gint remove_socket_path_find (gconstpointer a, gconstpointer b) { GObject * obj = (GObject *)a; const gchar * path = (const gchar *)b; gchar * objpath = g_object_get_qdata(obj, proxy_path_quark()); return g_strcmp0(objpath, path); } /* Cleans up if we need to early */ static gboolean remove_socket_path (const gchar * path) { GList * thisproxy = g_list_find_custom(open_proxies, path, remove_socket_path_find); if (thisproxy == NULL) return FALSE; g_debug("Removing Mir Socket Proxy: %s", path); GObject * obj = G_OBJECT(thisproxy->data); open_proxies = g_list_delete_link(open_proxies, thisproxy); /* Remove ourselves from DBus if we weren't already */ g_dbus_interface_skeleton_unexport(G_DBUS_INTERFACE_SKELETON(obj)); /* If we still have FD, close it */ int mirfd = GPOINTER_TO_INT(g_object_get_qdata(obj, mir_fd_quark())); if (mirfd != 0) { close(mirfd); /* This is actually an error, we should expect not to find this here to do anything with it. */ const gchar * props[3] = { "UbuntuAppLaunchProxyDbusPath", NULL, NULL }; props[1] = path; report_recoverable_problem("ubuntu-app-launch-mir-fd-proxy", 0, TRUE, props); } g_object_unref(obj); return TRUE; } /* Small timeout function that shouldn't, in most cases, ever do anything. But we need it here to ensure we don't leave things on the bus */ static gboolean proxy_timeout (gpointer user_data) { const gchar * path = (const gchar *)user_data; remove_socket_path(path); return G_SOURCE_REMOVE; } /* Removes the whole list of proxies if they are there */ static void proxy_cleanup_list (void) { while (open_proxies) { GObject * obj = G_OBJECT(open_proxies->data); gchar * path = g_object_get_qdata(obj, proxy_path_quark()); remove_socket_path(path); } } static gboolean proxy_mir_socket (GObject * obj, GDBusMethodInvocation * invocation, gpointer user_data) { g_debug("Called to give Mir socket"); int fd = GPOINTER_TO_INT(user_data); if (fd == 0) { g_critical("No FDs to give!"); return FALSE; } /* Index into fds */ GVariant* handle = g_variant_new_handle(0); GVariant* tuple = g_variant_new_tuple(&handle, 1); GError* error = NULL; GUnixFDList* list = g_unix_fd_list_new(); g_unix_fd_list_append(list, fd, &error); if (error == NULL) { g_dbus_method_invocation_return_value_with_unix_fd_list(invocation, tuple, list); } else { g_variant_ref_sink(tuple); g_variant_unref(tuple); } g_object_unref(list); if (error != NULL) { g_critical("Unable to pass FD %d: %s", fd, error->message); g_error_free(error); return FALSE; } g_object_set_qdata(obj, mir_fd_quark(), GINT_TO_POINTER(0)); return TRUE; } /* Sets up the DBus proxy to send to the demangler */ static gchar * build_proxy_socket_path (const gchar * appid, int mirfd) { static gboolean final_cleanup = FALSE; if (!final_cleanup) { g_atexit(proxy_cleanup_list); final_cleanup = TRUE; } GError * error = NULL; GDBusConnection * session = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error); if (error != NULL) { g_warning("Unable to get session bus: %s", error->message); g_error_free(error); return NULL; } /* Export an Object on DBus */ proxySocketDemangler * skel = proxy_socket_demangler_skeleton_new(); g_signal_connect(G_OBJECT(skel), "handle-get-mir-socket", G_CALLBACK(proxy_mir_socket), GINT_TO_POINTER(mirfd)); gchar * encoded_appid = escape_dbus_string(appid); gchar * socket_name = NULL; /* Loop until we fine an object path that isn't taken (probably only once) */ while (socket_name == NULL) { gchar* tryname = g_strdup_printf("/com/canonical/UbuntuAppLaunch/%s/%X", encoded_appid, g_random_int()); g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(skel), session, tryname, &error); if (error == NULL) { socket_name = tryname; g_debug("Exporting Mir socket on path: %s", socket_name); } else { /* Always print the error, but if the object path is in use let's not exit the loop. Let's just try again. */ bool exitnow = (error->domain != G_DBUS_ERROR || error->code != G_DBUS_ERROR_OBJECT_PATH_IN_USE); g_critical("Unable to export trusted session object: %s", error->message); g_clear_error(&error); g_free(tryname); if (exitnow) { break; } } } g_free(encoded_appid); /* If we didn't get a socket name, we should just exit. And make sure to clean up the socket. */ if (socket_name == NULL) { g_object_unref(skel); g_object_unref(session); g_critical("Unable to export object to any name"); return NULL; } g_object_set_qdata_full(G_OBJECT(skel), proxy_path_quark(), g_strdup(socket_name), g_free); g_object_set_qdata(G_OBJECT(skel), mir_fd_quark(), GINT_TO_POINTER(mirfd)); open_proxies = g_list_prepend(open_proxies, skel); g_timeout_add_seconds_full(G_PRIORITY_DEFAULT, 2, proxy_timeout, g_strdup(socket_name), g_free); g_object_unref(session); return socket_name; } gchar * ubuntu_app_launch_start_session_helper (const gchar * type, MirPromptSession * session, const gchar * appid, const gchar * const * uris) { g_return_val_if_fail(type != NULL, NULL); g_return_val_if_fail(session != NULL, NULL); g_return_val_if_fail(appid != NULL, NULL); g_return_val_if_fail(g_strstr_len(type, -1, ":") == NULL, NULL); int mirfd = get_mir_session_fd(session); if (mirfd == 0) return NULL; gchar * socket_path = build_proxy_socket_path(appid, mirfd); if (socket_path == NULL) { close(mirfd); return NULL; } gchar * instanceid = g_strdup_printf("%" G_GUINT64_FORMAT, g_get_real_time()); if (start_helper_core(type, appid, uris, instanceid, socket_path)) { return instanceid; } remove_socket_path(socket_path); g_free(socket_path); close(mirfd); g_free(instanceid); return NULL; } /* Print an error if we couldn't stop it */ static void stop_helper_callback (GObject * obj, GAsyncResult * res, gpointer user_data) { GError * error = NULL; GVariant * result = NULL; result = g_dbus_connection_call_finish(G_DBUS_CONNECTION(obj), res, &error); if (result != NULL) g_variant_unref(result); if (error != NULL) { g_warning("Unable to stop helper: %s", error->message); g_error_free(error); } } /* Implements the basis of sending the stop message to Upstart for an instance of the untrusted-helper job. That also can have an instance in that we allow for random instance ids to be used for helpers that are not unique */ static gboolean stop_helper_core (const gchar * type, const gchar * appid, const gchar * instanceid) { GDBusConnection * con = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); g_return_val_if_fail(con != NULL, FALSE); const gchar * jobpath = get_jobpath(con, "untrusted-helper"); /* Build up our environment */ GVariantBuilder builder; g_variant_builder_init(&builder, G_VARIANT_TYPE_TUPLE); g_variant_builder_open(&builder, G_VARIANT_TYPE_ARRAY); g_variant_builder_add_value(&builder, g_variant_new_take_string(g_strdup_printf("APP_ID=%s", appid))); g_variant_builder_add_value(&builder, g_variant_new_take_string(g_strdup_printf("HELPER_TYPE=%s", type))); if (instanceid != NULL) { g_variant_builder_add_value(&builder, g_variant_new_take_string(g_strdup_printf("INSTANCE_ID=%s", instanceid))); } g_variant_builder_close(&builder); g_variant_builder_add_value(&builder, g_variant_new_boolean(TRUE)); /* Call the job start function */ g_dbus_connection_call(con, DBUS_SERVICE_UPSTART, jobpath, DBUS_INTERFACE_UPSTART_JOB, "Stop", g_variant_builder_end(&builder), NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, /* cancelable */ stop_helper_callback, NULL); g_object_unref(con); return TRUE; } gboolean ubuntu_app_launch_stop_helper (const gchar * type, const gchar * appid) { g_return_val_if_fail(type != NULL, FALSE); g_return_val_if_fail(appid != NULL, FALSE); g_return_val_if_fail(g_strstr_len(type, -1, ":") == NULL, FALSE); return stop_helper_core(type, appid, NULL); } gboolean ubuntu_app_launch_stop_multiple_helper (const gchar * type, const gchar * appid, const gchar * instanceid) { g_return_val_if_fail(type != NULL, FALSE); g_return_val_if_fail(appid != NULL, FALSE); g_return_val_if_fail(instanceid != NULL, FALSE); g_return_val_if_fail(g_strstr_len(type, -1, ":") == NULL, FALSE); return stop_helper_core(type, appid, instanceid); } typedef struct { gchar * type_prefix; /* Type with the colon sperator */ size_t type_len; /* Length in characters of the prefix */ GArray * retappids; /* Array of appids to return */ } helpers_helper_t; /* Look at each instance and see if it matches this type, if so add the appid portion to the array of appids */ static void list_helpers_helper (GDBusConnection * con, GVariant * props_dict, gpointer user_data) { helpers_helper_t * data = (helpers_helper_t *)user_data; GVariant * namev = g_variant_lookup_value(props_dict, "name", G_VARIANT_TYPE_STRING); if (namev == NULL) { return; } const gchar * name = g_variant_get_string(namev, NULL); if (g_str_has_prefix(name, data->type_prefix)) { /* Skip the type name */ name += data->type_len; /* Skip a possible instance ID */ name = g_strstr_len(name, -1, ":"); name++; /* Now copy the app id */ gchar * appid = g_strdup(name); g_array_append_val(data->retappids, appid); } g_variant_unref(namev); return; } gchar ** ubuntu_app_launch_list_helpers (const gchar * type) { g_return_val_if_fail(type != NULL, FALSE); g_return_val_if_fail(g_strstr_len(type, -1, ":") == NULL, FALSE); GDBusConnection * con = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); g_return_val_if_fail(con != NULL, FALSE); helpers_helper_t helpers_helper_data = { .type_prefix = g_strdup_printf("%s:", type), .type_len = strlen(type) + 1, /* 1 for the colon */ .retappids = g_array_new(TRUE, TRUE, sizeof(gchar *)) }; foreach_job_instance(con, "untrusted-helper", list_helpers_helper, &helpers_helper_data); g_object_unref(con); g_free(helpers_helper_data.type_prefix); return (gchar **)g_array_free(helpers_helper_data.retappids, FALSE); } typedef struct { gchar * type_prefix; /* Type with the colon sperator */ size_t type_len; /* Length in characters of the prefix */ GArray * retappids; /* Array of appids to return */ gchar * appid_suffix; /* The appid for the end */ } helper_instances_t; /* Look at each instance and see if it matches this type and appid. If so, add the instance ID to the array of instance IDs */ static void list_helper_instances (GDBusConnection * con, GVariant * props_dict, gpointer user_data) { helper_instances_t * data = (helper_instances_t *)user_data; GVariant * namev = g_variant_lookup_value(props_dict, "name", G_VARIANT_TYPE_STRING); if (namev == NULL) { return; } const gchar * name = g_variant_get_string(namev, NULL); gchar * suffix_loc = NULL; if (g_str_has_prefix(name, data->type_prefix) && (suffix_loc = g_strrstr(name, data->appid_suffix)) != NULL) { /* Skip the type name */ name += data->type_len; /* Now copy the instance id */ gchar * instanceid = g_strndup(name, suffix_loc - name); g_array_append_val(data->retappids, instanceid); } g_variant_unref(namev); return; } gchar ** ubuntu_app_launch_list_helper_instances (const gchar * type, const gchar * appid) { g_return_val_if_fail(type != NULL, FALSE); g_return_val_if_fail(g_strstr_len(type, -1, ":") == NULL, FALSE); GDBusConnection * con = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); g_return_val_if_fail(con != NULL, FALSE); helper_instances_t helper_instances_data = { .type_prefix = g_strdup_printf("%s:", type), .type_len = strlen(type) + 1, /* 1 for the colon */ .retappids = g_array_new(TRUE, TRUE, sizeof(gchar *)), .appid_suffix = g_strdup_printf(":%s", appid) }; foreach_job_instance(con, "untrusted-helper", list_helper_instances, &helper_instances_data); g_object_unref(con); g_free(helper_instances_data.type_prefix); g_free(helper_instances_data.appid_suffix); return (gchar **)g_array_free(helper_instances_data.retappids, FALSE); } /* The data we keep for each observer */ typedef struct _helper_observer_t helper_observer_t; struct _helper_observer_t { GDBusConnection * conn; guint sighandle; gchar * type; UbuntuAppLaunchHelperObserver func; gpointer user_data; }; /* The lists of helper observers */ static GList * helper_started_obs = NULL; static GList * helper_stopped_obs = NULL; static void helper_observer_cb (GDBusConnection * conn, const gchar * sender, const gchar * object, const gchar * interface, const gchar * signal, GVariant * params, gpointer user_data) { helper_observer_t * observer = (helper_observer_t *)user_data; gchar * env = NULL; GVariant * envs = g_variant_get_child_value(params, 1); GVariantIter iter; g_variant_iter_init(&iter, envs); gboolean job_found = FALSE; gchar * instance = NULL; while (g_variant_iter_loop(&iter, "s", &env)) { if (g_strcmp0(env, "JOB=untrusted-helper") == 0) { job_found = TRUE; } else if (g_str_has_prefix(env, "INSTANCE=")) { instance = g_strdup(env + strlen("INSTANCE=")); } } g_variant_unref(envs); if (instance != NULL && !g_str_has_prefix(instance, observer->type)) { g_free(instance); instance = NULL; } gchar * appid = NULL; gchar * instanceid = NULL; gchar * type = NULL; if (instance != NULL) { gchar ** split = g_strsplit(instance, ":", 3); type = split[0]; instanceid = split[1]; appid = split[2]; g_free(split); } g_free(instance); if (instanceid != NULL && instanceid[0] == '\0') { g_free(instanceid); instanceid = NULL; } if (job_found && appid != NULL) { observer->func(appid, instanceid, type, observer->user_data); } g_free(appid); g_free(instanceid); g_free(type); } /* Creates the observer structure and registers for the signal with GDBus so that we can get a callback */ static gboolean add_helper_generic (UbuntuAppLaunchHelperObserver observer, const gchar * helper_type, gpointer user_data, const gchar * signal, GList ** list) { GDBusConnection * conn = gdbus_upstart_ref(); if (conn == NULL) { return FALSE; } helper_observer_t * observert = g_new0(helper_observer_t, 1); observert->conn = conn; observert->func = observer; observert->user_data = user_data; observert->type = g_strdup_printf("%s:", helper_type); *list = g_list_prepend(*list, observert); observert->sighandle = g_dbus_connection_signal_subscribe(conn, NULL, /* sender */ DBUS_INTERFACE_UPSTART, /* interface */ "EventEmitted", /* signal */ DBUS_PATH_UPSTART, /* path */ signal, /* arg0 */ G_DBUS_SIGNAL_FLAGS_NONE, helper_observer_cb, observert, NULL); /* user data destroy */ return TRUE; } static gboolean delete_helper_generic (UbuntuAppLaunchHelperObserver observer, const gchar * type, gpointer user_data, GList ** list) { helper_observer_t * observert = NULL; GList * look; for (look = *list; look != NULL; look = g_list_next(look)) { observert = (helper_observer_t *)look->data; if (observert->func == observer && observert->user_data == user_data && g_str_has_prefix(observert->type, type)) { break; } } if (look == NULL) { return FALSE; } g_dbus_connection_signal_unsubscribe(observert->conn, observert->sighandle); g_object_unref(observert->conn); g_free(observert->type); g_free(observert); *list = g_list_delete_link(*list, look); return TRUE; } gboolean ubuntu_app_launch_observer_add_helper_started (UbuntuAppLaunchHelperObserver observer, const gchar * helper_type, gpointer user_data) { g_return_val_if_fail(observer != NULL, FALSE); g_return_val_if_fail(helper_type != NULL, FALSE); g_return_val_if_fail(g_strstr_len(helper_type, -1, ":") == NULL, FALSE); return add_helper_generic(observer, helper_type, user_data, "started", &helper_started_obs); } gboolean ubuntu_app_launch_observer_add_helper_stop (UbuntuAppLaunchHelperObserver observer, const gchar * helper_type, gpointer user_data) { g_return_val_if_fail(observer != NULL, FALSE); g_return_val_if_fail(helper_type != NULL, FALSE); g_return_val_if_fail(g_strstr_len(helper_type, -1, ":") == NULL, FALSE); return add_helper_generic(observer, helper_type, user_data, "stopped", &helper_stopped_obs); } gboolean ubuntu_app_launch_observer_delete_helper_started (UbuntuAppLaunchHelperObserver observer, const gchar * helper_type, gpointer user_data) { g_return_val_if_fail(observer != NULL, FALSE); g_return_val_if_fail(helper_type != NULL, FALSE); g_return_val_if_fail(g_strstr_len(helper_type, -1, ":") == NULL, FALSE); return delete_helper_generic(observer, helper_type, user_data, &helper_started_obs); } gboolean ubuntu_app_launch_observer_delete_helper_stop (UbuntuAppLaunchHelperObserver observer, const gchar * helper_type, gpointer user_data) { g_return_val_if_fail(observer != NULL, FALSE); g_return_val_if_fail(helper_type != NULL, FALSE); g_return_val_if_fail(g_strstr_len(helper_type, -1, ":") == NULL, FALSE); return delete_helper_generic(observer, helper_type, user_data, &helper_stopped_obs); } /* Sets an environment variable in Upstart */ static void set_var (GDBusConnection * bus, const gchar * job_name, const gchar * instance_name, const gchar * envvar) { GVariantBuilder builder; /* Target: (assb) */ g_variant_builder_init(&builder, G_VARIANT_TYPE_TUPLE); /* Setup the job properties */ g_variant_builder_open(&builder, G_VARIANT_TYPE_ARRAY); g_variant_builder_add_value(&builder, g_variant_new_string(job_name)); if (instance_name != NULL) g_variant_builder_add_value(&builder, g_variant_new_string(instance_name)); g_variant_builder_close(&builder); g_variant_builder_add_value(&builder, g_variant_new_string(envvar)); /* Do we want to replace? Yes, we do! */ g_variant_builder_add_value(&builder, g_variant_new_boolean(TRUE)); g_dbus_connection_call(bus, "com.ubuntu.Upstart", "/com/ubuntu/Upstart", "com.ubuntu.Upstart0_6", "SetEnv", g_variant_builder_end(&builder), NULL, /* reply */ G_DBUS_CALL_FLAGS_NONE, -1, /* timeout */ NULL, /* cancelable */ NULL, NULL); /* callback */ } gboolean ubuntu_app_launch_helper_set_exec (const gchar * execline, const gchar * directory) { g_return_val_if_fail(execline != NULL, FALSE); g_return_val_if_fail(execline[0] != '\0', FALSE); /* Check to see if we can get the job environment */ const gchar * job_name = g_getenv("UPSTART_JOB"); const gchar * instance_name = g_getenv("UPSTART_INSTANCE"); const gchar * demangler = g_getenv("UBUNTU_APP_LAUNCH_DEMANGLE_NAME"); g_return_if_fail(job_name != NULL); GError * error = NULL; GDBusConnection * bus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error); if (error != NULL) { g_warning("Unable to get session bus: %s", error->message); g_error_free(error); return FALSE; } /* The exec value */ gchar * envstr = NULL; if (demangler) { envstr = g_strdup_printf("APP_EXEC=%s %s", DEMANGLER_PATH, execline); } else { envstr = g_strdup_printf("APP_EXEC=%s", execline); } set_var(bus, job_name, instance_name, envstr); g_free(envstr); /* The directory value */ if (directory != NULL) { gchar * direnv = g_strdup_printf("APP_DIR=%s", directory); set_var(bus, job_name, instance_name, direnv); g_free(direnv); } g_object_unref(bus); return TRUE; } /* ensure that all characters are valid in the dbus output string */ static gchar * escape_dbus_string (const gchar * input) { static const gchar *xdigits = "0123456789abcdef"; GString *escaped; gchar c; g_return_val_if_fail (input != NULL, NULL); escaped = g_string_new (NULL); while ((c = *input++)) { if (g_ascii_isalnum (c)) { g_string_append_c (escaped, c); } else { g_string_append_c (escaped, '_'); g_string_append_c (escaped, xdigits[c >> 4]); g_string_append_c (escaped, xdigits[c & 0xf]); } } return g_string_free (escaped, FALSE); } ubuntu-app-launch-0.5+15.10.20150817/libubuntu-app-launch/libubuntu-app-launch.map0000644000015300001610000000005612564452056030072 0ustar pbuserpbgroup00000000000000{ global: ubuntu_app_launch_*; local: *; }; ubuntu-app-launch-0.5+15.10.20150817/libubuntu-app-launch/click-exec.c0000644000015300001610000001162712564452110025504 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include #include #include "helpers.h" #include "ubuntu-app-launch-trace.h" #include "ual-tracepoint.h" /* INTRODUCTION: This is the utility that executes a click package based on the Application ID. Actually it just determines what needs to be executed, and asks Upstart to execute it so that it can be tracked better. This process runs OUTSIDE of the app armor confinement for the application. It also DOES NOT use any files that can be modified by the user. So things like the desktop file in ~/.local/share/applications are all off limits. For information on Click packages and the manifest look at the Click package documentation: https://click.readthedocs.org/en/latest/ */ gboolean click_task_setup (GDBusConnection * bus, const gchar * app_id, EnvHandle * handle) { g_return_val_if_fail(bus != NULL, FALSE); g_return_val_if_fail(app_id != NULL, FALSE); g_return_val_if_fail(handle != NULL, FALSE); ual_tracepoint(click_start, app_id); GError * error = NULL; handshake_t * handshake = starting_handshake_start(app_id); if (handshake == NULL) { g_warning("Unable to setup starting handshake"); } ual_tracepoint(click_starting_sent, app_id); gchar * package = NULL; /* 'Parse' the App ID */ if (!app_id_to_triplet(app_id, &package, NULL, NULL)) { g_warning("Unable to parse App ID: '%s'", app_id); return FALSE; } /* Check click to find out where the files are */ ClickDB * db = click_db_new(); /* If TEST_CLICK_DB is unset, this reads the system database. */ click_db_read(db, g_getenv("TEST_CLICK_DB"), &error); if (error != NULL) { g_warning("Unable to read Click database: %s", error->message); g_error_free(error); g_free(package); return FALSE; } /* If TEST_CLICK_USER is unset, this uses the current user name. */ ClickUser * user = click_user_new_for_user(db, g_getenv("TEST_CLICK_USER"), &error); if (error != NULL) { g_warning("Unable to read Click database: %s", error->message); g_error_free(error); g_free(package); g_object_unref(db); return FALSE; } gchar * pkgdir = click_user_get_path(user, package, &error); if (error != NULL) { g_warning("Unable to get the Click package directory for %s: %s", package, error->message); g_error_free(error); g_free(package); g_object_unref(user); g_object_unref(db); return FALSE; } g_object_unref(user); g_object_unref(db); ual_tracepoint(click_found_pkgdir, app_id); if (!g_file_test(pkgdir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { g_warning("Application directory '%s' doesn't exist", pkgdir); g_free(pkgdir); g_free(package); return FALSE; } g_debug("Setting 'APP_DIR' to '%s'", pkgdir); env_handle_add(handle, "APP_DIR", pkgdir); set_confined_envvars(handle, package, pkgdir); ual_tracepoint(click_configured_env, app_id); gchar * desktopfile = manifest_to_desktop(pkgdir, app_id); g_free(pkgdir); g_free(package); if (desktopfile == NULL) { g_warning("Desktop file unable to be found"); return FALSE; } ual_tracepoint(click_read_manifest, app_id); GKeyFile * keyfile = g_key_file_new(); env_handle_add(handle, "APP_DESKTOP_FILE_PATH", desktopfile); g_key_file_load_from_file(keyfile, desktopfile, 0, &error); if (error != NULL) { g_warning("Unable to load desktop file '%s': %s", desktopfile, error->message); g_error_free(error); g_key_file_free(keyfile); g_free(desktopfile); return FALSE; } if (g_key_file_has_key(keyfile, "Desktop Entry", "X-Ubuntu-XMir-Enable", NULL)) { if (g_key_file_get_boolean(keyfile, "Desktop Entry", "X-Ubuntu-XMir-Enable", NULL)) { env_handle_add(handle, "APP_XMIR_ENABLE", "1"); } else { env_handle_add(handle, "APP_XMIR_ENABLE", "0"); } } /* This string is quoted using desktop file quoting: http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#exec-variables */ gchar * exec = desktop_to_exec(keyfile, desktopfile); if (exec == NULL) { return FALSE; } ual_tracepoint(click_read_desktop, app_id); g_debug("Setting 'APP_EXEC' to '%s'", exec); env_handle_add(handle, "APP_EXEC", exec); g_free(exec); g_key_file_unref(keyfile); g_free(desktopfile); ual_tracepoint(handshake_wait, app_id); starting_handshake_wait(handshake); ual_tracepoint(handshake_complete, app_id); return TRUE; } ubuntu-app-launch-0.5+15.10.20150817/libubuntu-app-launch/ubuntu-app-launch.h0000644000015300001610000006454112564452125027063 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include #include #ifndef __UBUNTU_APP_LAUNCH_H__ #define __UBUNTU_APP_LAUNCH_H__ 1 #pragma GCC visibility push(default) #ifdef __cplusplus extern "C" { #endif /** * UbuntuAppLaunchAppFailed: * * Types of failure that we report. */ typedef enum { /*< prefix=UBUNTU_APP_LAUNCH_APP_FAILED */ UBUNTU_APP_LAUNCH_APP_FAILED_CRASH, /*< nick=crash */ UBUNTU_APP_LAUNCH_APP_FAILED_START_FAILURE, /*< nick=start-failure */ } UbuntuAppLaunchAppFailed; /** * UbuntuAppLaunchAppObserver: * * Function prototype for application observers. */ typedef void (*UbuntuAppLaunchAppObserver) (const gchar * appid, gpointer user_data); /** * UbuntuAppLaunchAppFailedObserver: * * Function prototype for application failed observers. */ typedef void (*UbuntuAppLaunchAppFailedObserver) (const gchar * appid, UbuntuAppLaunchAppFailed failure_type, gpointer user_data); /** * UbuntuAppLaunchAppPausedResumedObserver: * @appid: App ID of the application being paused * @pids: Zero terminated array of PIDs * * Function prototype for application paused and resumed observers. */ typedef void (*UbuntuAppLaunchAppPausedResumedObserver) (const gchar * appid, GPid * pids, gpointer user_data); /** * UbuntuAppLaunchHelperObserver: * * Function to watch for helpers that are starting and stopping */ typedef void (*UbuntuAppLaunchHelperObserver) (const gchar * appid, const gchar * instanceid, const gchar * helpertype, gpointer user_data); /** * ubuntu_app_launch_start_application: * @appid: ID of the application to launch * @uris: (allow-none) (array zero-terminated=1) (element-type utf8) (transfer none): A NULL terminated list of URIs to send to the application * * Asks upstart to launch an application. * * Return value: Whether the launch succeeded (may fail later, but upstart * will report the error in that case. */ gboolean ubuntu_app_launch_start_application (const gchar * appid, const gchar * const * uris); /** * ubuntu_app_launch_start_application_test: * @appid: ID of the application to launch * @uris: (allow-none) (array zero-terminated=1) (element-type utf8) (transfer none): A NULL terminated list of URIs to send to the application * * Asks upstart to launch an application with environment variables set * to enable testing. Should only be used in testing. * * Return value: Whether the launch succeeded (may fail later, but upstart * will report the error in that case. */ gboolean ubuntu_app_launch_start_application_test (const gchar * appid, const gchar * const * uris); /** * ubuntu_app_launch_stop_application: * @appid: ID of the application to launch * * Asks upstart to stop an application. * * Return value: Whether we were able to ask Ubuntu to stop the process, * used ubuntu_app_launch_observer_add_app_stop() to know when it is * finally stopped. */ gboolean ubuntu_app_launch_stop_application (const gchar * appid); /** * ubuntu_app_launch_pause_application: * @appid: ID of the application to pause * * Sends SIGSTOP to all processes related to the application * * Return value: Whether we were able to send SIGSTOP to all processes. */ gboolean ubuntu_app_launch_pause_application (const gchar * appid); /** * ubuntu_app_launch_resume_application: * @appid: ID of the application to pause * * Sends SIGCONT to all processes related to the application * * Return value: Whether we were able to send SIGCONT to all processes. */ gboolean ubuntu_app_launch_resume_application (const gchar * appid); /** * ubuntu_app_launch_application_log_path: * @appid: ID of the application * * Calculates the path for the log file that may be generated by * the application. The log file won't be created until the application * prints some output. Also, this doens't work for legacy applications * that are multi-instance, only single instance ones. * * Return value: Path to a log file or NULL if unavailable */ gchar * ubuntu_app_launch_application_log_path (const gchar * appid); /** * ubuntu_app_launch_application_info: * @appid: ID of the application * @appdir: (allow-none) (transfer full): Directory for the application * @appdesktop: (allow-none) (transfer full): Relative path to desktop file * * Finds a location for information on an application and the relative * directory that it was found in. So this should be used to find icons * relating to that desktop file. * * Return value: Path to a log file or NULL if unavailable */ gboolean ubuntu_app_launch_application_info (const gchar * appid, gchar ** appdir, gchar ** appdesktop); /** * ubuntu_app_launch_observer_add_app_starting: * @observer: (scope notified): Callback when an application is about to start * @user_data: (closure) (allow-none): Data to pass to the observer * * Sets up a callback to get called each time an application * is about to start. The application will not start until the * function returns. * * Return value: Whether adding the observer was successful. */ gboolean ubuntu_app_launch_observer_add_app_starting (UbuntuAppLaunchAppObserver observer, gpointer user_data); /** * ubuntu_app_launch_observer_add_app_started: * @observer: (scope notified): Callback when an application started * @user_data: (closure) (allow-none): Data to pass to the observer * * Sets up a callback to get called each time an application * has been started. * * Return value: Whether adding the observer was successful. */ gboolean ubuntu_app_launch_observer_add_app_started (UbuntuAppLaunchAppObserver observer, gpointer user_data); /** * ubuntu_app_launch_observer_add_app_stop: * @observer: (scope notified): Callback when an application stops * @user_data: (closure) (allow-none): Data to pass to the observer * * Sets up a callback to get called each time an application * stops. * * Return value: Whether adding the observer was successful. */ gboolean ubuntu_app_launch_observer_add_app_stop (UbuntuAppLaunchAppObserver observer, gpointer user_data); /** * ubuntu_app_launch_observer_add_app_focus: * @observer: (scope notified): Callback when an application is started for the second time * @user_data: (closure) (allow-none): Data to pass to the observer * * Sets up a callback to get called each time an app gets called * that is already running, so we request it to be focused again. * * Return value: Whether adding the observer was successful. */ gboolean ubuntu_app_launch_observer_add_app_focus (UbuntuAppLaunchAppObserver observer, gpointer user_data); /** * ubuntu_app_launch_observer_add_app_resume: * @observer: (scope notified): Callback when an application is started and possibly asleep * @user_data: (closure) (allow-none): Data to pass to the observer * * Sets up a callback to get called each time an app gets called * that is already running, so we request it to be given CPU time. * At the end of the observer running the app as assumed to be active. * * Return value: Whether adding the observer was successful. */ gboolean ubuntu_app_launch_observer_add_app_resume (UbuntuAppLaunchAppObserver observer, gpointer user_data); /** * ubuntu_app_launch_observer_add_app_failed: * @observer: (scope notified): Callback when an application fails * @user_data: (allow-none) (closure): Data to pass to the observer * * Sets up a callback to get called each time an application * stops via failure. * * Return value: Whether adding the observer was successful. */ gboolean ubuntu_app_launch_observer_add_app_failed (UbuntuAppLaunchAppFailedObserver observer, gpointer user_data); /** * ubuntu_app_launch_observer_add_app_paused: * @observer: (scope notified): Callback when an application is paused * @user_data: (allow-none) (closure): Data to pass to the observer * * Sets up a callback to get called each time an application * is paused. * * Return value: Whether adding the observer was successful. */ gboolean ubuntu_app_launch_observer_add_app_paused (UbuntuAppLaunchAppPausedResumedObserver observer, gpointer user_data); /** * ubuntu_app_launch_observer_add_app_resumed: * @observer: (scope notified): Callback when an application is resumed * @user_data: (allow-none) (closure): Data to pass to the observer * * Sets up a callback to get called each time an application * is resumed. Which is after the SIGCONT has been sent to the pids. * * Return value: Whether adding the observer was successful. */ gboolean ubuntu_app_launch_observer_add_app_resumed (UbuntuAppLaunchAppPausedResumedObserver observer, gpointer user_data); /** * ubuntu_app_launch_observer_delete_app_starting: * @observer: (scope notified): Callback to remove * @user_data: (closure) (allow-none): Data that was passed to the observer * * Removes a previously registered callback to ensure it no longer * gets signaled. * * Return value: Whether deleting the observer was successful. */ gboolean ubuntu_app_launch_observer_delete_app_starting (UbuntuAppLaunchAppObserver observer, gpointer user_data); /** * ubuntu_app_launch_observer_delete_app_started: * @observer: (scope notified): Callback to remove * @user_data: (closure) (allow-none): Data that was passed to the observer * * Removes a previously registered callback to ensure it no longer * gets signaled. * * Return value: Whether deleting the observer was successful. */ gboolean ubuntu_app_launch_observer_delete_app_started (UbuntuAppLaunchAppObserver observer, gpointer user_data); /** * ubuntu_app_launch_observer_delete_app_stop: * @observer: (scope notified): Callback to remove * @user_data: (closure) (allow-none): Data that was passed to the observer * * Removes a previously registered callback to ensure it no longer * gets signaled. * * Return value: Whether deleting the observer was successful. */ gboolean ubuntu_app_launch_observer_delete_app_stop (UbuntuAppLaunchAppObserver observer, gpointer user_data); /** * ubuntu_app_launch_observer_delete_app_focus: * @observer: (scope notified): Callback to remove * @user_data: (closure) (allow-none): Data that was passed to the observer * * Removes a previously registered callback to ensure it no longer * gets signaled. * * Return value: Whether deleting the observer was successful. */ gboolean ubuntu_app_launch_observer_delete_app_focus (UbuntuAppLaunchAppObserver observer, gpointer user_data); /** * ubuntu_app_launch_observer_delete_app_resume: * @observer: (scope notified): Callback to remove * @user_data: (closure) (allow-none): Data that was passed to the observer * * Removes a previously registered callback to ensure it no longer * gets signaled. * * Return value: Whether deleting the observer was successful. */ gboolean ubuntu_app_launch_observer_delete_app_resume (UbuntuAppLaunchAppObserver observer, gpointer user_data); /** * ubuntu_app_launch_observer_delete_app_failed: * @observer: (scope notified): Callback to remove * @user_data: (closure) (allow-none): Data to pass to the observer * * Removes a previously registered callback to ensure it no longer * gets signaled. * * Return value: Whether deleting the observer was successful. */ gboolean ubuntu_app_launch_observer_delete_app_failed (UbuntuAppLaunchAppFailedObserver observer, gpointer user_data); /** * ubuntu_app_launch_observer_delete_app_paused: * @observer: (scope notified): Callback to remove * @user_data: (closure) (allow-none): Data to pass to the observer * * Removes a previously registered callback to ensure it no longer * gets signaled. * * Return value: Whether deleting the observer was successful. */ gboolean ubuntu_app_launch_observer_delete_app_paused (UbuntuAppLaunchAppPausedResumedObserver observer, gpointer user_data); /** * ubuntu_app_launch_observer_delete_app_resumed: * @observer: (scope notified): Callback to remove * @user_data: (closure) (allow-none): Data to pass to the observer * * Removes a previously registered callback to ensure it no longer * gets signaled. * * Return value: Whether deleting the observer was successful. */ gboolean ubuntu_app_launch_observer_delete_app_resumed (UbuntuAppLaunchAppPausedResumedObserver observer, gpointer user_data); /** * ubuntu_app_launch_list_running_apps: * * Gets the Application IDs of all the running applications * in the system. * * Return value: (transfer full): A NULL terminated list of * application IDs. Should be free'd with g_strfreev(). */ gchar ** ubuntu_app_launch_list_running_apps (void); /** * ubuntu_app_launch_get_primary_pid: * @appid: ID of the application to look for * * Checks to see if an application is running and returns its * main PID if so. * * Return Value: Either the PID of the application or 0 if it * is not running. */ GPid ubuntu_app_launch_get_primary_pid (const gchar * appid); /** * ubuntu_app_launch_pid_in_app_id: * @pid: Process ID to check on * @appid: ID of the application to look in * * Checks to see if a PID is associated with the current application ID. * * Currently the implementation just calls ubuntu_app_launch_get_primary_pid() * and checks to see if they're the same. But in the future this will check * any PID created in the cgroup to see if it is associated. * * Return Value: Whether @pid is associated with the @appid */ gboolean ubuntu_app_launch_pid_in_app_id (GPid pid, const gchar * appid); /** * ubuntu_app_launch_triplet_to_app_id: * @pkg: Click package name * @app: (allow-none): Application name, see description * @version: (allow-none): Specific version or wildcard, see description * * Constructs an appid from pkg, app, version triple. Wildcards are allowed * for the @app and @version parameters. * * For the @app parameter the wildcards * "first-listed-app", "last-listed-app" * and "only-listed-app" can be used. A NULL value will default to the * first listed app. * * For the @version parameter only one wildcard is allowed, "current-user-version". * If NULL is passed that is the default. * * Return Value: Either the properly constructed @appid or NULL if it failed * to construct it. */ gchar * ubuntu_app_launch_triplet_to_app_id (const gchar * pkg, const gchar * app, const gchar * version); /** * ubuntu_app_launch_app_id_parse: * @appid: Application ID to parse * @package: (out) (transfer full) (allow-none): Package section of @appid * @application: (out) (transfer full) (allow-none): Application section of @appid * @version: (out) (transfer full) (allow-none): Version section of @appid * * Takes an application ID @appid and breaks it into its component parts. Each * of them can be NULL if those parts aren't desired. If all are NULL it will * still parse to generate a proper return value check if @appid is valid. * * Return value: Whether @appid is valid */ gboolean ubuntu_app_launch_app_id_parse (const gchar * appid, gchar ** package, gchar ** application, gchar ** version); /** * ubuntu_app_launch_start_helper: * @type: Type of helper * @appid: App ID of the helper * @uris: (allow-none) (array zero-terminated=1) (element-type utf8) (transfer none): A NULL terminated list of URIs to send to the helper * * Start an untrusted helper for a specific @type on a given * @appid. We don't know how that is done specifically, as Upstart * will call a helper for that type. And then execute it under the * AppArmor profile for the helper as defined in its manifest. * * Return value: Whether the helper was able to be started */ gboolean ubuntu_app_launch_start_helper (const gchar * type, const gchar * appid, const gchar * const * uris); /** * ubuntu_app_launch_start_multiple_helper: * @type: Type of helper * @appid: App ID of the helper * @uris: (allow-none) (array zero-terminated=1) (element-type utf8) (transfer none): A NULL terminated list of URIs to send to the helper * * Start an untrusted helper for a specific @type of a given * @appid. We don't know how that is done specifically, as Upstart * will call a helper for that type. And then execute it under the * Apparmor profile for that helper type. This function is different * from @ubuntu_app_launch_start_helper in that it works for helpers * that aren't single instance and the manager will be managing the * instances as well. * * Return value: The generated instance ID or NULL on failure */ gchar * ubuntu_app_launch_start_multiple_helper (const gchar * type, const gchar * appid, const gchar * const * uris); /** * ubuntu_app_launch_start_session_helper: * @type: Type of helper * @session: Mir Trusted Prompt Session to run the helper under * @appid: App ID of the helper * @uris: (allow-none) (array zero-terminated=1) (element-type utf8) (transfer none): A NULL terminated list of URIs to send to the helper * * Start an untrusted helper for a specific @type of a given * @appid running under a Mir Trusted Prompt Session @session. The * helper's MIR_SOCKET environment variable will be set appropriately * so that the helper will draw on the correct surfaces. Otherwise this * is the same as #ubuntu_app_launch_start_multiple_helper. * * It is important that all exec tools for @type call the function * #ubuntu_app_launch_helper_set_exec to set the exec line. * * Return value: The generated instance ID or NULL on failure */ gchar * ubuntu_app_launch_start_session_helper (const gchar * type, MirPromptSession * session, const gchar * appid, const gchar * const * uris); /** * ubuntu_app_launch_stop_helper: * @type: Type of helper * @appid: App ID of the helper * * Asks Upstart to kill a helper. In general, this should be a last resort * as we should ask the helper a better way probably with an in-band protocol * of use. * * Return value: Whether the helper is stopped */ gboolean ubuntu_app_launch_stop_helper (const gchar * type, const gchar * appid); /** * ubuntu_app_launch_stop_multiple_helper: * @type: Type of helper * @appid: App ID of the helper * @instanceid: The instance ID returned when starting the helper * * Asks Upstart to kill a helper. In general, this should be a last resort * as we should ask the helper a better way probably with an in-band protocol * of use. * * Return value: Whether the helper is stopped */ gboolean ubuntu_app_launch_stop_multiple_helper (const gchar * type, const gchar * appid, const gchar * instanceid); /** * ubuntu_app_launch_list_helpers: * @type: Type of helper * * List all App IDs of helpers of a given @type. * * Return value: (transfer full): List of application IDs */ gchar ** ubuntu_app_launch_list_helpers (const gchar * type); /** * ubuntu_app_launch_list_helper_instances: * @type: Type of helper * @appid: AppID of helper * * List all the instances for a particular AppID * * Return value: (transfer full): List of instance IDs */ gchar ** ubuntu_app_launch_list_helper_instances (const gchar * type, const gchar * appid); /** * ubuntu_app_launch_observer_add_helper_started: * @observer: (scope notified): Callback when a helper started * @helper_type: (closure) (allow-none): Type of helpers to look for * @user_data: (allow-none): Data to pass to the observer * * Sets up a callback to get called each time a helper of * @helper_type has been started. * * Return value: Whether adding the observer was successful. */ gboolean ubuntu_app_launch_observer_add_helper_started (UbuntuAppLaunchHelperObserver observer, const gchar * helper_type, gpointer user_data); /** * ubuntu_app_launch_observer_add_helper_stop: * @observer: (scope notified): Callback when a helper stops * @helper_type: (closure) (allow-none): Type of helpers to look for * @user_data: (allow-none): Data to pass to the observer * * Sets up a callback to get called each time a helper of * @helper_type stops. * * Return value: Whether adding the observer was successful. */ gboolean ubuntu_app_launch_observer_add_helper_stop (UbuntuAppLaunchHelperObserver observer, const gchar * helper_type, gpointer user_data); /** * ubuntu_app_launch_observer_delete_helper_started: * @observer: (scope notified): Callback to remove * @helper_type: (closure) (allow-none): Type of helpers it looked for * @user_data: (allow-none): Data that was passed to the observer * * Removes a previously registered callback to ensure it no longer * gets signaled. * * Return value: Whether deleting the observer was successful. */ gboolean ubuntu_app_launch_observer_delete_helper_started (UbuntuAppLaunchHelperObserver observer, const gchar * helper_type, gpointer user_data); /** * ubuntu_app_launch_observer_delete_helper_stop: * @observer: (scope notified): Callback to remove * @helper_type: (closure) (allow-none): Type of helpers it looked for * @user_data: (allow-none): Data that was passed to the observer * * Removes a previously registered callback to ensure it no longer * gets signaled. * * Return value: Whether deleting the observer was successful. */ gboolean ubuntu_app_launch_observer_delete_helper_stop (UbuntuAppLaunchHelperObserver observer, const gchar * helper_type, gpointer user_data); /** * ubuntu_app_launch_helper_set_exec: * @execline: Exec line to be executed, in Desktop file format * @directory: (allow-none): The directory that the exec line should * be executed in. * * A function to be called by an untrusted helper exec * tool to set the exec line. The exec tool should determine * what should be executed from some sort of configuration * based on its type (usually a configuration file from a click * package). Once it determines the exec line it can set it * with this function and exit. * * Return Value: Whether we were able to set the exec line */ gboolean ubuntu_app_launch_helper_set_exec (const gchar * execline, const gchar * directory); #ifdef __cplusplus } #endif #pragma GCC visibility pop #endif /* __UBUNTU_APP_LAUNCH_H__ */ ubuntu-app-launch-0.5+15.10.20150817/libubuntu-app-launch/second-exec-core.c0000644000015300001610000003125112564452056026624 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include #include #include #include "libubuntu-app-launch/ubuntu-app-launch.h" #include "helpers.h" #include "second-exec-core.h" #include "ubuntu-app-launch-trace.h" #include "ual-tracepoint.h" typedef struct { GDBusConnection * bus; gchar * appid; gchar * input_uris; GPid app_pid; guint connections_open; GVariant * app_data; gchar * dbus_path; guint64 unity_starttime; guint timer; guint signal; } second_exec_t; static void second_exec_complete (second_exec_t * data); /* Unity didn't respond in time, continue on */ static gboolean timer_cb (gpointer user_data) { ual_tracepoint(second_exec_resume_timeout, ((second_exec_t *)user_data)->appid); g_warning("Unity didn't respond in 500ms to resume the app"); second_exec_complete(user_data); return G_SOURCE_REMOVE; } /* Lower the connection count and process if it gets to zero */ static void connection_count_dec (second_exec_t * data) { ual_tracepoint(second_exec_connection_complete, data->appid); data->connections_open--; if (data->connections_open == 0) { g_debug("Finished finding connections"); /* Check time here, either we've already heard from Unity and we should send the data to the app (quit) or we should wait some more */ guint64 timespent = g_get_monotonic_time() - data->unity_starttime; if (timespent > 500 /* ms */ * 1000 /* ms to us */) { second_exec_complete(data); } else { g_debug("Timer Set"); data->timer = g_timeout_add(500 - (timespent / 1000), timer_cb, data); } } return; } /* Called when Unity is done unfreezing the application, if we're done determining the PID, we can send signals */ static void unity_resume_cb (GDBusConnection * connection, const gchar * sender, const gchar * path, const gchar * interface, const gchar * signal, GVariant * params, gpointer user_data) { second_exec_t * data = (second_exec_t *)user_data; g_debug("Unity Completed Resume"); ual_tracepoint(second_exec_resume_complete, data->appid); if (data->timer != 0) { g_source_remove(data->timer); data->timer = 0; } if (data->connections_open == 0) { second_exec_complete(data); } else { /* Make it look like we started *forever* ago */ data->unity_starttime = 0; } return; } /* Turn the input string into something we can send to apps */ static void parse_uris (second_exec_t * data) { if (data->app_data != NULL) { /* Already done */ return; } GVariant * uris = NULL; gchar ** uri_split = NULL; GError * error = NULL; g_shell_parse_argv(data->input_uris, NULL, &uri_split, &error); if (uri_split == NULL || uri_split[0] == NULL || error != NULL) { if (error != NULL) { g_warning("Unable to parse URLs '%s': %s", data->input_uris, error->message); g_error_free(error); } uris = g_variant_new_array(G_VARIANT_TYPE_STRING, NULL, 0); if (uri_split != NULL) { g_strfreev(uri_split); } } else { GVariantBuilder builder; g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY); int i; for (i = 0; uri_split[i] != NULL; i++) { g_variant_builder_add_value(&builder, g_variant_new_take_string(uri_split[i])); } g_free(uri_split); uris = g_variant_builder_end(&builder); } GVariant * platform = g_variant_new_array(G_VARIANT_TYPE("{sv}"), NULL, 0); GVariantBuilder tuple; g_variant_builder_init(&tuple, G_VARIANT_TYPE_TUPLE); g_variant_builder_add_value(&tuple, uris); g_variant_builder_add_value(&tuple, platform); data->app_data = g_variant_builder_end(&tuple); g_variant_ref_sink(data->app_data); return; } /* Finds us our dbus path to use. Basically this is the name of the application with dots replaced by / and a / tacted on the front. This is recommended here: http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#dbus */ static void app_id_to_dbus_path (second_exec_t * data) { if (data->dbus_path != NULL) { return; } GString * str = g_string_sized_new(strlen(data->appid) + 2); /* base case, we just need a / and a null */ g_string_append_c(str, '/'); int i; for (i = 0; data->appid[i] != '\0'; i++) { if ((data->appid[i] >= 'a' && data->appid[i] <= 'z') || (data->appid[i] >= 'A' && data->appid[i] <= 'Z') || (data->appid[i] >= '0' && data->appid[i] <= '9' && i != 0)) { g_string_append_c(str, data->appid[i]); continue; } g_string_append_printf(str, "_%2x", data->appid[i]); } data->dbus_path = g_string_free(str, FALSE); g_debug("DBus Path: %s", data->dbus_path); return; } /* Finish the send and decrement the counter */ static void send_open_cb (GObject * object, GAsyncResult * res, gpointer user_data) { GError * error = NULL; ual_tracepoint(second_exec_app_contacted, ((second_exec_t *)user_data)->appid); g_dbus_connection_call_finish(G_DBUS_CONNECTION(object), res, &error); if (error != NULL) { ual_tracepoint(second_exec_app_error, ((second_exec_t *)user_data)->appid); /* Mostly just to free the error, but printing for debugging */ g_debug("Unable to send Open: %s", error->message); g_error_free(error); } connection_count_dec(user_data); return; } /* Sends the Open message to the connection with the URIs we were given */ static void contact_app (GDBusConnection * bus, const gchar * dbus_name, second_exec_t * data) { ual_tracepoint(second_exec_contact_app, data->appid, dbus_name); parse_uris(data); app_id_to_dbus_path(data); /* Using the FD.o Application interface */ g_dbus_connection_call(bus, dbus_name, data->dbus_path, "org.freedesktop.Application", "Open", data->app_data, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, send_open_cb, data); g_debug("Sending Open request to: %s", dbus_name); return; } typedef struct { gchar * name; second_exec_t * data; } get_pid_t; /* Gets the PID for a connection, and if it matches the one we're looking for then it tries to send a message to that connection */ static void get_pid_cb (GObject * object, GAsyncResult * res, gpointer user_data) { get_pid_t * data = (get_pid_t *)user_data; GError * error = NULL; GVariant * vpid = NULL; ual_tracepoint(second_exec_got_pid, data->data->appid, data->name); vpid = g_dbus_connection_call_finish(G_DBUS_CONNECTION(object), res, &error); if (error != NULL) { g_warning("Unable to query PID for dbus name '%s': %s", data->name, error->message); g_error_free(error); /* Lowering the connection count, this one is terminal, even if in error */ connection_count_dec(data->data); g_free(data->name); g_free(data); return; } guint pid = 0; g_variant_get(vpid, "(u)", &pid); g_variant_unref(vpid); if (pid == data->data->app_pid) { /* Trying to send a message to the connection */ contact_app(G_DBUS_CONNECTION(object), data->name, data->data); } else { /* See if we can quit now */ connection_count_dec(data->data); } g_free(data->name); g_free(data); return; } /* Starts to look for the PID and the connections for that PID */ void find_appid_pid (GDBusConnection * session, second_exec_t * data) { GError * error = NULL; /* List all the connections on dbus. This sucks that we have to do this, but in the future we should add DBus API to do this lookup instead of having to do it with a bunch of requests */ GVariant * listnames = g_dbus_connection_call_sync(session, "org.freedesktop.DBus", "/", "org.freedesktop.DBus", "ListNames", NULL, G_VARIANT_TYPE("(as)"), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (error != NULL) { g_warning("Unable to get list of names from DBus: %s", error->message); g_error_free(error); return; } g_debug("Got bus names"); ual_tracepoint(second_exec_got_dbus_names, data->appid); /* Next figure out what we're looking for (and if there is something to look for) */ /* NOTE: We're getting the PID *after* the list of connections so that some new process can't come in, be the same PID as it's connection will not be in teh list we just got. */ data->app_pid = ubuntu_app_launch_get_primary_pid(data->appid); if (data->app_pid == 0) { g_warning("Unable to find pid for app id '%s'", data->appid); return; } g_debug("Primary PID: %d", data->app_pid); ual_tracepoint(second_exec_got_primary_pid, data->appid); /* Get the names */ GVariant * names = g_variant_get_child_value(listnames, 0); GVariantIter iter; g_variant_iter_init(&iter, names); gchar * name = NULL; while (g_variant_iter_loop(&iter, "s", &name)) { /* We only want to ask each connection once, this makes that so */ if (!g_dbus_is_unique_name(name)) { continue; } get_pid_t * pid_data = g_new0(get_pid_t, 1); pid_data->data = data; pid_data->name = g_strdup(name); ual_tracepoint(second_exec_request_pid, data->appid, pid_data->name); /* Get the PIDs */ g_dbus_connection_call(session, "org.freedesktop.DBus", "/", "org.freedesktop.DBus", "GetConnectionUnixProcessID", g_variant_new("(s)", name), G_VARIANT_TYPE("(u)"), G_DBUS_CALL_FLAGS_NONE, -1, NULL, get_pid_cb, pid_data); data->connections_open++; } g_variant_unref(names); g_variant_unref(listnames); return; } gboolean second_exec (const gchar * app_id, const gchar * appuris) { ual_tracepoint(second_exec_start, app_id, appuris); /* DBus tell us! */ GError * error = NULL; GDBusConnection * session = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error); if (error != NULL) { g_error("Unable to get session bus"); g_error_free(error); return FALSE; } /* Setup our continuation data */ second_exec_t * data = g_new0(second_exec_t, 1); data->appid = g_strdup(app_id); data->input_uris = g_strdup(appuris); data->bus = session; /* Set up listening for the unfrozen signal from Unity */ data->signal = g_dbus_connection_signal_subscribe(session, NULL, /* sender */ "com.canonical.UbuntuAppLaunch", /* interface */ "UnityResumeResponse", /* signal */ "/", /* path */ app_id, /* arg0 */ G_DBUS_SIGNAL_FLAGS_NONE, unity_resume_cb, data, NULL); /* user data destroy */ g_debug("Sending resume request"); ual_tracepoint(second_exec_emit_resume, app_id); /* Send unfreeze to to Unity */ g_dbus_connection_emit_signal(session, NULL, /* destination */ "/", /* path */ "com.canonical.UbuntuAppLaunch", /* interface */ "UnityResumeRequest", /* signal */ g_variant_new("(s)", app_id), &error); /* Now we start a race, we try to get to the point of knowing who to send things to, and Unity is unfrezing it. When both are done we can send something to the app */ data->unity_starttime = g_get_monotonic_time(); if (error != NULL) { /* On error let's not wait for Unity */ g_warning("Unable to signal Unity: %s", error->message); g_error_free(error); error = NULL; data->unity_starttime = 0; } /* If we've got something to give out, start looking for how */ if (data->input_uris != NULL) { find_appid_pid(session, data); } /* Loop and wait for everything to align */ if (data->connections_open == 0 && data->unity_starttime == 0) { second_exec_complete(data); } return TRUE; } static void second_exec_complete (second_exec_t * data) { GError * error = NULL; ual_tracepoint(second_exec_emit_focus, data->appid); /* Now that we're done sending the info to the app, we can ask Unity to focus the application. */ g_dbus_connection_emit_signal(data->bus, NULL, /* destination */ "/", /* path */ "com.canonical.UbuntuAppLaunch", /* interface */ "UnityFocusRequest", /* signal */ g_variant_new("(s)", data->appid), &error); if (error != NULL) { g_warning("Unable to request focus to Unity: %s", error->message); g_error_free(error); error = NULL; } /* Make sure the signal hits the bus */ g_dbus_connection_flush_sync(data->bus, NULL, &error); if (error != NULL) { g_warning("Unable to flush session bus: %s", error->message); g_error_free(error); error = NULL; } ual_tracepoint(second_exec_finish, data->appid); /* Clean up */ if (data->signal != 0) g_dbus_connection_signal_unsubscribe(data->bus, data->signal); g_object_unref(data->bus); if (data->app_data != NULL) g_variant_unref(data->app_data); g_free(data->appid); g_free(data->input_uris); g_free(data->dbus_path); g_free(data); return; } ubuntu-app-launch-0.5+15.10.20150817/libubuntu-app-launch/CMakeLists.txt0000644000015300001610000000615612564452117026101 0ustar pbuserpbgroup00000000000000 include_directories(${CMAKE_CURRENT_SOURCE_DIR}) include_directories(${CMAKE_CURRENT_BINARY_DIR}) ########################## # Version Info ########################## set(API_VERSION 2) set(ABI_VERSION 2) ########################## # Library ########################## add_lttng_gen_tp(NAME ubuntu-app-launch-trace) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden") add_definitions ( -DOOM_HELPER="${pkglibexecdir}/oom-adjust-setuid-helper" -DDEMANGLER_PATH="${pkglibexecdir}/socket-demangler" ) add_definitions ( -DLIBERTINE_LAUNCH="${CMAKE_INSTALL_FULL_BINDIR}/libertine-launch" ) set(LAUNCHER_HEADERS ubuntu-app-launch.h ) set(LAUNCHER_SOURCES ubuntu-app-launch.c second-exec-core.c click-exec.c desktop-exec.c ubuntu-app-launch-trace.c app-info.c ) set(LAUNCHER_GEN_SOURCES ) add_gdbus_codegen_with_namespace(LAUNCHER_GEN_SOURCES proxy-socket-demangler com.canonical.UbuntuAppLaunch. proxy ${CMAKE_SOURCE_DIR}/data/com.canonical.UbuntuAppLaunch.SocketDemangler.xml) add_library(ubuntu-launcher SHARED ${LAUNCHER_SOURCES} ${LAUNCHER_GEN_SOURCES}) set_target_properties(ubuntu-launcher PROPERTIES VERSION ${ABI_VERSION}.0.0 SOVERSION ${ABI_VERSION} OUTPUT_NAME "ubuntu-app-launch" LINK_FLAGS "${ldflags} -Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/libubuntu-app-launch.map" LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/libubuntu-app-launch.map" ) target_link_libraries(ubuntu-launcher ${GLIB2_LIBARIES} ${GOBJECT2_LIBRARIES} ${LIBUPSTART_LIBRARIES} ${GIO2_LIBRARIES} ${LTTNG_LIBRARIES} ${JSONGLIB_LIBRARIES} ${CLICK_LIBRARIES} ${ZEITGEIST_LIBRARIES} ${MIR_LIBRARIES} helpers -Wl,--no-undefined ) install( FILES ${LAUNCHER_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/libubuntu-app-launch-${API_VERSION}" ) install( TARGETS ubuntu-launcher LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ) ########################## # Pkg Config ########################## set(apiversion "${API_VERSION}") set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}") set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}") set(VERSION "${API_VERSION}") configure_file("ubuntu-app-launch.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/ubuntu-app-launch-${API_VERSION}.pc" @ONLY) install( FILES "${CMAKE_CURRENT_BINARY_DIR}/ubuntu-app-launch-${API_VERSION}.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" ) ########################## # Introspection ########################## include(UseGObjectIntrospection) set(INTROSPECTION_GIRS) set(_introspection_files ${LAUNCHER_HEADERS}) set(UbuntuAppLaunch_2_gir "ubuntu-app-launch") set(UbuntuAppLaunch_2_gir_INCLUDES GObject-2.0) gir_get_cflags(_cflags) list_prefix(MIR_C_INCLUDES MIR_INCLUDE_DIRS "-I") set(UbuntuAppLaunch_2_gir_CFLAGS ${c_flags} ${MIR_C_INCLUDES}) set(UbuntuAppLaunch_2_gir_LIBS ubuntu-app-launch) list_make_absolute(_abs_introspection_files _introspection_files "${CMAKE_CURRENT_SOURCE_DIR}/") set(UbuntuAppLaunch_2_gir_FILES ${_abs_introspection_files}) set(UbuntuAppLaunch_2_gir_SCANNERFLAGS --c-include "ubuntu-app-launch.h") set(UbuntuAppLaunch_2_gir_EXPORT_PACKAGES "ubuntu-app-launch-${API_VERSION}") list(APPEND INTROSPECTION_GIRS UbuntuAppLaunch-2.gir) gir_add_introspections(INTROSPECTION_GIRS) ubuntu-app-launch-0.5+15.10.20150817/libubuntu-app-launch/recoverable-problem.c0000644000015300001610000000747412564452056027442 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include "recoverable-problem.h" #include #include #include /* Helpers to ensure we write nicely */ static void write_string (int fd, const gchar *string) { int res; do res = write (fd, string, strlen (string)); while (G_UNLIKELY (res == -1 && errno == EINTR)); } /* Make NULLs fast and fun! */ static void write_null (int fd) { int res; do res = write (fd, "", 1); while (G_UNLIKELY (res == -1 && errno == EINTR)); } /* Child watcher */ static gboolean apport_child_watch (GPid pid, gint status, gpointer user_data) { g_main_loop_quit((GMainLoop *)user_data); return FALSE; } static gboolean apport_child_timeout (gpointer user_data) { g_warning("Recoverable Error Reporter Timeout"); g_main_loop_quit((GMainLoop *)user_data); return FALSE; } /* Code to report an error */ void report_recoverable_problem (const gchar * signature, GPid report_pid, gboolean wait, const gchar * additional_properties[]) { GError * error = NULL; gint error_stdin = 0; GPid pid = 0; gchar * pid_str = NULL; gchar ** argv = NULL; gchar * argv_nopid[2] = { "/usr/share/apport/recoverable_problem", NULL }; gchar * argv_pid[4] = { "/usr/share/apport/recoverable_problem", "-p", NULL, /* put pid_str when allocated here */ NULL }; argv = (gchar **)argv_nopid; if (report_pid != 0) { pid_str = g_strdup_printf("%d", report_pid); argv_pid[2] = pid_str; argv = (gchar**)argv_pid; } GSpawnFlags flags = G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL; if (wait) { flags |= G_SPAWN_DO_NOT_REAP_CHILD; } g_spawn_async_with_pipes(NULL, /* cwd */ argv, NULL, /* envp */ flags, NULL, NULL, /* child setup func */ &pid, &error_stdin, NULL, /* stdout */ NULL, /* stderr */ &error); if (error != NULL) { g_warning("Unable to report a recoverable error: %s", error->message); g_error_free(error); } gboolean first = TRUE; if (error_stdin != 0 && signature != NULL) { write_string(error_stdin, "DuplicateSignature"); write_null(error_stdin); write_string(error_stdin, signature); first = FALSE; } if (error_stdin != 0 && additional_properties != NULL) { gint i; for (i = 0; additional_properties[i] != NULL; i++) { if (!first) { write_null(error_stdin); } else { first = FALSE; } write_string(error_stdin, additional_properties[i]); } } if (error_stdin != 0) { close(error_stdin); } if (wait && pid != 0) { GSource * child_source, * timeout_source; GMainContext * context = g_main_context_new(); GMainLoop * loop = g_main_loop_new(context, FALSE); child_source = g_child_watch_source_new(pid); g_source_attach(child_source, context); g_source_set_callback(child_source, (GSourceFunc)apport_child_watch, loop, NULL); timeout_source = g_timeout_source_new_seconds(5); g_source_attach(timeout_source, context); g_source_set_callback(timeout_source, apport_child_timeout, loop, NULL); g_main_loop_run(loop); g_source_destroy(timeout_source); g_source_destroy(child_source); g_main_loop_unref(loop); g_main_context_unref(context); g_spawn_close_pid(pid); } g_free(pid_str); return; } ubuntu-app-launch-0.5+15.10.20150817/libubuntu-app-launch/app-info.c0000644000015300001610000002145512564452125025214 0ustar pbuserpbgroup00000000000000/* * Copyright © 2015 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include #include #include "ubuntu-app-launch.h" #include "app-info.h" /* Try and get a manifest and do a couple sanity checks on it */ JsonObject * get_manifest (const gchar * pkg, gchar ** pkgpath) { /* Get the directory from click */ GError * error = NULL; ClickDB * db = click_db_new(); /* If TEST_CLICK_DB is unset, this reads the system database. */ click_db_read(db, g_getenv("TEST_CLICK_DB"), &error); if (error != NULL) { g_warning("Unable to read Click database: %s", error->message); g_error_free(error); g_object_unref(db); return NULL; } /* If TEST_CLICK_USER is unset, this uses the current user name. */ ClickUser * user = click_user_new_for_user(db, g_getenv("TEST_CLICK_USER"), &error); if (error != NULL) { g_warning("Unable to read Click database: %s", error->message); g_error_free(error); g_object_unref(db); return NULL; } g_object_unref(db); JsonObject * manifest = click_user_get_manifest(user, pkg, &error); if (error != NULL) { g_warning("Unable to get manifest for '%s' package: %s", pkg, error->message); g_error_free(error); g_object_unref(user); return NULL; } if (pkgpath != NULL) { *pkgpath = click_user_get_path(user, pkg, &error); if (error != NULL) { g_warning("Unable to get the Click package directory for %s: %s", pkg, error->message); g_error_free(error); g_object_unref(user); return NULL; } } g_object_unref(user); if (!json_object_has_member(manifest, "version")) { g_warning("Manifest file for package '%s' does not have a version", pkg); json_object_unref(manifest); return NULL; } return manifest; } /* Types of search we can do for an app name */ typedef enum _app_name_t app_name_t; enum _app_name_t { APP_NAME_ONLY, APP_NAME_FIRST, APP_NAME_LAST }; /* Figure out the app name if it's one of the keywords */ static const gchar * manifest_app_name (JsonObject ** manifest, const gchar * pkg, const gchar * original_app) { app_name_t app_type = APP_NAME_FIRST; if (original_app == NULL) { /* first */ } else if (g_strcmp0(original_app, "first-listed-app") == 0) { /* first */ } else if (g_strcmp0(original_app, "last-listed-app") == 0) { app_type = APP_NAME_LAST; } else if (g_strcmp0(original_app, "only-listed-app") == 0) { app_type = APP_NAME_ONLY; } else { return original_app; } if (*manifest == NULL) { *manifest = get_manifest(pkg, NULL); } JsonObject * hooks = json_object_get_object_member(*manifest, "hooks"); if (hooks == NULL) { return NULL; } GList * apps = json_object_get_members(hooks); if (apps == NULL) { return NULL; } const gchar * retapp = NULL; switch (app_type) { case APP_NAME_ONLY: if (g_list_length(apps) == 1) { retapp = (const gchar *)apps->data; } break; case APP_NAME_FIRST: retapp = (const gchar *)apps->data; break; case APP_NAME_LAST: retapp = (const gchar *)(g_list_last(apps)->data); break; default: break; } g_list_free(apps); return retapp; } /* Figure out the app version using the manifest */ static const gchar * manifest_version (JsonObject ** manifest, const gchar * pkg, const gchar * original_ver) { if (original_ver != NULL && g_strcmp0(original_ver, "current-user-version") != 0) { return original_ver; } else { if (*manifest == NULL) { *manifest = get_manifest(pkg, NULL); } g_return_val_if_fail(*manifest != NULL, NULL); return g_strdup(json_object_get_string_member(*manifest, "version")); } return NULL; } /* A click triplet can require using the Click DB and getting a manifest. This code does that to look up the versions */ gchar * click_triplet_to_app_id (const gchar * pkg, const gchar * app, const gchar * ver) { const gchar * version = NULL; const gchar * application = NULL; JsonObject * manifest = NULL; version = manifest_version(&manifest, pkg, ver); g_return_val_if_fail(version != NULL, NULL); application = manifest_app_name(&manifest, pkg, app); g_return_val_if_fail(application != NULL, NULL); gchar * retval = g_strdup_printf("%s_%s_%s", pkg, application, version); /* The object may hold allocation for some of our strings used above */ if (manifest) json_object_unref(manifest); return retval; } /* Build an appid how we think it should exist and then make sure we can find it. Then pull it together. */ gchar * libertine_triplet_to_app_id (const gchar * pkg, const gchar * app, const gchar * ver) { if (app == NULL) { return NULL; } gchar * synthappid = g_strdup_printf("%s_%s_0.0", pkg, app); if (app_info_libertine(synthappid, NULL, NULL)) { return synthappid; } else { g_free(synthappid); return NULL; } } /* Look to see if the app id results in a desktop file, if so, fill in the params */ static gboolean evaluate_dir (const gchar * dir, const gchar * desktop, gchar ** appdir, gchar ** appdesktop) { char * fulldir = g_build_filename(dir, "applications", desktop, NULL); gboolean found = FALSE; if (g_file_test(fulldir, G_FILE_TEST_EXISTS)) { if (appdir != NULL) { *appdir = g_strdup(dir); } if (appdesktop != NULL) { *appdesktop = g_strdup_printf("applications/%s", desktop); } found = TRUE; } g_free(fulldir); return found; } /* Handle the legacy case where we look through the data directories */ gboolean app_info_legacy (const gchar * appid, gchar ** appdir, gchar ** appdesktop) { gchar * desktop = g_strdup_printf("%s.desktop", appid); /* Special case the user's dir */ if (evaluate_dir(g_get_user_data_dir(), desktop, appdir, appdesktop)) { g_free(desktop); return TRUE; } const char * const * data_dirs = g_get_system_data_dirs(); int i; for (i = 0; data_dirs[i] != NULL; i++) { if (evaluate_dir(data_dirs[i], desktop, appdir, appdesktop)) { g_free(desktop); return TRUE; } } return FALSE; } /* Handle the libertine case where we look in the container */ gboolean app_info_libertine (const gchar * appid, gchar ** appdir, gchar ** appdesktop) { char * container = NULL; char * app = NULL; if (!ubuntu_app_launch_app_id_parse(appid, &container, &app, NULL)) { return FALSE; } gchar * desktopname = g_strdup_printf("%s.desktop", app); gchar * desktopdir = g_build_filename(g_get_user_cache_dir(), "libertine-container", container, "rootfs", "usr", "share", NULL); gchar * desktopfile = g_build_filename(desktopdir, "applications", desktopname, NULL); if (!g_file_test(desktopfile, G_FILE_TEST_EXISTS)) { g_free(desktopdir); g_free(desktopfile); desktopdir = g_build_filename(g_get_user_data_dir(), "libertine-container", "user-data", container, ".local", "share", NULL); desktopfile = g_build_filename(desktopdir, "applications", desktopname, NULL); if (!g_file_test(desktopfile, G_FILE_TEST_EXISTS)) { g_free(desktopdir); g_free(desktopfile); g_free(desktopname); g_free(container); g_free(app); return FALSE; } } if (appdir != NULL) { *appdir = desktopdir; } else { g_free(desktopdir); } if (appdesktop != NULL) { *appdesktop = g_build_filename("applications", desktopname, NULL); } g_free(desktopfile); g_free(desktopname); g_free(container); g_free(app); return TRUE; } /* Get the information on where the desktop file is from libclick */ gboolean app_info_click (const gchar * appid, gchar ** appdir, gchar ** appdesktop) { gchar * package = NULL; gchar * application = NULL; if (!ubuntu_app_launch_app_id_parse(appid, &package, &application, NULL)) { return FALSE; } JsonObject * manifest = get_manifest(package, appdir); if (manifest == NULL) { g_free(package); g_free(application); return FALSE; } g_free(package); if (appdesktop != NULL) { JsonObject * hooks = json_object_get_object_member(manifest, "hooks"); if (hooks == NULL) { json_object_unref(manifest); g_free(application); return FALSE; } JsonObject * appobj = json_object_get_object_member(hooks, application); g_free(application); if (appobj == NULL) { json_object_unref(manifest); return FALSE; } const gchar * desktop = json_object_get_string_member(appobj, "desktop"); if (desktop == NULL) { json_object_unref(manifest); return FALSE; } *appdesktop = g_strdup(desktop); } else { g_free(application); } json_object_unref(manifest); return TRUE; } ubuntu-app-launch-0.5+15.10.20150817/libubuntu-app-launch/second-exec-core.h0000644000015300001610000000143612564452056026633 0ustar pbuserpbgroup00000000000000 /* * Copyright 2013 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include gboolean second_exec (const gchar * app_id, const gchar * appuris); ubuntu-app-launch-0.5+15.10.20150817/MERGE-REVIEW0000644000015300001610000000141012564452056021051 0ustar pbuserpbgroup00000000000000 This documents the expections that the project has on what both submitters and reviewers should ensure that they've done for a merge into the project. == Submitter Responsibilities == * Ensure the project compiles and the test suite executes without error * Ensure that non-obvious code has comments explaining it == Reviewer Responsibilities == * Did the Jenkins build compile? Pass? Run unit tests successfully? * Are there appropriate tests to cover any new functionality? * If this MR effects application startup: * Run test case: ubuntu-app-launch/click-app * Run test case: ubuntu-app-launch/legacy-app * Run test case: ubuntu-app-launch/secondary-activation * If this MR effect untrusted-helpers: * Run test case: ubuntu-app-launch/helper-run ubuntu-app-launch-0.5+15.10.20150817/helpers-shared.c0000644000015300001610000002050312564452117022344 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include "helpers.h" #include #include #include "ual-tracepoint.h" #include "libubuntu-app-launch/recoverable-problem.h" /* Check to make sure we have the sections and keys we want */ gboolean verify_keyfile (GKeyFile * inkeyfile, const gchar * desktop) { if (inkeyfile == NULL) return FALSE; if (!g_key_file_has_group(inkeyfile, "Desktop Entry")) { g_warning("Desktop file '%s' is missing the 'Desktop Entry' group", desktop); return FALSE; } if (!g_key_file_has_key(inkeyfile, "Desktop Entry", "Exec", NULL)) { g_warning("Desktop file '%s' is missing the 'Exec' key", desktop); return FALSE; } return TRUE; } /* Try to find a desktop file in a particular data directory */ static GKeyFile * try_dir (const char * dir, const gchar * desktop) { gchar * fullpath = g_build_filename(dir, "applications", desktop, NULL); GKeyFile * keyfile = g_key_file_new(); /* NOTE: Leaving off the error here as we'll get a bunch of them, so individuals aren't really useful */ gboolean loaded = g_key_file_load_from_file(keyfile, fullpath, G_KEY_FILE_NONE, NULL); g_free(fullpath); if (!loaded) { g_key_file_free(keyfile); return NULL; } if (!verify_keyfile(keyfile, desktop)) { g_key_file_free(keyfile); return NULL; } return keyfile; } /* Find the keyfile that we need for a particular AppID and return it. Or NULL if we can't find it. */ GKeyFile * keyfile_for_appid (const gchar * appid, gchar ** desktopfile) { gchar * desktop = g_strdup_printf("%s.desktop", appid); const char * const * data_dirs = g_get_system_data_dirs(); GKeyFile * keyfile = NULL; int i; keyfile = try_dir(g_get_user_data_dir(), desktop); if (keyfile != NULL && desktopfile != NULL && *desktopfile == NULL) { *desktopfile = g_build_filename(g_get_user_data_dir(), "applications", desktop, NULL); } for (i = 0; data_dirs[i] != NULL && keyfile == NULL; i++) { keyfile = try_dir(data_dirs[i], desktop); if (keyfile != NULL && desktopfile != NULL && *desktopfile == NULL) { *desktopfile = g_build_filename(data_dirs[i], "applications", desktop, NULL); } } g_free(desktop); return keyfile; } /* Structure to handle data for the cgmanager connection set of callbacks */ typedef struct { GMainLoop * loop; GCancellable * cancel; GDBusConnection * con; } cgm_connection_t; /* Function that gets executed when we timeout trying to connect. This is related to: LP #1377332 */ static gboolean cgroup_manager_connection_timeout_cb (gpointer data) { cgm_connection_t * connection = (cgm_connection_t *)data; g_cancellable_cancel(connection->cancel); return G_SOURCE_CONTINUE; } static void cgroup_manager_connection_core_cb (GDBusConnection *(*finish_func)(GAsyncResult * res, GError ** error), GAsyncResult * res, cgm_connection_t * connection) { GError * error = NULL; connection->con = finish_func(res, &error); if (error != NULL) { g_warning("Unable to get cgmanager connection: %s", error->message); g_error_free(error); } g_main_loop_quit(connection->loop); } static void cgroup_manager_connection_bus_cb (GObject * obj, GAsyncResult * res, gpointer data) { cgroup_manager_connection_core_cb(g_bus_get_finish, res, (cgm_connection_t *)data); } static void cgroup_manager_connection_addr_cb (GObject * obj, GAsyncResult * res, gpointer data) { cgroup_manager_connection_core_cb(g_dbus_connection_new_for_address_finish, res, (cgm_connection_t *)data); } /* Get the connection to the cgroup manager */ GDBusConnection * cgroup_manager_connection (void) { gboolean use_session_bus = g_getenv("UBUNTU_APP_LAUNCH_CG_MANAGER_SESSION_BUS") != NULL; GMainContext * context = g_main_context_new(); g_main_context_push_thread_default(context); cgm_connection_t connection = { .loop = g_main_loop_new(context, FALSE), .con = NULL, .cancel = g_cancellable_new() }; GSource * timesrc = g_timeout_source_new_seconds(1); g_source_set_callback(timesrc, cgroup_manager_connection_timeout_cb, &connection, NULL); g_source_attach(timesrc, context); if (use_session_bus) { /* For working dbusmock */ g_debug("Connecting to CG Manager on session bus"); g_bus_get(G_BUS_TYPE_SESSION, connection.cancel, cgroup_manager_connection_bus_cb, &connection); } else { g_dbus_connection_new_for_address( CGMANAGER_DBUS_PATH, G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT, NULL, /* Auth Observer */ connection.cancel, /* Cancellable */ cgroup_manager_connection_addr_cb, &connection); } g_main_loop_run(connection.loop); g_source_destroy(timesrc); g_source_unref(timesrc); g_main_loop_unref(connection.loop); g_object_unref(connection.cancel); g_main_context_pop_thread_default(context); if (!use_session_bus && connection.con != NULL) { g_object_set_data(G_OBJECT(connection.con), "cgmanager-context", context); } else { g_main_context_unref(context); } return connection.con; } /* This does a complex unref for the case that we're not using a shared pointer. In that case the initialization happens under the context that we used for the timeout, and it turns out GDBus saves that context to use for the close event. Upon the task closing it sends an idle source to that context which free's the last bit of memory. So we need the events on that context to be executed or we just leak. So what this does is force a close synchronously so that the event gets placed on the context and then frees the context to ensure that all of the events are processed. */ void cgroup_manager_unref (GDBusConnection * cgmanager) { if (cgmanager == NULL) return; GMainContext * creationcontext = g_object_get_data(G_OBJECT(cgmanager), "cgmanager-context"); if (creationcontext == NULL) { g_object_unref(cgmanager); return; } GError * error = NULL; g_dbus_connection_close_sync(cgmanager, NULL, &error); if (error != NULL) { g_warning("Unable to close CGManager Connection: %s", error->message); g_error_free(error); } g_object_unref(cgmanager); g_main_context_unref(creationcontext); } /* Get the PIDs for a particular cgroup */ /* We're using the base cgroup 'freezer' in this code (and in the Upstart jobs). Really the actual group is meaningless we just need one that is in every kernel we need to support. We're just using the cgroup as a bag of PIDs, not for restricting any particular resource. */ GList * pids_from_cgroup (GDBusConnection * cgmanager, const gchar * jobname, const gchar * instancename) { GError * error = NULL; const gchar * name = g_getenv("UBUNTU_APP_LAUNCH_CG_MANAGER_NAME"); gchar * groupname = NULL; if (jobname != NULL) { groupname = g_strdup_printf("upstart/%s-%s", jobname, instancename); } g_debug("Looking for cg manager '%s' group '%s'", name, groupname); GVariant * vtpids = g_dbus_connection_call_sync(cgmanager, name, /* bus name for direct connection is NULL */ "/org/linuxcontainers/cgmanager", "org.linuxcontainers.cgmanager0_0", "GetTasksRecursive", g_variant_new("(ss)", "freezer", groupname ? groupname : ""), G_VARIANT_TYPE("(ai)"), G_DBUS_CALL_FLAGS_NONE, -1, /* default timeout */ NULL, /* cancellable */ &error); g_free(groupname); if (error != NULL) { g_warning("Unable to get PID list from cgroup manager: %s", error->message); g_error_free(error); return NULL; } GVariant * vpids = g_variant_get_child_value(vtpids, 0); GVariantIter iter; g_variant_iter_init(&iter, vpids); gint32 pid; GList * retval = NULL; while (g_variant_iter_loop(&iter, "i", &pid)) { retval = g_list_prepend(retval, GINT_TO_POINTER(pid)); } g_variant_unref(vpids); g_variant_unref(vtpids); return retval; } /* Global markers for the ual_tracepoint macro */ int _ual_tracepoints_env_checked = 0; int _ual_tracepoints_enabled = 0; ubuntu-app-launch-0.5+15.10.20150817/CMakeLists.txt0000644000015300001610000001565012564452110022032 0ustar pbuserpbgroup00000000000000project(ubuntu-app-launch C CXX) cmake_minimum_required(VERSION 2.8.9) option (enable_tests "Build tests" ON) option (enable_lcov "Generate Coverage Reports" ON) set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" "${CMAKE_MODULE_PATH}") set(PACKAGE ${CMAKE_PROJECT_NAME}) find_package(PkgConfig REQUIRED) find_package(GObjectIntrospection REQUIRED) include(GNUInstallDirs) include(CheckIncludeFile) include(CheckFunctionExists) include(Coverage) include(UseGlibGeneration) include(UseGdbusCodegen) include(UseConstantBuilder) include(UseLttngGenTp) # Workaround for libexecdir on debian if (EXISTS "/etc/debian_version") set(CMAKE_INSTALL_LIBEXECDIR ${CMAKE_INSTALL_LIBDIR}) set(CMAKE_INSTALL_FULL_LIBEXECDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBEXECDIR}") endif() set(pkglibexecdir "${CMAKE_INSTALL_FULL_LIBEXECDIR}/${CMAKE_PROJECT_NAME}") set(CMAKE_INSTALL_PKGLIBEXECDIR "${CMAKE_INSTALL_LIBEXECDIR}/${CMAKE_PROJECT_NAME}") set(CMAKE_INSTALL_FULL_PKGLIBEXECDIR "${CMAKE_INSTALL_FULL_LIBEXECDIR}/${CMAKE_PROJECT_NAME}") set(CMAKE_INSTALL_FULL_PKGDATADIR "${CMAKE_INSTALL_FULL_DATADIR}/${CMAKE_PROJECT_NAME}") execute_process(COMMAND dpkg-architecture -qDEB_BUILD_MULTIARCH OUTPUT_VARIABLE UBUNTU_APP_LAUNCH_ARCH OUTPUT_STRIP_TRAILING_WHITESPACE ) set(ubuntu_app_launch_arch "${UBUNTU_APP_LAUNCH_ARCH}") # Deprecated needed for g_atexit() in libual set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -Wno-error=unused-function -Wno-error=deprecated-declarations -std=c99") enable_testing() pkg_check_modules(GLIB2 REQUIRED glib-2.0) include_directories(${GLIB2_INCLUDE_DIRS}) pkg_check_modules(GOBJECT2 REQUIRED gobject-2.0) include_directories(${GOBJECT2_INCLUDE_DIRS}) pkg_check_modules(GIO2 REQUIRED gio-2.0 gio-unix-2.0) include_directories(${GIO2_INCLUDE_DIRS}) pkg_check_modules(JSONGLIB REQUIRED json-glib-1.0) include_directories(${JSONGLIB_INCLUDE_DIRS}) pkg_check_modules(ZEITGEIST REQUIRED zeitgeist-2.0) include_directories(${ZEITGEIST_INCLUDE_DIRS}) pkg_check_modules(CLICK REQUIRED click-0.4>=0.4.18) include_directories(${CLICK_INCLUDE_DIRS}) pkg_check_modules(LIBUPSTART REQUIRED libupstart) include_directories(${LIBUPSTART_INCLUDE_DIRS}) pkg_check_modules(DBUS REQUIRED dbus-1) include_directories(${DBUS_INCLUDE_DIRS}) pkg_check_modules(DBUSTEST REQUIRED dbustest-1>=14.04.0) include_directories(${DBUSTEST_INCLUDE_DIRS}) pkg_check_modules(LTTNG REQUIRED lttng-ust) include_directories(${LTTNG_INCLUDE_DIRS}) pkg_check_modules(CGMANAGER REQUIRED libcgmanager) include_directories(${CGMANAGER_INCLUDE_DIRS}) pkg_check_modules(MIR mirclient) include_directories(${MIR_INCLUDE_DIRS}) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") add_definitions( -DXMIR_HELPER="${pkglibexecdir}/xmir-helper" ) #################### # Helpers #################### add_library(helpers STATIC helpers.c helpers-shared.c libubuntu-app-launch/recoverable-problem.c) target_link_libraries(helpers ${GIO2_LIBRARIES} ${JSONGLIB_LIBRARIES} ${CLICK_LIBRARIES}) #################### # desktop-hook #################### add_executable(desktop-hook desktop-hook.c) set_target_properties(desktop-hook PROPERTIES OUTPUT_NAME "desktop-hook") target_link_libraries(desktop-hook helpers ${CLICK_LIBRARIES}) install(TARGETS desktop-hook RUNTIME DESTINATION "${pkglibexecdir}") #################### # exec-line-exec #################### add_lttng_gen_tp(NAME exec-line-exec-trace) include_directories(${CMAKE_CURRENT_BINARY_DIR}) add_executable(exec-line-exec exec-line-exec.c "${CMAKE_CURRENT_BINARY_DIR}/exec-line-exec-trace.c") set_target_properties(exec-line-exec PROPERTIES OUTPUT_NAME "exec-line-exec") target_link_libraries(exec-line-exec helpers ${LTTNG_LIBRARIES}) install(TARGETS exec-line-exec RUNTIME DESTINATION "${pkglibexecdir}") #################### # zg-report-app #################### add_executable(zg-report-app zg-report-app.c) set_target_properties(zg-report-app PROPERTIES OUTPUT_NAME "zg-report-app") target_link_libraries(zg-report-app ubuntu-launcher ${ZEITGEIST_LIBRARIES} ${GOBJECT2_LIBRARIES} ${GLIB2_LIBRARIES}) install(TARGETS zg-report-app RUNTIME DESTINATION "${pkglibexecdir}") #################### # application-job #################### add_executable(application-job application-job.c) set_target_properties(application-job PROPERTIES OUTPUT_NAME "application-job") target_link_libraries(application-job ubuntu-launcher) install(TARGETS application-job RUNTIME DESTINATION "${pkglibexecdir}") #################### # application-failed #################### add_executable(application-failed application-failed.c) set_target_properties(application-failed PROPERTIES OUTPUT_NAME "application-failed") target_link_libraries(application-failed ${GIO2_LIBRARIES}) install(TARGETS application-failed RUNTIME DESTINATION "${pkglibexecdir}") #################### # xmir-helper #################### add_executable(xmir-helper xmir-helper.c) set_target_properties(xmir-helper PROPERTIES OUTPUT_NAME "xmir-helper") install(TARGETS xmir-helper RUNTIME DESTINATION "${pkglibexecdir}") #################### # untrusted-helper-type-end #################### add_executable(untrusted-helper-type-end untrusted-helper-type-end.c) set_target_properties(untrusted-helper-type-end PROPERTIES OUTPUT_NAME "untrusted-helper-type-end") target_link_libraries(untrusted-helper-type-end ubuntu-launcher) install(TARGETS untrusted-helper-type-end RUNTIME DESTINATION "${pkglibexecdir}") #################### # cgroup-reap-all #################### add_executable(cgroup-reap-all cgroup-reap-all.c) set_target_properties(cgroup-reap-all PROPERTIES OUTPUT_NAME "cgroup-reap-all") target_link_libraries(cgroup-reap-all helpers) install(TARGETS cgroup-reap-all RUNTIME DESTINATION "${pkglibexecdir}") #################### # oom-adjust-setuid-helper #################### add_executable(oom-adjust-setuid-helper oom-adjust-setuid-helper.c) set_target_properties(oom-adjust-setuid-helper PROPERTIES OUTPUT_NAME "oom-adjust-setuid-helper") install(TARGETS oom-adjust-setuid-helper RUNTIME DESTINATION "${pkglibexecdir}") #################### # socket-demangler #################### add_executable(socket-demangler-helper socket-demangler.c) set_target_properties(socket-demangler-helper PROPERTIES OUTPUT_NAME "socket-demangler") target_link_libraries(socket-demangler-helper ${GIO2_LIBRARIES}) install(TARGETS socket-demangler-helper RUNTIME DESTINATION "${pkglibexecdir}") #################### # ubuntu-app-launch-desktop.click-hook #################### configure_file("ubuntu-app-launch-desktop.click-hook.in" "${CMAKE_CURRENT_SOURCE_DIR}/debian/ubuntu-app-launch-desktop.click-hook" @ONLY) add_subdirectory(libubuntu-app-launch) add_subdirectory(upstart-jobs) add_subdirectory(tools) add_subdirectory(ubuntu-app-test) # testing & coverage if (${enable_tests}) set (GTEST_SOURCE_DIR /usr/src/gtest/src) set (GTEST_INCLUDE_DIR ${GTEST_SOURCE_DIR}/..) set (GTEST_LIBS -lpthread) enable_testing () if (${enable_lcov}) # include(GCov) endif () add_subdirectory(tests) endif () ubuntu-app-launch-0.5+15.10.20150817/application-failed.c0000644000015300001610000000376712564452056023202 0ustar pbuserpbgroup00000000000000 /* * Copyright 2013 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #include int main (int argc, char * argv[]) { const gchar * job = g_getenv("JOB"); g_return_val_if_fail(job != NULL, -1); const gchar * instance = g_getenv("INSTANCE"); g_return_val_if_fail(instance != NULL, -1); gboolean crashed = FALSE; if (g_getenv("EXIT_STATUS") != NULL || g_getenv("EXIT_SIGNAL") != NULL) { crashed = TRUE; } gchar * appid = g_strdup(instance); if (g_strcmp0(job, "application-legacy") == 0) { gchar * lasthyphenstanding = g_strrstr(appid, "-"); if (lasthyphenstanding != NULL) { lasthyphenstanding[0] = '\0'; } else { g_warning("Legacy job instance '%s' is missing a hyphen", appid); } } GDBusConnection * bus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); g_return_val_if_fail(bus != NULL, -1); GError * error = NULL; g_dbus_connection_emit_signal(bus, NULL, /* destination */ "/", /* path */ "com.canonical.UbuntuAppLaunch", "ApplicationFailed", g_variant_new("(ss)", appid, crashed ? "crash" : "start-failure"), &error); g_debug("Emitting failed event '%s' for app '%s'", crashed ? "crash" : "start-failure", appid); if (error != NULL) { g_warning("Unable to emit signal: %s", error->message); g_error_free(error); return -1; } g_dbus_connection_flush_sync(bus, NULL, NULL); g_object_unref(bus); g_free(appid); return 0; } ubuntu-app-launch-0.5+15.10.20150817/oom-adjust-setuid-helper.c0000644000015300001610000000666712564452056024311 0ustar pbuserpbgroup00000000000000/* * Copyright © 2014 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #define _POSIX_C_SOURCE 200809L #include #include #include #include #include #include #include int main (int argc, char * argv[]) { if (argc != 3) { fprintf(stderr, "Usage: %s \n", argv[0]); exit(EXIT_FAILURE); } /* Not we turn the pid into an integer and back so that we can ensure we don't get used for nefarious tasks. */ int pidval = atoi(argv[1]); if ((pidval < 1) || (pidval >= 32768)) { fprintf(stderr, "PID passed is invalid: %d\n", pidval); exit(EXIT_FAILURE); } /* Not we turn the oom value into an integer and back so that we can ensure we don't get used for nefarious tasks. */ int oomval = atoi(argv[2]); if ((oomval < -1000) || (oomval >= 1000)) { fprintf(stderr, "OOM Value passed is invalid: %d\n", oomval); exit(EXIT_FAILURE); } /* Open up the PID directory first, to ensure that it is actually one of ours, so that we can't be used to set a OOM value on just anything */ char pidpath[32]; snprintf(pidpath, sizeof(pidpath), "/proc/%d", pidval); int piddir = open(pidpath, O_RDONLY | O_DIRECTORY); if (piddir < 0) { fprintf(stderr, "Unable open PID directory '%s' for '%d': %s\n", pidpath, pidval, strerror(errno)); exit(EXIT_FAILURE); } struct stat piddirstat = {0}; if (fstat(piddir, &piddirstat) < 0) { close(piddir); fprintf(stderr, "Unable stat PID directory '%s' for '%d': %s\n", pidpath, pidval, strerror(errno)); exit(EXIT_FAILURE); } if (getuid() != piddirstat.st_uid) { close(piddir); fprintf(stderr, "PID directory '%s' is not owned by %d but by %d\n", pidpath, getuid(), piddirstat.st_uid); exit(EXIT_FAILURE); } /* Looks good, let's try to get the actual oom_adj_score file to write the value to it. */ int adj = openat(piddir, "oom_score_adj", O_WRONLY); int openerr = errno; if (adj < 0) { close(piddir); /* ENOENT happens a fair amount because of races, so it's not worth printing a warning about */ if (openerr != ENOENT) { fprintf(stderr, "Unable to set OOM value of '%d' on '%d': %s\n", oomval, pidval, strerror(openerr)); exit(EXIT_FAILURE); } else { exit(EXIT_SUCCESS); } } char oomstring[32]; snprintf(oomstring, sizeof(oomstring), "%d", oomval); size_t writesize = write(adj, oomstring, strlen(oomstring)); int writeerr = errno; close(adj); close(piddir); if (writesize == strlen(oomstring)) exit(EXIT_SUCCESS); if (writeerr != 0) fprintf(stderr, "Unable to set OOM value of '%d' on '%d': %s\n", oomval, pidval, strerror(writeerr)); else /* No error, but yet, wrong size. Not sure, what could cause this. */ fprintf(stderr, "Unable to set OOM value of '%d' on '%d': Wrote %d bytes\n", oomval, pidval, (int)writesize); exit(EXIT_FAILURE); } ubuntu-app-launch-0.5+15.10.20150817/data/0000755000015300001610000000000012564452317020205 5ustar pbuserpbgroup00000000000000ubuntu-app-launch-0.5+15.10.20150817/data/com.canonical.UbuntuAppLaunch.xml0000644000015300001610000000155512564452056026516 0ustar pbuserpbgroup00000000000000 ubuntu-app-launch-0.5+15.10.20150817/data/com.canonical.UbuntuAppLaunch.SocketDemangler.xml0000644000015300001610000000034312564452056031556 0ustar pbuserpbgroup00000000000000 ubuntu-app-launch-0.5+15.10.20150817/socket-demangler.c0000644000015300001610000000631112564452102022655 0ustar pbuserpbgroup00000000000000/* * Copyright © 2014 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranties of * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . * * Authors: * Ted Gould */ #define _POSIX_C_SOURCE 200112L #include #include #include #include #include #include int main (int argc, char * argv[]) { const gchar * mir_name = g_getenv("UBUNTU_APP_LAUNCH_DEMANGLE_NAME"); const gchar * mir_socket = g_getenv("UBUNTU_APP_LAUNCH_DEMANGLE_PATH"); if (mir_socket == NULL || mir_socket[0] == '\0') { g_error("Unable to find Mir path for service"); return -1; } if (mir_name == NULL || mir_name[0] == '\0') { g_error("Unable to find Mir name for service"); return -1; } g_debug("Mir socket connection to %s:%s", mir_name, mir_socket); GError * error = NULL; GDBusConnection * bus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error); if (error != NULL) { g_error("Unable to get session bus: %s", error->message); g_error_free(error); return -1; } GVariant * retval; GUnixFDList * fdlist; retval = g_dbus_connection_call_with_unix_fd_list_sync( bus, mir_name, mir_socket, "com.canonical.UbuntuAppLaunch.SocketDemangler", "GetMirSocket", NULL, G_VARIANT_TYPE("(h)"), G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, /* timeout */ NULL, /* fd list in */ &fdlist, NULL, /* cancelable */ &error); g_clear_object(&bus); if (error != NULL) { g_error("Unable to get Mir socket over dbus: %s", error->message); g_error_free(error); return -1; } GVariant * outhandle = g_variant_get_child_value(retval, 0); if (outhandle == NULL) { g_error("Unable to get data from function"); return -1; } gint32 handle = g_variant_get_handle(outhandle); g_variant_unref(outhandle); g_variant_unref(retval); if (handle >= g_unix_fd_list_get_length(fdlist)) { g_error("Handle is %d but the FD list only has %d entries", handle, g_unix_fd_list_get_length(fdlist)); g_clear_object(&fdlist); return -1; } gint32 fd = g_unix_fd_list_get(fdlist, handle, &error); g_clear_object(&fdlist); if (error != NULL) { g_error("Unable to Unix FD: %s", error->message); g_error_free(error); return -1; } errno = 0; fcntl(fd, F_GETFD); if (errno != 0) { perror("File descriptor is invalid"); return -1; } /* Make sure the FD doesn't close on exec */ fcntl(fd, F_SETFD, 0); gchar * mirsocketbuf = g_strdup_printf("fd://%d", fd); setenv("MIR_SOCKET", mirsocketbuf, 1); g_debug("MIR_SOCKET=%s", mirsocketbuf); g_free(mirsocketbuf); /* Don't let people guess about these */ g_unsetenv("UBUNTU_APP_LAUNCH_DEMANGLE_NAME"); g_unsetenv("UBUNTU_APP_LAUNCH_DEMANGLE_PATH"); return execvp(argv[1], argv + 1); }