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

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