From 4c109df9b59e55699bd42023cf4007ee359793e9 Mon Sep 17 00:00:00 2001 From: Curtis Gedak Date: Sun, 9 Jun 2013 09:46:18 -0600 Subject: [PATCH] Use systemctl runtime mask to prevent automounting (#701676) With the beta release of Fedora 19, invoking gparted appears to automatically mount partitions. The systemd daemon appears to be performing the automounting. Hence use systemctl runtime mask to prevent this automounting from occurring. Bug #701676 - gparted doesn't inhibit systemd mounting, leading to potential data loss --- gparted.in | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/gparted.in b/gparted.in index 5e09df4c..7cf8433a 100644 --- a/gparted.in +++ b/gparted.in @@ -7,7 +7,7 @@ # File system problems can occur if devices are mounted # prior to the completion of GParted's operations. # -# Copyright (C) 2008, 2009, 2010 Curtis Gedak +# Copyright (C) 2008, 2009, 2010, 2013 Curtis Gedak # # This file is part of GParted. # @@ -25,6 +25,20 @@ # along with GParted. If not, see . # +# +# Search PATH to determine if systemctl program can be found +# and if appropriate daemon is running. +# +HAVE_SYSTEMCTL=no +for k in '' `echo "$PATH" | sed 's,:, ,g'`; do + if test -x "$k/systemctl"; then + if test "z`ps -e | grep systemd`" != "z"; then + HAVE_SYSTEMCTL=yes + break + fi + fi +done + # # Search PATH to determine if udisks program can be found # and if appropriate daemon is running. @@ -86,6 +100,14 @@ if test "x`id -u`" != "x0"; then exit 1 fi +# +# Use systemctl to prevent automount by masking currently unmasked mount points +# +if test "x$HAVE_SYSTEMCTL" = "xyes"; then + MOUNTLIST=`systemctl list-unit-files --full --all -t mount --no-legend | grep -v masked | cut -f1 -d' '` + systemctl --runtime mask --quiet -- $MOUNTLIST +fi + # # Use both udisks and hal-lock for invocation if both binaries exist and both # daemons are running. @@ -114,3 +136,10 @@ elif test "x$HAVE_HAL_LOCK" = "xyes"; then else $BASE_CMD fi + +# +# Use systemctl to restore that status of any mount points changed above +# +if test "x$HAVE_SYSTEMCTL" = "xyes"; then + systemctl --runtime unmask --quiet -- $MOUNTLIST +fi