]> git.pld-linux.org Git - packages/net-snmp.git/blob - swinst_apt.patch
Bug 1314610 - snmpd complaining twice "Cannot statfs net:[********]#***: No such...
[packages/net-snmp.git] / swinst_apt.patch
1 improvements to HOST-RESOURCES-MIB::hrSWInstalled on debian systems
2
3 - add Install Date information instead of bogus 0-1-1
4 - include Arch in package names, like rpm output does
5 - use debian native separators `_` for package components, not rpm ones: `-`
6
7 to test:
8 snmpbulkwalk localhost HOST-RESOURCES-MIB::hrSWInstalled
9
10 Signed-Off-By: Elan Ruusamäe <glen@pld-linux.org>
11
12 --- net-snmp-5.7.3/agent/mibgroup/host/data_access/swinst_apt.c~        2016-04-23 17:40:44.000000000 +0300
13 +++ net-snmp-5.7.3/agent/mibgroup/host/data_access/swinst_apt.c 2016-04-23 17:40:49.740392789 +0300
14 @@ -22,6 +22,7 @@
15  #ifdef HAVE_FCNTL_H
16  #include <fcntl.h>
17  #endif
18 +#include <sys/stat.h>
19  
20  #include <net-snmp/net-snmp-includes.h>
21  #include <net-snmp/agent/net-snmp-agent-includes.h>
22 @@ -29,8 +30,11 @@
23  #include <net-snmp/library/snmp_debug.h>
24  #include <net-snmp/data_access/swinst.h>
25  
26 +netsnmp_feature_require(date_n_time)
27 +
28  char pkg_directory[SNMP_MAXBUF];
29  static char apt_fmt[SNMP_MAXBUF];
30 +static char file[SNMP_MAXBUF];
31  
32  /* ---------------------------------------------------------------------
33   */
34 @@ -38,8 +42,8 @@
35  netsnmp_swinst_arch_init(void)
36  {
37      strlcpy(pkg_directory, "/var/lib/dpkg/info", sizeof(pkg_directory));
38 -    snprintf(apt_fmt, SNMP_MAXBUF, "%%%d[^#]#%%%d[^#]#%%%d[^#]#%%%d[^#]#%%%d[^#]#%%%ds",
39 -       SNMP_MAXBUF-1, SNMP_MAXBUF-1, SNMP_MAXBUF-1,
40 +    snprintf(apt_fmt, SNMP_MAXBUF, "%%%d[^#]#%%%d[^#]#%%%d[^#]#%%%d[^#]#%%%d[^#]#%%%d[^#]#%%%ds",
41 +       SNMP_MAXBUF-1, SNMP_MAXBUF-1, SNMP_MAXBUF-1, SNMP_MAXBUF-1,
42         SNMP_MAXBUF-1, SNMP_MAXBUF-1, SNMP_MAXBUF-1);
43  }
44  
45 @@ -55,15 +59,19 @@
46  int
47  netsnmp_swinst_arch_load( netsnmp_container *container, u_int flags)
48  {
49 -    FILE *p = popen("dpkg-query --show --showformat '${Package}#${Version}#${Section}#${Priority}#${Essential}#${Status}\n'", "r");
50 +    FILE *p = popen("dpkg-query --show --showformat '${Package}#${Version}#${Section}#${Priority}#${Essential}#${Architecture}#${Status}\n'", "r");
51      char package[SNMP_MAXBUF];
52      char version[SNMP_MAXBUF];
53      char section[SNMP_MAXBUF];
54      char priority[SNMP_MAXBUF];
55      char essential[SNMP_MAXBUF];
56 +    char arch[SNMP_MAXBUF];
57      char status[SNMP_MAXBUF];
58      char buf[BUFSIZ];
59 +    struct stat stat_buf;
60      netsnmp_swinst_entry *entry;
61 +    u_char *date_buf;
62 +    size_t date_len;
63      int i = 0;
64  
65      if (p == NULL) {
66 @@ -78,20 +86,39 @@
67              continue;   /* error already logged by function */
68          CONTAINER_INSERT(container, entry);
69  
70 -       sscanf(buf, apt_fmt, package, version, section, priority, essential, status);
71 +       sscanf(buf, apt_fmt, package, version, section, priority, essential, arch, status);
72         if (strstr(status, "not-installed"))
73             continue;
74  
75          entry->swName_len = snprintf( entry->swName, sizeof(entry->swName),
76 -                                      "%s-%s", package, version);
77 +                                      "%s_%s_%s", package, version, arch);
78         if (entry->swName_len >= sizeof(entry->swName))
79             entry->swName_len = sizeof(entry->swName)-1;
80          entry->swType = (strcmp(essential, "yes") == 0)
81                          ? 2      /* operatingSystem */
82                          : 4;     /*  application    */
83  
84 -        entry->swDate_len = 8;
85 -       memcpy(entry->swDate, "\0\0\1\1\0\0\0\0", 8);
86 +        /* get the last mod date */
87 +        snprintf(file, sizeof(file), "%s/%s.list", pkg_directory, package);
88 +        if(stat(file, &stat_buf) != -1) {
89 +            date_buf = date_n_time(&stat_buf.st_mtime, &date_len);
90 +            entry->swDate_len = date_len;
91 +            memcpy(entry->swDate, date_buf, entry->swDate_len);
92 +        } else {
93 +            /* somewhy some files include :arch in .list name */
94 +            snprintf(file, sizeof(file), "%s/%s:%s.list", pkg_directory, package, arch);
95 +            if(stat(file, &stat_buf) != -1) {
96 +                date_buf = date_n_time(&stat_buf.st_mtime, &date_len);
97 +                entry->swDate_len = date_len;
98 +                memcpy(entry->swDate, date_buf, entry->swDate_len);
99 +            }
100 +        }
101 +        /* FIXME, or fallback to whatever nonsesnse was here before, or leave it uninitialied?
102 +             else {
103 +            entry->swDate_len = 8;
104 +            memcpy(entry->swDate, "\0\0\1\1\0\0\0\0", 8);
105 +        }
106 +        */
107      }
108      pclose(p);
109      DEBUGMSGTL(("swinst:load:arch"," loaded %d entries\n",
This page took 0.117558 seconds and 3 git commands to generate.