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

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