~ubuntu-branches/ubuntu/wily/net-snmp/wily-proposed

« back to all changes in this revision

Viewing changes to agent/mibgroup/host/hr_swinst.c

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2010-06-28 14:59:36 UTC
  • mfrom: (1.2.3 upstream) (1.1.12 sid)
  • Revision ID: james.westby@ubuntu.com-20100628145936-cbiallic69pn044g
Tags: 5.4.3~dfsg-1ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Set Ubuntu maintainer address.
  - net-snmp-config: Use bash. (LP: #104738)
  - Removed multiuser option when calling update-rc.d. (LP: #254261)
  - debian/snmpd.init: LSBify the init script.
  - debian/patches/52_fix_snmpcmd_1_typo.patch: Adjust a typo in snmpcmd.1
    (LP: #250459)
  - debian/snmpd.postinst: source debconf before doing work, LP: #589056
  - debian/snmp.preinst, debian/snmp.prerm: kill any/all processes owned by
    snmp user before install/uninstall, LP: #573391
  - Add apport hook (LP: #533603):
  - debian/{snmp,snmpd}.apport: Added.
  - debian/control: Build-depends on dh-apport.
  - debian/rules: 
    + Add --with apport.
    + override_dh_apport to install hook on snmpd package only.
 * Dropped patches:
   - debian/patches/99-fix-ubuntu-div0.patch: Fix dvision by zero.. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
136
136
extern void     Init_HR_SWInst(void);
137
137
extern int      Get_Next_HR_SWInst(void);
138
138
extern void     End_HR_SWInst(void);
139
 
extern void     Save_HR_SW_info(int ix);
 
139
extern int      Save_HR_SW_info(int ix);
140
140
 
141
141
#ifdef HAVE_LIBRPM
142
142
static void     Mark_HRSW_token(void);
288
288
    oid             newname[MAX_OID_LEN];
289
289
    int             swinst_idx, LowIndex = -1;
290
290
    int             result;
 
291
    int             err = 0, errcount = 0;
291
292
 
292
293
    DEBUGMSGTL(("host/hr_swinst", "var_hrswinstEntry: "));
293
294
    DEBUGMSGOID(("host/hr_swinst", name, *length));
298
299
     * Find "next" installed software entry 
299
300
     */
300
301
 
301
 
    Init_HR_SWInst();
302
 
    while ((swinst_idx = Get_Next_HR_SWInst()) != -1) {
303
 
        DEBUGMSG(("host/hr_swinst", "(index %d ....", swinst_idx));
 
302
    do {
 
303
        Init_HR_SWInst();
 
304
        while ((swinst_idx = Get_Next_HR_SWInst()) != -1) {
 
305
            DEBUGMSG(("host/hr_swinst", "(index %d ....", swinst_idx));
304
306
 
305
 
        newname[HRSWINST_ENTRY_NAME_LENGTH] = swinst_idx;
306
 
        DEBUGMSGOID(("host/hr_swinst", newname, *length));
307
 
        DEBUGMSG(("host/hr_swinst", "\n"));
308
 
        result = snmp_oid_compare(name, *length, newname, vp->namelen + 1);
309
 
        if (exact && (result == 0)) {
310
 
            LowIndex = swinst_idx;
311
 
            Save_HR_SW_info(LowIndex);
312
 
            break;
313
 
        }
314
 
        if ((!exact && (result < 0)) &&
315
 
            (LowIndex == -1 || swinst_idx < LowIndex)) {
316
 
            LowIndex = swinst_idx;
317
 
            Save_HR_SW_info(LowIndex);
 
307
            newname[HRSWINST_ENTRY_NAME_LENGTH] = swinst_idx;
 
308
            DEBUGMSGOID(("host/hr_swinst", newname, *length));
 
309
            DEBUGMSG(("host/hr_swinst", "\n"));
 
310
            result = snmp_oid_compare(name, *length, newname, vp->namelen + 1);
 
311
            if (exact && (result == 0)) {
 
312
                LowIndex = swinst_idx;
 
313
                err = Save_HR_SW_info(LowIndex);
 
314
                break;
 
315
            }
 
316
            if ((!exact && (result < 0)) &&
 
317
                (LowIndex == -1 || swinst_idx < LowIndex)) {
 
318
                LowIndex = swinst_idx;
 
319
                err = Save_HR_SW_info(LowIndex);
318
320
#ifdef HRSWINST_MONOTONICALLY_INCREASING
319
 
            break;
 
321
                break;
320
322
#endif
 
323
            }
321
324
        }
 
325
        if (err != 0 )
 
326
            errcount++;
 
327
    /* restart until Save_HR_SW_info() succeeds,max. 3 times */
 
328
    } while (err != 0 && errcount < 3); 
 
329
    if (err != 0) {
 
330
        DEBUGMSGTL(("host/hr_swinst", "restart did not help, bailing out\n"));
 
331
        return (MATCH_FAILED);
322
332
    }
323
 
 
 
333
            
324
334
    Mark_HRSW_token();
325
335
    End_HR_SWInst();
326
336
 
417
427
#ifdef HAVE_PKGINFO
418
428
            pver = pkgparam(swi->swi_name, "VERSION");
419
429
            /* 1 spot for the terminating null and one for the dash */
420
 
            if (strlen(pver) + 2 + strlen(string) <= sizeof(string)) {
 
430
            if (pver &&
 
431
               (strlen(pver) + 2 + strlen(string) <= sizeof(string))) {
421
432
                strcat(string, "-");
422
433
                strcat(string, pver);
423
434
            }
477
488
    case HRSWINST_DATE:
478
489
        {
479
490
#ifdef HAVE_LIBRPM
480
 
            int_32         *rpm_data;
 
491
            int         *rpm_data;
481
492
            if ( headerGetEntry(swi->swi_h, RPMTAG_INSTALLTIME, NULL, (void **) &rpm_data, NULL) ) {
482
493
                time_t          installTime = *rpm_data;
483
494
                ret = date_n_time(&installTime, var_len);
634
645
    return -1;
635
646
}
636
647
 
637
 
void
 
648
int
638
649
Save_HR_SW_info(int ix)
639
650
{
640
651
    SWI_t          *swi = &_myswi;      /* XXX static for now */
663
674
        h = rpmdbGetRecord(swi->swi_rpmdb, offset);
664
675
#endif
665
676
 
666
 
        if (h == NULL)
667
 
            return;
 
677
        if (h == NULL) {
 
678
            DEBUGMSGTL(("host/hr_swinst",
 
679
                    "RPM cache has probably expired when reading entry %d, "
 
680
                    "reloading...\n", ix));
 
681
            swi->swi_timestamp = 0;
 
682
            return -1;
 
683
        }
668
684
        if (swi->swi_h != NULL)
669
685
            headerFree(swi->swi_h);
670
686
        swi->swi_h = h;
682
698
    snprintf(swi->swi_name, sizeof(swi->swi_name), swi->swi_dep->d_name);
683
699
    swi->swi_name[ sizeof(swi->swi_name)-1 ] = 0;
684
700
#endif
 
701
    return 0;
685
702
}
686
703
 
687
704
#ifdef  HAVE_LIBRPM