Re: FreeBSD pkg HOST-RESOURCES-MIB::hrSWInstalled stops working

Mark Felder <[email protected]>
Newsgroups gmane.network.net-snmp.devel
Message-ID <1526058978.2824355.1368963760.32E1D51E@webmail.messagingengine.com>
On Mon, May 7, 2018, at 15:08, Robert Story wrote:
> On Mon, 07 May 2018 11:44:59 -0500 Mark wrote:
> MF> The HOST-RESOURCES-MIB::hrSWInstalled support for FreeBSD pkg
> MF> stops working after so many queries and requires an snmpd
> MF> process restart. I have been observing this for quite some time
> MF> and have only recently started to debug it. The code in
> MF> question is at:
> MF> 
> MF> agent/mibgroup/host/data_access/swinst_pkginfo.c
> MF> 
> MF> When debugging I see it throw either:
> MF> 
> MF> snmp_log( LOG_ERR, "SWInst: error initializing pkgng db\n" );
> MF> 
> MF> or
> MF> 
> MF> snmp_log( LOG_ERR, "SWInst: error opening pkgng db\n" );
> MF> 
> MF> neither of which should be true as nothing on the system
> MF> changes. After seeing one of these for a few times there are no
> MF> further messages [...]
> 
> Can you run with "-Dswinst:load:arch --logTimestamp=yes", and
> then run "grep -i swinst" on the log file and send it?
> 
> MF> Could anyone provide any possible insight or ideas on what
> MF> could be the issue here? I have compared the code with that
> MF> used internally in FreeBSD pkg tool and it's nearly identical.
> MF> The only thing that I felt was missing was declaring a readonly
> MF> lock on the database but even adding that into the snmp code
> MF> had no effect...
> 
> There are quite a few places that don't clean up properly before
> returning, but that should only affect error paths.
> 
> You can also try this patch to see if you get more useful debug
> info:
> 
> diff --git a/agent/mibgroup/host/data_access/swinst_pkginfo.c b/agent/
> mibgroup/host/data_access/swinst_pkginfo.c
> index 861d79f0f..de2abf19b 100644
> --- a/agent/mibgroup/host/data_access/swinst_pkginfo.c
> +++ b/agent/mibgroup/host/data_access/swinst_pkginfo.c
> @@ -118,12 +118,15 @@ netsnmp_swinst_arch_load( netsnmp_container 
> *container, u_int flags)
> 
>      if (pkgdb_open(&db, PKGDB_DEFAULT) != EPKG_OK) {
>         snmp_log( LOG_ERR, "SWInst: error opening pkgng db\n" );
> +        pkg_shutdown();
>         return 1;
>      }
> 
>      if (pkg_status(NULL) == PKG_STATUS_ACTIVE) {
>         pkgng = 1;
>      } else {
> +        pkgdb_close(db);
> +        pkg_shutdown();
>         snmp_log( LOG_INFO, "SWInst: not a pkgng system\n" );
>      }
> 
> @@ -131,9 +134,12 @@ netsnmp_swinst_arch_load( netsnmp_container 
> *container, u_int flags)
>      if (pkgng) {
>          if ((it = pkgdb_query(db, NULL, MATCH_ALL)) == NULL) {
>              snmp_log( LOG_ERR, "SWInst: error querying pkgng db\n" );
> +            pkgdb_close(db);
> +            pkg_shutdown();
>              return 1;
>          }
> 
> +        DEBUGMSGTL(("swinst:load:arch"," pkgdb available\n"));
>          while (pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC) == EPKG_OK) {
>              pkg_snprintf(pkgname, sizeof(pkgname), "%n-%v", pkg, pkg);
>              pkg_snprintf(pkgdate, sizeof(pkgdate), "%t", pkg);
> @@ -162,13 +168,18 @@ netsnmp_swinst_arch_load( netsnmp_container 
> *container, u_int flags)
>      } else {
>  #endif /* HAVE_LIBPKG */
>          if ( !pkg_directory[0] ) {
> +            NETSNMP_LOGONCE(LOG_ERR, "SWInst: no pkg_directory 
> available\n");
>              return 1;    /* Can't report installed packages
>                           if there isn't a list of them! */
>          }
> 
> +        DEBUGMSGTL(("swinst:load:arch"," pkgdb available\n"));
>          d = opendir( pkg_directory );
> -        if (!d)
> +        if (!d) {
> +            snmp_log( LOG_ERR, "SWInst: error querying pkg_directory %s\n",
> +                      pkg_directory );
>              return 1;
> +        }
> 
>          while ((dp = readdir(d)) != NULL) {
>              if ( '.' == dp->d_name[0] )


Hi Robert,

I had to tweak your patch slightly, but this is the result showing it working and then suddenly it stops.


2018-05-11 17:11:42     -- hrSWInstalledDate.241
2018-05-11 17:11:42     -- hrSWInstalledDate.242
2018-05-11 17:11:42     -- hrSWInstalledDate.243
2018-05-11 17:11:42     -- hrSWInstalledDate.244
2018-05-11 17:11:42     -- hrSWInstalledDate.245
2018-05-11 17:11:42     -- hrSWInstalledDate.246
2018-05-11 17:11:42     -- hrSWInstalledDate.247
2018-05-11 17:11:42     -- hrSWInstalledDate.248
2018-05-11 17:11:43     -- hrSWInstalled
2018-05-11 17:11:43 SWInst: error opening pkgng db
2018-05-11 17:11:43     -- hrSWInstalled
2018-05-11 17:11:50     -- hrSWInstalled
2018-05-11 17:11:50     -- hrSWInstalled
2018-05-11 17:11:58     -- hrSWInstalled
2018-05-11 17:11:58     -- hrSWInstalled
2018-05-11 17:12:02     -- hrSWInstalled
2018-05-11 17:12:02     -- hrSWInstalled


Patch change was  NETSNMP_LOGONCE() -> snmp_log() because it didn't like it:

host/data_access/swinst_pkginfo.c:170:38: error: too many arguments provided to function-like macro invocation
            NETSNMP_LOGONCE(LOG_ERR, "SWInst: no pkg_directory available\n");


Thanks for your time.


Mark


-- 
  Mark Felder
  ports-secteam & portmgr member
  [email protected]

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.