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