Blame SOURCES/autofs-5.1.8-improve-descriptor-open-error-reporting.patch

f3080c
autofs-5.1.8 - improve descriptor open error reporting
f3080c
f3080c
From: Ian Kent <raven@themaw.net>
f3080c
f3080c
Add error message reporting to the descriptor open functions.
f3080c
f3080c
Signed-off-by: Ian Kent <raven@themaw.net>
f3080c
---
f3080c
 CHANGELOG                |    1 +
f3080c
 daemon/automount.c       |    3 ---
f3080c
 daemon/spawn.c           |   29 +++++++++++++++++++++++++++++
f3080c
 lib/mounts.c             |   10 ++--------
f3080c
 modules/lookup_program.c |    5 +----
f3080c
 5 files changed, 33 insertions(+), 15 deletions(-)
f3080c
f3080c
--- autofs-5.1.4.orig/CHANGELOG
f3080c
+++ autofs-5.1.4/CHANGELOG
f3080c
@@ -80,6 +80,7 @@
f3080c
 - remove intr hosts map mount option.
f3080c
 - fix kernel mount status notification.
f3080c
 - fix set open file limit.
f3080c
+- improve descriptor open error reporting.
f3080c
 
f3080c
 xx/xx/2018 autofs-5.1.5
f3080c
 - fix flag file permission.
