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

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