--- a/xdm/dm.c
+++ b/xdm/dm.c
@@ -160,6 +160,13 @@
 	InitErrorLog ();
     if (debugLevel >= 10)
 	nofork_session = 1;
+    /*
+     * Ensure graceful signal handling when the pid file exists
+     */
+    (void) Signal (SIGHUP, RescanNotify);
+    (void) Signal (SIGUSR2, ReopenLogFileNotify);
+    if (atexit (RemovePid))
+	LogError ("could not register RemovePid() with atexit()\n");
     /* SUPPRESS 560 */
     if ((oldpid = StorePid ()))
     {
@@ -173,9 +180,6 @@
 
     LogInfo ("Starting\n");
 
-    if (atexit (RemovePid))
-	LogError ("could not register RemovePid() with atexit()\n");
-
     if (nofork_session == 0) {
 	/* Clean up any old Authorization files */
 	/* AUD: all good? */
@@ -211,8 +215,6 @@
 #if !defined(HAVE_ARC4RANDOM) && !defined(DEV_RANDOM)
     AddOtherEntropy();
 #endif
-    (void) Signal (SIGHUP, RescanNotify);
-    (void) Signal (SIGUSR2, ReopenLogFileNotify);
 #ifndef UNRELIABLE_SIGNALS
     (void) Signal (SIGCHLD, ChildNotify);
 #endif
