|
|
a856a8 |
From f4958b548776e8b9c9c5ef211116eb503aff8e5b Mon Sep 17 00:00:00 2001
|
|
|
a856a8 |
From: Jiri Vymazal <jvymazal@redhat.com>
|
|
|
a856a8 |
Date: Tue, 18 Apr 2017 16:42:22 +0200
|
|
|
a856a8 |
Subject: [PATCH] Putting process name into ratelimiter with imuxsock
|
|
|
a856a8 |
|
|
|
a856a8 |
---
|
|
|
a856a8 |
plugins/imuxsock/imuxsock.c | 25 ++++++++++++++++++++-----
|
|
|
a856a8 |
1 file changed, 20 insertions(+), 5 deletions(-)
|
|
|
a856a8 |
|
|
|
a856a8 |
diff --git a/plugins/imuxsock/imuxsock.c b/plugins/imuxsock/imuxsock.c
|
|
|
a856a8 |
index 277c30e..1a57f6e 100644
|
|
|
a856a8 |
--- a/plugins/imuxsock/imuxsock.c
|
|
|
a856a8 |
+++ b/plugins/imuxsock/imuxsock.c
|
|
|
a856a8 |
@@ -594,7 +594,7 @@ findRatelimiter(lstn_t *pLstn, struct ucred *cred, ratelimit_t **prl)
|
|
|
a856a8 |
ratelimit_t *rl = NULL;
|
|
|
a856a8 |
int r;
|
|
|
a856a8 |
pid_t *keybuf;
|
|
|
a856a8 |
- char pidbuf[256];
|
|
|
a856a8 |
+ char pinfobuf[512];
|
|
|
a856a8 |
DEFiRet;
|
|
|
a856a8 |
|
|
|
a856a8 |
if(cred == NULL)
|
|
|
a856a8 |
@@ -616,10 +616,25 @@ findRatelimiter(lstn_t *pLstn, struct ucred *cred, ratelimit_t **prl)
|
|
|
a856a8 |
DBGPRINTF("imuxsock: no ratelimiter for pid %lu, creating one\n",
|
|
|
a856a8 |
(unsigned long) cred->pid);
|
|
|
a856a8 |
STATSCOUNTER_INC(ctrNumRatelimiters, mutCtrNumRatelimiters);
|
|
|
a856a8 |
- snprintf(pidbuf, sizeof(pidbuf), "pid %lu",
|
|
|
a856a8 |
- (unsigned long) cred->pid);
|
|
|
a856a8 |
- pidbuf[sizeof(pidbuf)-1] = '\0'; /* to be on safe side */
|
|
|
a856a8 |
- CHKiRet(ratelimitNew(&rl, "imuxsock", pidbuf));
|
|
|
a856a8 |
+ /* read process name from system */
|
|
|
a856a8 |
+ char procName[256]; /* enough for any sane process name */
|
|
|
a856a8 |
+ snprintf(procName, sizeof(procName), "/proc/%lu/cmdline", (unsigned long) cred->pid);
|
|
|
a856a8 |
+ FILE *f = fopen(procName, "r");
|
|
|
a856a8 |
+ if (f) {
|
|
|
a856a8 |
+ size_t len;
|
|
|
a856a8 |
+ len = fread(procName, sizeof(char), 256, f);
|
|
|
a856a8 |
+ if (len > 0) {
|
|
|
a856a8 |
+ snprintf(pinfobuf, sizeof(pinfobuf), "pid: %lu, name: %s",
|
|
|
a856a8 |
+ (unsigned long) cred->pid, procName);
|
|
|
a856a8 |
+ }
|
|
|
a856a8 |
+ fclose(f);
|
|
|
a856a8 |
+ }
|
|
|
a856a8 |
+ else {
|
|
|
a856a8 |
+ snprintf(pinfobuf, sizeof(pinfobuf), "pid: %lu",
|
|
|
a856a8 |
+ (unsigned long) cred->pid);
|
|
|
a856a8 |
+ }
|
|
|
a856a8 |
+ pinfobuf[sizeof(pinfobuf)-1] = '\0'; /* to be on safe side */
|
|
|
a856a8 |
+ CHKiRet(ratelimitNew(&rl, "imuxsock", pinfobuf));
|
|
|
a856a8 |
ratelimitSetLinuxLike(rl, pLstn->ratelimitInterval, pLstn->ratelimitBurst);
|
|
|
a856a8 |
ratelimitSetSeverity(rl, pLstn->ratelimitSev);
|
|
|
a856a8 |
CHKmalloc(keybuf = malloc(sizeof(pid_t)));
|