diff --git a/Makefile.am b/Makefile.am index 4edcd82b..549d2a1a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -34,7 +34,8 @@ CLEANFILES = $(bin_SCRIPTS) $(DESKTOP_IN_FILES) $(polkit_action_in_FILES) do_subst = sed -e 's,[@]sbindir[@],$(sbindir),g' \ -e 's,[@]bindir[@],$(bindir),g' \ - -e 's,[@]gksuprog[@],$(GKSUPROG),g' + -e 's,[@]gksuprog[@],$(GKSUPROG),g' \ + -e 's,[@]enable_xhost_root[@],$(ENABLE_XHOST_ROOT),g' gparted.desktop.in: gparted.desktop.in.in Makefile $(do_subst) < $(srcdir)/gparted.desktop.in.in > gparted.desktop.in diff --git a/README b/README index 374073fd..d3398b1f 100644 --- a/README +++ b/README @@ -145,6 +145,11 @@ b. Building from Source specifically enabled with the --enable-online-resize flag: E.g., ./configure --enable-online-resize + If you wish to build GParted to allow it to use xhost to grant root + access to the X11 server use the --enable-xhost-root flag. This is + required to allow GParted to display under Wayland. + ./configure --enable-xhost-root + Please note that more than one configure flag can be used: E.g., ./configure --disable-doc --enable-libparted-dmraid @@ -332,4 +337,6 @@ system. These commands include: udevinfo - used in dmraid to query udev name udevadm - used in dmraid to query udev name yelp - used to display help manual + xhost - used to grant root access to the X11 server, only + when configured to do so diff --git a/configure.ac b/configure.ac index 7d31f07e..e22034f6 100644 --- a/configure.ac +++ b/configure.ac @@ -392,6 +392,25 @@ else fi +dnl Check whether to explicitly grant root access to the display. +AC_ARG_ENABLE( + [xhost-root], + AS_HELP_STRING( + [--enable-xhost-root], + [enable explicitly granting root access to the display @<:@default=disabled@:>@]), + [enable_xhost_root=$enableval], + [enable_xhost_root=no] +) + +AC_MSG_CHECKING([whether to explicitly grant root access to the display]) +if test "x$enable_xhost_root" = 'xyes'; then + AC_MSG_RESULT([yes]) +else + AC_MSG_RESULT([no]) +fi +AC_SUBST([ENABLE_XHOST_ROOT], $enable_xhost_root) + + AC_CONFIG_FILES([ Makefile compose/Makefile @@ -422,6 +441,8 @@ echo " Build help documentation? : $enable_doc" echo "" echo " Use native libparted dmraid support? : $enable_libparted_dmraid" echo "" +echo " Explicitly grant root access to the display? : $enable_xhost_root" +echo "" echo " --- Features Based On Libparted Version ---" echo " Need delete old partitions before" echo " creating a loop table workaround? : $need_loop_delete_old_ptns_workaround" diff --git a/gparted.in b/gparted.in index 4eb63005..9ff05126 100755 --- a/gparted.in +++ b/gparted.in @@ -56,8 +56,35 @@ if test "x`id -u`" != "x0"; then exit 1 fi + # + # Interim workaround to allow GParted run by root access to the + # X11 display server under Wayland. If configured with + # './configure --enable-xhost-root', the xhost command is + # available and root has not been granted access to the X11 + # display via xhost, then grant access. + # + ENABLE_XHOST_ROOT=@enable_xhost_root@ + GRANTED_XHOST_ROOT=no + if test "x$ENABLE_XHOST_ROOT" = 'xyes' && xhost 1> /dev/null 2>&1; then + if ! xhost | grep -qi 'SI:localuser:root$'; then + xhost +SI:localuser:root + GRANTED_XHOST_ROOT=yes + fi + fi + + # + # Run gparted as root. + # @gksuprog@ '@bindir@/gparted' "$@" - exit $? + status=$? + + # + # Revoke root access to the X11 display, only if we granted it. + # + if test "x$GRANTED_XHOST_ROOT" = 'xyes'; then + xhost -SI:localuser:root + fi + exit $status fi #