~ubuntu-branches/ubuntu/lucid/net-snmp/lucid

« back to all changes in this revision

Viewing changes to snmplib/callback.c

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-11-26 01:27:00 UTC
  • mfrom: (1.1.9 sid)
  • Revision ID: james.westby@ubuntu.com-20091126012700-pox7w0a5j2x305h9
Tags: 5.4.2.1~dfsg-3ubuntu1
* Merge from debian testing.  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/patches/99-fix-ubuntu-div0.patch: Fix dvision by zero.
    (LP: #426813).
 * Dropped patches:
   - debian/patches/101-fix-ipalias.patch: Applied upstream.
   - debian/patches/99-fix-net-snmp-syslog.patch: Applied upstream.
   - debian/patches/99-fix-perl-counter-in-subagent.patch: Applied upstream.
   - ebian/patches/103-fix-ubuntu-lmsensors.patch: No longer needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
#include <dmalloc.h>
39
39
#endif
40
40
 
 
41
#if HAVE_SYS_SOCKET_H
 
42
#include <sys/socket.h>
 
43
#endif
 
44
#if HAVE_SYS_TIME_H
 
45
#include <sys/time.h>
 
46
#endif
 
47
 
41
48
#include <net-snmp/types.h>
42
49
#include <net-snmp/output_api.h>
43
50
#include <net-snmp/utilities.h>
94
101
#define LOCK_PER_CALLBACK_SUBID 1
95
102
#ifdef LOCK_PER_CALLBACK_SUBID
96
103
static int _locks[MAX_CALLBACK_IDS][MAX_CALLBACK_SUBIDS];
97
 
#define CALLBACK_LOCK(maj,min) ++_locks[major][minor]
98
 
#define CALLBACK_UNLOCK(maj,min) --_locks[major][minor]
99
 
#define CALLBACK_LOCK_COUNT(maj,min) _locks[major][minor]
 
104
#define CALLBACK_LOCK(maj,min) ++_locks[maj][min]
 
105
#define CALLBACK_UNLOCK(maj,min) --_locks[maj][min]
 
106
#define CALLBACK_LOCK_COUNT(maj,min) _locks[maj][min]
100
107
#else
101
108
static int _lock;
102
109
#define CALLBACK_LOCK(maj,min) ++_lock
107
114
NETSNMP_STATIC_INLINE int
108
115
_callback_lock(int major, int minor, const char* warn, int assert)
109
116
{
 
117
    int lock_holded=0;
 
118
    struct timeval lock_time = { 0, 1000 };
 
119
 
110
120
#ifdef NETSNMP_PARANOID_LEVEL_HIGH
111
121
    if (major >= MAX_CALLBACK_IDS || minor >= MAX_CALLBACK_SUBIDS) {
112
122
        netsnmp_assert("bad callback id");
119
129
                types[major], (SNMP_CALLBACK_LIBRARY == major) ?
120
130
                SNMP_STRORNULL(lib[minor]) : "null"));
121
131
#endif
122
 
    if (CALLBACK_LOCK(major,minor) > 1)
123
 
        {
 
132
    while (CALLBACK_LOCK_COUNT(major,minor) >= 1 && ++lock_holded < 100)
 
133
        select(0, NULL, NULL, NULL, &lock_time);
 
134
 
 
135
    if(lock_holded >= 100) {
124
136
        if (NULL != warn)
125
137
            snmp_log(LOG_WARNING,
126
 
                     "_callback_lock already locket in %s\n", warn);
 
138
                     "lock in _callback_lock sleeps more than 100 milliseconds in %s\n", warn);
127
139
        if (assert)
128
 
            netsnmp_assert(1==CALLBACK_LOCK_COUNT(major,minor));
 
140
            netsnmp_assert(lock_holded < 100);
129
141
        
130
142
        return 1;
131
143
    }
132
 
    else
133
 
        return 0;
134
 
    
 
144
 
 
145
    CALLBACK_LOCK(major,minor);
 
146
    return 0;
135
147
}
136
148
 
137
149
NETSNMP_STATIC_INLINE void