[gparted] Reliably detect running gpartedbin using pidof (!54)



commit dcceb7b83c10cb09e91aa1fd1763e0bd820b15f1
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Sat Feb 29 15:53:23 2020 +0000

    Reliably detect running gpartedbin using pidof (!54)
    
    Debian user reported a bug [1] that when they had PS_FORMAT environment
    variable set it prevented GParted running:
    
        # export PS_FORMAT='ruser,uid,pid,ppid,pri,ni,%cpu,%mem,vsz,rss,stat,tty,start,time,command'
        # gparted
        The process gpartedbin is already running.
        Only one gpartedbin process is permitted.
        # echo $?
        1
    
    Using ps column 'command' includes the command and all it's arguments,
    rather than just the command name as ps displays by default.  Thus the
    shell wrapper finds the grep command it's using when searching for the
    gpartedbin executable.
    
        # ps -e | grep gpartedbin
        root         0 26114 14777  19   0  0.0  0.0 112712   940 S+   pts/0    10:42:02 00:00:00 grep 
--color=auto gpartedbin
    
    Fix by searching for running processes using pidof.  pgrep does regular
    expression matching where as pidof checks program name is the same [2].
    Therefore use of pidof is preferred over pgrep [3].
    
    [1] Debian bug #864932 - gparted fails if PS_FORMAT options are
                             specified
        https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=864932
    
    [2] Difference between pidof and pgrep?
        https://stackoverflow.com/questions/52151698/difference-between-pidof-and-pgrep
    
    [3] [PATCH] gparted.in: Use reliable way of detecting gpartedbin process
        existence
        
https://git.alpinelinux.org/aports/tree/community/gparted/gparted.in-Use-reliable-way-of-detecting-gpartedbin-.patch
    
    Closes !54 - Fix gparted not launching when PS_FORMAT environment
                 variable set

 gparted.in | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
---
diff --git a/gparted.in b/gparted.in
index 3f9b0f1a..e021eb25 100755
--- a/gparted.in
+++ b/gparted.in
@@ -30,7 +30,7 @@
 #
 #  Only permit one instance of GParted to execute at a time
 #
-if test "z`ps -e | grep gpartedbin`" != "z"; then
+if pidof gpartedbin 1> /dev/null; then
        echo "The process gpartedbin is already running."
        echo "Only one gpartedbin process is permitted."
        exit 1
@@ -94,7 +94,7 @@ fi
 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
+               if pidof systemd 1> /dev/null; then
                        HAVE_SYSTEMCTL=yes
                        break
                fi
@@ -107,7 +107,7 @@ done
 #
 HAVE_UDISKS2_INHIBIT=no
 if test -x "/usr/lib/udisks2/udisks2-inhibit"; then
-       if test "z`ps -e | grep 'udisksd'`" != "z"; then
+       if pidof udisksd 1> /dev/null; then
                HAVE_UDISKS2_INHIBIT=yes
        fi
 fi
@@ -119,7 +119,7 @@ fi
 HAVE_UDISKS=no
 for k in '' `echo "$PATH" | sed 's,:, ,g'`; do
        if test -x "$k/udisks"; then
-               if test "z`ps -e | grep udisks-daemon`" != "z"; then
+               if pidof udisks-daemon 1> /dev/null; then
                        HAVE_UDISKS=yes
                        break
                fi
@@ -133,7 +133,7 @@ done
 HAVE_HAL_LOCK=no
 for k in '' `echo "$PATH" | sed 's,:, ,g'`; do
        if test -x "$k/hal-lock"; then
-               if test "z`ps -e | grep hald`" != "z"; then
+               if pidof hald 1> /dev/null; then
                        HAVE_HAL_LOCK=yes
                        break
                fi


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]