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

X Strike Force SVN commit: rev 506 - trunk/debian



Author: branden
Date: 2003-09-10 18:08:13 -0500 (Wed, 10 Sep 2003)
New Revision: 506

Modified:
   trunk/debian/changelog
   trunk/debian/xdm.config.in
   trunk/debian/xdm.postinst.in
   trunk/debian/xdm.postrm.in
   trunk/debian/xdm.preinst.in
   trunk/debian/xdm.prerm.in
Log:
Robustify xdm maintainer scripts.
- debian/xdm.{config,preinst,postinst,prerm,postrm}.in:
  + improve comments
  + wrap bare db_* commands with safe_debconf()
  + quote shell variables where reasonable to do so
  + don't do things that depend on the value of $RET after a db_* if a
    null value doesn't make sense
  + wrap long lines at 80 columns
- debian/xdm.config.in:
  + debconf is not a registry; use the basename of the path listed in
    /etc/X11/default-display-manager as the default answer to the
    shared/default-x-display-manager question if it is available;
    otherwise fall back to existing value
  + uh, let's try defining the DEFAULT_DISPLAY_MANAGER_FILE variable since
    we dereference it
- debian/xdm.postinst.in:
  + use HOST as our iterator variable when checking $DISPLAY instead of
    HOSTNAME, which is often already defined
  + discard error messages from hostname command
  + stop searching for a $DISPLAY on $HOST:0 once we've found one
- debian/xdm.prerm.in:
  + don't attempt to find any children of the xdm daemon, and don't make
    any effort to stop it, if pidof doesn't report any xdm processes
    running


Modified: trunk/debian/changelog
===================================================================
--- trunk/debian/changelog	2003-09-10 21:56:11 UTC (rev 505)
+++ trunk/debian/changelog	2003-09-10 23:08:13 UTC (rev 506)
@@ -108,8 +108,33 @@
     + patch #000_stolen_from_HEAD: in with the new
     + patch #095: out with the old (deleted)
 
- -- Branden Robinson <branden@debian.org>  Wed, 10 Sep 2003 16:53:26 -0500
+  * Robustify xdm maintainer scripts.
+    - debian/xdm.{config,preinst,postinst,prerm,postrm}.in:
+      + improve comments
+      + wrap bare db_* commands with safe_debconf()
+      + quote shell variables where reasonable to do so
+      + don't do things that depend on the value of $RET after a db_* if a
+        null value doesn't make sense
+      + wrap long lines at 80 columns
+    - debian/xdm.config.in:
+      + debconf is not a registry; use the basename of the path listed in
+        /etc/X11/default-display-manager as the default answer to the
+        shared/default-x-display-manager question if it is available;
+        otherwise fall back to existing value
+      + uh, let's try defining the DEFAULT_DISPLAY_MANAGER_FILE variable since
+        we dereference it
+    - debian/xdm.postinst.in:
+      + use HOST as our iterator variable when checking $DISPLAY instead of
+        HOSTNAME, which is often already defined
+      + discard error messages from hostname command
+      + stop searching for a $DISPLAY on $HOST:0 once we've found one
+    - debian/xdm.prerm.in:
+      + don't attempt to find any children of the xdm daemon, and don't make
+        any effort to stop it, if pidof doesn't report any xdm processes
+        running
 
+ -- Branden Robinson <branden@debian.org>  Wed, 10 Sep 2003 17:39:00 -0500
+
 xfree86 (4.2.1-11) unstable; urgency=medium
 
   * urgency set to medium because bug #206790 bites a lot of people (but,

Modified: trunk/debian/xdm.config.in
===================================================================
--- trunk/debian/xdm.config.in	2003-09-10 21:56:11 UTC (rev 505)
+++ trunk/debian/xdm.config.in	2003-09-10 23:08:13 UTC (rev 506)
@@ -18,29 +18,41 @@
 
 # set default display manager
 
