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