Check localhost_number expansion for failure.
[exim.git] / src / OS / os.c-GNU
1 /*************************************************
2 * Exim - an Internet mail transport agent *
3 *************************************************/
4
5 /* See the file NOTICE for conditions of use and distribution. */
6
7 /* GNU-specific code. This is concatenated onto the generic src/os.c file.
8 GNU/Hurd has approximately the same way to determine the load average as NeXT,
9 so a variant of this could also be in the generic os.c file. See the GNU EMacs
10 getloadavg.c file, from which this snippet was derived. getloadavg.c from Emacs
11 is copyrighted by the FSF under the terms of the GPLv2 or any later version.
12 Changes are hereby placed under the same license, as requested by the GPL. */
13
14 #ifndef OS_LOAD_AVERAGE
15 #define OS_LOAD_AVERAGE
16
17 #include <mach.h>
18
19 static processor_set_t default_set;
20 static int getloadavg_initialized;
21
22 int
23 os_getloadavg (void)
24 {
25 host_t host;
26 struct processor_set_basic_info info;
27 unsigned info_count;
28
29 if (!getloadavg_initialized)
30 {
31 if (processor_set_default (mach_host_self(), &default_set) == KERN_SUCCESS)
32 getloadavg_initialized = 1;
33 }
34
35 if (getloadavg_initialized)
36 {
37 info_count = PROCESSOR_SET_BASIC_INFO_COUNT;
38 if (processor_set_info(default_set, PROCESSOR_SET_BASIC_INFO, &host,
39 (processor_set_info_t)&info, &info_count) != KERN_SUCCESS)
40 getloadavg_initialized = 0;
41 else
42 {
43 #if LOAD_SCALE == 1000
44 return info.load_average;
45 #else
46 return (int) (((double) info.load_average * 1000) / LOAD_SCALE));
47 #endif
48 }
49 }
50
51 return -1;
52 }
53 #endif /* OS_LOAD_AVERAGE */
54
55 /* End of os.c-GNU */