~ubuntu-branches/ubuntu/precise/net-snmp/precise

« back to all changes in this revision

Viewing changes to agent/mibgroup/hardware/cpu/cpu_linux.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:
100
100
    static int   bsize = 0;
101
101
    static int   first = 1;
102
102
    static int   has_cpu_26 = 1;
103
 
    int          statfd, i;
 
103
    int          bytes_read, statfd, i;
104
104
    char        *b1, *b2;
105
105
    unsigned long long cusell = 0, cicell = 0, csysll = 0, cidell = 0,
106
106
                       ciowll = 0, cirqll = 0, csoftll = 0;
111
111
        return -1;
112
112
    }
113
113
    if (bsize == 0) {
114
 
        bsize = 256;
115
 
        buff = malloc(bsize);
 
114
        bsize = getpagesize()-1;
 
115
        buff = malloc(bsize+1);
116
116
    }
117
 
    while (read(statfd, buff, bsize) == bsize) {
118
 
        bsize += 256;
119
 
        buff = realloc(buff, bsize);
 
117
    while ((bytes_read = read(statfd, buff, bsize)) == bsize) {
 
118
        bsize += BUFSIZ;
 
119
        buff = realloc(buff, bsize+1);
120
120
        DEBUGMSGTL(("cpu", "/proc/stat buffer increased to %d\n", bsize));
121
121
        close(statfd);
122
122
        statfd = open(STAT_FILE, O_RDONLY, 0);
123
123
    }
124
124
    close(statfd);
125
125
 
 
126
    if ( bytes_read < 0 ) {
 
127
        snmp_log_perror(STAT_FILE "read error");
 
128
        return -1;
 
129
    }
 
130
    buff[bytes_read] = '\0';
 
131
 
126
132
        /*
127
133
         * CPU statistics (overall and per-CPU)
128
134
         */
194
200
    static char *vmbuff  = NULL;
195
201
    static int   vmbsize = 0;
196
202
    static int   first   = 1;
197
 
    int          vmstatfd;
 
203
    int          bytes_read, vmstatfd;
198
204
    char        *b;
199
205
    unsigned long long pin, pout, swpin, swpout;
200
206
    unsigned long long itot, iticks, ctx;
201
207
 
202
208
    if (has_vmstat && (vmstatfd = open(VMSTAT_FILE, O_RDONLY, 0)) != -1) {
203
209
        if (vmbsize == 0) {
204
 
            vmbsize = 256;
205
 
            vmbuff = malloc(vmbsize);
 
210
            vmbsize = getpagesize()-1;
 
211
            vmbuff = malloc(vmbsize+1);
206
212
        }
207
 
        while (read(vmstatfd, vmbuff, vmbsize) == vmbsize) {
208
 
            vmbsize += 256;
209
 
            vmbuff = realloc(vmbuff, vmbsize);
 
213
        while ((bytes_read = read(vmstatfd, vmbuff, vmbsize)) == vmbsize) {
 
214
            vmbsize += BUFSIZ;
 
215
            vmbuff = realloc(vmbuff, vmbsize+1);
210
216
            close(vmstatfd);
211
217
            vmstatfd = open(VMSTAT_FILE, O_RDONLY, 0);
212
218
        }
213
219
        close(vmstatfd);
 
220
 
 
221
        if ( bytes_read < 0 ) {
 
222
            snmp_log_perror(STAT_FILE "read error");
 
223
            return -1;
 
224
        }
 
225
        vmbuff[bytes_read] = '\0';
214
226
    }
215
227
    else
216
228
        has_vmstat = 0;