282
return (proc_descriptions[idx & HRDEV_TYPE_MASK]);
289
netsnmp_cpu_info *cpu;
290
cpu = netsnmp_cpu_get_byIdx( idx & HRDEV_TYPE_MASK, 0 );
291
return (cpu ? cpu->descr : NULL );
284
293
int cidx = idx & HRDEV_TYPE_MASK;
285
294
snprintf(proc_description,sizeof(proc_description)-1,
298
307
char tmpbuf[BUFSIZ], *cp;
302
* Clear the buffers...
304
for ( i=0 ; i<MAX_NUM_HRPROC; i++ ) {
305
memset( proc_descriptions[i], '\0', BUFSIZ);
311
DEBUGMSG(("hr_proc::detect_hrproc",""));
309
314
* ... and try to interpret the CPU information
311
316
fp = fopen("/proc/cpuinfo", "r");
313
sprintf( proc_descriptions[0],
314
"An electronic chip that makes the computer work.");
318
DEBUGMSG(("hr_proc::detect_hrproc","could not open /proc/cpuinfo"));
320
proc_descriptions = (char**)malloc(sizeof(char*));
321
proc_descriptions[0] =
322
strdup("An electronic chip that makes the computer work.");
326
proc_descriptions = (char**)malloc(sizeof(char*)*nrprocs);
327
if (!proc_descriptions) {
331
proc_descriptions[0] =
332
strdup("An electronic chip that makes the computer work.");
334
while (fgets(tmpbuf, sizeof(tmpbuf), fp)) {
335
/* note that some older (eg 2.4) kernels don't have a processor line */
336
if (!strncmp(tmpbuf,"processor\t",strlen("processor\t")))
338
if (!strncmp(tmpbuf,"processor ",strlen("processor ")))
340
if ((i!=-1) && (i >= nrprocs)) {
342
proc_descriptions = (char**)realloc(proc_descriptions, sizeof(char*)*nrprocs);
343
if (!proc_descriptions) {
347
proc_descriptions[nrprocs-1] = strdup("An electronic chip that makes the computer work."); /* will be overwritten */
319
while (fgets(tmpbuf, BUFSIZ, fp)) {
350
#if defined(__i386__) || defined(__x86_64__)
320
351
if ( !strncmp( tmpbuf, "vendor_id", 9)) {
321
352
/* Stomp on trailing newline... */
322
353
cp = &tmpbuf[strlen(tmpbuf)-1];
327
358
while ( cp && isspace(*cp))
329
snprintf( proc_descriptions[i], BUFSIZ, "%s", cp);
360
if (proc_descriptions[nrprocs-1])
361
free(proc_descriptions[nrprocs-1]);
362
proc_descriptions[nrprocs-1] = strdup(cp);
331
364
if ( !strncmp( tmpbuf, "model name", 10)) {
332
366
/* Stomp on trailing newline... */
333
367
cp = &tmpbuf[strlen(tmpbuf)-1];
338
372
while ( cp && isspace(*cp))
340
strncat( proc_descriptions[i], ": ",
341
BUFSIZ-strlen(proc_descriptions[i]));
342
strncat( proc_descriptions[i], cp,
343
BUFSIZ-strlen(proc_descriptions[i]));
345
if (i >= MAX_NUM_HRPROC) {
374
if (!proc_descriptions[nrprocs-1]) {
375
s = malloc(strlen(": ")+strlen(cp)+1);
378
proc_descriptions[nrprocs-1] = s;
380
s = malloc(strlen(proc_descriptions[nrprocs-1])+strlen(": ")+strlen(cp)+1);
381
strcpy(s,proc_descriptions[nrprocs-1]);
384
free(proc_descriptions[nrprocs-1]);
385
proc_descriptions[nrprocs-1] = s;
389
#if defined(__powerpc__) || defined(__powerpc64__)
390
if ( !strncmp( tmpbuf, "cpu\t", 4)) {
393
/* Stomp on trailing newline... */
394
cp = &tmpbuf[strlen(tmpbuf)-1];
396
/* ... and then extract the value */
397
cp = index( tmpbuf, ':');
399
while ( cp && isspace(*cp))
401
if (proc_descriptions[nrprocs-1])
402
free(proc_descriptions[nrprocs-1]);
403
proc_descriptions[nrprocs-1] = strdup(cp);
406
#if defined(__ia64__)
407
/* since vendor is always Intel ... we don't parse vendor */
408
if ( !strncmp( tmpbuf, "family\t", 6)) {
411
/* Stomp on trailing newline... */
412
cp = &tmpbuf[strlen(tmpbuf)-1];
414
/* ... and then extract the value */
415
cp = index( tmpbuf, ':');
417
while ( cp && isspace(*cp))
419
if (proc_descriptions[nrprocs-1])
420
free(proc_descriptions[nrprocs-1]);
421
proc_descriptions[nrprocs-1] = strdup(cp);
424
#if defined(__s390__) || defined(__s390x__)
425
if (proc_descriptions[nrprocs-1])
426
free(proc_descriptions[nrprocs-1]);
427
proc_descriptions[nrprocs-1] = strdup("An S/390 CPU");
430
DEBUGMSG(("hr_proc::detect_hrproc","registered %d processors", nrprocs));
431
HRP_max_index = nrprocs;