f3080c
--- autofs-5.1.4.orig/daemon/automount.c
f3080c
+++ autofs-5.1.4/daemon/automount.c
f3080c
@@ -864,9 +864,6 @@ static int create_logpri_fifo(struct aut
f3080c
 
f3080c
 	fd = open_fd(fifo_name, O_RDWR|O_NONBLOCK);
f3080c
 	if (fd < 0) {
f3080c
-		char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
f3080c
-		crit(ap->logopt,
f3080c
-		     "Failed to open %s: %s", fifo_name, estr);
f3080c
 		unlink(fifo_name);
f3080c
 		ret = -1;
f3080c
 		goto out_free;
f3080c
--- autofs-5.1.4.orig/daemon/spawn.c
f3080c
+++ autofs-5.1.4/daemon/spawn.c
f3080c
@@ -94,7 +94,12 @@ int open_fd(const char *path, int flags)
f3080c
 #endif
f3080c
 	fd = open(path, flags);
f3080c
 	if (fd == -1) {
f3080c
+		char buf[MAX_ERR_BUF];
f3080c
+		char *estr;
f3080c
+
f3080c
 		open_mutex_unlock();
f3080c
+		estr = strerror_r(errno, buf, sizeof(buf));
f3080c
+		logerr("failed to open file: %s", estr);
f3080c
 		return -1;
f3080c
 	}
f3080c
 	check_cloexec(fd);
f3080c
@@ -113,7 +118,12 @@ int open_fd_mode(const char *path, int f
f3080c
 #endif
f3080c
 	fd = open(path, flags, mode);
f3080c
 	if (fd == -1) {
f3080c
+		char buf[MAX_ERR_BUF];
f3080c
+		char *estr;
f3080c
+
f3080c
 		open_mutex_unlock();
f3080c
+		estr = strerror_r(errno, buf, sizeof(buf));
f3080c
+		logerr("failed to open file: %s", estr);
f3080c
 		return -1;
f3080c
 	}
f3080c
 	check_cloexec(fd);
f3080c
@@ -123,6 +133,8 @@ int open_fd_mode(const char *path, int f
f3080c
 
f3080c
 int open_pipe(int pipefd[2])
f3080c
 {
f3080c
+	char buf[MAX_ERR_BUF];
f3080c
+	char *estr;
f3080c
 	int ret;
f3080c
 
f3080c
 	open_mutex_lock();
f3080c
@@ -145,6 +157,8 @@ done:
f3080c
 	return 0;
f3080c
 err:
f3080c
 	open_mutex_unlock();
f3080c
+	estr = strerror_r(errno, buf, sizeof(buf));
f3080c
+	logerr("failed to open pipe: %s", estr);
f3080c
 	return -1;
f3080c
 }
f3080c
 
f3080c
@@ -159,7 +173,12 @@ int open_sock(int domain, int type, int
f3080c
 #endif
f3080c
 	fd = socket(domain, type, protocol);
f3080c
 	if (fd == -1) {
f3080c
+		char buf[MAX_ERR_BUF];
f3080c
+		char *estr;
f3080c
+
f3080c
 		open_mutex_unlock();
f3080c
+		estr = strerror_r(errno, buf, sizeof(buf));
f3080c
+		logerr("failed to open socket: %s", estr);
f3080c
 		return -1;
f3080c
 	}
f3080c
 	check_cloexec(fd);
f3080c
@@ -184,7 +203,12 @@ FILE *open_fopen_r(const char *path)
f3080c
 #endif
f3080c
 	f = fopen(path, "r");
f3080c
 	if (f == NULL) {
f3080c
+		char buf[MAX_ERR_BUF];
f3080c
+		char *estr;
f3080c
+
f3080c
 		open_mutex_unlock();
f3080c
+		estr = strerror_r(errno, buf, sizeof(buf));
f3080c
+		logerr("failed to open file: %s", estr);
f3080c
 		return NULL;
f3080c
 	}
f3080c
 	check_cloexec(fileno(f));
f3080c
@@ -209,7 +233,12 @@ FILE *open_setmntent_r(const char *table
f3080c
 #endif
f3080c
 	tab = fopen(table, "r");
f3080c
 	if (tab == NULL) {
f3080c
+		char buf[MAX_ERR_BUF];
f3080c
+		char *estr;
f3080c
+
f3080c
 		open_mutex_unlock();
f3080c
+		estr = strerror_r(errno, buf, sizeof(buf));
f3080c
+		logerr("failed to open mount table: %s", estr);
f3080c
 		return NULL;
f3080c
 	}
f3080c
 	check_cloexec(fileno(tab));
f3080c
--- autofs-5.1.4.orig/lib/mounts.c
f3080c
+++ autofs-5.1.4/lib/mounts.c
f3080c
@@ -2169,11 +2169,8 @@ struct mnt_list *get_mnt_list(const char
f3080c
 		return NULL;
f3080c
 
f3080c
 	tab = open_fopen_r(_PROC_MOUNTS);
f3080c
-	if (!tab) {
f3080c
-		char *estr = strerror_r(errno, buf, PATH_MAX - 1);
f3080c
-		logerr("fopen: %s", estr);
f3080c
+	if (!tab)
f3080c
 		return NULL;
f3080c
-	}
f3080c
 
f3080c
 	while ((mnt = local_getmntent_r(tab, &mnt_wrk, buf, PATH_MAX * 3))) {
f3080c
 		len = strlen(mnt->mnt_dir);
f3080c
@@ -2280,11 +2277,8 @@ static int table_is_mounted(const char *
f3080c
 		return 0;
f3080c
 
f3080c
 	tab = open_fopen_r(_PROC_MOUNTS);
f3080c
-	if (!tab) {
f3080c
-		char *estr = strerror_r(errno, buf, PATH_MAX - 1);
f3080c
-		logerr("fopen: %s", estr);
f3080c
+	if (!tab)
f3080c
 		return 0;
f3080c
-	}
f3080c
 
f3080c
 	while ((mnt = local_getmntent_r(tab, &mnt_wrk, buf, PATH_MAX * 3))) {
f3080c
 		size_t len = strlen(mnt->mnt_dir);
f3080c
--- autofs-5.1.4.orig/modules/lookup_program.c
f3080c
+++ autofs-5.1.4/modules/lookup_program.c
f3080c
@@ -214,11 +214,8 @@ static char *lookup_one(struct autofs_po
f3080c
 	 * want to send stderr to the syslog, and we don't use spawnl()
f3080c
 	 * because we need the pipe hooks
f3080c
 	 */
f3080c
-	if (open_pipe(pipefd)) {
f3080c
-		char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
f3080c
-		logerr(MODPREFIX "pipe: %s", estr);
f3080c
+	if (open_pipe(pipefd))
f3080c
 		goto out_error;
f3080c
-	}
f3080c
 	if (open_pipe(epipefd)) {
f3080c
 		close(pipefd[0]);
f3080c
 		close(pipefd[1]);