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

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