69 |
|
#endif |
70 |
|
|
71 |
|
if((uname(&os)) < 0){ |
72 |
+ |
sg_set_error(SG_ERROR_UNAME, NULL); |
73 |
|
return NULL; |
74 |
|
} |
75 |
|
|
82 |
|
/* get uptime */ |
83 |
|
#ifdef SOLARIS |
84 |
|
if ((kc = kstat_open()) == NULL) { |
85 |
+ |
sg_set_error(SG_ERROR_KSTAT_OPEN, NULL); |
86 |
|
return NULL; |
87 |
|
} |
88 |
|
if((ksp=kstat_lookup(kc, "unix", -1, "system_misc"))==NULL){ |
89 |
+ |
sg_set_error(SG_ERROR_KSTAT_LOOKUP, "unix,-1,system_misc"); |
90 |
|
return NULL; |
91 |
|
} |
92 |
|
if (kstat_read(kc, ksp, 0) == -1) { |
93 |
+ |
sg_set_error(SG_ERROR_KSTAT_READ, NULL); |
94 |
|
return NULL; |
95 |
|
} |
96 |
|
if((kn=kstat_data_lookup(ksp, "boot_time")) == NULL){ |
97 |
+ |
sg_set_error(SG_ERROR_KSTAT_DATA_LOOKUP, "boot_time"); |
98 |
|
return NULL; |
99 |
|
} |
100 |
|
boottime=(kn->value.ui32); |
106 |
|
#endif |
107 |
|
#if defined(LINUX) || defined(CYGWIN) |
108 |
|
if ((f=fopen("/proc/uptime", "r")) == NULL) { |
109 |
+ |
sg_set_error(SG_ERROR_OPEN, "/proc/uptime"); |
110 |
|
return NULL; |
111 |
|
} |
112 |
|
if((fscanf(f,"%lu %*d",&general_stat.uptime)) != 1){ |
113 |
+ |
sg_set_error(SG_ERROR_PARSE, NULL); |
114 |
|
return NULL; |
115 |
|
} |
116 |
|
fclose(f); |
120 |
|
mib[1] = KERN_BOOTTIME; |
121 |
|
size = sizeof boottime; |
122 |
|
if (sysctl(mib, 2, &boottime, &size, NULL, 0) < 0){ |
123 |
+ |
sg_set_error(SG_ERROR_SYSCTL, "CTL_KERN.KERN_BOOTTIME"); |
124 |
|
return NULL; |
125 |
|
} |
126 |
|
time(&curtime); |