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