-db_get shared/default-x-display-manager
-OLD_DEFAULT="$RET"
+DEFAULT_DISPLAY_MANAGER_FILE=/etc/X11/default-display-manager
 
-db_metaget shared/default-x-display-manager owners
+safe_debconf db_metaget shared/default-x-display-manager owners
 OWNERS="$RET"
-db_metaget shared/default-x-display-manager choices
+safe_debconf db_metaget shared/default-x-display-manager choices
 CHOICES="$RET"
 
-if [ "$OWNERS" != "$CHOICES" ]; then
-  db_subst shared/default-x-display-manager choices $OWNERS
-  db_fset shared/default-x-display-manager seen false
+if [ -n "$OWNERS" -a -n "$CHOICES" ]; then
+  if [ "$OWNERS" != "$CHOICES" ]; then
+    safe_debconf db_subst shared/default-x-display-manager choices "$OWNERS"
+    safe_debconf db_fset shared/default-x-display-manager seen false
+  fi
+
+  # debconf is not a registry; use the current contents of the default display
+  # manager to pre-answer the question if possible
+  if [ -e "$DEFAULT_DISPLAY_MANAGER_FILE" ]; then
+    CURRENT_DEFAULT=$(basename $(head -n 1 "$DEFAULT_DISPLAY_MANAGER_FILE"))
+  else
+    safe_debconf db_get shared/default-x-display-manager
+    CURRENT_DEFAULT="$RET"
+  fi
+
+  safe_debconf db_input high shared/default-x-display-manager
+  safe_debconf db_go
 fi
 
-db_input high shared/default-x-display-manager || true
-db_go
-
 # using this display manager?
-db_get shared/default-x-display-manager
-CURRENT_DEFAULT="$RET"
+safe_debconf db_get shared/default-x-display-manager
+NEW_DEFAULT="$RET"
 
 # remove the default display manager file if we're going to change it
-if [ "$OLD_DEFAULT" != "$CURRENT_DEFAULT" ]; then
-  rm -f $DEFAULT_DISPLAY_MANAGER_FILE
+if [ -n "$NEW_DEFAULT" ]; then
+  if [ "$NEW_DEFAULT" != "$CURRENT_DEFAULT" ]; then
+    rm -f "$DEFAULT_DISPLAY_MANAGER_FILE"
+  fi
 fi
 
 exit 0

Modified: trunk/debian/xdm.postinst.in
===================================================================
--- trunk/debian/xdm.postinst.in	2003-09-10 21:56:11 UTC (rev 505)
+++ trunk/debian/xdm.postinst.in	2003-09-10 23:08:13 UTC (rev 506)
@@ -36,36 +36,44 @@
   fi
 done
 
-DEFAULT_DISPLAY_MANAGER_FILE=/etc/X11/default-display-manager
-
 # debconf is not a registry, so we only fiddle with the default file if it
 # does not exist
-if [ ! -e $DEFAULT_DISPLAY_MANAGER_FILE ]; then
-  db_get shared/default-x-display-manager
-  if [ "$THIS_PACKAGE" != "$RET" ]; then
-    message "Please be sure to run \"dpkg --configure $RET\"."
+DEFAULT_DISPLAY_MANAGER_FILE=/etc/X11/default-display-manager
+if [ ! -e "$DEFAULT_DISPLAY_MANAGER_FILE" ]; then
+  safe_debconf db_get shared/default-x-display-manager
+  if [ -n "$RET" ]; then
+    if [ "$THIS_PACKAGE" != "$RET" ]; then
+      message "Please be sure to run \"dpkg --configure $RET\"."
+    fi
+    safe_debconf db_get "$RET"/daemon_name
+    if [ -n "$RET" ]; then
+      echo "$RET" > "$DEFAULT_DISPLAY_MANAGER_FILE"
+    fi
   fi
-  db_get "$RET"/daemon_name
-  echo "$RET" > $DEFAULT_DISPLAY_MANAGER_FILE
 fi
 
 # restarting the daemon may cause output to stdout
