Failures of archive_command calls report a confusing exit status such as:

LOG:  archive command "cp 'pg_xlog/000000010000000000000000' 
'/nonexistent/000000010000000000000000'" failed: return code 256

The actual return code is 1; it neglects to apply WEXITSTATUS().

I figured it would make sense if pgarch.c used the same mechanism that
postmaster.c uses to report the various variants of regular and signal
exits.

I have attached a patch in that direction.  It obviously needs a bit of
string struggling to get all the cases right, but the idea should be
clear.  Comments?

-- 
Peter Eisentraut
http://developer.postgresql.org/~petere/
diff -ur ../cvs-pgsql/src/backend/postmaster/pgarch.c ./src/backend/postmaster/pgarch.c
--- ../cvs-pgsql/src/backend/postmaster/pgarch.c	2007-11-26 13:29:36.000000000 +0100
+++ ./src/backend/postmaster/pgarch.c	2007-12-10 17:59:18.000000000 +0100
@@ -480,15 +480,11 @@
 		 * SIGQUIT while waiting; so a signal is very likely something that
 		 * should have interrupted us too.	If we overreact it's no big deal,
 		 * the postmaster will just start the archiver again.
-		 *
-		 * Per the Single Unix Spec, shells report exit status > 128 when a
-		 * called command died on a signal.
 		 */
-		bool		signaled = WIFSIGNALED(rc) || WEXITSTATUS(rc) > 128;
 
-		ereport(signaled ? FATAL : LOG,
-				(errmsg("archive command \"%s\" failed: return code %d",
-						xlogarchcmd, rc)));
+		// FIXME: "archive command \"%s\"", xlogarchcmd
+		// FIXME: get rid of PID = 0
+		LogChildExit(WIFSIGNALED(rc) ? FATAL : LOG, "archive command", 0, rc);
 
 		return false;
 	}
diff -ur ../cvs-pgsql/src/backend/postmaster/postmaster.c ./src/backend/postmaster/postmaster.c
--- ../cvs-pgsql/src/backend/postmaster/postmaster.c	2007-11-19 13:38:49.000000000 +0100
+++ ./src/backend/postmaster/postmaster.c	2007-12-10 18:00:04.000000000 +0100
@@ -305,8 +305,6 @@
 static void dummy_handler(SIGNAL_ARGS);
 static void CleanupBackend(int pid, int exitstatus);
 static void HandleChildCrash(int pid, int exitstatus, const char *procname);
-static void LogChildExit(int lev, const char *procname,
-			 int pid, int exitstatus);
 static void PostmasterStateMachine(void);
 static void BackendInitialize(Port *port);
 static int	BackendRun(Port *port);
@@ -2477,7 +2475,7 @@
 /*
  * Log the death of a child process.
  */
-static void
+void
 LogChildExit(int lev, const char *procname, int pid, int exitstatus)
 {
 	if (WIFEXITED(exitstatus))
diff -ur ../cvs-pgsql/src/include/postmaster/postmaster.h ./src/include/postmaster/postmaster.h
--- ../cvs-pgsql/src/include/postmaster/postmaster.h	2007-02-19 11:05:59.000000000 +0100
+++ ./src/include/postmaster/postmaster.h	2007-12-10 18:00:02.000000000 +0100
@@ -37,6 +37,8 @@
 
 extern int	PostmasterMain(int argc, char *argv[]);
 extern void ClosePostmasterPorts(bool am_syslogger);
+extern void LogChildExit(int lev, const char *procname,
+			 int pid, int exitstatus);
 
 #ifdef EXEC_BACKEND
 extern pid_t postmaster_forkexec(int argc, char *argv[]);
---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Reply via email to