get_rload.c revision a8bb11d0
1 2#include <stdio.h> 3#include <X11/Intrinsic.h> 4#include <fcntl.h> 5#include <stdlib.h> 6#include <unistd.h> 7#include "xload.h" 8 9/* Not all OS supports get_rload 10 steal the STUB idea from get_load 11 */ 12#if defined(QNX4) || defined(__CYGWIN__) 13#define RLOADSTUB 14#endif 15 16#ifdef RLOADSTUB 17void GetRLoadPoint( 18 Widget w, /* unused */ 19 XtPointer closure, /* unused */ 20 XtPointer call_data) /* pointer to (double) return value */ 21 22{ 23 *(double *)call_data = 1.0; 24} 25#else /* RLOADSTUB */ 26 27#include <protocols/rwhod.h> 28#ifndef _PATH_RWHODIR 29#define _PATH_RWHODIR "/var/spool/rwho" 30#endif 31 32#define WHDRSIZE ((int)(sizeof (buf) - sizeof (buf.wd_we))) 33 34void GetRLoadPoint( 35 Widget w, /* unused */ 36 XtPointer closure, /* unused */ 37 XtPointer call_data) /* pointer to (double) return value */ 38{ 39 int f; 40 static char *fname = NULL; 41 static struct whod buf; 42 int cc; 43 44 *(double *)call_data = 0.0; /* to be on the safe side */ 45 46 if (fname == NULL) { 47 if ((fname = malloc(strlen(_PATH_RWHODIR)+strlen("/whod.")+strlen(resources.remote)+1)) == NULL) { 48 fprintf(stderr,"GetRLoadPoint: malloc() failed\n"); 49 exit(1); 50 } 51 strcpy(fname,_PATH_RWHODIR); 52 strcat(fname,"/whod."); 53 strcat(fname,resources.remote); 54 } 55 if ((f = open(fname, O_RDONLY, 0)) < 0) 56 return; 57 58 cc = read(f, &buf, sizeof(buf)); 59 close(f); 60 if (cc < WHDRSIZE) 61 return; 62 63 *(double *)call_data = buf.wd_loadav[0] / 100.0; 64} 65 66#endif /* RLOADSTUB */ 67