~ubuntu-branches/ubuntu/trusty/linuxlogo/trusty

« back to all changes in this revision

Viewing changes to libsysinfo-0.1.0/FreeBSD/sysinfo_bsd.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2008-06-20 09:19:00 UTC
  • mfrom: (4.1.2 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080620091900-4xzuv7c7ntxvs7wt
Tags: 5.03-4
* Adding patch to fix FTBFS on s390x.
* Updating to standards 3.8.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/******************************************************************
2
 
 *     sysinfo_bsd.c  - FreeBSD patch for linux_logo              * 
3
 
 * August 31, 2000 by Shawn Rapp                                  *
4
 
 * - Made cute little devil pic from daemon screen saver for the  *
5
 
 *   linux_logo to use.  Bye Bye fat little penguin  =)           *
6
 
 * - CPU information                                              *
7
 
 * - OS information                                               *
8
 
 * - Somewhat gets the build date (needs parsing)                 *
9
 
 * - BogoMips                                                     *
10
 
 * - Physical Memory total (not averaged to convention though)    *
11
 
 *                                                                *
12
 
 * Left to be done                                                *
13
 
 * - CPU mgz                                                      *
14
 
 * - Patch telnetd to display /etc/issue when specified in        * 
15
 
 *   /etc/gettytab.                                               *
16
 
 ******************************************************************/
17
 
 
18
 
#include <stdio.h>
19
 
#include <ctype.h>
20
 
#include <unistd.h>
21
 
#include <sys/stat.h>
22
 
#include <sys/utsname.h>
23
 
#include <sys/sysctl.h>
24
 
#include <string.h>
25
 
 
26
 
#include "sysinfo.h"
27
 
#include "generic.h"
28
 
#include "uname.h"
29
 
 
30
 
#define SIZE(x) sizeof(x)/sizeof(x[0])
31
 
 
32
 
 
33
 
int get_os_info(os_info_t *os_info) {
34
 
    return uname_get_os_info(os_info);
35
 
}
36
 
 
37
 
 
38
 
/* Based on /usr/src/usr.bin/w/w.c */
39
 
int get_uptime (void) {
40
 
 
41
 
     struct timeval boottime;
42
 
     time_t uptime, now;
43
 
     size_t size;
44
 
     int mib[2];
45
 
 
46
 
     now=time(NULL);
47
 
 
48
 
        /*
49
 
         * Print how long system has been up.
50
 
         * (Found by looking getting "boottime" from the kernel)
51
 
         */
52
 
      mib[0] = CTL_KERN;
53
 
      mib[1] = KERN_BOOTTIME;
54
 
      size = sizeof(boottime);
55
 
      if (sysctl(mib, 2, &boottime, &size, NULL, 0) != -1 &&
56
 
         boottime.tv_sec != 0) {
57
 
 
58
 
         uptime = now - boottime.tv_sec;
59
 
 
60
 
      }
61
 
      return uptime;
62
 
}
63
 
 
64
 
/* Based on /usr/src/usr.bin/w/w.c */
65
 
void get_load_average(float *load_1,float *load_5,float *load_15) {
66
 
   
67
 
   double avenrun[3];
68
 
   int i;
69
 
   
70
 
   getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0]));
71
 
   
72
 
   *load_1=avenrun[0];
73
 
   *load_5=avenrun[1];
74
 
   *load_15=avenrun[2];
75
 
   
76
 
   
77
 
   return;
78
 
}
79
 
 
80
 
 
81
 
 
82
 
char *get_host_name(char hostname[65],char domain[65]) {
83
 
    return uname_get_host_name(hostname,domain);
84
 
}
85
 
 
86
 
 
87
 
long int get_mem_size(void) {
88
 
   
89
 
    int ctl_ram[] = { CTL_HW, HW_PHYSMEM };
90
 
    long int mem_size=-1;
91
 
 
92
 
    int val_int;
93
 
    int val_len;
94
 
   
95
 
    val_len = sizeof(val_int);
96
 
    if (sysctl(ctl_ram, SIZE(ctl_ram), &val_int, &val_len,0,0))
97
 
       perror("sysctl");
98
 
    else {
99
 
       mem_size=(val_int/1000000);
100
 
    }
101
 
      
102
 
    return mem_size;     
103
 
}
104