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

156 lines
4.7 KiB
Diff

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