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

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