Blame SOURCES/autofs-5.1.5-optionally-log-mount-requestor-process-info.patch

c3f1f8
autofs-5.1.5 - optionally log mount requestor process info
c3f1f8
c3f1f8
From: Lars R. Damerow <lars@pixar.com>
c3f1f8
c3f1f8
This information can be helpful to determine who or what is making
c3f1f8
particular mount requests, especially when used in conjunction with
c3f1f8
the use_mount_request_log_id option.
c3f1f8
c3f1f8
Signed-off-by: Lars R. Damerow <lars@pixar.com>
c3f1f8
Signed-off-by: Ian Kent <raven@themaw.net>
c3f1f8
---
c3f1f8
 CHANGELOG                      |    1 +
c3f1f8
 daemon/direct.c                |    6 ++++++
c3f1f8
 daemon/indirect.c              |    6 ++++++
c3f1f8
 include/log.h                  |    2 ++
c3f1f8
 lib/log.c                      |   39 +++++++++++++++++++++++++++++++++++++++
c3f1f8
 man/autofs.conf.5.in           |    3 ++-
c3f1f8
 redhat/autofs.conf.default.in  |    4 +++-
c3f1f8
 samples/autofs.conf.default.in |    4 +++-
c3f1f8
 8 files changed, 62 insertions(+), 3 deletions(-)
c3f1f8
c3f1f8
--- autofs-5.1.4.orig/CHANGELOG
c3f1f8
+++ autofs-5.1.4/CHANGELOG
c3f1f8
@@ -48,6 +48,7 @@ xx/xx/2018 autofs-5.1.5
c3f1f8
 - add NULL check for get_addr_string() return.
c3f1f8
 - use malloc(3) in spawn.c.
c3f1f8
 - add mount_verbose configuration option.
c3f1f8
+- optionally log mount requestor process info.
c3f1f8
 
c3f1f8
 19/12/2017 autofs-5.1.4
c3f1f8
 - fix spec file url.
c3f1f8
--- autofs-5.1.4.orig/daemon/direct.c
c3f1f8
+++ autofs-5.1.4/daemon/direct.c
c3f1f8
@@ -1242,6 +1242,12 @@ static void *do_mount_direct(void *arg)
c3f1f8
 
c3f1f8
 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &state);
c3f1f8
 
c3f1f8
+	if (defaults_get_mount_verbose()) {
c3f1f8
+		pid_t ppid = log_pidinfo(ap, mt.pid, "requestor");
c3f1f8
+		if (ppid > 0)
c3f1f8
+			log_pidinfo(ap, ppid, "parent");
c3f1f8
+	}
c3f1f8
+
c3f1f8
 	status = fstat(mt.ioctlfd, &st);
