~ubuntu-branches/ubuntu/utopic/linuxlogo/utopic

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Reichle-Schmehl
  • Date: 2010-03-10 11:25:34 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20100310112534-sbweh2jsk041w73u
Tags: 5.10-1
* New upstream release.
* Drop patches/01-s390x.patch and patches/02-sh.patch
  (both were pplied upstream)
* remove quilt, as we don't have any more patches
* Add $remote_fs to Required-Start and Required-Stop of the init scripts
  LSB header
* Bump standards version (no changes needed)

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 <stdlib.h> /* getloadavg() */
20
 
#include <ctype.h>
21
 
#include <unistd.h>
22
 
#include <sys/stat.h>
23
 
#include <sys/utsname.h>
24
 
#include <sys/sysctl.h>
25
 
#include <string.h>
26
 
 
27
 
#include "sysinfo.h"
28
 
#include "include/generic.h"
29
 
#include "include/uname.h"
30
 
 
31
 
#define SIZE(x) sizeof(x)/sizeof(x[0])
32
 
 
33
 
 
34
 
int get_os_info(struct os_info_type *os_info) {
35
 
    return uname_get_os_info(os_info);
36
 
}
37
 
 
38
 
 
39
 
/* Based on /usr/src/usr.bin/w/w.c */
40
 
int get_uptime (void) {
41
 
 
42
 
     struct timeval boottime;
43
 
     time_t uptime=0, now;
44
 
     size_t size;
45
 
     int mib[2];
46
 
 
47
 
     now=time(NULL);
48
 
 
49
 
        /*
50
 
         * Print how long system has been up.
51
 
         * (Found by looking getting "boottime" from the kernel)
52
 
         */
53
 
      mib[0] = CTL_KERN;
54
 
      mib[1] = KERN_BOOTTIME;
55
 
      size = sizeof(boottime);
56
 
      if (sysctl(mib, 2, &boottime, &size, NULL, 0) != -1 &&
57
 
         boottime.tv_sec != 0) {
58
 
 
59
 
         uptime = now - boottime.tv_sec;
60
 
 
61
 
      }
62
 
      return uptime;
63
 
}
64
 
 
65
 
/* Based on /usr/src/usr.bin/w/w.c */
66
 
void get_load_average(float *load_1,float *load_5,float *load_15) {
67
 
   
68
 
   double avenrun[3];
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
 
   return;
77
 
}
78
 
 
79
 
 
80
 
 
81
 
char *get_host_name(char *hostname,char *domain) {
82
 
    return uname_get_host_name(hostname,domain);
83
 
}
84
 
 
85
 
 
86
 
long int get_mem_size(void) {
87
 
   
88
 
    int ctl_ram[] = { CTL_HW, HW_PHYSMEM };
89
 
    long int mem_size=-1;
90
 
 
91
 
    int val_int;
92
 
    int val_len;
93
 
   
94
 
    val_len = sizeof(val_int);
95
 
    if (sysctl(ctl_ram, SIZE(ctl_ram), &val_int, &val_len,0,0))
96
 
       perror("sysctl");
97
 
    else {
98
 
       mem_size=(val_int/1000000);
99
 
    }
100
 
      
101
 
    return mem_size;     
102
 
}
103