upstart-app-launch-0.3+14.04.20140411/ 0000755 0000153 0177776 00000000000 12322065100 017465 5 ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/tools/ 0000755 0000153 0177776 00000000000 12322065100 020625 5 ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/tools/upstart-app-pid.c 0000644 0000153 0177776 00000001763 12322064515 024043 0 ustar pbuser nogroup 0000000 0000000 /*
* 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 "libupstart-app-launch/upstart-app-launch.h"
int
main (int argc, gchar * argv[]) {
if (argc != 2) {
g_printerr("Usage: %s \n", argv[0]);
return 1;
}
GPid pid = upstart_app_launch_get_primary_pid(argv[1]);
if (pid == 0) {
return 1;
}
g_print("%d\n", pid);
return 0;
}
upstart-app-launch-0.3+14.04.20140411/tools/upstart-helper-list.c 0000644 0000153 0177776 00000002546 12322064515 024741 0 ustar pbuser nogroup 0000000 0000000 /*
* 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 "libupstart-app-launch/upstart-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 = upstart_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;
}
upstart-app-launch-0.3+14.04.20140411/tools/upstart-app-watch.c 0000644 0000153 0177776 00000004770 12322064515 024376 0 ustar pbuser nogroup 0000000 0000000 /*
* 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 "libupstart-app-launch/upstart-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
resume (const gchar * appid, gpointer user_data)
{
g_print("Resume %s\n", appid);
return;
}
void
focus (const gchar * appid, gpointer user_data)
{
g_print("Focus %s\n", appid);
return;
}
void
fail (const gchar * appid, upstart_app_launch_app_failed_t failhow, gpointer user_data)
{
const gchar * failstr = "unknown";
switch (failhow) {
case UPSTART_APP_LAUNCH_APP_FAILED_CRASH:
failstr = "crashed";
break;
case UPSTART_APP_LAUNCH_APP_FAILED_START_FAILURE:
failstr = "startup";
break;
}
g_print("Fail %s (%s)\n", appid, failstr);
return;
}
int
main (int argc, gchar * argv[])
{
upstart_app_launch_observer_add_app_starting(starting, NULL);
upstart_app_launch_observer_add_app_started(started, NULL);
upstart_app_launch_observer_add_app_stop(stopped, NULL);
upstart_app_launch_observer_add_app_focus(focus, NULL);
upstart_app_launch_observer_add_app_resume(resume, NULL);
upstart_app_launch_observer_add_app_failed(fail, NULL);
GMainLoop * mainloop = g_main_loop_new(NULL, FALSE);
g_main_loop_run(mainloop);
upstart_app_launch_observer_delete_app_starting(starting, NULL);
upstart_app_launch_observer_delete_app_started(started, NULL);
upstart_app_launch_observer_delete_app_stop(stopped, NULL);
upstart_app_launch_observer_delete_app_focus(focus, NULL);
upstart_app_launch_observer_delete_app_resume(resume, NULL);
upstart_app_launch_observer_delete_app_failed(fail, NULL);
g_main_loop_unref(mainloop);
return 0;
}
upstart-app-launch-0.3+14.04.20140411/tools/upstart-app-stop.c 0000644 0000153 0177776 00000001720 12322064515 024245 0 ustar pbuser nogroup 0000000 0000000 /*
* 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 "libupstart-app-launch/upstart-app-launch.h"
int
main (int argc, gchar * argv[]) {
if (argc != 2) {
g_printerr("Usage: %s \n", argv[0]);
return 1;
}
if (upstart_app_launch_stop_application(argv[1])) {
return 0;
} else {
return 1;
}
}
upstart-app-launch-0.3+14.04.20140411/tools/upstart-app-launch.c 0000644 0000153 0177776 00000004514 12322064515 024536 0 ustar pbuser nogroup 0000000 0000000 /*
* 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 "libupstart-app-launch/upstart-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, upstart_app_launch_app_failed_t failure_type, gpointer user_data)
{
if (g_strcmp0(appid, global_appid) != 0) {
return;
}
g_debug("Application '%s' failed: %s", appid, failure_type == UPSTART_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];
}
}
upstart_app_launch_observer_add_app_started(good_observer, mainloop);
upstart_app_launch_observer_add_app_focus(good_observer, mainloop);
upstart_app_launch_observer_add_app_failed(bad_observer, mainloop);
upstart_app_launch_start_application(global_appid, (const gchar * const *)uris);
g_main_loop_run(mainloop);
upstart_app_launch_observer_delete_app_started(good_observer, mainloop);
upstart_app_launch_observer_delete_app_focus(good_observer, mainloop);
upstart_app_launch_observer_delete_app_failed(bad_observer, mainloop);
g_main_loop_unref(mainloop);
g_free(uris);
return retval;
}
upstart-app-launch-0.3+14.04.20140411/tools/upstart-helper-start.c 0000644 0000153 0177776 00000002465 12322064515 025123 0 ustar pbuser nogroup 0000000 0000000 /*
* 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 "libupstart-app-launch/upstart-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 (upstart_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;
}
upstart-app-launch-0.3+14.04.20140411/tools/upstart-helper-stop.c 0000644 0000153 0177776 00000002424 12322064515 024746 0 ustar pbuser nogroup 0000000 0000000 /*
* 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 "libupstart-app-launch/upstart-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 (upstart_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;
}
upstart-app-launch-0.3+14.04.20140411/tools/upstart-app-list.c 0000644 0000153 0177776 00000001722 12322064515 024235 0 ustar pbuser nogroup 0000000 0000000 /*
* 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 "libupstart-app-launch/upstart-app-launch.h"
int
main (int argc, char * argv[])
{
gchar ** apps;
apps = upstart_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;
}
upstart-app-launch-0.3+14.04.20140411/tools/CMakeLists.txt 0000644 0000153 0177776 00000006235 12322064515 023404 0 ustar pbuser nogroup 0000000 0000000
########################
# upstart-app-list
########################
add_executable(upstart-app-list upstart-app-list.c)
set_target_properties(upstart-app-list PROPERTIES OUTPUT_NAME "upstart-app-list")
target_link_libraries(upstart-app-list upstart-launcher)
install(TARGETS upstart-app-list RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}")
########################
# upstart-app-launch
########################
add_executable(upstart-app-launch upstart-app-launch.c)
set_target_properties(upstart-app-launch PROPERTIES OUTPUT_NAME "upstart-app-launch")
target_link_libraries(upstart-app-launch upstart-launcher)
install(TARGETS upstart-app-launch RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}")
########################
# upstart-app-watch
########################
add_executable(upstart-app-watch upstart-app-watch.c)
set_target_properties(upstart-app-watch PROPERTIES OUTPUT_NAME "upstart-app-watch")
target_link_libraries(upstart-app-watch upstart-launcher)
install(TARGETS upstart-app-watch RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}")
########################
# upstart-app-pid
########################
add_executable(upstart-app-pid upstart-app-pid.c)
set_target_properties(upstart-app-pid PROPERTIES OUTPUT_NAME "upstart-app-pid")
target_link_libraries(upstart-app-pid upstart-launcher)
install(TARGETS upstart-app-pid RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}")
########################
# upstart-app-stop
########################
add_executable(upstart-app-stop upstart-app-stop.c)
set_target_properties(upstart-app-stop PROPERTIES OUTPUT_NAME "upstart-app-stop")
target_link_libraries(upstart-app-stop upstart-launcher)
install(TARGETS upstart-app-stop RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}")
########################
# upstart-app-triplet
########################
add_executable(upstart-app-triplet upstart-app-triplet.c)
set_target_properties(upstart-app-triplet PROPERTIES OUTPUT_NAME "upstart-app-triplet")
target_link_libraries(upstart-app-triplet upstart-launcher)
install(TARGETS upstart-app-triplet RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}")
########################
# upstart-helper-start
########################
add_executable(upstart-helper-start upstart-helper-start.c)
set_target_properties(upstart-helper-start PROPERTIES OUTPUT_NAME "upstart-helper-start")
target_link_libraries(upstart-helper-start upstart-launcher)
install(TARGETS upstart-helper-start RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}")
########################
# upstart-helper-stop
########################
add_executable(upstart-helper-stop upstart-helper-stop.c)
set_target_properties(upstart-helper-stop PROPERTIES OUTPUT_NAME "upstart-helper-stop")
target_link_libraries(upstart-helper-stop upstart-launcher)
install(TARGETS upstart-helper-stop RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}")
########################
# upstart-helper-list
########################
add_executable(upstart-helper-list upstart-helper-list.c)
set_target_properties(upstart-helper-list PROPERTIES OUTPUT_NAME "upstart-helper-list")
target_link_libraries(upstart-helper-list upstart-launcher)
install(TARGETS upstart-helper-list RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}")
upstart-app-launch-0.3+14.04.20140411/tools/upstart-app-triplet.c 0000644 0000153 0177776 00000002317 12322064515 024746 0 ustar pbuser nogroup 0000000 0000000 /*
* 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 "libupstart-app-launch/upstart-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 = upstart_app_launch_triplet_to_app_id(pkg, app, ver);
if (appid == NULL) {
return -1;
}
g_print("%s\n", appid);
g_free(appid);
return 0;
}
upstart-app-launch-0.3+14.04.20140411/desktop-exec-trace.tp 0000644 0000153 0177776 00000000641 12322064515 023533 0 ustar pbuser nogroup 0000000 0000000
TRACEPOINT_EVENT(upstart_app_launch, desktop_start, TP_ARGS(0), TP_FIELDS())
TRACEPOINT_EVENT(upstart_app_launch, desktop_starting_sent, TP_ARGS(0), TP_FIELDS())
TRACEPOINT_EVENT(upstart_app_launch, desktop_found, TP_ARGS(0), TP_FIELDS())
TRACEPOINT_EVENT(upstart_app_launch, desktop_handshake_wait, TP_ARGS(0), TP_FIELDS())
TRACEPOINT_EVENT(upstart_app_launch, desktop_handshake_complete, TP_ARGS(0), TP_FIELDS())
upstart-app-launch-0.3+14.04.20140411/cmake/ 0000755 0000153 0177776 00000000000 12322065100 020545 5 ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/cmake/UseLttngGenTp.cmake 0000644 0000153 0177776 00000001332 12322064515 024262 0 ustar pbuser nogroup 0000000 0000000 cmake_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)
upstart-app-launch-0.3+14.04.20140411/cmake/FindGObjectIntrospection.cmake 0000644 0000153 0177776 00000003765 12322064515 026472 0 ustar pbuser nogroup 0000000 0000000 # - 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
)
upstart-app-launch-0.3+14.04.20140411/cmake/Coverage.cmake 0000644 0000153 0177776 00000004146 12322064515 023320 0 ustar pbuser nogroup 0000000 0000000 if (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()
upstart-app-launch-0.3+14.04.20140411/cmake/UseGdbusCodegen.cmake 0000644 0000153 0177776 00000002146 12322064515 024571 0 ustar pbuser nogroup 0000000 0000000 cmake_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()
function(add_gdbus_codegen)
set(_one_value OUTFILES NAME PREFIX NAMESPACE SERVICE_XML)
set(_multi_value DEPENDS)
cmake_parse_arguments (arg "" "${_one_value}" "${_multi_value}" ${ARGN})
if(arg_PREFIX)
set(PREFIX --interface-prefix ${arg_PREFIX})
endif()
if(arg_NAMESPACE)
set(NAMESPACE --c-namespace ${arg_NAMESPACE})
endif()
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${arg_NAME}.h" "${CMAKE_CURRENT_BINARY_DIR}/${arg_NAME}.c"
COMMAND "${GDBUS_CODEGEN}"
--generate-c-code "${arg_NAME}"
${PREFIX}
${NAMESPACE}
"${arg_SERVICE_XML}"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${arg_DEPENDS} "${arg_SERVICE_XML}"
)
set(${arg_OUTFILES} ${${arg_OUTFILES}} "${CMAKE_CURRENT_BINARY_DIR}/${arg_NAME}.c" PARENT_SCOPE)
endfunction(add_gdbus_codegen)
upstart-app-launch-0.3+14.04.20140411/cmake/UseConstantBuilder.cmake 0000644 0000153 0177776 00000001232 12322064515 025333 0 ustar pbuser nogroup 0000000 0000000 cmake_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)
upstart-app-launch-0.3+14.04.20140411/cmake/UseGObjectIntrospection.cmake 0000644 0000153 0177776 00000007516 12322064515 026344 0 ustar pbuser nogroup 0000000 0000000 # 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)
upstart-app-launch-0.3+14.04.20140411/cmake/ListOperations.cmake 0000644 0000153 0177776 00000000735 12322064515 024544 0 ustar pbuser nogroup 0000000 0000000
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)
upstart-app-launch-0.3+14.04.20140411/cmake/UseGSettings.cmake 0000644 0000153 0177776 00000003715 12322064515 024152 0 ustar pbuser nogroup 0000000 0000000 # 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()
upstart-app-launch-0.3+14.04.20140411/cmake/UseGlibGeneration.cmake 0000644 0000153 0177776 00000005445 12322064515 025136 0 ustar pbuser nogroup 0000000 0000000 cmake_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)
upstart-app-launch-0.3+14.04.20140411/upstart-app-launch-desktop.click-hook.in 0000644 0000153 0177776 00000000207 12322064515 027246 0 ustar pbuser nogroup 0000000 0000000 Pattern: ${home}/.cache/upstart-app-launch/desktop/${id}.desktop
Exec: @pkglibexecdir@/desktop-hook
User-Level: yes
Hook-Name: desktop
upstart-app-launch-0.3+14.04.20140411/application-job.c 0000644 0000153 0177776 00000006440 12322064515 022721 0 ustar pbuser nogroup 0000000 0000000 /*
* 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 "libupstart-app-launch/upstart-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, upstart_app_launch_app_failed_t 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);
upstart_app_launch_observer_add_app_started(app_started, mainloop);
upstart_app_launch_observer_add_app_focus(app_focus, mainloop);
upstart_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(upstart_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);
upstart_app_launch_observer_delete_app_started(app_started, mainloop);
upstart_app_launch_observer_delete_app_focus(app_focus, mainloop);
upstart_app_launch_observer_delete_app_failed(app_failed, mainloop);
g_main_loop_unref(mainloop);
g_object_unref(con);
return retval;
}
upstart-app-launch-0.3+14.04.20140411/tests/ 0000755 0000153 0177776 00000000000 12322065100 020627 5 ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/tests/zg-test.cc 0000644 0000153 0177776 00000007611 12322064515 022551 0 ustar pbuser nogroup 0000000 0000000 /*
* 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(100000);
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();
/* Four seconds to do a two second op -- ARM Jenkins is slow */
EXPECT_LT(end - start, 4 * 1000 * 1000);
g_object_unref(zgevent);
g_object_unref(service);
g_main_loop_unref(mainloop);
}
upstart-app-launch-0.3+14.04.20140411/tests/failure-test.cc 0000644 0000153 0177776 00000007557 12322064515 023571 0 ustar pbuser nogroup 0000000 0000000 /*
* 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, upstart_app_launch_app_failed_t reason, gpointer user_data)
{
if (reason == UPSTART_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(upstart_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(upstart_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(upstart_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(upstart_app_launch_observer_delete_app_failed(failed_observer, &last_observer));
return;
}
static void
failed_start_observer (const gchar * appid, upstart_app_launch_app_failed_t reason, gpointer user_data)
{
if (reason == UPSTART_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(upstart_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(upstart_app_launch_observer_delete_app_failed(failed_start_observer, &last_observer));
return;
}
upstart-app-launch-0.3+14.04.20140411/tests/exec-test-archcolon.sh 0000755 0000153 0177776 00000000327 12322064515 025050 0 ustar pbuser nogroup 0000000 0000000 #!/bin/bash -e
if [ "$PATH" != "$APP_DIR:/path" ] ; then
echo "Bad PATH: $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
upstart-app-launch-0.3+14.04.20140411/tests/exec-util-test.cc 0000644 0000153 0177776 00000016012 12322064515 024023 0 ustar pbuser nogroup 0000000 0000000 /*
* 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 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);
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,
"SetEnv",
G_VARIANT_TYPE("(assb)"),
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 */
upstart_app_launch_observer_add_app_starting(starting_cb, NULL);
}
virtual void TearDown() {
upstart_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++;
}
}
};
TEST_F(ExecUtil, ClickExec)
{
DbusTestDbusMockObject * obj = dbus_test_dbus_mock_get_object(mock, "/com/ubuntu/Upstart", "com.ubuntu.Upstart0_6", NULL);
g_setenv("APP_ID", "com.test.good_application_1.2.3", TRUE);
g_setenv("TEST_CLICK_DB", "click-db-dir", TRUE);
g_setenv("TEST_CLICK_USER", "test-user", TRUE);
g_spawn_command_line_sync(CLICK_EXEC_TOOL, NULL, NULL, NULL, NULL);
guint len = 0;
const DbusTestDbusMockCall * calls = dbus_test_dbus_mock_object_get_method_calls(mock, obj, "SetEnv", &len, NULL);
ASSERT_EQ(12, len);
ASSERT_NE(nullptr, calls);
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;
bool got_app_dir = false;
bool got_app_exec = false;
bool got_app_desktop = false;
bool got_app_desktop_path = false;
#define APP_DIR CMAKE_SOURCE_DIR "/click-root-dir/.click/users/test-user/com.test.good"
for (i = 0; i < len; i++) {
EXPECT_STREQ("SetEnv", calls[i].name);
GVariant * envvar = g_variant_get_child_value(calls[i].params, 1);
gchar * var = g_variant_dup_string(envvar, NULL);
g_variant_unref(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) {
EXPECT_STREQ("1", value);
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) {
EXPECT_TRUE(g_str_has_prefix(value, APP_DIR ":"));
got_data_dirs = true;
} else if (g_strcmp0(var, "TMPDIR") == 0) {
EXPECT_TRUE(g_str_has_suffix(value, "com.test.good"));
got_temp_dir = true;
} else if (g_strcmp0(var, "__GL_SHADER_DISK_CACHE_PATH") == 0) {
EXPECT_TRUE(g_str_has_suffix(value, "com.test.good"));
got_shader_dir = true;
} else if (g_strcmp0(var, "APP_DIR") == 0) {
EXPECT_STREQ(APP_DIR, value);
got_app_dir = true;
} else if (g_strcmp0(var, "APP_EXEC") == 0) {
EXPECT_STREQ("foo", value);
got_app_exec = true;
} else if (g_strcmp0(var, "APP_DESKTOP_FILE") == 0) {
got_app_desktop = true;
} else if (g_strcmp0(var, "APP_DESKTOP_FILE_PATH") == 0) {
EXPECT_STREQ(APP_DIR "/application.desktop", value);
got_app_desktop_path = true;
} else {
g_warning("Unknown variable! %s", var);
EXPECT_TRUE(false);
}
g_free(var);
}
#undef APP_DIR
EXPECT_TRUE(got_app_isolation);
EXPECT_TRUE(got_cache_home);
EXPECT_TRUE(got_config_home);
EXPECT_TRUE(got_data_home);
EXPECT_TRUE(got_runtime_dir);
EXPECT_TRUE(got_data_dirs);
EXPECT_TRUE(got_temp_dir);
EXPECT_TRUE(got_shader_dir);
EXPECT_TRUE(got_app_dir);
EXPECT_TRUE(got_app_exec);
EXPECT_TRUE(got_app_desktop);
EXPECT_TRUE(got_app_desktop_path);
}
TEST_F(ExecUtil, DesktopExec)
{
DbusTestDbusMockObject * obj = dbus_test_dbus_mock_get_object(mock, "/com/ubuntu/Upstart", "com.ubuntu.Upstart0_6", NULL);
g_setenv("APP_ID", "foo", TRUE);
g_spawn_command_line_sync(DESKTOP_EXEC_TOOL, NULL, NULL, NULL, NULL);
guint len = 0;
const DbusTestDbusMockCall * calls = dbus_test_dbus_mock_object_get_method_calls(mock, obj, "SetEnv", &len, NULL);
ASSERT_EQ(4, len);
ASSERT_NE(nullptr, calls);
unsigned int i;
bool got_app_exec = false;
bool got_app_desktop = false;
bool got_app_desktop_path = false;
bool got_app_exec_policy = false;
for (i = 0; i < len; i++) {
EXPECT_STREQ("SetEnv", calls[i].name);
GVariant * envvar = g_variant_get_child_value(calls[i].params, 1);
gchar * var = g_variant_dup_string(envvar, NULL);
g_variant_unref(envvar);
gchar * equal = g_strstr_len(var, -1, "=");
ASSERT_NE(equal, nullptr);
equal[0] = '\0';
gchar * value = &(equal[1]);
if (g_strcmp0(var, "APP_EXEC") == 0) {
EXPECT_STREQ("foo", value);
got_app_exec = true;
} else if (g_strcmp0(var, "APP_DESKTOP_FILE") == 0) {
got_app_desktop = true;
} else if (g_strcmp0(var, "APP_DESKTOP_FILE_PATH") == 0) {
EXPECT_STREQ(CMAKE_SOURCE_DIR "/applications/foo.desktop", value);
got_app_desktop_path = true;
} else if (g_strcmp0(var, "APP_EXEC_POLICY") == 0) {
EXPECT_STREQ("unconfined", value);
got_app_exec_policy = true;
} else {
g_warning("Unknown variable! %s", var);
EXPECT_TRUE(false);
}
g_free(var);
}
EXPECT_TRUE(got_app_exec);
EXPECT_TRUE(got_app_desktop);
EXPECT_TRUE(got_app_desktop_path);
EXPECT_TRUE(got_app_exec_policy);
}
upstart-app-launch-0.3+14.04.20140411/tests/click-app-dir/ 0000755 0000153 0177776 00000000000 12322065100 023246 5 ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/tests/click-app-dir/application.desktop 0000644 0000153 0177776 00000000073 12322064515 027155 0 ustar pbuser nogroup 0000000 0000000 [Desktop Entry]
Name=Application
Type=Application
Exec=foo
upstart-app-launch-0.3+14.04.20140411/tests/click-app-dir/.click/ 0000755 0000153 0177776 00000000000 12322065100 024411 5 ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/tests/click-app-dir/.click/info/ 0000755 0000153 0177776 00000000000 12322065100 025344 5 ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/tests/click-app-dir/.click/info/com.test.no-json.manifest 0000644 0000153 0177776 00000000101 12322064515 032213 0 ustar pbuser nogroup 0000000 0000000
Lovin' some data
upstart-app-launch-0.3+14.04.20140411/tests/click-app-dir/.click/info/com.test.multiple.manifest 0000644 0000153 0177776 00000000467 12322064515 032502 0 ustar pbuser nogroup 0000000 0000000 {
"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"
}
}
}
upstart-app-launch-0.3+14.04.20140411/tests/click-app-dir/.click/info/com.test.no-app.manifest 0000644 0000153 0177776 00000000146 12322064515 032033 0 ustar pbuser nogroup 0000000 0000000 {
"version": "1.2.3",
"hooks": {
"no-application": {
"desktop": "application.desktop"
}
}
}
upstart-app-launch-0.3+14.04.20140411/tests/click-app-dir/.click/info/com.test.bad-version.manifest 0000644 0000153 0177776 00000000143 12322064515 033047 0 ustar pbuser nogroup 0000000 0000000 {
"version": "4.5.6",
"hooks": {
"application": {
"desktop": "application.desktop"
}
}
}
upstart-app-launch-0.3+14.04.20140411/tests/click-app-dir/.click/info/com.test.good.manifest 0000644 0000153 0177776 00000000143 12322064515 031566 0 ustar pbuser nogroup 0000000 0000000 {
"version": "1.2.3",
"hooks": {
"application": {
"desktop": "application.desktop"
}
}
}
upstart-app-launch-0.3+14.04.20140411/tests/click-app-dir/.click/info/com.test.no-hooks.manifest 0000644 0000153 0177776 00000000144 12322064515 032374 0 ustar pbuser nogroup 0000000 0000000 {
"version": "1.2.3",
"hookie": {
"application": {
"desktop": "application.desktop"
}
}
}
upstart-app-launch-0.3+14.04.20140411/tests/click-app-dir/.click/info/com.test.no-object.manifest 0000644 0000153 0177776 00000000033 12322064515 032514 0 ustar pbuser nogroup 0000000 0000000 [
"foo",
"bar",
5,
6
]
upstart-app-launch-0.3+14.04.20140411/tests/click-app-dir/.click/info/com.test.no-version.manifest 0000644 0000153 0177776 00000000137 12322064515 032740 0 ustar pbuser nogroup 0000000 0000000 {
"ver": "1.2.3",
"hooks": {
"application": {
"desktop": "application.desktop"
}
}
}
upstart-app-launch-0.3+14.04.20140411/tests/exec-test-noarch.sh 0000755 0000153 0177776 00000000327 12322064515 024352 0 ustar pbuser nogroup 0000000 0000000 #!/bin/bash -e
if [ "$PATH" != "$APP_DIR:/path" ] ; then
echo "Bad PATH: $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
upstart-app-launch-0.3+14.04.20140411/tests/click-db-dir/ 0000755 0000153 0177776 00000000000 12322065100 023053 5 ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/tests/click-db-dir/test.conf.in 0000644 0000153 0177776 00000000102 12322064515 025310 0 ustar pbuser nogroup 0000000 0000000 [Click Database]
root = @CMAKE_CURRENT_SOURCE_DIR@/click-root-dir
upstart-app-launch-0.3+14.04.20140411/tests/applications/ 0000755 0000153 0177776 00000000000 12322065100 023315 5 ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/tests/applications/scope.desktop 0000644 0000153 0177776 00000000131 12322064515 026025 0 ustar pbuser nogroup 0000000 0000000 [Desktop Entry]
Name=Foo
Type=Scope
Exec=foo
NoDisplay=false
Hidden=false
Terminal=false
upstart-app-launch-0.3+14.04.20140411/tests/applications/bar.desktop 0000644 0000153 0177776 00000000156 12322064515 025467 0 ustar pbuser nogroup 0000000 0000000
"But still valid XML"
upstart-app-launch-0.3+14.04.20140411/tests/applications/foo.desktop 0000644 0000153 0177776 00000000137 12322064515 025505 0 ustar pbuser nogroup 0000000 0000000 [Desktop Entry]
Name=Foo
Type=Application
Exec=foo
NoDisplay=false
Hidden=false
Terminal=false
upstart-app-launch-0.3+14.04.20140411/tests/applications/no-entry.desktop 0000644 0000153 0177776 00000000143 12322064515 026472 0 ustar pbuser nogroup 0000000 0000000 [Desktop Non-Entry]
Name=Foo
Type=Application
Exec=foo
NoDisplay=false
Hidden=false
Terminal=false
upstart-app-launch-0.3+14.04.20140411/tests/applications/nodisplay.desktop 0000644 0000153 0177776 00000000136 12322064515 026723 0 ustar pbuser nogroup 0000000 0000000 [Desktop Entry]
Name=Foo
Type=Application
Exec=foo
NoDisplay=true
Hidden=false
Terminal=false
upstart-app-launch-0.3+14.04.20140411/tests/applications/terminal.desktop 0000644 0000153 0177776 00000000136 12322064515 026534 0 ustar pbuser nogroup 0000000 0000000 [Desktop Entry]
Name=Foo
Type=Application
Exec=foo
NoDisplay=false
Hidden=false
Terminal=true
upstart-app-launch-0.3+14.04.20140411/tests/applications/multiple.desktop 0000644 0000153 0177776 00000000210 12322064515 026545 0 ustar pbuser nogroup 0000000 0000000 [Desktop Entry]
Name=Multiple
Type=Application
Exec=multiple
NoDisplay=false
Hidden=false
Terminal=false
X-Ubuntu-Single-Instance=false
upstart-app-launch-0.3+14.04.20140411/tests/applications/no-exec.desktop 0000644 0000153 0177776 00000000126 12322064515 026256 0 ustar pbuser nogroup 0000000 0000000 [Desktop Entry]
Name=Foo
Type=Application
NoDisplay=false
Hidden=false
Terminal=false
upstart-app-launch-0.3+14.04.20140411/tests/applications/hidden.desktop 0000644 0000153 0177776 00000000136 12322064515 026154 0 ustar pbuser nogroup 0000000 0000000 [Desktop Entry]
Name=Foo
Type=Application
Exec=foo
NoDisplay=false
Hidden=true
Terminal=false
upstart-app-launch-0.3+14.04.20140411/tests/applications/single.desktop 0000644 0000153 0177776 00000000203 12322064515 026175 0 ustar pbuser nogroup 0000000 0000000 [Desktop Entry]
Name=Single
Type=Application
Exec=single
NoDisplay=false
Hidden=false
Terminal=false
X-Ubuntu-Single-Instance=true
upstart-app-launch-0.3+14.04.20140411/tests/upstart-app-launch-mock.c 0000644 0000153 0177776 00000002105 12322064515 025461 0 ustar pbuser nogroup 0000000 0000000 /*
* 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 "upstart-app-launch.h"
#include "upstart-app-launch-mock.h"
static GPid primary_pid = 0;
static gchar * primary_pid_appid = NULL;
GPid
upstart_app_launch_get_primary_pid (const gchar * appid)
{
g_free(primary_pid_appid);
primary_pid_appid = g_strdup(appid);
return primary_pid;
}
void
upstart_app_launch_mock_set_primary_pid (GPid pid)
{
primary_pid = pid;
return;
}
upstart-app-launch-0.3+14.04.20140411/tests/libual-test.cc 0000644 0000153 0177776 00000106240 12322064515 023377 0 ustar pbuser nogroup 0000000 0000000 /*
* 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
extern "C" {
#include "upstart-app-launch.h"
#include "libdbustest/dbus-test.h"
}
class LibUAL : public ::testing::Test
{
protected:
DbusTestService * service = NULL;
DbusTestDbusMock * mock = 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() {
gchar * linkfarmpath = g_build_filename(CMAKE_SOURCE_DIR, "link-farm", NULL);
g_setenv("UPSTART_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, 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);
/* 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=foo':"
" 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("foo"),
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);
/* Put it together */
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);
ASSERT_TRUE(upstart_app_launch_observer_add_app_focus(focus_cb, this));
ASSERT_TRUE(upstart_app_launch_observer_add_app_resume(resume_cb, this));
}
virtual void TearDown() {
upstart_app_launch_observer_delete_app_focus(focus_cb, this);
upstart_app_launch_observer_delete_app_resume(resume_cb, this);
g_clear_object(&mock);
g_clear_object(&service);
g_object_unref(bus);
unsigned int cleartry = 0;
while (bus != NULL && cleartry < 100) {
pause(100);
cleartry++;
}
ASSERT_EQ(bus, nullptr);
}
bool check_env (GVariant * env_array, const gchar * var, const gchar * value) {
GVariantIter iter;
g_variant_iter_init(&iter, env_array);
gchar * envvar = NULL;
bool found = false;
while (g_variant_iter_loop(&iter, "s", &envvar)) {
if (g_str_has_prefix(envvar, var)) {
if (found) {
g_warning("Found the env var more than once!");
return false;
}
if (value != NULL) {
gchar * combined = g_strdup_printf("%s=%s", var, value);
if (g_strcmp0(envvar, combined) == 0) {
found = true;
}
g_free(combined);
} else {
found = true;
}
}
}
if (!found) {
gchar * envstr = g_variant_print(env_array, FALSE);
g_warning("Unable to find '%s' with value '%s' in '%s'", var, value, envstr);
g_free(envstr);
}
return found;
}
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);
}
}
};
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(upstart_app_launch_start_application("foolike", 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(upstart_app_launch_start_application("foolike", 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", "foolike"));
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(upstart_app_launch_start_application("foolike", 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", "foolike"));
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(upstart_app_launch_start_application_test("foolike", 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", "foolike"));
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(upstart_app_launch_stop_application("foo"));
ASSERT_EQ(dbus_test_dbus_mock_object_check_method_call(mock, obj, "Stop", NULL, NULL), 1);
}
TEST_F(LibUAL, ApplicationLog)
{
gchar * click_log = upstart_app_launch_application_log_path("foo");
EXPECT_STREQ(CMAKE_SOURCE_DIR "/upstart/application-click-foo.log", click_log);
g_free(click_log);
gchar * legacy_single = upstart_app_launch_application_log_path("single");
EXPECT_STREQ(CMAKE_SOURCE_DIR "/upstart/application-legacy-single-.log", legacy_single);
g_free(legacy_single);
gchar * legacy_multiple = upstart_app_launch_application_log_path("bar");
EXPECT_STREQ(CMAKE_SOURCE_DIR "/upstart/application-legacy-bar-2342345.log", legacy_multiple);
g_free(legacy_multiple);
}
TEST_F(LibUAL, ApplicationPid)
{
EXPECT_EQ(upstart_app_launch_get_primary_pid("foo"), getpid());
EXPECT_EQ(upstart_app_launch_get_primary_pid("bar"), 5678);
EXPECT_TRUE(upstart_app_launch_pid_in_app_id(getpid(), "foo"));
EXPECT_FALSE(upstart_app_launch_pid_in_app_id(5678, "foo"));
}
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", upstart_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", upstart_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", upstart_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", upstart_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", upstart_app_launch_triplet_to_app_id("com.test.multiple", "first-listed-app", NULL));
EXPECT_STREQ("com.test.multiple_first_1.2.3", upstart_app_launch_triplet_to_app_id("com.test.multiple", NULL, NULL));
EXPECT_STREQ("com.test.multiple_fifth_1.2.3", upstart_app_launch_triplet_to_app_id("com.test.multiple", "last-listed-app", NULL));
EXPECT_EQ(nullptr, upstart_app_launch_triplet_to_app_id("com.test.multiple", "only-listed-app", NULL));
EXPECT_STREQ("com.test.good_application_1.2.3", upstart_app_launch_triplet_to_app_id("com.test.good", "only-listed-app", NULL));
/* A bunch that should be NULL */
EXPECT_EQ(nullptr, upstart_app_launch_triplet_to_app_id("com.test.no-hooks", NULL, NULL));
EXPECT_EQ(nullptr, upstart_app_launch_triplet_to_app_id("com.test.no-json", NULL, NULL));
EXPECT_EQ(nullptr, upstart_app_launch_triplet_to_app_id("com.test.no-object", NULL, NULL));
EXPECT_EQ(nullptr, upstart_app_launch_triplet_to_app_id("com.test.no-version", NULL, NULL));
}
TEST_F(LibUAL, AppIdParse)
{
EXPECT_TRUE(upstart_app_launch_app_id_parse("com.ubuntu.test_test_123", NULL, NULL, NULL));
EXPECT_FALSE(upstart_app_launch_app_id_parse("inkscape", NULL, NULL, NULL));
EXPECT_FALSE(upstart_app_launch_app_id_parse("music-app", NULL, NULL, NULL));
gchar * pkg;
gchar * app;
gchar * version;
ASSERT_TRUE(upstart_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 = upstart_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], "foo") == 0) {
ASSERT_STREQ(apps[0], "foo");
ASSERT_STREQ(apps[1], "bar");
} else {
ASSERT_STREQ(apps[0], "bar");
ASSERT_STREQ(apps[1], "foo");
}
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(upstart_app_launch_observer_add_app_started(observer_cb, &start_data));
ASSERT_TRUE(upstart_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=foo'])"),
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=foo'])"),
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 = "foo";
stop_data.count = 0;
stop_data.name = "foo";
/* 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=foo'])"),
NULL
);
dbus_test_dbus_mock_object_emit_signal(mock, obj,
"EventEmitted",
G_VARIANT_TYPE("(sas)"),
g_variant_new_parsed("('started', ['JOB=application-click', 'INSTANCE=foo'])"),
NULL
);
dbus_test_dbus_mock_object_emit_signal(mock, obj,
"EventEmitted",
G_VARIANT_TYPE("(sas)"),
g_variant_new_parsed("('stopping', ['JOB=application-click', 'INSTANCE=foo'])"),
NULL
);
dbus_test_dbus_mock_object_emit_signal(mock, obj,
"EventEmitted",
G_VARIANT_TYPE("(sas)"),
g_variant_new_parsed("('stopped', ['JOB=application-click', 'INSTANCE=foo'])"),
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(upstart_app_launch_observer_delete_app_started(observer_cb, &start_data));
ASSERT_TRUE(upstart_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(upstart_app_launch_observer_add_app_starting(starting_observer, &last_observer));
g_dbus_connection_emit_signal(session,
NULL, /* destination */
"/", /* path */
"com.canonical.UpstartAppLaunch", /* interface */
"UnityStartingBroadcast", /* signal */
g_variant_new("(s)", "foo"), /* params, the same */
NULL);
pause(100);
EXPECT_EQ("foo", last_observer);
EXPECT_EQ(1, starting_count);
EXPECT_TRUE(upstart_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(upstart_app_launch_start_application("foo", NULL));
pause(50); /* Ensure all the events come through */
EXPECT_EQ("foo", this->last_focus_appid);
EXPECT_EQ("foo", 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)"/foo",
NULL);
const gchar * uris[] = {
"http://www.test.com",
NULL
};
ASSERT_TRUE(upstart_app_launch_start_application("foo", uris));
pause(100); /* Ensure all the events come through */
EXPECT_EQ("foo", this->last_focus_appid);
EXPECT_EQ("foo", 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.UpstartAppLaunch", /* interface */
"UnityResumeResponse", /* signal */
g_variant_new("(s)", "foo"), /* 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(upstart_app_launch_start_application("foo", uris));
pause(100); /* Ensure all the events come through */
EXPECT_EQ("foo", this->last_focus_appid);
EXPECT_EQ("foo", this->last_resume_appid);
}
TEST_F(LibUAL, UnityTimeoutTest)
{
this->resume_timeout = 100;
ASSERT_TRUE(upstart_app_launch_start_application("foo", NULL));
pause(1000); /* Ensure all the events come through */
EXPECT_EQ("foo", this->last_focus_appid);
EXPECT_EQ("foo", this->last_resume_appid);
}
TEST_F(LibUAL, UnityTimeoutUriTest)
{
this->resume_timeout = 200;
const gchar * uris[] = {
"http://www.test.com",
NULL
};
ASSERT_TRUE(upstart_app_launch_start_application("foo", uris));
pause(1000); /* Ensure all the events come through */
EXPECT_EQ("foo", this->last_focus_appid);
EXPECT_EQ("foo", 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(upstart_app_launch_start_application("foo", uris));
guint end = g_get_monotonic_time();
EXPECT_LT(end - start, 600 * 1000);
pause(1000); /* Ensure all the events come through */
EXPECT_EQ("foo", this->last_focus_appid);
EXPECT_EQ("foo", 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(upstart_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(upstart_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, upstart_app_launch_app_failed_t reason, gpointer user_data)
{
if (reason == UPSTART_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(upstart_app_launch_observer_add_app_failed(failed_observer, &last_observer));
g_dbus_connection_emit_signal(session,
NULL, /* destination */
"/", /* path */
"com.canonical.UpstartAppLaunch", /* interface */
"ApplicationFailed", /* signal */
g_variant_new("(ss)", "foo", "crash"), /* params, the same */
NULL);
pause(100);
EXPECT_EQ("foo", last_observer);
last_observer.clear();
g_dbus_connection_emit_signal(session,
NULL, /* destination */
"/", /* path */
"com.canonical.UpstartAppLaunch", /* interface */
"ApplicationFailed", /* signal */
g_variant_new("(ss)", "foo", "blahblah"), /* params, the same */
NULL);
pause(100);
EXPECT_EQ("foo", last_observer);
last_observer.clear();
g_dbus_connection_emit_signal(session,
NULL, /* destination */
"/", /* path */
"com.canonical.UpstartAppLaunch", /* interface */
"ApplicationFailed", /* signal */
g_variant_new("(ss)", "foo", "start-failure"), /* params, the same */
NULL);
pause(100);
EXPECT_TRUE(last_observer.empty());
EXPECT_TRUE(upstart_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(upstart_app_launch_start_helper("untrusted-type", "foolike", 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(upstart_app_launch_start_helper("untrusted-type", "foolike", 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", "foolike"));
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 = upstart_app_launch_start_multiple_helper("untrusted-type", "foolike", 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", "foolike"));
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(upstart_app_launch_start_helper("untrusted-type", "foolike", 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", "foolike"));
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(upstart_app_launch_stop_helper("untrusted-type", "foo"));
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", "foo"));
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(upstart_app_launch_stop_multiple_helper("untrusted-type", "foo", "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", "foo"));
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 = upstart_app_launch_list_helpers("not-a-type");
EXPECT_NE(nullptr, blanktype);
EXPECT_EQ(0, g_strv_length(blanktype));
g_strfreev(blanktype);
gchar ** goodtype = upstart_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 = upstart_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 = upstart_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(upstart_app_launch_observer_add_helper_started(helper_observer_cb, "my-type-is-scorpio", &start_data));
ASSERT_TRUE(upstart_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(upstart_app_launch_observer_delete_helper_started(helper_observer_cb, "my-type-is-scorpio", &start_data));
ASSERT_TRUE(upstart_app_launch_observer_delete_helper_stop(helper_observer_cb, "my-type-is-libra", &stop_data));
}
upstart-app-launch-0.3+14.04.20140411/tests/exec-test-colon.sh 0000755 0000153 0177776 00000000316 12322064515 024210 0 ustar pbuser nogroup 0000000 0000000 #!/bin/bash -e
if [ "$PATH" != "/path" ] ; then
echo "Bad PATH: $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
upstart-app-launch-0.3+14.04.20140411/tests/manual 0000644 0000153 0177776 00000005113 12322064515 022040 0 ustar pbuser nogroup 0000000 0000000 Test-case upstart-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: upstart-app-list
- Clock application shouldn't be listed
- Launch the clock application: upstart-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 upstart-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: upstart-app-list
- Settings shouldn't be listed
- Launch the settings application: upstart-app-launch ubuntu-system-settings
- The settings application should be brought to focus and shown to the user
Test-case upstart-app-launch/secondary-activation
- Run test case: upstart-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: upstart-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 upstart-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 upstart-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
upstart-app-launch-0.3+14.04.20140411/tests/exec-test-full.sh 0000755 0000153 0177776 00000000421 12322064515 024035 0 ustar pbuser nogroup 0000000 0000000 #!/bin/bash -e
if [ "$PATH" != "$APP_DIR/lib/64bit-amazing/bin:$APP_DIR:/path" ] ; then
echo "Bad PATH: $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
upstart-app-launch-0.3+14.04.20140411/tests/helper-test.cc 0000644 0000153 0177776 00000036000 12322064515 023402 0 ustar pbuser nogroup 0000000 0000000 /*
* 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,
"SetEnv",
G_VARIANT_TYPE("(assb)"),
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" */
set_confined_envvars("foo-app-pkg", "/foo/bar");
guint len = 0;
const DbusTestDbusMockCall * calls = dbus_test_dbus_mock_object_get_method_calls(mock, obj, "SetEnv", &len, NULL);
ASSERT_EQ(len, 8);
ASSERT_NE(calls, nullptr);
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;
for (i = 0; i < len; i++) {
EXPECT_STREQ("SetEnv", calls[i].name);
GVariant * envvar = g_variant_get_child_value(calls[i].params, 1);
gchar * var = g_variant_dup_string(envvar, NULL);
g_variant_unref(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);
}
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(desktop, CMAKE_SOURCE_DIR "/click-app-dir/application.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;
}
upstart-app-launch-0.3+14.04.20140411/tests/CMakeLists.txt 0000644 0000153 0177776 00000004431 12322064515 023402 0 ustar pbuser nogroup 0000000 0000000
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}/libupstart-app-launch")
add_executable (libual-test
libual-test.cc)
target_link_libraries (libual-test helpers gtest ${GTEST_LIBS} ${LIBUPSTART_LIBRARIES} ${DBUSTEST_LIBRARIES} upstart-launcher)
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} upstart-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_definitions ( -DCLICK_EXEC_TOOL="${CMAKE_BINARY_DIR}/click-exec" )
add_definitions ( -DDESKTOP_EXEC_TOOL="${CMAKE_BINARY_DIR}/desktop-exec" )
add_executable (exec-util-test
exec-util-test.cc)
target_link_libraries (exec-util-test gtest upstart-launcher ${GTEST_LIBS} ${DBUSTEST_LIBRARIES} ${GIO2_LIBRARIES})
add_test (exec-util-test exec-util-test)
upstart-app-launch-0.3+14.04.20140411/tests/click-root-dir/ 0000755 0000153 0177776 00000000000 12322065100 023451 5 ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/tests/click-root-dir/com.test.multiple/ 0000755 0000153 0177776 00000000000 12322065100 027037 5 ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/tests/click-root-dir/com.test.multiple/1.2.3 0000777 0000153 0177776 00000000000 12322065100 032410 2../../click-app-dir ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/tests/click-root-dir/com.test.no-hooks/ 0000755 0000153 0177776 00000000000 12322065100 026741 5 ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/tests/click-root-dir/com.test.no-hooks/1.2.3 0000777 0000153 0177776 00000000000 12322065100 032312 2../../click-app-dir ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/tests/click-root-dir/com.test.good/ 0000755 0000153 0177776 00000000000 12322065100 026134 5 ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/tests/click-root-dir/com.test.good/1.2.3 0000777 0000153 0177776 00000000000 12322065100 031505 2../../click-app-dir ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/tests/click-root-dir/.click/ 0000755 0000153 0177776 00000000000 12322065100 024614 5 ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/tests/click-root-dir/.click/users/ 0000755 0000153 0177776 00000000000 12322065100 025755 5 ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/tests/click-root-dir/.click/users/test-user/ 0000755 0000153 0177776 00000000000 12322065100 027710 5 ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/tests/click-root-dir/.click/users/test-user/com.test.multiple 0000777 0000153 0177776 00000000000 12322065100 040031 2../../../com.test.multiple/1.2.3 ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/tests/click-root-dir/.click/users/test-user/com.test.no-hooks 0000777 0000153 0177776 00000000000 12322065100 037635 2../../../com.test.no-hooks/1.2.3 ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/tests/click-root-dir/.click/users/test-user/com.test.good 0000777 0000153 0177776 00000000000 12322065100 036223 2../../../com.test.good/1.2.3 ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/tests/click-root-dir/.click/users/test-user/com.test.no-app 0000777 0000153 0177776 00000000000 12322065100 036727 2../../../com.test.no-app/1.2.3 ustar pbuser nogroup 0000000 0000000 ././@LongLink 0000000 0000000 0000000 00000000146 00000000000 011216 L ustar 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/tests/click-root-dir/.click/users/test-user/com.test.no-version upstart-app-launch-0.3+14.04.20140411/tests/click-root-dir/.click/users/test-user/com.test.no-versio0000777 0000153 0177776 00000000000 12322065100 040363 2../../../com.test.no-version/1.2.3 ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/tests/click-root-dir/.click/users/test-user/com.test.no-object0000777 0000153 0177776 00000000000 12322065100 040103 2../../../com.test.no-object/1.2.3 ustar pbuser nogroup 0000000 0000000 ././@LongLink 0000000 0000000 0000000 00000000147 00000000000 011217 L ustar 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/tests/click-root-dir/.click/users/test-user/com.test.bad-version upstart-app-launch-0.3+14.04.20140411/tests/click-root-dir/.click/users/test-user/com.test.bad-versi0000777 0000153 0177776 00000000000 12322065100 040430 2../../../com.test.bad-version/1.2.3 ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/tests/click-root-dir/.click/users/test-user/com.test.no-json 0000777 0000153 0177776 00000000000 12322065100 037311 2../../../com.test.no-json/1.2.3 ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/tests/click-root-dir/com.test.no-app/ 0000755 0000153 0177776 00000000000 12322065100 026376 5 ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/tests/click-root-dir/com.test.no-app/1.2.3 0000777 0000153 0177776 00000000000 12322065100 031747 2../../click-app-dir ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/tests/click-root-dir/com.test.no-version/ 0000755 0000153 0177776 00000000000 12322065100 027303 5 ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/tests/click-root-dir/com.test.no-version/1.2.3 0000777 0000153 0177776 00000000000 12322065100 032654 2../../click-app-dir ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/tests/click-root-dir/com.test.no-object/ 0000755 0000153 0177776 00000000000 12322065100 027064 5 ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/tests/click-root-dir/com.test.no-object/1.2.3 0000777 0000153 0177776 00000000000 12322065100 032435 2../../click-app-dir ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/tests/click-root-dir/com.test.bad-version/ 0000755 0000153 0177776 00000000000 12322065100 027415 5 ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/tests/click-root-dir/com.test.bad-version/1.2.3 0000777 0000153 0177776 00000000000 12322065100 032766 2../../click-app-dir ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/tests/click-root-dir/com.test.no-json/ 0000755 0000153 0177776 00000000000 12322065100 026567 5 ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/tests/click-root-dir/com.test.no-json/1.2.3 0000777 0000153 0177776 00000000000 12322065100 032140 2../../click-app-dir ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/tests/helper-handshake-test.cc 0000644 0000153 0177776 00000006121 12322064515 025327 0 ustar pbuser nogroup 0000000 0000000 /*
* 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.UpstartAppLaunch", /* 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;
}
upstart-app-launch-0.3+14.04.20140411/tests/exec-test-noinit.sh 0000755 0000153 0177776 00000000373 12322064515 024401 0 ustar pbuser nogroup 0000000 0000000 #!/bin/bash -e
if [ "$PATH" != "$APP_DIR/lib/64bit-amazing/bin:$APP_DIR" ] ; then
echo "Bad PATH: $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
upstart-app-launch-0.3+14.04.20140411/tests/link-farm/ 0000755 0000153 0177776 00000000000 12322065100 022507 5 ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/tests/link-farm/foolike.desktop 0000644 0000153 0177776 00000000017 12322064515 025541 0 ustar pbuser nogroup 0000000 0000000 Needs to exist
upstart-app-launch-0.3+14.04.20140411/tests/link-farm/foo.desktop 0000644 0000153 0177776 00000000017 12322064515 024674 0 ustar pbuser nogroup 0000000 0000000 Needs to exist
upstart-app-launch-0.3+14.04.20140411/tests/link-farm/README 0000644 0000153 0177776 00000000260 12322064515 023376 0 ustar pbuser nogroup 0000000 0000000 This 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.
upstart-app-launch-0.3+14.04.20140411/tests/exec-test.sh.in 0000755 0000153 0177776 00000002516 12322064515 023511 0 ustar pbuser nogroup 0000000 0000000 #!/bin/bash -e
export PATH=/path
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 UPSTART_APP_LAUNCH_ARCH=64bit-amazing
echo "Testing Full Test"
@CMAKE_BINARY_DIR@/exec-line-exec
export PATH=/path
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 UPSTART_APP_LAUNCH_ARCH
echo "Testing Noarch Test"
@CMAKE_BINARY_DIR@/exec-line-exec
unset PATH
export APP_EXEC=@CMAKE_CURRENT_SOURCE_DIR@/exec-test-noinit.sh
export APP_DIR=@CMAKE_CURRENT_BINARY_DIR@
unset QML2_IMPORT_PATH
export UPSTART_APP_LAUNCH_ARCH=64bit-amazing
echo "Testing Uninitialized Test"
@CMAKE_BINARY_DIR@/exec-line-exec
export PATH=/path
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 UPSTART_APP_LAUNCH_ARCH=64bit-amazing
echo "Testing Colon Test"
@CMAKE_BINARY_DIR@/exec-line-exec
export PATH=/path
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 UPSTART_APP_LAUNCH_ARCH=64bit-amazing:amazinger
echo "Testing Arch Colon Test"
@CMAKE_BINARY_DIR@/exec-line-exec
upstart-app-launch-0.3+14.04.20140411/tests/upstart-app-launch-mock.h 0000644 0000153 0177776 00000001305 12322064515 025467 0 ustar pbuser nogroup 0000000 0000000 /*
* 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 upstart_app_launch_mock_set_primary_pid (GPid pid);
upstart-app-launch-0.3+14.04.20140411/desktop-hook.c 0000644 0000153 0177776 00000035524 12322064515 022262 0 ustar pbuser nogroup 0000000 0000000 /*
* 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 upstart-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
upstart-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 upstart-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;
};
/* 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 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;
}
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 * 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, "DuplicateSignature");
write_null(error_stdin);
write_string(error_stdin, "icon-path-unhandled-");
write_string(error_stdin, app_id);
/* 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 Entry", "Path", NULL)) {
gchar * oldpath = g_key_file_get_string(keyfile, "Desktop Entry", "Path", NULL);
g_debug("Desktop file '%s' has a Path set to '%s'. Setting as X-Ubuntu-Old-Path.", from, oldpath);
g_key_file_set_string(keyfile, "Desktop Entry", "X-Ubuntu-Old-Path", oldpath);
g_free(oldpath);
}
g_key_file_set_string(keyfile, "Desktop Entry", "Path", appdir);
/* Icon Handling */
if (g_key_file_has_key(keyfile, "Desktop Entry", "Icon", NULL)) {
gchar * originalicon = g_key_file_get_string(keyfile, "Desktop Entry", "Icon", 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 Entry", "Icon", iconpath);
/* Save the old value, because, debugging */
g_key_file_set_string(keyfile, "Desktop Entry", "X-Ubuntu-Old-Icon", 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, 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 Entry", "Exec", newexec);
g_free(newexec);
g_free(oldexec);
/* Adding an Application ID */
g_key_file_set_string(keyfile, "Desktop Entry", "X-Ubuntu-Application-ID", app_id);
/* 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;
}
/* Check click to find out where the files are */
ClickUser * user = click_user_new_for_user(NULL, NULL, &error);
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 Entry", "X-Ubuntu-Application-ID", 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(), "upstart-app-launch", "desktop", NULL);
if (!g_file_test(symlinkdir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
g_warning("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_warning("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;
}
upstart-app-launch-0.3+14.04.20140411/desktop-exec.c 0000644 0000153 0177776 00000007166 12322064515 022247 0 ustar pbuser nogroup 0000000 0000000 /*
* 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 "desktop-exec-trace.h"
int
main (int argc, char * argv[])
{
if (argc != 1) {
g_error("Should be called as: %s", argv[0]);
return 1;
}
const gchar * app_id = g_getenv("APP_ID");
if (app_id == NULL) {
g_error("No APP_ID environment variable defined");
return 1;
}
g_setenv("LTTNG_UST_REGISTER_TIMEOUT", "0", FALSE); /* Set to zero if not set */
tracepoint(upstart_app_launch, desktop_start);
/* Ensure we keep one connection open to the bus for the entire
script even though different people need it throughout */
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;
}
handshake_t * handshake = starting_handshake_start(app_id);
if (handshake == NULL) {
g_warning("Unable to setup starting handshake");
}
tracepoint(upstart_app_launch, desktop_starting_sent);
gchar * desktopfilename = NULL;
GKeyFile * keyfile = keyfile_for_appid(app_id, &desktopfilename);
if (keyfile == NULL) {
g_error("Unable to find keyfile for application '%s'", app_id);
return 1;
}
tracepoint(upstart_app_launch, desktop_found);
/* TODO: This is for Surface Flinger. When we drop support, we can drop this code */
if (desktopfilename != NULL) {
set_upstart_variable("APP_DESKTOP_FILE", desktopfilename, FALSE);
/* This is not for SF, it's for platform API only above is for SF */
set_upstart_variable("APP_DESKTOP_FILE_PATH", desktopfilename, FALSE);
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);
set_upstart_variable("APP_DIR", path, FALSE);
g_free(path);
}
gchar * apparmor = g_key_file_get_string(keyfile, "Desktop Entry", "X-Ubuntu-AppArmor-Profile", NULL);
if (apparmor != NULL) {
set_upstart_variable("APP_EXEC_POLICY", apparmor, FALSE);
set_confined_envvars(app_id, "/usr/share");
g_free(apparmor);
} else {
set_upstart_variable("APP_EXEC_POLICY", "unconfined", FALSE);
}
/* 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);
/* NOTE: This should be the last upstart variable set as it is sync
so it will wait for a reply from Upstart implying that Upstart
has seen all the other variable requests we made */
set_upstart_variable("APP_EXEC", execline, TRUE);
g_free(execline);
g_key_file_free(keyfile);
tracepoint(upstart_app_launch, desktop_handshake_wait);
starting_handshake_wait(handshake);
tracepoint(upstart_app_launch, desktop_handshake_complete);
g_object_unref(bus);
return 0;
}
upstart-app-launch-0.3+14.04.20140411/upstart-jobs/ 0000755 0000153 0177776 00000000000 12322065100 022122 5 ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/upstart-jobs/test-conffile.sh 0000755 0000153 0177776 00000000636 12322064515 025241 0 ustar pbuser nogroup 0000000 0000000 #!/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
upstart-app-launch-0.3+14.04.20140411/upstart-jobs/application-legacy.conf.in 0000644 0000153 0177776 00000001325 12322064515 027155 0 ustar pbuser nogroup 0000000 0000000 description "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
# For Surface Flinger
env APP_DESKTOP_FILE
# This will be set to "unconfined" by desktop-exec if there is no confinement defined
apparmor switch $APP_EXEC_POLICY
pre-start script
if pgrep -u system surfaceflinger ; then
initctl set-env USING_SURFACE_FLINGER=1
fi
exec @pkglibexecdir@/desktop-exec
end script
exec @pkglibexecdir@/exec-line-exec
post-start exec @pkglibexecdir@/zg-report-app open
post-stop exec @pkglibexecdir@/zg-report-app close
upstart-app-launch-0.3+14.04.20140411/upstart-jobs/untrusted-helper.conf.in 0000644 0000153 0177776 00000001271 12322064515 026722 0 ustar pbuser nogroup 0000000 0000000 description "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 UPSTART_APP_LAUNCH_ARCH="@upstart_app_launch_arch@"
export UPSTART_APP_LAUNCH_ARCH
apparmor switch ${APP_ID}
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
upstart-app-launch-0.3+14.04.20140411/upstart-jobs/untrusted-helper-type-end.conf.in 0000644 0000153 0177776 00000000345 12322064515 030446 0 ustar pbuser nogroup 0000000 0000000 description "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
upstart-app-launch-0.3+14.04.20140411/upstart-jobs/application-failed.conf.in 0000644 0000153 0177776 00000000256 12322064515 027137 0 ustar pbuser nogroup 0000000 0000000 description "Application Failing"
start on stopped application-legacy RESULT=failed or stopped application-click RESULT=failed
task
exec @pkglibexecdir@/application-failed
upstart-app-launch-0.3+14.04.20140411/upstart-jobs/application.conf.in 0000644 0000153 0177776 00000000523 12322064515 025712 0 ustar pbuser nogroup 0000000 0000000 description "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
upstart-app-launch-0.3+14.04.20140411/upstart-jobs/CMakeLists.txt 0000644 0000153 0177776 00000005077 12322064515 024704 0 ustar pbuser nogroup 0000000 0000000
####################
# 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")
####################
# 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")
upstart-app-launch-0.3+14.04.20140411/upstart-jobs/application-click.conf.in 0000644 0000153 0177776 00000001560 12322064525 027000 0 ustar pbuser nogroup 0000000 0000000 description "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
# For Surface Flinger
env APP_DESKTOP_FILE
env APP_PROCESS_GROUP
env UPSTART_APP_LAUNCH_ARCH="@upstart_app_launch_arch@"
export UPSTART_APP_LAUNCH_ARCH
apparmor switch ${APP_ID}
pre-start script
if pgrep -u system surfaceflinger ; then
initctl set-env USING_SURFACE_FLINGER=1
fi
exec @pkglibexecdir@/click-exec
end script
# Remember, this is confined
exec @pkglibexecdir@/exec-line-exec
post-start script
initctl set-env APP_PROCESS_GROUP=`upstart-app-pid ${APP_ID}`
@pkglibexecdir@/zg-report-app open
end script
post-stop script
pkill -KILL -g "${APP_PROCESS_GROUP}" || true
@pkglibexecdir@/zg-report-app close
end script
upstart-app-launch-0.3+14.04.20140411/data/ 0000755 0000153 0177776 00000000000 12322065100 020376 5 ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/data/com.canonical.UpstartAppLaunch.xml 0000644 0000153 0177776 00000001210 12322064515 027064 0 ustar pbuser nogroup 0000000 0000000
upstart-app-launch-0.3+14.04.20140411/exec-line-exec.c 0000644 0000153 0177776 00000010326 12322064515 022437 0 ustar pbuser nogroup 0000000 0000000 /*
* 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"
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;
}
g_setenv("LTTNG_UST_REGISTER_TIMEOUT", "0", FALSE); /* Set to zero if not set */
tracepoint(upstart_app_launch, exec_start);
/* URIs */
const gchar * app_uris = g_getenv("APP_URIS");
const gchar * app_desktop = g_getenv("APP_DESKTOP_FILE");
/* 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");
gchar * path_libpath = NULL;
const gchar * path_joinable[4] = { 0 };
const gchar * import_path = g_getenv("QML2_IMPORT_PATH");
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("UPSTART_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;
/* 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;
import_joinable[0] = import_path;
}
gchar * newpath = g_strjoinv(":", (gchar**)path_joinable);
g_setenv("PATH", newpath, TRUE);
g_free(path_libpath);
g_free(newpath);
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;
}
tracepoint(upstart_app_launch, exec_parse_complete);
/* Surface flinger check */
if (g_getenv("USING_SURFACE_FLINGER") != NULL && app_desktop != NULL) {
gchar * sf = g_strdup_printf("--desktop_file_hint=%s", app_desktop);
g_array_append_val(newargv, sf);
}
/* Now exec */
gchar ** nargv = (gchar**)g_array_free(newargv, FALSE);
tracepoint(upstart_app_launch, exec_pre_exec);
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;
}
upstart-app-launch-0.3+14.04.20140411/application-failed.c 0000644 0000153 0177776 00000003770 12322064515 023376 0 ustar pbuser nogroup 0000000 0000000
/*
* 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.UpstartAppLaunch",
"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;
}
upstart-app-launch-0.3+14.04.20140411/helpers.h 0000644 0000153 0177776 00000003602 12322064515 021312 0 ustar pbuser nogroup 0000000 0000000 /*
* 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 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);
void set_upstart_variable (const gchar * variable,
const gchar * value,
gboolean sync);
GArray * desktop_exec_parse (const gchar * execline,
const gchar * uri_list);
GKeyFile * keyfile_for_appid (const gchar * appid,
gchar * * desktopfile);
void set_confined_envvars (const gchar * package,
const gchar * app_dir);
typedef struct _handshake_t handshake_t;
handshake_t * starting_handshake_start (const gchar * app_id);
void starting_handshake_wait (handshake_t * handshake);
upstart-app-launch-0.3+14.04.20140411/untrusted-helper-type-end.c 0000644 0000153 0177776 00000003677 12322064515 024714 0 ustar pbuser nogroup 0000000 0000000 /*
* 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 "libupstart-app-launch/upstart-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 = upstart_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 = upstart_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 (!upstart_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 (!upstart_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;
}
upstart-app-launch-0.3+14.04.20140411/libupstart-app-launch/ 0000755 0000153 0177776 00000000000 12322065100 023704 5 ustar pbuser nogroup 0000000 0000000 upstart-app-launch-0.3+14.04.20140411/libupstart-app-launch/second-exec-core.h 0000644 0000153 0177776 00000001436 12322064515 027215 0 ustar pbuser nogroup 0000000 0000000
/*
* 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);
upstart-app-launch-0.3+14.04.20140411/libupstart-app-launch/upstart-app-launch.c 0000644 0000153 0177776 00000137660 12322064515 027626 0 ustar pbuser nogroup 0000000 0000000 /*
* 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 "upstart-app-launch.h"
#include
#include
#include
#include
#include
#include "upstart-app-launch-trace.h"
#include "second-exec-core.h"
#include "../helpers.h"
static void apps_for_job (GDBusConnection * con, const gchar * name, GArray * apps, gboolean truncate_legacy);
static void free_helper (gpointer value);
/* 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;
tracepoint(upstart_app_launch, 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("upstart-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)
{
tracepoint(upstart_app_launch, 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;
}
tracepoint(upstart_app_launch, 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);
tracepoint(upstart_app_launch, 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("UPSTART_APP_LAUNCH_LINK_FARM");
if (G_LIKELY(link_farm_dir == NULL)) {
click_link = g_build_filename(g_get_home_dir(), ".cache", "upstart-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;
}
static gboolean
start_application_core (const gchar * appid, const gchar * const * uris, gboolean test)
{
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);
tracepoint(upstart_app_launch, libual_determine_type, appid, click ? "click" : "legacy");
/* 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)
return FALSE;
tracepoint(upstart_app_launch, 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)));
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 (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"));
}
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);
tracepoint(upstart_app_launch, libual_start_message_sent, appid);
g_object_unref(con);
return TRUE;
}
gboolean
upstart_app_launch_start_application (const gchar * appid, const gchar * const * uris)
{
return start_application_core(appid, uris, FALSE);
}
gboolean
upstart_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
upstart_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;
}
gchar *
upstart_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 (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;
}
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;
upstart_app_launch_app_observer_t 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;
upstart_app_launch_app_failed_observer_t func;
gpointer user_data;
};
/* 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 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);
tracepoint(upstart_app_launch, 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);
}
tracepoint(upstart_app_launch, 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 (upstart_app_launch_app_observer_t 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
upstart_app_launch_observer_add_app_started (upstart_app_launch_app_observer_t observer, gpointer user_data)
{
return add_app_generic(observer, user_data, "started", &started_array);
}
gboolean
upstart_app_launch_observer_add_app_stop (upstart_app_launch_app_observer_t 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 (upstart_app_launch_app_observer_t 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.UpstartAppLaunch", /* interface */
signal, /* signal */
"/", /* path */
NULL, /* arg0 */
G_DBUS_SIGNAL_FLAGS_NONE,
session_cb,
observert,
NULL); /* user data destroy */
return TRUE;
}
/* 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)
{
observer_t * observer = (observer_t *)user_data;
const gchar * appid = NULL;
tracepoint(upstart_app_launch, observer_start, "focus");
if (observer->func != NULL) {
g_variant_get(params, "(&s)", &appid);
observer->func(appid, observer->user_data);
}
tracepoint(upstart_app_launch, observer_finish, "focus");
}
gboolean
upstart_app_launch_observer_add_app_focus (upstart_app_launch_app_observer_t 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)
{
tracepoint(upstart_app_launch, observer_start, "resume");
focus_signal_cb(conn, sender, object, interface, signal, params, user_data);
GError * error = NULL;
g_dbus_connection_emit_signal(conn,
sender, /* destination */
"/", /* path */
"com.canonical.UpstartAppLaunch", /* 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);
}
tracepoint(upstart_app_launch, observer_finish, "resume");
}
gboolean
upstart_app_launch_observer_add_app_resume (upstart_app_launch_app_observer_t 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)
{
tracepoint(upstart_app_launch, observer_start, "starting");
focus_signal_cb(conn, sender, object, interface, signal, params, user_data);
GError * error = NULL;
g_dbus_connection_emit_signal(conn,
sender, /* destination */
"/", /* path */
"com.canonical.UpstartAppLaunch", /* 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);
}
tracepoint(upstart_app_launch, observer_finish, "starting");
}
gboolean
upstart_app_launch_observer_add_app_starting (upstart_app_launch_app_observer_t 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;
tracepoint(upstart_app_launch, observer_start, "failed");
if (observer->func != NULL) {
upstart_app_launch_app_failed_t type = UPSTART_APP_LAUNCH_APP_FAILED_CRASH;
g_variant_get(params, "(&s&s)", &appid, &typestr);
if (g_strcmp0("crash", typestr) == 0) {
type = UPSTART_APP_LAUNCH_APP_FAILED_CRASH;
} else if (g_strcmp0("start-failure", typestr) == 0) {
type = UPSTART_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);
}
tracepoint(upstart_app_launch, observer_finish, "failed");
}
gboolean
upstart_app_launch_observer_add_app_failed (upstart_app_launch_app_failed_observer_t 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.UpstartAppLaunch", /* interface */
"ApplicationFailed", /* signal */
"/", /* path */
NULL, /* arg0 */
G_DBUS_SIGNAL_FLAGS_NONE,
failed_signal_cb,
observert,
NULL); /* user data destroy */
return TRUE;
}
static gboolean
delete_app_generic (upstart_app_launch_app_observer_t 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
upstart_app_launch_observer_delete_app_started (upstart_app_launch_app_observer_t observer, gpointer user_data)
{
return delete_app_generic(observer, user_data, &started_array);
}
gboolean
upstart_app_launch_observer_delete_app_stop (upstart_app_launch_app_observer_t observer, gpointer user_data)
{
return delete_app_generic(observer, user_data, &stop_array);
}
gboolean
upstart_app_launch_observer_delete_app_resume (upstart_app_launch_app_observer_t observer, gpointer user_data)
{
return delete_app_generic(observer, user_data, &resume_array);
}
gboolean
upstart_app_launch_observer_delete_app_focus (upstart_app_launch_app_observer_t observer, gpointer user_data)
{
return delete_app_generic(observer, user_data, &focus_array);
}
gboolean
upstart_app_launch_observer_delete_app_starting (upstart_app_launch_app_observer_t observer, gpointer user_data)
{
return delete_app_generic(observer, user_data, &starting_array);
}
gboolean
upstart_app_launch_observer_delete_app_failed (upstart_app_launch_app_failed_observer_t 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;
}
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 **
upstart_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
upstart_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;
}
gboolean
upstart_app_launch_pid_in_app_id (GPid pid, const gchar * appid)
{
g_return_val_if_fail(appid != NULL, FALSE);
if (pid == 0) {
return FALSE;
}
GPid primary = upstart_app_launch_get_primary_pid(appid);
return primary == pid;
}
gboolean
upstart_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;
}
/* Try and get a manifest and do a couple sanity checks on it */
static JsonObject *
get_manifest (const gchar * pkg)
{
/* 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);
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;
}
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);
}
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);
}
g_return_val_if_fail(*manifest != NULL, NULL);
return g_strdup(json_object_get_string_member(*manifest, "version"));
}
return NULL;
}
gchar *
upstart_app_launch_triplet_to_app_id (const gchar * pkg, const gchar * app, const gchar * ver)
{
g_return_val_if_fail(pkg != NULL, NULL);
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;
}
/* 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)
{
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)));
}
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
upstart_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);
}
gchar *
upstart_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)) {
return instanceid;
}
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
upstart_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
upstart_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 **
upstart_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 **
upstart_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;
UpstartAppLaunchHelperObserver 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 (UpstartAppLaunchHelperObserver 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 (UpstartAppLaunchHelperObserver 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
upstart_app_launch_observer_add_helper_started (UpstartAppLaunchHelperObserver 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
upstart_app_launch_observer_add_helper_stop (UpstartAppLaunchHelperObserver 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
upstart_app_launch_observer_delete_helper_started (UpstartAppLaunchHelperObserver 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
upstart_app_launch_observer_delete_helper_stop (UpstartAppLaunchHelperObserver 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);
}
upstart-app-launch-0.3+14.04.20140411/libupstart-app-launch/second-exec-core.c 0000644 0000153 0177776 00000031564 12322064515 027215 0 ustar pbuser nogroup 0000000 0000000 /*
* 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 "libupstart-app-launch/upstart-app-launch.h"
#include "helpers.h"
#include "second-exec-core.h"
#include "upstart-app-launch-trace.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)
{
tracepoint(upstart_app_launch, 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)
{
tracepoint(upstart_app_launch, 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");
tracepoint(upstart_app_launch, 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;
tracepoint(upstart_app_launch, second_exec_app_contacted, ((second_exec_t *)user_data)->appid);
g_dbus_connection_call_finish(G_DBUS_CONNECTION(object), res, &error);
if (error != NULL) {
tracepoint(upstart_app_launch, 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)
{
tracepoint(upstart_app_launch, 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;
tracepoint(upstart_app_launch, 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");
tracepoint(upstart_app_launch, 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 = upstart_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);
tracepoint(upstart_app_launch, 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);
tracepoint(upstart_app_launch, 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)
{
tracepoint(upstart_app_launch, 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.UpstartAppLaunch", /* 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");
tracepoint(upstart_app_launch, second_exec_emit_resume, app_id);
/* Send unfreeze to to Unity */
g_dbus_connection_emit_signal(session,
NULL, /* destination */
"/", /* path */
"com.canonical.UpstartAppLaunch", /* 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;
tracepoint(upstart_app_launch, 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.UpstartAppLaunch", /* 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;
}
tracepoint(upstart_app_launch, 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;
}
upstart-app-launch-0.3+14.04.20140411/libupstart-app-launch/upstart-app-launch.h 0000644 0000153 0177776 00000051637 12322064515 027632 0 ustar pbuser nogroup 0000000 0000000 /*
* 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
#ifndef __UPSTART_APP_LAUNCH_H__
#define __UPSTART_APP_LAUNCH_H__ 1
#pragma GCC visibility push(default)
#ifdef __cplusplus
extern "C" {
#endif
/**
* UpstartAppLaunchAppFailed:
*
* Types of failure that we report.
*/
typedef enum { /*< prefix=UPSTART_APP_LAUNCH_APP_FAILED */
UPSTART_APP_LAUNCH_APP_FAILED_CRASH, /*< nick=crash */
UPSTART_APP_LAUNCH_APP_FAILED_START_FAILURE, /*< nick=start-failure */
} UpstartAppLaunchAppFailed;
typedef UpstartAppLaunchAppFailed upstart_app_launch_app_failed_t;
/**
* UpstartAppLaunchAppObserver:
*
* Function prototype for application observers.
*/
typedef void (*UpstartAppLaunchAppObserver) (const gchar * appid, gpointer user_data);
/* Backwards compatible. Drop when making API bump. */
typedef UpstartAppLaunchAppObserver upstart_app_launch_app_observer_t;
/**
* UpstartAppLaunchAppFailedObserver:
*
* Function prototype for application failed observers.
*/
typedef void (*UpstartAppLaunchAppFailedObserver) (const gchar * appid, UpstartAppLaunchAppFailed failure_type, gpointer user_data);
/* Backwards compatible. Drop when making API bump. */
typedef UpstartAppLaunchAppFailedObserver upstart_app_launch_app_failed_observer_t;
/**
* UpstartAppLaunchHelperObserver:
*
* Function to watch for helpers that are starting and stopping
*/
typedef void (*UpstartAppLaunchHelperObserver) (const gchar * appid, const gchar * instanceid, const gchar * helpertype, gpointer user_data);
/**
* upstart_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 upstart_app_launch_start_application (const gchar * appid,
const gchar * const * uris);
/**
* upstart_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 upstart_app_launch_start_application_test (const gchar * appid,
const gchar * const * uris);
/**
* upstart_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 Upstart to stop the process,
* used upstart_app_launch_observer_add_app_stop() to know when it is
* finally stopped.
*/
gboolean upstart_app_launch_stop_application (const gchar * appid);
/**
* upstart_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 * upstart_app_launch_application_log_path (const gchar * appid);
/**
* upstart_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 upstart_app_launch_observer_add_app_starting (UpstartAppLaunchAppObserver observer,
gpointer user_data);
/**
* upstart_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 upstart_app_launch_observer_add_app_started (UpstartAppLaunchAppObserver observer,
gpointer user_data);
/**
* upstart_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 upstart_app_launch_observer_add_app_stop (UpstartAppLaunchAppObserver observer,
gpointer user_data);
/**
* upstart_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 upstart_app_launch_observer_add_app_focus (UpstartAppLaunchAppObserver observer,
gpointer user_data);
/**
* upstart_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 upstart_app_launch_observer_add_app_resume (UpstartAppLaunchAppObserver observer,
gpointer user_data);
/**
* upstart_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 upstart_app_launch_observer_add_app_failed (UpstartAppLaunchAppFailedObserver observer,
gpointer user_data);
/**
* upstart_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 upstart_app_launch_observer_delete_app_starting (UpstartAppLaunchAppObserver observer,
gpointer user_data);
/**
* upstart_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 upstart_app_launch_observer_delete_app_started (UpstartAppLaunchAppObserver observer,
gpointer user_data);
/**
* upstart_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 upstart_app_launch_observer_delete_app_stop (UpstartAppLaunchAppObserver observer,
gpointer user_data);
/**
* upstart_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 upstart_app_launch_observer_delete_app_focus (UpstartAppLaunchAppObserver observer,
gpointer user_data);
/**
* upstart_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 upstart_app_launch_observer_delete_app_resume (UpstartAppLaunchAppObserver observer,
gpointer user_data);
/**
* upstart_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 upstart_app_launch_observer_delete_app_failed (UpstartAppLaunchAppFailedObserver observer,
gpointer user_data);
/**
* upstart_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 ** upstart_app_launch_list_running_apps (void);
/**
* upstart_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 upstart_app_launch_get_primary_pid (const gchar * appid);
/**
* upstart_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 upstart_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 upstart_app_launch_pid_in_app_id (GPid pid,
const gchar * appid);
/**
* upstart_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 * upstart_app_launch_triplet_to_app_id (const gchar * pkg,
const gchar * app,
const gchar * version);
/**
* upstart_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 upstart_app_launch_app_id_parse (const gchar * appid,
gchar ** package,
gchar ** application,
gchar ** version);
/**
* upstart_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 upstart_app_launch_start_helper (const gchar * type,
const gchar * appid,
const gchar * const * uris);
/**
* upstart_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 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 that helper type. This function is different
* from @upstart_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 * upstart_app_launch_start_multiple_helper (const gchar * type,
const gchar * appid,
const gchar * const * uris);
/**
* upstart_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 upstart_app_launch_stop_helper (const gchar * type,
const gchar * appid);
/**
* upstart_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 upstart_app_launch_stop_multiple_helper (const gchar * type,
const gchar * appid,
const gchar * instanceid);
/**
* upstart_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 ** upstart_app_launch_list_helpers (const gchar * type);
/**
* upstart_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 ** upstart_app_launch_list_helper_instances (const gchar * type,
const gchar * appid);
/**
* upstart_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 upstart_app_launch_observer_add_helper_started (UpstartAppLaunchHelperObserver observer,
const gchar * helper_type,
gpointer user_data);
/**
* upstart_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 upstart_app_launch_observer_add_helper_stop (UpstartAppLaunchHelperObserver observer,
const gchar * helper_type,
gpointer user_data);
/**
* upstart_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 upstart_app_launch_observer_delete_helper_started (UpstartAppLaunchHelperObserver observer,
const gchar * helper_type,
gpointer user_data);
/**
* upstart_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 upstart_app_launch_observer_delete_helper_stop (UpstartAppLaunchHelperObserver observer,
const gchar * helper_type,
gpointer user_data);
#ifdef __cplusplus
}
#endif
#pragma GCC visibility pop
#endif /* __UPSTART_APP_LAUNCH_H__ */
upstart-app-launch-0.3+14.04.20140411/libupstart-app-launch/upstart-app-launch.pc.in 0000644 0000153 0177776 00000000425 12322064515 030377 0 ustar pbuser nogroup 0000000 0000000 libdir=@libdir@
includedir=@includedir@
Cflags: -I${includedir}/libupstart-app-launch-@apiversion@
Requires: glib-2.0
Libs: -L${libdir} -lupstart-app-launch
Name: libupstart-app-launch
Description: A library to manage and watch applications under Upstart
Version: @VERSION@
upstart-app-launch-0.3+14.04.20140411/libupstart-app-launch/CMakeLists.txt 0000644 0000153 0177776 00000004634 12322064515 026464 0 ustar pbuser nogroup 0000000 0000000
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 upstart-app-launch-trace)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
set(LAUNCHER_HEADERS
upstart-app-launch.h
)
set(LAUNCHER_SOURCES
upstart-app-launch.c
second-exec-core.c
upstart-app-launch-trace.c
"${CMAKE_SOURCE_DIR}/helpers-keyfile.c"
)
add_library(upstart-launcher SHARED ${LAUNCHER_SOURCES})
set_target_properties(upstart-launcher PROPERTIES
VERSION ${ABI_VERSION}.0.0
SOVERSION ${ABI_VERSION}
OUTPUT_NAME "upstart-app-launch"
)
target_link_libraries(upstart-launcher
${GLIB2_LIBARIES}
${GOBJECT2_LIBRARIES}
${LIBUPSTART_LIBRARIES}
${GIO2_LIBRARIES}
${LTTNG_LIBRARIES}
${JSONGLIB_LIBRARIES}
${CLICK_LIBRARIES}
-Wl,--no-undefined
)
install(
FILES ${LAUNCHER_HEADERS}
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/libupstart-app-launch-${API_VERSION}"
)
install(
TARGETS upstart-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("upstart-app-launch.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/upstart-app-launch-${API_VERSION}.pc" @ONLY)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/upstart-app-launch-${API_VERSION}.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
)
##########################
# Introspection
##########################
include(UseGObjectIntrospection)
set(INTROSPECTION_GIRS)
set(_introspection_files ${LAUNCHER_HEADERS})
set(UpstartAppLaunch_2_gir "upstart-app-launch")
set(UpstartAppLaunch_2_gir_INCLUDES GObject-2.0)
gir_get_cflags(_cflags)
set(UpstartAppLaunch_2_gir_CFLAGS ${c_flags})
set(UpstartAppLaunch_2_gir_LIBS upstart-app-launch)
list_make_absolute(_abs_introspection_files _introspection_files "${CMAKE_CURRENT_SOURCE_DIR}/")
set(UpstartAppLaunch_2_gir_FILES ${_abs_introspection_files})
set(UpstartAppLaunch_2_gir_SCANNERFLAGS --c-include "upstart-app-launch.h")
set(UpstartAppLaunch_2_gir_EXPORT_PACKAGES "upstart-app-launch-${API_VERSION}")
list(APPEND INTROSPECTION_GIRS UpstartAppLaunch-2.gir)
gir_add_introspections(INTROSPECTION_GIRS)
upstart-app-launch-0.3+14.04.20140411/libupstart-app-launch/upstart-app-launch-trace.tp 0000644 0000153 0177776 00000007671 12322064515 031121 0 ustar pbuser nogroup 0000000 0000000
/*******************************
LibUAL start function
*******************************/
TRACEPOINT_EVENT(upstart_app_launch, libual_start,
TP_ARGS(const char *, appid),
TP_FIELDS(
ctf_string(appid, appid)
)
)
TRACEPOINT_EVENT(upstart_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(upstart_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(upstart_app_launch, libual_start_message_sent,
TP_ARGS(const char *, appid),
TP_FIELDS(
ctf_string(appid, appid)
)
)
TRACEPOINT_EVENT(upstart_app_launch, libual_start_message_callback,
TP_ARGS(const char *, appid),
TP_FIELDS(
ctf_string(appid, appid)
)
)
/*******************************
LibUAL observers
*******************************/
TRACEPOINT_EVENT(upstart_app_launch, observer_start,
TP_ARGS(const char *, type),
TP_FIELDS(
ctf_string(type, type)
)
)
TRACEPOINT_EVENT(upstart_app_launch, observer_finish,
TP_ARGS(const char *, type),
TP_FIELDS(
ctf_string(type, type)
)
)
/*******************************
Second Exec tracking
*******************************/
TRACEPOINT_EVENT(upstart_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(upstart_app_launch, second_exec_emit_resume,
TP_ARGS(const char *, appid),
TP_FIELDS(
ctf_string(appid, appid)
)
)
TRACEPOINT_EVENT(upstart_app_launch, second_exec_resume_complete,
TP_ARGS(const char *, appid),
TP_FIELDS(
ctf_string(appid, appid)
)
)
TRACEPOINT_EVENT(upstart_app_launch, second_exec_resume_timeout,
TP_ARGS(const char *, appid),
TP_FIELDS(
ctf_string(appid, appid)
)
)
TRACEPOINT_EVENT(upstart_app_launch, second_exec_emit_focus,
TP_ARGS(const char *, appid),
TP_FIELDS(
ctf_string(appid, appid)
)
)
TRACEPOINT_EVENT(upstart_app_launch, second_exec_finish,
TP_ARGS(const char *, appid),
TP_FIELDS(
ctf_string(appid, appid)
)
)
TRACEPOINT_EVENT(upstart_app_launch, second_exec_got_dbus_names,
TP_ARGS(const char *, appid),
TP_FIELDS(
ctf_string(appid, appid)
)
)
TRACEPOINT_EVENT(upstart_app_launch, second_exec_got_primary_pid,
TP_ARGS(const char *, appid),
TP_FIELDS(
ctf_string(appid, appid)
)
)
TRACEPOINT_EVENT(upstart_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(upstart_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(upstart_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(upstart_app_launch, second_exec_app_contacted,
TP_ARGS(const char *, appid),
TP_FIELDS(
ctf_string(appid, appid)
)
)
TRACEPOINT_EVENT(upstart_app_launch, second_exec_app_error,
TP_ARGS(const char *, appid),
TP_FIELDS(
ctf_string(appid, appid)
)
)
TRACEPOINT_EVENT(upstart_app_launch, second_exec_connection_complete,
TP_ARGS(const char *, appid),
TP_FIELDS(
ctf_string(appid, appid)
)
)
/*******************************
Desktop File Single Instance
*******************************/
TRACEPOINT_EVENT(upstart_app_launch, desktop_single_start,
TP_ARGS(const char *, appid),
TP_FIELDS(
ctf_string(appid, appid)
)
)
TRACEPOINT_EVENT(upstart_app_launch, desktop_single_found,
TP_ARGS(const char *, appid),
TP_FIELDS(
ctf_string(appid, appid)
)
)
TRACEPOINT_EVENT(upstart_app_launch, desktop_single_finished,
TP_ARGS(const char *, appid, const char *, apptype),
TP_FIELDS(
ctf_string(appid, appid)
ctf_string(apptype, apptype)
)
)
upstart-app-launch-0.3+14.04.20140411/click-exec-trace.tp 0000644 0000153 0177776 00000001227 12322064515 023150 0 ustar pbuser nogroup 0000000 0000000
TRACEPOINT_EVENT(upstart_app_launch, click_start, TP_ARGS(0), TP_FIELDS())
TRACEPOINT_EVENT(upstart_app_launch, click_starting_sent, TP_ARGS(0), TP_FIELDS())
TRACEPOINT_EVENT(upstart_app_launch, click_found_pkgdir, TP_ARGS(0), TP_FIELDS())
TRACEPOINT_EVENT(upstart_app_launch, click_configured_env, TP_ARGS(0), TP_FIELDS())
TRACEPOINT_EVENT(upstart_app_launch, click_read_manifest, TP_ARGS(0), TP_FIELDS())
TRACEPOINT_EVENT(upstart_app_launch, click_read_desktop, TP_ARGS(0), TP_FIELDS())
TRACEPOINT_EVENT(upstart_app_launch, click_handshake_wait, TP_ARGS(0), TP_FIELDS())
TRACEPOINT_EVENT(upstart_app_launch, click_handshake_complete, TP_ARGS(0), TP_FIELDS())
upstart-app-launch-0.3+14.04.20140411/CMakeLists.txt 0000644 0000153 0177776 00000013435 12322064515 022244 0 ustar pbuser nogroup 0000000 0000000 project(upstart-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}")
execute_process(COMMAND dpkg-architecture -qDEB_BUILD_MULTIARCH
OUTPUT_VARIABLE UPSTART_APP_LAUNCH_ARCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(upstart_app_launch_arch "${UPSTART_APP_LAUNCH_ARCH}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -Wno-error=unused-function")
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)
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})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -fPIC")
####################
# Helpers
####################
add_library(helpers STATIC helpers.c helpers-keyfile.c)
target_link_libraries(helpers ${GIO2_LIBRARIES} ${JSONGLIB_LIBRARIES} ${CLICK_LIBRARIES})
####################
# desktop-exec
####################
add_lttng_gen_tp(NAME desktop-exec-trace)
add_executable(desktop-exec desktop-exec.c desktop-exec-trace.c)
set_target_properties(desktop-exec PROPERTIES OUTPUT_NAME "desktop-exec")
target_link_libraries(desktop-exec helpers ${LTTNG_LIBRARIES})
install(TARGETS desktop-exec RUNTIME DESTINATION "${pkglibexecdir}")
####################
# click-exec
####################
add_lttng_gen_tp(NAME click-exec-trace)
add_executable(click-exec click-exec.c click-exec-trace.c)
set_target_properties(click-exec PROPERTIES OUTPUT_NAME "click-exec")
target_link_libraries(click-exec helpers ${LTTNG_LIBRARIES} ${CLICK_LIBRARIES})
install(TARGETS click-exec RUNTIME DESTINATION "${pkglibexecdir}")
####################
# 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 ${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 upstart-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}")
####################
# 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 upstart-launcher)
install(TARGETS untrusted-helper-type-end RUNTIME DESTINATION "${pkglibexecdir}")
####################
# upstart-app-launch-desktop.click-hook
####################
configure_file("upstart-app-launch-desktop.click-hook.in" "${CMAKE_CURRENT_SOURCE_DIR}/debian/upstart-app-launch-desktop.click-hook" @ONLY)
add_subdirectory(libupstart-app-launch)
add_subdirectory(upstart-jobs)
add_subdirectory(tools)
# 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 ()
upstart-app-launch-0.3+14.04.20140411/helpers.c 0000644 0000153 0177776 00000043613 12322064515 021313 0 ustar pbuser nogroup 0000000 0000000 /*
* 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;
}
/* Sets an upstart variable, currently using initctl */
void
set_upstart_variable (const gchar * variable, const gchar * value, gboolean sync)
{
/* 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 */
gchar * envstr = g_strdup_printf("%s=%s", variable, value);
g_variant_builder_add_value(&builder, g_variant_new_take_string(envstr));
/* Do we want to replace? Yes, we do! */
g_variant_builder_add_value(&builder, g_variant_new_boolean(TRUE));
if (sync) {
GError * error = NULL;
GVariant * reply = g_dbus_connection_call_sync(bus,
DBUS_SERVICE_UPSTART,
DBUS_PATH_UPSTART,
DBUS_INTERFACE_UPSTART,
"SetEnv",
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 variable '%s' to '%s': %s", variable, value, error->message);
g_error_free(error);
}
} else {
g_dbus_connection_call(bus,
DBUS_SERVICE_UPSTART,
DBUS_PATH_UPSTART,
DBUS_INTERFACE_UPSTART,
"SetEnv",
g_variant_builder_end(&builder),
NULL, /* reply */
G_DBUS_CALL_FLAGS_NONE,
-1, /* timeout */
NULL, /* cancelable */
NULL, NULL); /* callback */
}
g_object_unref(bus);
}
/* 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 (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'");
set_upstart_variable("UBUNTU_APPLICATION_ISOLATION", "1", FALSE);
/* 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()");
set_upstart_variable("XDG_CACHE_HOME", g_get_user_cache_dir(), FALSE);
g_debug("Setting 'XDG_CONFIG_HOME' using g_get_user_config_dir()");
set_upstart_variable("XDG_CONFIG_HOME", g_get_user_config_dir(), FALSE);
g_debug("Setting 'XDG_DATA_HOME' using g_get_user_data_dir()");
set_upstart_variable("XDG_DATA_HOME", g_get_user_data_dir(), FALSE);
g_debug("Setting 'XDG_RUNTIME_DIR' using g_get_user_runtime_dir()");
set_upstart_variable("XDG_RUNTIME_DIR", g_get_user_runtime_dir(), FALSE);
/* Add the application's dir to the list of sources for data */
gchar * datadirs = g_strjoin(":", app_dir, g_getenv("XDG_DATA_DIRS"), NULL);
set_upstart_variable("XDG_DATA_DIRS", datadirs, FALSE);
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);
set_upstart_variable("TMPDIR", tmpdir, FALSE);
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);
set_upstart_variable("__GL_SHADER_DISK_CACHE_PATH", nv_shader_cachedir, FALSE);
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.UpstartAppLaunch", /* 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.UpstartAppLaunch", /* 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);
}
upstart-app-launch-0.3+14.04.20140411/MERGE-REVIEW 0000644 0000153 0177776 00000001414 12322064515 021257 0 ustar pbuser nogroup 0000000 0000000
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: upstart-app-launch/click-app
* Run test case: upstart-app-launch/legacy-app
* Run test case: upstart-app-launch/secondary-activation
* If this MR effect untrusted-helpers:
* Run test case: upstart-app-launch/helper-run
upstart-app-launch-0.3+14.04.20140411/COPYING 0000644 0000153 0177776 00000104513 12322064515 020535 0 ustar pbuser nogroup 0000000 0000000 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
.
upstart-app-launch-0.3+14.04.20140411/exec-line-exec-trace.tp 0000644 0000153 0177776 00000000353 12322064515 023733 0 ustar pbuser nogroup 0000000 0000000
TRACEPOINT_EVENT(upstart_app_launch, exec_start, TP_ARGS(0), TP_FIELDS())
TRACEPOINT_EVENT(upstart_app_launch, exec_parse_complete, TP_ARGS(0), TP_FIELDS())
TRACEPOINT_EVENT(upstart_app_launch, exec_pre_exec, TP_ARGS(0), TP_FIELDS())
upstart-app-launch-0.3+14.04.20140411/click-exec.c 0000644 0000153 0177776 00000013054 12322064515 021654 0 ustar pbuser nogroup 0000000 0000000 /*
* 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 "click-exec-trace.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/
*/
int
main (int argc, char * argv[])
{
if (argc != 1 && argc != 3) {
g_error("Should be called as: %s", argv[0]);
return 1;
}
const gchar * app_id = g_getenv("APP_ID");
if (app_id == NULL) {
g_error("No APP ID defined");
return 1;
}
tracepoint(upstart_app_launch, click_start);
/* Ensure we keep one connection open to the bus for the entire
script even though different people need it throughout */
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;
}
handshake_t * handshake = starting_handshake_start(app_id);
if (handshake == NULL) {
g_warning("Unable to setup starting handshake");
}
tracepoint(upstart_app_launch, click_starting_sent);
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 1;
}
/* 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 1;
}
/* 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 1;
}
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 1;
}
g_object_unref(user);
g_object_unref(db);
tracepoint(upstart_app_launch, click_found_pkgdir);
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 1;
}
g_debug("Setting 'APP_DIR' to '%s'", pkgdir);
set_upstart_variable("APP_DIR", pkgdir, FALSE);
set_confined_envvars(package, pkgdir);
tracepoint(upstart_app_launch, click_configured_env);
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 1;
}
tracepoint(upstart_app_launch, click_read_manifest);
GKeyFile * keyfile = g_key_file_new();
set_upstart_variable("APP_DESKTOP_FILE_PATH", desktopfile, FALSE);
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 1;
}
/* 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 1;
}
tracepoint(upstart_app_launch, click_read_desktop);
/* TODO: This is for Surface Flinger, when we drop support we can drop this */
gchar * userdesktopfile = g_strdup_printf("%s.desktop", app_id);
gchar * userdesktoppath = g_build_filename(g_get_home_dir(), ".local", "share", "applications", userdesktopfile, NULL);
set_upstart_variable("APP_DESKTOP_FILE", userdesktoppath, FALSE);
g_free(userdesktopfile);
g_free(userdesktoppath);
g_debug("Setting 'APP_EXEC' to '%s'", exec);
/* NOTE: This should be the last upstart variable set as it is sync
so it will wait for a reply from Upstart implying that Upstart
has seen all the other variable requests we made */
set_upstart_variable("APP_EXEC", exec, TRUE);
g_free(exec);
g_key_file_unref(keyfile);
g_free(desktopfile);
tracepoint(upstart_app_launch, click_handshake_wait);
starting_handshake_wait(handshake);
tracepoint(upstart_app_launch, click_handshake_complete);
g_object_unref(bus);
return 0;
}
upstart-app-launch-0.3+14.04.20140411/zg-report-app.c 0000644 0000153 0177776 00000005410 12322064515 022351 0 ustar pbuser nogroup 0000000 0000000 /*
* 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
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_error("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 = g_strdup_printf("application://%s.desktop", appid);
ZeitgeistLog * log = zeitgeist_log_get_default();
ZeitgeistEvent * event = zeitgeist_event_new();
zeitgeist_event_set_actor(event, "application://upstart-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;
}
upstart-app-launch-0.3+14.04.20140411/helpers-keyfile.c 0000644 0000153 0177776 00000005270 12322064515 022736 0 ustar pbuser nogroup 0000000 0000000 /*
* 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"
/* Check to make sure we have the sections and keys we want */
static 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;
}