c3f1f8
 	if (status == -1) {
c3f1f8
 		error(ap->logopt,
c3f1f8
--- autofs-5.1.4.orig/daemon/indirect.c
c3f1f8
+++ autofs-5.1.4/daemon/indirect.c
c3f1f8
@@ -758,6 +758,12 @@ static void *do_mount_indirect(void *arg
c3f1f8
 
c3f1f8
 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &state);
c3f1f8
 
c3f1f8
+	if (defaults_get_mount_verbose()) {
c3f1f8
+		pid_t ppid = log_pidinfo(ap, mt.pid, "requestor");
c3f1f8
+		if (ppid > 0)
c3f1f8
+			log_pidinfo(ap, ppid, "parent");
c3f1f8
+	}
c3f1f8
+
c3f1f8
 	len = ncat_path(buf, sizeof(buf), ap->path, mt.name, mt.len);
c3f1f8
 	if (!len) {
c3f1f8
 		crit(ap->logopt, "path to be mounted is to long");
c3f1f8
--- autofs-5.1.4.orig/include/log.h
c3f1f8
+++ autofs-5.1.4/include/log.h
c3f1f8
@@ -46,6 +46,8 @@ extern void log_crit(unsigned, const cha
c3f1f8
 extern void log_debug(unsigned int, const char* msg, ...);
c3f1f8
 extern void logmsg(const char* msg, ...);
c3f1f8
 
c3f1f8
+extern pid_t log_pidinfo(struct autofs_point *ap, pid_t pid, char *label);
c3f1f8
+
c3f1f8
 #define debug(opt, msg, args...)	\
c3f1f8
 	do { log_debug(opt, "%s: " msg,  __FUNCTION__, ##args); } while (0)
c3f1f8
 
c3f1f8
--- autofs-5.1.4.orig/lib/log.c
c3f1f8
+++ autofs-5.1.4/lib/log.c
c3f1f8
@@ -325,3 +325,42 @@ void log_to_stderr(void)
c3f1f8
 
c3f1f8
 	return;
c3f1f8
 }
c3f1f8
+
c3f1f8
+pid_t log_pidinfo(struct autofs_point *ap, pid_t pid, char *label) {
c3f1f8
+	char buf[PATH_MAX + 1] = "";
c3f1f8
+	FILE *statfile;
c3f1f8
+
c3f1f8
+	pid_t tgid, ppid;
c3f1f8
+	int uid, euid, gid, egid;
c3f1f8
+	char comm[64] = "";
c3f1f8
+
c3f1f8
+	sprintf(buf, "/proc/%d/status", pid);
c3f1f8
+	statfile = fopen(buf, "r");
c3f1f8
+	if (statfile == NULL) {
c3f1f8
+		info(ap->logopt, "pidinfo %s: failed to open %s", label, buf);
c3f1f8
+		return -1;
c3f1f8
+	}
c3f1f8
+
c3f1f8
+	while (fgets(buf, sizeof(buf), statfile) != NULL) {
c3f1f8
+	        if (strncmp(buf, "Name:", 5) == 0) {
c3f1f8
+			sscanf(buf, "Name:\t%s", (char *) &comm);
c3f1f8
+		} else if (strncmp(buf, "Tgid:", 5) == 0) {
c3f1f8
+			sscanf(buf, "Tgid:\t%d", (int *) &tgid);
c3f1f8
+		} else if (strncmp(buf, "PPid:", 5) == 0) {
c3f1f8
+			sscanf(buf, "PPid:\t%d", (int *) &ppid);
c3f1f8
+		} else if (strncmp(buf, "Uid:", 4) == 0) {
c3f1f8
+			sscanf(buf,
c3f1f8
+			      "Uid:\t%d\t%d", (int *) &uid, (int *) &euid);
c3f1f8
+		} else if (strncmp(buf, "Gid:", 4) == 0) {
c3f1f8
+			sscanf(buf,
c3f1f8
+			      "Gid:\t%d\t%d", (int *) &gid, (int *) &egid);
c3f1f8
+		}
c3f1f8
+	}
c3f1f8
+	fclose(statfile);
c3f1f8
+
c3f1f8
+	info(ap->logopt,
c3f1f8
+	  "pidinfo %s: pid:%d comm:%s tgid:%d uid:%d euid:%d gid:%d egid:%d",
c3f1f8
+	   label, pid, comm, tgid, uid, euid, gid, egid);
c3f1f8
+
c3f1f8
+	return ppid;
c3f1f8
+}
c3f1f8
--- autofs-5.1.4.orig/man/autofs.conf.5.in
c3f1f8
+++ autofs-5.1.4/man/autofs.conf.5.in
c3f1f8
@@ -43,7 +43,8 @@ setting.
c3f1f8
 .TP
c3f1f8
 .B mount_verbose
c3f1f8
 .br
c3f1f8
-Use the verbose flag when spawning mount(8) (program default "no").
c3f1f8
+Use the verbose flag when spawning mount(8), and log some process info
c3f1f8
+about the requestor and its parent (program default "no").
c3f1f8
 .TP
c3f1f8
 .B mount_wait
c3f1f8
 .br
c3f1f8
--- autofs-5.1.4.orig/redhat/autofs.conf.default.in
c3f1f8
+++ autofs-5.1.4/redhat/autofs.conf.default.in
c3f1f8
@@ -26,7 +26,9 @@ timeout = 300
c3f1f8
 #
c3f1f8
 #negative_timeout = 60
c3f1f8
 #
c3f1f8
-# mount_verbose - use the -v flag when calling mount(8).
c3f1f8
+# mount_verbose - use the -v flag when calling mount(8) and log some
c3f1f8
+#		  process information about the requestor and its
c3f1f8
+#		  parent.
c3f1f8
 #
c3f1f8
 #mount_verbose = no
c3f1f8
 #
c3f1f8
--- autofs-5.1.4.orig/samples/autofs.conf.default.in
c3f1f8
+++ autofs-5.1.4/samples/autofs.conf.default.in
c3f1f8
@@ -26,7 +26,9 @@ timeout = 300
c3f1f8
 #
c3f1f8
 #negative_timeout = 60
c3f1f8
 #
c3f1f8
-# mount_verbose - use the -v flag when calling mount(8).
c3f1f8
+# mount_verbose - use the -v flag when calling mount(8) and log some
c3f1f8
+#		  process information about the requestor and its
c3f1f8
+#		  parent.
c3f1f8
 #
c3f1f8
 #mount_verbose = no
c3f1f8
 #