"Fossies" - the Fresh Open Source Software Archive

Member "linux_logo-6.0/libsysinfo-0.3.0/SunOS/sysinfo_solaris.c" (8 May 2020, 3217 Bytes) of package /linux/misc/linux_logo-6.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #include <stdio.h>
    2 #include <stdlib.h>  /* atol   */
    3 #include <string.h>  /* strstr */
    4 #include <ctype.h>   /* isdigit */
    5 #include <sys/stat.h> /* stat */
    6 #include <unistd.h>  /* stat */
    7 
    8 #include "sysinfo.h"
    9 #include "include/uname.h"
   10 
   11     /* Not supported under solaris yet */
   12 int get_uptime (void) {            
   13    
   14 //    FILE *fff;
   15 //    float uptime_seconds;
   16    
   17     return 0;
   18 }
   19 
   20     /* Based on code contributed by Anders Rundegren <anders@rundegren.com> */
   21 void get_load_average(float *load_1,float *load_5,float *load_15) {
   22    
   23     FILE *fff;
   24     char throw_away[BUFSIZ];
   25    
   26     fff=popen("w | head -n 1","r");
   27     if (fff!=NULL) {
   28        fscanf(fff,"%64s %64s %64s %64s %64s %64s %64s %f %f %f", 
   29           throw_away,throw_away,throw_away,
   30           throw_away,throw_away,throw_away,throw_away,
   31           load_1, load_5, load_15);
   32        fclose (fff);
   33     }
   34 }
   35 
   36 int get_os_info(struct os_info_type *os_info) {
   37     int result,i,after_point=0,j=0;
   38     char temp_version[33];
   39    
   40     result=uname_get_os_info(os_info);
   41    
   42 
   43        /* This won't work with pre-Solaris versions */
   44     strncpy(os_info->os_name,"Solaris",8);
   45        
   46     i=0;
   47     while(i<strlen(os_info->os_version)) {
   48        if (after_point) {
   49       temp_version[j]=os_info->os_version[i];
   50       j++;
   51        }
   52 
   53        if (os_info->os_version[i]=='.') {
   54       after_point=1;
   55        }
   56        i++;
   57     }
   58     temp_version[j]='\0';
   59     strncpy(os_info->os_version,temp_version,SYSINFO_OS_VERSION_SIZE);
   60     
   61     return result;
   62 }
   63 
   64 char *get_host_name(char *hostname,char *domain) {
   65     return uname_get_host_name(hostname,domain);
   66 }
   67 
   68 
   69     
   70 long long get_mem_size(void) {
   71 
   72     FILE *pipe;
   73     char string[BUFSIZ];
   74     long long memsize;
   75    
   76     pipe=popen("/usr/sbin/prtconf","r");
   77     fgets(string,BUFSIZ,pipe); /* skip line */
   78     fscanf(pipe,"%*s %*s %lld",&memsize);
   79    
   80     return memsize;
   81  
   82 }
   83 
   84 extern float external_bogomips(void);
   85 
   86     
   87 int get_cpu_info(struct cpu_info_type *cpu_info) {
   88    
   89     FILE *pipe;
   90     char string[BUFSIZ];
   91     int cpus=0;
   92     float version;
   93    
   94     cpu_info->bogomips=external_bogomips();
   95 
   96     pipe=popen("/usr/sbin/psrinfo","r");
   97     while(fgets(string,BUFSIZ,pipe)!=NULL) {
   98       cpus++;
   99     }
  100     pclose(pipe);
  101    
  102     cpu_info->num_cpus=cpus;
  103     strncpy(cpu_info->chip_vendor,"SPARC",33);
  104     
  105     pipe=popen("uname -r","r");
  106     fscanf(pipe,"%f",&version);
  107     pclose(pipe);
  108    
  109     /* Solaris 9 psrinfo doesn't support -p option */
  110     if (version>5.2) {
  111        /* don't support -p option, do something else */
  112        pipe=popen("/usr/sbin/psrinfo -v","r");
  113        fgets(string,BUFSIZ,pipe);  /* ignore line */
  114        fgets(string,BUFSIZ,pipe);  /* ignore line */
  115        fscanf(pipe,"%*s %64s %*s %*s %*s %f",cpu_info->chip_type,
  116           &cpu_info->megahertz);
  117        pclose(pipe);
  118     }
  119     else {
  120        /* we support -p option... */
  121        pipe=popen("/usr/sbin/psrinfo -p -v","r");
  122        fgets(string,BUFSIZ,pipe);  /* ignore line */
  123        fscanf(pipe,"%64s %*s %*s %*s %f",cpu_info->chip_type,
  124           &cpu_info->megahertz);
  125        pclose(pipe);
  126     }
  127 
  128     return 0;
  129 }
  130 
  131 
  132 double get_cpu_mhz(void) {
  133    
  134       struct cpu_info_type cpu_info;
  135    
  136       get_cpu_info(&cpu_info);
  137    
  138       return (double)cpu_info.megahertz;
  139    
  140 }