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

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