File ppc64-diag.bug-945385_create_dump_directory_on_startup.patch of Package ppc64-diag

From 25797e8420d6cbcf8b64f062d347f21649d9d1f7 Mon Sep 17 00:00:00 2001
From: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
Date: Wed, 9 Sep 2015 10:43:29 +0530
Subject: [PATCH] opal_errd/extract_opal_dump: Create dump directory on startup
To: ltcras@lists.linux.ibm.com

extract_opal_dump is called, while starting opal_errd daemon. Following
failure message from extract_opal_dump is observed when output dump
directory (/var/log/dump default) is missing to extract the dump to.

opal_errd.service - opal_errd (PowerNV platform error handling) Service
   Loaded: loaded (/usr/lib/systemd/system/opal_errd.service; enabled)
   Active: active (running) since Wed 2015-09-09 09:41:03 BST; 2s ago
  Process: 84467 ExecStop=/usr/lib/opal_errd stop (code=exited, status=0/SUCCESS)
  Process: 84488 ExecStart=/usr/lib/opal_errd start (code=exited, status=0/SUCCESS)
 Main PID: 84500 (opal_errd)
   CGroup: /system.slice/opal_errd.service
           `-84500 /usr/sbin/opal_errd

Sep 09 09:41:03 linux ELOG[84500]: /usr/sbin/extract_opal_dump command execution failed
Sep 09 09:41:03 linux opal_errd[84488]: Starting opal_errd daemon: ..done
Sep 09 09:41:04 linux ELOG[84500]: /usr/sbin/extract_opal_dump command execution failed
Sep 09 09:41:05 linux ELOG[84500]: /usr/sbin/extract_opal_dump command execution failed

Fix this issue by creating missing output directory, mimicking opal_errd (creates
opal-elog directory, if missing on startup) instead of bailing out. Also replace
stat() with access(), in places where access() is sufficient.

Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
Cc: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
---
 opal_errd/extract_opal_dump.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/opal_errd/extract_opal_dump.c b/opal_errd/extract_opal_dump.c
index 800d308bdbf5..6c3923bb1432 100644
--- a/opal_errd/extract_opal_dump.c
+++ b/opal_errd/extract_opal_dump.c
@@ -100,7 +100,6 @@ static void ack_dump(const char* dump_dir_path)
  */
 static void check_dup_dump_file(char *dumpname)
 {
-	struct stat sbuf;
 	char dump_path[PATH_MAX];
 	int rc;
 
@@ -111,7 +110,7 @@ static void check_dup_dump_file(char *dumpname)
 		return;
 	}
 
-	if (stat(dump_path, &sbuf) == -1)
+	if (access(dump_path, R_OK) == -1)
 		return;
 
 	if (unlink(dump_path) < 0)
@@ -379,7 +378,6 @@ int main(int argc, char *argv[])
 	int rc;
 	int fd;
 	fd_set exceptfds;
-	struct stat s;
 
 	setlogmask(LOG_UPTO(LOG_NOTICE));
 	openlog("OPAL_DUMP", LOG_CONS | LOG_PID | LOG_NDELAY | LOG_PERROR,
@@ -422,18 +420,29 @@ int main(int argc, char *argv[])
 	snprintf(sysfs_path, sizeof(sysfs_path), "%s/firmware/opal/dump",
 		 opt_sysfs);
 
-	rc = stat(sysfs_path, &s);
+	rc = access(sysfs_path, R_OK);
 	if (rc != 0) {
 		syslog(LOG_ERR, "Error accessing sysfs: %s (%d: %s)\n",
 		       sysfs_path, errno, strerror(errno));
 		goto err_out;
 	}
 
-	rc = stat(opt_output_dir, &s);
+	rc = access(opt_output_dir, W_OK);
 	if (rc != 0) {
-		syslog(LOG_ERR, "Error accessing output dir: %s (%d: %s)\n",
-		       opt_output_dir, errno, strerror(errno));
-		goto err_out;
+		if (errno == ENOENT) {
+			rc = mkdir(opt_output_dir,
+				   S_IRGRP | S_IRUSR | S_IWGRP | S_IWUSR | S_IXUSR);
+			if (rc != 0) {
+				syslog(LOG_ERR, "Error creating output directory:"
+						"%s (%d: %s)\n", opt_output_dir,
+						errno, strerror(errno));
+				goto err_out;
+			}
+		} else {
+			syslog(LOG_ERR, "Error accessing output dir: %s (%d: %s)\n",
+					opt_output_dir, errno, strerror(errno));
+			goto err_out;
+		}
 	}
 
 start:
-- 
1.9.1

openSUSE Build Service is sponsored by