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