diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/CMakeLists.txt | 11 | ||||
| -rwxr-xr-x | tools/compiz-profile-selector.in | 19 | ||||
| -rw-r--r-- | tools/systemd-prestart-check | 29 | ||||
| -rwxr-xr-x | tools/unity-compiz-profile-select.in | 25 | ||||
| -rwxr-xr-x | tools/unity.cmake | 80 | ||||
| -rw-r--r-- | tools/upstart-prestart-check | 17 |
6 files changed, 135 insertions, 46 deletions
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index cd2eb0c91..a9a5bc283 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,7 +1,7 @@ # # Some unity tools # -install(FILES makebootchart.py PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE DESTINATION ${CMAKE_INSTALL_LIBDIR}/unity) +install(FILES makebootchart.py PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE DESTINATION ${UNITY_INSTALL_LIBDIR}) configure_file (${CMAKE_CURRENT_SOURCE_DIR}/unity.cmake ${CMAKE_BINARY_DIR}/bin/unity) install(FILES ${CMAKE_BINARY_DIR}/bin/unity PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ @@ -27,7 +27,10 @@ link_directories(${LIB_PATHS}) add_executable(unity-active-plugins-safety-check unity_active_plugins_safety_check.cpp) target_link_libraries(unity-active-plugins-safety-check ${LIBS}) -install(TARGETS unity-active-plugins-safety-check DESTINATION ${CMAKE_INSTALL_LIBDIR}/unity/) +install(TARGETS unity-active-plugins-safety-check DESTINATION ${UNITY_INSTALL_LIBDIR}) -configure_file (${CMAKE_CURRENT_SOURCE_DIR}/unity-compiz-profile-select.in ${CMAKE_CURRENT_BINARY_DIR}/unity-compiz-profile-select @ONLY) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/unity-compiz-profile-select DESTINATION ${CMAKE_INSTALL_LIBDIR}/unity/) +configure_file (${CMAKE_CURRENT_SOURCE_DIR}/compiz-profile-selector.in ${CMAKE_CURRENT_BINARY_DIR}/compiz-profile-selector @ONLY) +install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/compiz-profile-selector DESTINATION ${UNITY_INSTALL_LIBDIR}) + +install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/systemd-prestart-check DESTINATION ${UNITY_INSTALL_LIBDIR}) +install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/upstart-prestart-check DESTINATION ${UNITY_INSTALL_LIBDIR}) diff --git a/tools/compiz-profile-selector.in b/tools/compiz-profile-selector.in new file mode 100755 index 000000000..8041f109b --- /dev/null +++ b/tools/compiz-profile-selector.in @@ -0,0 +1,19 @@ +#!/bin/bash + +set -e +compiz_profile="ubuntu" + +if ! /usr/lib/nux/unity_support_test -p; then + compiz_profile="ubuntu-lowgfx" +fi + +echo "Using compiz profile '$compiz_profile'" + +if [ -n "$UPSTART_SESSION" ]; then + initctl set-env -g COMPIZ_CONFIG_PROFILE="$compiz_profile" +fi + +dbus-update-activation-environment --verbose --systemd COMPIZ_CONFIG_PROFILE="$compiz_profile" + +export COMPIZ_CONFIG_PROFILE="$compiz_profile" +exec @UNITY_LIBDIR@/unity-active-plugins-safety-check diff --git a/tools/systemd-prestart-check b/tools/systemd-prestart-check new file mode 100644 index 000000000..191ff4f10 --- /dev/null +++ b/tools/systemd-prestart-check @@ -0,0 +1,29 @@ +#!/bin/bash + +this_unit=$(sed -n "s,.*:name=systemd:.*/\([^/]\+\.service\)/\?.*,\1,p" /proc/self/cgroup) + +if [ -n "$this_unit" ] && [[ $this_unit == "unity"* ]]; then + this_job=$(systemctl --user list-jobs $this_unit | sed -n "s,\([0-9]\+\)\s\+${this_unit//./\\.}.*,\1,p") +fi + +# If gnome-session is going to start compiz, +# we don't want to be the ones doing it. +if grep -q compiz /usr/share/gnome-session/sessions/ubuntu.session; then + echo "GNOME Session is starting Compiz" + [ -n "$this_job" ] && systemctl --user cancel $this_job + exit 1 +fi + +if [ -z "$UPSTART_SESSION" ]; then + exit 0 +fi + +upstart_status=$(initctl status unity7) || true + +if (echo "$upstart_status" | grep -q "start/running"); then + echo "Unity is managed by Upstart" + [ -n "$this_job" ] && systemctl --user cancel $this_job + exit 1 +fi + +exit 0 diff --git a/tools/unity-compiz-profile-select.in b/tools/unity-compiz-profile-select.in deleted file mode 100755 index e3ab7e59c..000000000 --- a/tools/unity-compiz-profile-select.in +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -set -e - -# If gnome-session is going to start compiz, -# we don't want to be the ones doing it. - -if grep -q compiz /usr/share/gnome-session/sessions/ubuntu.session ; then - echo "GNOME Session is starting Compiz" - stop ; exit 0 -fi - -compiz_profile="ubuntu" - -if ! /usr/lib/nux/unity_support_test -p; then - compiz_profile="ubuntu-lowgfx" -fi - -echo "Using compiz profile '$compiz_profile'" - -initctl set-env -g COMPIZ_CONFIG_PROFILE="$compiz_profile" -systemctl set-environment --user COMPIZ_CONFIG_PROFILE="$compiz_profile" - -export COMPIZ_CONFIG_PROFILE="$compiz_profile" -exec @CMAKE_INSTALL_LIBDIR@/unity/unity-active-plugins-safety-check diff --git a/tools/unity.cmake b/tools/unity.cmake index 7be8f7d14..72f646a40 100755 --- a/tools/unity.cmake +++ b/tools/unity.cmake @@ -27,6 +27,7 @@ import signal import subprocess import sys import time +import xdg.BaseDirectory DEFAULT_COMMAND = "compiz --replace" home_dir = os.path.expanduser("~%s" % os.getenv("SUDO_USER")) @@ -74,8 +75,49 @@ def reset_launcher_icons (): '''Reset the default launcher icon and restart it.''' subprocess.Popen(["gsettings", "reset" ,"com.canonical.Unity.Launcher" , "favorites"]) +def call_silently(cmd): + return subprocess.call(cmd.split(), stdout=open(os.devnull, 'w'), stderr=subprocess.STDOUT) == 0 + +def session_manager_command(service, what): + if is_systemd_session() and not is_running_in_upstart(service): + return "systemctl --user {} {}.service".format(what, service) + elif is_upstart_session(): + return "{} {}".format(what, service) + def is_upstart_session(): - return 'UPSTART_SESSION' in os.environ.keys() and len(os.environ['UPSTART_SESSION']) + return 'UPSTART_SESSION' in os.environ.keys() and len(os.environ['UPSTART_SESSION']) + +def is_running_in_upstart(service): + return is_upstart_session() and b'start/running' in subprocess.check_output("status {}".format(service).split()) + +def is_unity_running_in_upstart(): + return is_running_in_upstart("unity7") + +def is_systemd_session(): + try: + return os.path.exists(os.path.join(xdg.BaseDirectory.get_runtime_dir(), "systemd")) + except: + return False + +def is_unity_running_in_systemd(): + return is_systemd_session() and not is_unity_running_in_upstart() and \ + call_silently(session_manager_command("unity7", "is-active")) + +def is_unity_running_in_session_manager(): + return is_unity_running_in_systemd() or is_unity_running_in_upstart() + +def start_with_session_manager(): + return subprocess.Popen(session_manager_command("unity7", "start").split()) + +def restart_with_session_manager(): + if is_unity_running_in_session_manager(): + return subprocess.Popen(session_manager_command("unity7", "restart").split()) + return start_with_session_manager() + +def stop_with_session_manager(): + if is_unity_running_in_session_manager(): + return call_silently(session_manager_command("unity7", "stop")) + return False def process_and_start_unity (compiz_args): '''launch unity under compiz (replace the current shell in any case)''' @@ -108,9 +150,14 @@ def process_and_start_unity (compiz_args): if options.log: cli.extend(['2>&1', '|', 'tee', options.log]) - if is_upstart_session(): - if b'start/running' in subprocess.check_output("status unity7".split()): - subprocess.call("stop unity7".split()) + run_command = " ".join(cli) + + if run_command == DEFAULT_COMMAND and not options.ignore_session_manager and \ + (is_upstart_session() or is_systemd_session()): + return restart_with_session_manager() + + if is_unity_running_in_upstart(): + stop_with_session_manager() # kill a previous compiz if was there (this is a hack as compiz can # sometimes get stuck and not exit on --replace) @@ -128,15 +175,10 @@ def process_and_start_unity (compiz_args): except IOError: continue - run_command = " ".join(cli) - - if is_upstart_session() and run_command == DEFAULT_COMMAND and not options.ignore_upstart: - return subprocess.Popen("start unity7".split()) - else: - # shell = True as it's the simpest way to | tee. - # In this case, we need a string and not a list - # FIXME: still some bug with 2>&1 not showing everything before wait() - return subprocess.Popen(" ".join(cli), env=dict(os.environ), shell=True) + # shell = True as it's the simpest way to | tee. + # In this case, we need a string and not a list + # FIXME: still some bug with 2>&1 not showing everything before wait() + return subprocess.Popen(run_command, env=dict(os.environ), shell=True) def run_unity (compiz_args): @@ -144,9 +186,9 @@ def run_unity (compiz_args): try: options.debug_mode = 2 if options.advanced_debug else 1 if options.debug else 0 - if is_upstart_session(): subprocess.call(["stop", "unity-panel-service"]) + session_manager_command("unity-panel-service", "stop") unity_instance = process_and_start_unity (compiz_args) - if is_upstart_session(): subprocess.call(["start", "unity-panel-service"]) + session_manager_command("unity-panel-service", "start") unity_instance.wait() except KeyboardInterrupt as e: try: @@ -199,8 +241,12 @@ if __name__ == '__main__': help="Store log under filename.") parser.add_option("--replace", action="store_true", help="Run unity /!\ This is for compatibility with other desktop interfaces and acts the same as running unity without --replace") - parser.add_option("--ignore-upstart", action="store_true", - help="Run unity without upstart support") + if is_systemd_session() and not is_unity_running_in_upstart(): + parser.add_option("--ignore-systemd", action="store_true", dest="ignore_session_manager", + help="Run unity without systemd support") + elif is_upstart_session(): + parser.add_option("--ignore-upstart", action="store_true", dest="ignore_session_manager", + help="Run unity without upstart support") parser.add_option("--reset", action="store_true", help="(deprecated: provided for backwards compatibility)") parser.add_option("--reset-icons", action="store_true", diff --git a/tools/upstart-prestart-check b/tools/upstart-prestart-check new file mode 100644 index 000000000..e846c4769 --- /dev/null +++ b/tools/upstart-prestart-check @@ -0,0 +1,17 @@ +#!/bin/bash + +# If gnome-session is going to start compiz, +# we don't want to be the ones doing it. +if grep -q compiz /usr/share/gnome-session/sessions/ubuntu.session ; then + echo "GNOME Session is starting Compiz" + stop + exit 1 +fi + +if (systemctl --user is-active unity7 &> /dev/null); then + echo "Unity instance is managed by Systemd, ignoring request..." + stop + exit 1 +fi + +exit 0 |