-db_stop
+safe_debconf db_stop
 
+# don't start xdm if we are upgrading without stopping it
 NOSTART=
 XDM_RUNNING=
-# don't start xdm if we are upgrading without stopping it
 if [ -e /var/run/xdm.upgrade ]; then
   NOSTART=yes
 fi
 # or if we're currently in X on the display it attempts to manage by default
-for HOSTNAME in "" "localhost" "$(hostname)" "$(hostname -f)"; do
-  if echo $DISPLAY | grep -q "^$HOSTNAME:0.*"; then
+for HOST in "" \
+                "localhost" \
+                "$(hostname 2> /dev/null)" \
+                "$(hostname -f 2> /dev/null)"; do
+  if echo "$DISPLAY" | grep -q "^$HOST:0.*"; then
     NOSTART=yes
+    break
   fi
 done
 # or if it's already running
-if start-stop-daemon --stop --quiet --signal 0 --pid /var/run/xdm.pid --exec /usr/bin/X11/xdm; then
+if start-stop-daemon --stop --quiet --signal 0 --pid /var/run/xdm.pid \
+                     --exec /usr/bin/X11/xdm; then
   NOSTART=yes
   XDM_RUNNING=yes
 fi
@@ -87,10 +95,10 @@
 fi
 
 if [ -e /etc/init.d/xdm ]; then
-  update-rc.d $THIS_PACKAGE defaults 99 01
+  update-rc.d "$THIS_PACKAGE" defaults 99 01
 fi
 
-[ -n "$NOSTART" ] || invoke-rc.d $THIS_PACKAGE start || true
+[ -n "$NOSTART" ] || invoke-rc.d "$THIS_PACKAGE" start || true
 
 #DEBHELPER#
 

Modified: trunk/debian/xdm.postrm.in
===================================================================
--- trunk/debian/xdm.postrm.in	2003-09-10 21:56:11 UTC (rev 505)
+++ trunk/debian/xdm.postrm.in	2003-09-10 23:08:13 UTC (rev 506)
@@ -15,7 +15,8 @@
 #INCLUDE_SHELL_LIB#
 
 if [ "$1" = "abort-install" -o "$1" = "abort-upgrade" ]; then
-  if [ -d /usr/X11R6/lib/X11/xdm.moved-by-preinst -a -L /usr/X11R6/lib/X11/xdm ]; then
+  if [ -d /usr/X11R6/lib/X11/xdm.moved-by-preinst -a \
+       -L /usr/X11R6/lib/X11/xdm ]; then
     rm /usr/X11R6/lib/X11/xdm
     mv /usr/X11R6/lib/X11/xdm.moved-by-preinst /usr/X11R6/lib/X11/xdm
   fi
@@ -29,10 +30,10 @@
 #DEBHELPER#
 
 if [ "$1" = "purge" ]; then
-  update-rc.d $THIS_PACKAGE remove
+  update-rc.d "$THIS_PACKAGE" remove
   for DIR in /etc/X11/xdm /var/lib/xdm; do
-    if [ -d $DIR ]; then
-      rm -r $DIR
+    if [ -d "$DIR" ]; then
+      rm -r "$DIR"
     fi
   done
 fi

Modified: trunk/debian/xdm.preinst.in
===================================================================
--- trunk/debian/xdm.preinst.in	2003-09-10 21:56:11 UTC (rev 505)
+++ trunk/debian/xdm.preinst.in	2003-09-10 23:08:13 UTC (rev 506)
@@ -15,13 +15,16 @@
 #INCLUDE_SHELL_LIB#
 
 if [ "$1" = "install" -o "$1" = "upgrade" ]; then
