Deleted Added
full compact
hostres_swinstalled_tbl.c (302408) hostres_swinstalled_tbl.c (310899)
1/*
2 * Copyright (c) 2005-2006 The FreeBSD Project
3 * All rights reserved.
4 *
5 * Author: Victor Cruceru <soc-victor@freebsd.org>
6 *
7 * Redistribution of this software and documentation and use in source and
8 * binary forms, with or without modification, are permitted provided that

--- 12 unchanged lines hidden (view full) ---

21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
1/*
2 * Copyright (c) 2005-2006 The FreeBSD Project
3 * All rights reserved.
4 *
5 * Author: Victor Cruceru <soc-victor@freebsd.org>
6 *
7 * Redistribution of this software and documentation and use in source and
8 * binary forms, with or without modification, are permitted provided that

--- 12 unchanged lines hidden (view full) ---

21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * $FreeBSD: stable/11/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_swinstalled_tbl.c 160341 2006-07-14 09:07:56Z harti $
29 * $FreeBSD: stable/11/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_swinstalled_tbl.c 310899 2016-12-31 10:28:59Z ngie $
30 *
31 * Host Resources MIB implementation for SNMPd: instrumentation for
32 * hrSWInstalledTable
33 */
34
35#include <sys/limits.h>
36#include <sys/stat.h>
37#include <sys/sysctl.h>

--- 7 unchanged lines hidden (view full) ---

45#include <string.h>
46#include <syslog.h>
47#include <sysexits.h>
48
49#include "hostres_snmp.h"
50#include "hostres_oid.h"
51#include "hostres_tree.h"
52
30 *
31 * Host Resources MIB implementation for SNMPd: instrumentation for
32 * hrSWInstalledTable
33 */
34
35#include <sys/limits.h>
36#include <sys/stat.h>
37#include <sys/sysctl.h>

--- 7 unchanged lines hidden (view full) ---

45#include <string.h>
46#include <syslog.h>
47#include <sysexits.h>
48
49#include "hostres_snmp.h"
50#include "hostres_oid.h"
51#include "hostres_tree.h"
52
53#define CONTENTS_FNAME "+CONTENTS"
53#define CONTENTS_FNAME "+CONTENTS"
54
55enum SWInstalledType {
56 SWI_UNKNOWN = 1,
57 SWI_OPERATING_SYSTEM = 2,
58 SWI_DEVICE_DRIVER = 3,
59 SWI_APPLICATION = 4
60};
61

--- 69 unchanged lines hidden (view full) ---

