pldmd: clean up exit logic

The event loop exit status is not checked.  Save the event loop exit
return code so that the daemon can exit with the correct status.  If the
event loop shuts down cleanly, an exit status of zero should be returned
to prevent undesired application restarts by an init manager (systemd).
If the event loop is terminated from within because of an error, the
daemon should exit with a non-zero status so it is restarted by an init
manager.

Do not exit with non-zero status for a socket shutdown error.  This will
cause an init manager to restart the application even when the event
loop shuts down cleanly.

Change-Id: Ib756978af2ca40dcfd3e54055c8d6bcafd374506
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/pldmd/pldmd.cpp b/pldmd/pldmd.cpp
index 8431dda..d1889ee 100644
--- a/pldmd/pldmd.cpp
+++ b/pldmd/pldmd.cpp
@@ -379,14 +379,16 @@
         hostPDRHandler->setHostFirmwareCondition();
     }
 #endif
-    event.loop();
+    returnCode = event.loop();
 
-    result = shutdown(sockfd, SHUT_RDWR);
-    if (-1 == result)
+    if (shutdown(sockfd, SHUT_RDWR))
     {
-        returnCode = -errno;
-        std::cerr << "Failed to shutdown the socket, RC=" << returnCode << "\n";
+        std::perror("Failed to shutdown the socket");
+    }
+    if (returnCode)
+    {
         exit(EXIT_FAILURE);
     }
-    exit(EXIT_FAILURE);
+
+    exit(EXIT_SUCCESS);
 }