-  # xdm dir moved to /etc/X11 in 4.x
+  # as of the xfree86 4.x packages, we expect /usr/X11R6/lib/X11/xdm to be a
+  # symbolic link to the /etc/X11/xdm directory; move an existing directory out
+  # of the way (even if we're installing over a non-packaged XFree86
+  # installation)
   if [ -e /usr/X11R6/lib/X11/xdm -a ! -L /usr/X11R6/lib/X11/xdm ]; then
     message "Note: Removing obsolete /usr/X11R6/lib/X11/xdm directory."
     mv /usr/X11R6/lib/X11/xdm /usr/X11R6/lib/X11/xdm.moved-by-preinst
   fi
 
-  # got rid of the shared libXdmGreeter in 4.0.3
+  # got rid of the shared libXdmGreet in 4.0.3
   if dpkg --compare-versions "$2" lt "4.0.3-1"; then
     if update-alternatives --display xdm-greeter | \
        fgrep -q /usr/X11R6/lib/libXdmGreet.so.1; then

Modified: trunk/debian/xdm.prerm.in
===================================================================
--- trunk/debian/xdm.prerm.in	2003-09-10 21:56:11 UTC (rev 505)
+++ trunk/debian/xdm.prerm.in	2003-09-10 23:08:13 UTC (rev 506)
@@ -32,47 +32,51 @@
 esac
 
 STOP=
-# are we supposed to restart on upgrade?  if REMOVING xdm, we don't care
-if grep -qs ^restart-on-upgrade /etc/X11/xdm/xdm.options || [ -n "$REMOVING" ]; then
+# are we supposed to restart on upgrade?  if REMOVING xdm, we don't care what
+# the user says, we have to stop the daemon
+if grep -qs ^restart-on-upgrade /etc/X11/xdm/xdm.options || \
+   [ -n "$REMOVING" ]; then
   # is there an xdm process running?
   if start-stop-daemon --stop --quiet --signal 0 --exec /usr/bin/X11/xdm; then
     # any children?
     PARENTS=$(pidof /usr/bin/X11/xdm || true)
     CHILDREN=
-    for PROCESS in $PARENTS; do
-      # make sure we got numbers back
-      if ! [ $PROCESS -eq $PROCESS ] 2> /dev/null; then
-        # freak out
-        errormsg "ERROR: pidof returned non-numeric value!"
-      fi
-      # we could use grep -q here if ps would ignore SIGPIPE :-P
-      if (ps axj | grep "^ *$PROCESS" > /dev/null 2>&1); then
-        CHILDREN=yes
-      fi
-    done
-    if [ -n "$CHILDREN" ]; then
-      if [ -n "$HAVE_DEBCONF" ]; then
-        # ask the question
-        db_input high xdm/stop_running_server_with_children || true
-        db_go
-        # what did the user say?
-        db_get xdm/stop_running_server_with_children
-        ANSWER="$RET"
-        if [ "$ANSWER" = "true" ]; then
-          STOP=yes
+    if [ -n "$PARENTS" ]; then
+      for PROCESS in $PARENTS; do
+        # make sure we got numbers back
+        if ! [ $PROCESS -eq $PROCESS ] 2> /dev/null; then
+          # freak out
+          errormsg "ERROR: pidof returned non-numeric value!"
         fi
-        # forget that we have seen the question; this is the sort of
-        # non-configuration question that should be asked every time
-        db_fset xdm/stop_running_server_with_children seen false
+        # we could use grep -q here if ps would ignore SIGPIPE :-P
+        if (ps axj | grep "^ *$PROCESS" > /dev/null 2>&1); then
+          CHILDREN=yes
+        fi
+      done
+      if [ -n "$CHILDREN" ]; then
+        if [ -n "$HAVE_DEBCONF" ]; then
+          # ask the question
+          safe_debconf db_input high xdm/stop_running_server_with_children
+          safe_debconf db_go
+          # what did the user say?
+          safe_debconf db_get xdm/stop_running_server_with_children
+          ANSWER="$RET"
+          if [ "$ANSWER" = "true" ]; then
+            STOP=yes
+          fi
+          # forget that we have seen the question; this is the sort of
+          # non-configuration question that should be asked every time
+          safe_debconf db_fset xdm/stop_running_server_with_children seen false
+        fi
+      else
+        STOP=yes
       fi
