Re: Process.CountEx

From: Alex Kirhenshtein <alk_at_DOMAIN_REMOVED>
Date: Tue, 24 Apr 2007 13:53:59 +0300

Поправил, вроде работает (проверял на Debian/testing)

Lobahin Ilya wrote:
> Здравствуйте NetXMS Users - Russian!
> 24 апреля 2007 г. вы писали.
>
>
> AK> А оно вообще работало?
> AK> Судя по коду — не должно.
> AK> Сейчас проверю патч — выложу.
>
> Работало.
> Был патч от Edgar Chupit <chupit_at_gmail.com>
> Он потом этот патчик в ветку netxms-dev засылал, 22 января.
>
>>> После обновления агента на 0.2.16 - перестал отрабатывать DCI:
>>> Process.CountEx(java,".+db.cfg.+resin.+$")
>
>
>
>
> ----------------
> С уважением.
> Lobahin Ilya
>
>

diff -ur netxms-0.2.16/src/agent/subagents/linux/proc.cpp netxms-0.2.16.new/src/agent/subagents/linux/proc.cpp
--- netxms-0.2.16/src/agent/subagents/linux/proc.cpp 2007-01-22 11:16:43.000000000 +0200
+++ netxms-0.2.16.new/src/agent/subagents/linux/proc.cpp 2007-04-24 13:44:37.000000000 +0300
@@ -151,10 +151,27 @@
             hFile = fopen(szFileName, "r");
             if (hFile != NULL)
             {
- char szBuff[1024] = {0};
- if (fgets(szBuff, sizeof(szBuff), hFile) != NULL)
+ char szBuff[1024];
+ memset(szBuff, 0, sizeof(szBuff));
+
+ int len = fread(szBuff, 1, sizeof(szBuff) - 1, hFile);
+ if (len > 0) // got a valid record in format: argv[0]\x00argv[1]\x00...
                {
- bCmdFound = RegexpMatch(szBuff, szCmdLine, bIgnoreCase);
+ int j;
+ char *pArgs;
+
+ j = strlen(szBuff) + 1;
+ pArgs = szBuff + j; // skip first (argv[0])
+ len -= j;
+ // replace 0x00 with spaces
+ for (j = 0; j < len - 1; j++)
+ {
+ if (pArgs[j] == 0)
+ {
+ pArgs[j] = ' ';
+ }
+ }
+ bCmdFound = RegexpMatch(pArgs, szCmdLine, bIgnoreCase);
                }
                else
                {
Received on Tue Apr 24 2007 - 13:53:59 EEST

This archive was generated by hypermail 2.2.0 : Tue Apr 24 2007 - 13:53:53 EEST