131 STAILQ_FOREACH(map, &swins_map, link)
132 if (strcmp((const char *)map->name, name) == 0)
133 break;
134
135 if (map == NULL) {
136 size_t name_len;
137 /* new object - get a new index */
138 if (next_swins_index > INT_MAX) {
54
55enum SWInstalledType {
56 SWI_UNKNOWN = 1,
57 SWI_OPERATING_SYSTEM = 2,
58 SWI_DEVICE_DRIVER = 3,
59 SWI_APPLICATION = 4
60};
61

--- 69 unchanged lines hidden (view full) ---

131 STAILQ_FOREACH(map, &swins_map, link)
132 if (strcmp((const char *)map->name, name) == 0)
133 break;
134
135 if (map == NULL) {
136 size_t name_len;
137 /* new object - get a new index */
138 if (next_swins_index > INT_MAX) {
139 syslog(LOG_ERR, "%s: hrSWInstalledTable index wrap",
139 syslog(LOG_ERR, "%s: hrSWInstalledTable index wrap",
140 __func__ );
141 /* There isn't much we can do here.
142 * If the next_swins_index is consumed
143 * then we can't add entries to this table
144 * So it is better to exit - if the table is sparsed
145 * at the next agent run we can fill it fully.
146 */
147 errx(EX_SOFTWARE, "hrSWInstalledTable index wrap");

--- 139 unchanged lines hidden (view full) ---

287 * Read the installed packages
288 */
289static int
290swins_get_packages(void)
291{
292 struct stat sb;
293 DIR *p_dir;
294 struct dirent *ent;
140 __func__ );
141 /* There isn't much we can do here.
142 * If the next_swins_index is consumed
143 * then we can't add entries to this table
144 * So it is better to exit - if the table is sparsed
145 * at the next agent run we can fill it fully.
146 */
147 errx(EX_SOFTWARE, "hrSWInstalledTable index wrap");

--- 139 unchanged lines hidden (view full) ---

287 * Read the installed packages
288 */
289static int
290swins_get_packages(void)
291{
292 struct stat sb;
293 DIR *p_dir;
294 struct dirent *ent;
295 struct tm k_ts;
295 struct tm k_ts;
296 char *pkg_file;
297 struct swins_entry *entry;
298 int ret = 0;
299
300 if (pkg_dir == NULL)
301 /* initialisation may have failed */
302 return (-1);
303

--- 18 unchanged lines hidden (view full) ---

322 }
323
324 if ((p_dir = opendir(pkg_dir)) == NULL) {
325 syslog(LOG_ERR, "hrSWInstalledTable: opendir(\"%s\") failed: "
326 "%m", pkg_dir);
327 return (-1);
328 }
329
296 char *pkg_file;
297 struct swins_entry *entry;
298 int ret = 0;
299
300 if (pkg_dir == NULL)
301 /* initialisation may have failed */
302 return (-1);
303

--- 18 unchanged lines hidden (view full) ---

322 }
323
324 if ((p_dir = opendir(pkg_dir)) == NULL) {
325 syslog(LOG_ERR, "hrSWInstalledTable: opendir(\"%s\") failed: "
326 "%m", pkg_dir);
327 return (-1);
328 }
329
330 while (errno = 0, (ent = readdir(p_dir)) != NULL) {
330 while (errno = 0, (ent = readdir(p_dir)) != NULL) {
331 HRDBG(" pkg file: %s", ent->d_name);
332
333 /* check that the contents file is a regular file */
334 if (asprintf(&pkg_file, "%s/%s/%s", pkg_dir, ent->d_name,
335 CONTENTS_FNAME) == -1)
336 continue;
337
338 if (stat(pkg_file, &sb) != 0 ) {

--- 27 unchanged lines hidden (view full) ---

366 goto PKG_LOOP_END;
367 }
368
369 entry->flags |= HR_SWINSTALLED_FOUND;
370 entry->id = &oid_zeroDotZero;
371 entry->type = (int32_t)SWI_APPLICATION;
372
373 entry->date_len = make_date_time(entry->date, &k_ts, 0);
331 HRDBG(" pkg file: %s", ent->d_name);
332
333 /* check that the contents file is a regular file */
334 if (asprintf(&pkg_file, "%s/%s/%s", pkg_dir, ent->d_name,
335 CONTENTS_FNAME) == -1)
336 continue;
337
338 if (stat(pkg_file, &sb) != 0 ) {

--- 27 unchanged lines hidden (view full) ---

366 goto PKG_LOOP_END;
367 }
368
369 entry->flags |= HR_SWINSTALLED_FOUND;
370 entry->id = &oid_zeroDotZero;
371 entry->type = (int32_t)SWI_APPLICATION;
372
373 entry->date_len = make_date_time(entry->date, &k_ts, 0);
374 }
374 }
375
376 if (errno != 0) {
377 syslog(LOG_ERR, "hrSWInstalledTable: readdir_r(\"%s\") failed:"
378 " %m", pkg_dir);
379 ret = -1;
380 } else {
381 /*
382 * save the timestamp of directory

--- 173 unchanged lines hidden ---
375
376 if (errno != 0) {
377 syslog(LOG_ERR, "hrSWInstalledTable: readdir_r(\"%s\") failed:"
378 " %m", pkg_dir);
379 ret = -1;
380 } else {
381 /*
382 * save the timestamp of directory

--- 173 unchanged lines hidden ---