-    else
-      STOP=yes
     fi
   fi
 fi
 
 if [ -n "$STOP" ]; then
-  invoke-rc.d $THIS_PACKAGE stop || true
+  invoke-rc.d "$THIS_PACKAGE" stop || true
 else
   if [ "$1" = "upgrade" -o "$1" = "failed-upgrade" ]; then
     touch /var/run/xdm.upgrade
@@ -84,34 +88,42 @@
 if [ "$1" = "remove" -o "$1" = "deconfigure" ]; then
   if [ -n "$HAVE_DEBCONF" ]; then
     # disown this question
-    db_unregister shared/default-x-display-manager
+    safe_debconf db_unregister shared/default-x-display-manager
     # does the question still exist?
     if db_get shared/default-x-display-manager; then
-      db_metaget shared/default-x-display-manager owners
-      db_subst shared/default-x-display-manager choices "$RET"
-      db_get shared/default-x-display-manager
+      safe_debconf db_metaget shared/default-x-display-manager owners
+      safe_debconf db_subst shared/default-x-display-manager choices "$RET"
+      safe_debconf db_get shared/default-x-display-manager
       # are we removing the currently selected display manager?
-      if [ "$THIS_PACKAGE" = "$RET" ]; then
-        if [ -e $DEFAULT_DISPLAY_MANAGER_FILE ]; then
-          db_get "$RET"/daemon_name
-          # does the display manager file reference the current default?
-          # if so, remove it because it will now be wrong
-          if [ "$(cat $DEFAULT_DISPLAY_MANAGER_FILE)" = "$RET" ]; then
-            rm $DEFAULT_DISPLAY_MANAGER_FILE
+      if [ -n "$RET" ]; then
+        if [ "$THIS_PACKAGE" = "$RET" ]; then
+          if [ -e "$DEFAULT_DISPLAY_MANAGER_FILE" ]; then
+            safe_debconf db_get "$RET/daemon_name"
+            # does the display manager file reference the current default?  if
+            # so, remove it because it will now be wrong
+            if [ -n "$RET" ]; then
+              if [ "$(cat "$DEFAULT_DISPLAY_MANAGER_FILE")" = "$RET" ]; then
+                rm "$DEFAULT_DISPLAY_MANAGER_FILE"
+              fi
+            fi
           fi
+          # ask the user to choose a new default
+          safe_debconf db_fset shared/default-x-display-manager seen false
+          safe_debconf db_input critical shared/default-x-display-manager
+          safe_debconf db_go
+          # if the display manager file doesn't exist, write it with the path
+          # to the new default display manager
+          if [ ! -e "$DEFAULT_DISPLAY_MANAGER_FILE" ]; then
+            safe_debconf db_get shared/default-x-display-manager
+            if [ -n "$RET" ]; then
+              message "Please be sure to run \"dpkg-reconfigure $RET\"."
+              safe_debconf db_get "$RET"/daemon_name
+              if [ -n "$RET" ]; then
+                echo "$RET" > "$DEFAULT_DISPLAY_MANAGER_FILE"
+              fi
+            fi
+          fi
         fi
-        # ask the user to choose a new default
-        db_fset shared/default-x-display-manager seen false
-        db_input critical shared/default-x-display-manager || true
-        db_go
-        # if the display manager file doesn't exist, write it with the path
-        # to the new default display manager
-        if [ ! -e $DEFAULT_DISPLAY_MANAGER_FILE ]; then
-          db_get shared/default-x-display-manager
-          message "Please be sure to run \"dpkg-reconfigure $RET\"."
-          db_get "$RET"/daemon_name
-          echo "$RET" > $DEFAULT_DISPLAY_MANAGER_FILE
-        fi
       fi
     fi
   fi



Reply to: