diff options
| author | Jim Meyering | 1997-01-16 03:33:02 +0000 |
|---|---|---|
| committer | Jim Meyering | 1997-01-16 03:33:02 +0000 |
| commit | 3da4f3679606bf1d990db49929d781d9dacf3693 (patch) | |
| tree | 8e407a2205562ecb7bb58f83e3ff39ccfab5ec6e /src | |
| parent | 93b649d3b37c50dd252047cb8aa4acc56f2bd391 (diff) | |
| download | emacs-3da4f3679606bf1d990db49929d781d9dacf3693.tar.gz emacs-3da4f3679606bf1d990db49929d781d9dacf3693.zip | |
[hpux && HAVE_PSTAT_GETDYNAMIC]: Use HPUX's pstat_getdynamic so
we don't need any special privileges to determine load averages.
Patch from Kaveh Ghazi, based on a sample implementation from
Richard J. Rauenzahn.
Indent cpp-directives to reflect nesting.
Diffstat (limited to 'src')
| -rw-r--r-- | src/getloadavg.c | 788 |
1 files changed, 409 insertions, 379 deletions
diff --git a/src/getloadavg.c b/src/getloadavg.c index 6209fef76f9..635e5ac534a 100644 --- a/src/getloadavg.c +++ b/src/getloadavg.c | |||
| @@ -65,7 +65,7 @@ | |||
| 65 | 65 | ||
| 66 | /* This should always be first. */ | 66 | /* This should always be first. */ |
| 67 | #ifdef HAVE_CONFIG_H | 67 | #ifdef HAVE_CONFIG_H |
| 68 | #include <config.h> | 68 | # include <config.h> |
| 69 | #endif | 69 | #endif |
| 70 | 70 | ||
| 71 | #include <sys/types.h> | 71 | #include <sys/types.h> |
| @@ -74,7 +74,7 @@ | |||
| 74 | configuration files' definitions for the LOAD_AVE_CVT macro (like | 74 | configuration files' definitions for the LOAD_AVE_CVT macro (like |
| 75 | sparc.h's) use macros like FSCALE, defined here. */ | 75 | sparc.h's) use macros like FSCALE, defined here. */ |
| 76 | #ifdef unix | 76 | #ifdef unix |
| 77 | #include <sys/param.h> | 77 | # include <sys/param.h> |
| 78 | #endif | 78 | #endif |
| 79 | 79 | ||
| 80 | 80 | ||
| @@ -103,25 +103,25 @@ extern int errno; | |||
| 103 | LOAD_AVE_CVT, but future machine config files should just define | 103 | LOAD_AVE_CVT, but future machine config files should just define |
| 104 | LDAV_CVT directly. */ | 104 | LDAV_CVT directly. */ |
| 105 | 105 | ||
| 106 | #if !defined(LDAV_CVT) && defined(LOAD_AVE_CVT) | 106 | # if !defined(LDAV_CVT) && defined(LOAD_AVE_CVT) |
| 107 | #define LDAV_CVT(n) (LOAD_AVE_CVT (n) / 100.0) | 107 | # define LDAV_CVT(n) (LOAD_AVE_CVT (n) / 100.0) |
| 108 | #endif | 108 | # endif |
| 109 | 109 | ||
| 110 | #if !defined (BSD) && defined (ultrix) | 110 | # if !defined (BSD) && defined (ultrix) |
| 111 | /* Ultrix behaves like BSD on Vaxen. */ | 111 | /* Ultrix behaves like BSD on Vaxen. */ |
| 112 | #define BSD | 112 | # define BSD |
| 113 | #endif | 113 | # endif |
| 114 | 114 | ||
| 115 | #ifdef NeXT | 115 | # ifdef NeXT |
| 116 | /* NeXT in the 2.{0,1,2} releases defines BSD in <sys/param.h>, which | 116 | /* NeXT in the 2.{0,1,2} releases defines BSD in <sys/param.h>, which |
| 117 | conflicts with the definition understood in this file, that this | 117 | conflicts with the definition understood in this file, that this |
| 118 | really is BSD. */ | 118 | really is BSD. */ |
| 119 | #undef BSD | 119 | # undef BSD |
| 120 | 120 | ||
| 121 | /* NeXT defines FSCALE in <sys/param.h>. However, we take FSCALE being | 121 | /* NeXT defines FSCALE in <sys/param.h>. However, we take FSCALE being |
| 122 | defined to mean that the nlist method should be used, which is not true. */ | 122 | defined to mean that the nlist method should be used, which is not true. */ |
| 123 | #undef FSCALE | 123 | # undef FSCALE |
| 124 | #endif | 124 | # endif |
| 125 | 125 | ||
| 126 | /* Set values that are different from the defaults, which are | 126 | /* Set values that are different from the defaults, which are |
| 127 | set a little farther down with #ifndef. */ | 127 | set a little farther down with #ifndef. */ |
| @@ -129,365 +129,375 @@ extern int errno; | |||
| 129 | 129 | ||
| 130 | /* Some shorthands. */ | 130 | /* Some shorthands. */ |
| 131 | 131 | ||
| 132 | #if defined (HPUX) && !defined (hpux) | 132 | # if defined (HPUX) && !defined (hpux) |
| 133 | #define hpux | 133 | # define hpux |
| 134 | #endif | 134 | # endif |
| 135 | 135 | ||
| 136 | #if defined (__hpux) && !defined (hpux) | 136 | # if defined (__hpux) && !defined (hpux) |
| 137 | #define hpux | 137 | # define hpux |
| 138 | #endif | 138 | # endif |
| 139 | 139 | ||
| 140 | #if defined (__sun) && !defined (sun) | 140 | # if defined (__sun) && !defined (sun) |
| 141 | #define sun | 141 | # define sun |
| 142 | #endif | 142 | # endif |
| 143 | 143 | ||
| 144 | #if defined(hp300) && !defined(hpux) | 144 | # if defined(hp300) && !defined(hpux) |
| 145 | #define MORE_BSD | 145 | # define MORE_BSD |
| 146 | #endif | 146 | # endif |
| 147 | 147 | ||
| 148 | #if defined(ultrix) && defined(mips) | 148 | # if defined(ultrix) && defined(mips) |
| 149 | #define decstation | 149 | # define decstation |
| 150 | #endif | 150 | # endif |
| 151 | 151 | ||
| 152 | #if (defined(sun) && defined(SVR4)) || defined (SOLARIS2) | 152 | # if defined (__SVR4) && !defined (SVR4) |
| 153 | #define SUNOS_5 | 153 | # define SVR4 |
| 154 | #endif | 154 | # endif |
| 155 | 155 | ||
| 156 | #if defined (__osf__) && (defined (__alpha) || defined (__alpha__)) | 156 | # if (defined(sun) && defined(SVR4)) || defined (SOLARIS2) |
| 157 | #define OSF_ALPHA | 157 | # define SUNOS_5 |
| 158 | #include <sys/table.h> | 158 | # endif |
| 159 | #endif | ||
| 160 | 159 | ||
| 161 | #if defined (__osf__) && (defined (mips) || defined (__mips__)) | 160 | # if defined (__osf__) && (defined (__alpha) || defined (__alpha__)) |
| 162 | #define OSF_MIPS | 161 | # define OSF_ALPHA |
| 163 | #include <sys/table.h> | 162 | # include <sys/table.h> |
| 164 | #endif | 163 | # endif |
| 164 | |||
| 165 | # if defined (__osf__) && (defined (mips) || defined (__mips__)) | ||
| 166 | # define OSF_MIPS | ||
| 167 | # include <sys/table.h> | ||
| 168 | # endif | ||
| 165 | 169 | ||
| 166 | /* UTek's /bin/cc on the 4300 has no architecture specific cpp define by | 170 | /* UTek's /bin/cc on the 4300 has no architecture specific cpp define by |
| 167 | default, but _MACH_IND_SYS_TYPES is defined in <sys/types.h>. Combine | 171 | default, but _MACH_IND_SYS_TYPES is defined in <sys/types.h>. Combine |
| 168 | that with a couple of other things and we'll have a unique match. */ | 172 | that with a couple of other things and we'll have a unique match. */ |
| 169 | #if !defined (tek4300) && defined (unix) && defined (m68k) && defined (mc68000) && defined (mc68020) && defined (_MACH_IND_SYS_TYPES) | 173 | # if !defined (tek4300) && defined (unix) && defined (m68k) && defined (mc68000) && defined (mc68020) && defined (_MACH_IND_SYS_TYPES) |
| 170 | #define tek4300 /* Define by emacs, but not by other users. */ | 174 | # define tek4300 /* Define by emacs, but not by other users. */ |
| 171 | #endif | 175 | # endif |
| 172 | 176 | ||
| 173 | 177 | ||
| 174 | /* VAX C can't handle multi-line #ifs, or lines longer than 256 chars. */ | 178 | /* VAX C can't handle multi-line #ifs, or lines longer than 256 chars. */ |
| 175 | #ifndef LOAD_AVE_TYPE | 179 | # ifndef LOAD_AVE_TYPE |
| 176 | 180 | ||
| 177 | #ifdef MORE_BSD | 181 | # ifdef MORE_BSD |
| 178 | #define LOAD_AVE_TYPE long | 182 | # define LOAD_AVE_TYPE long |
| 179 | #endif | 183 | # endif |
| 180 | 184 | ||
| 181 | #ifdef sun | 185 | # ifdef sun |
| 182 | #define LOAD_AVE_TYPE long | 186 | # define LOAD_AVE_TYPE long |
| 183 | #endif | 187 | # endif |
| 184 | 188 | ||
| 185 | #ifdef decstation | 189 | # ifdef decstation |
| 186 | #define LOAD_AVE_TYPE long | 190 | # define LOAD_AVE_TYPE long |
| 187 | #endif | 191 | # endif |
| 188 | 192 | ||
| 189 | #ifdef _SEQUENT_ | 193 | # ifdef _SEQUENT_ |
| 190 | #define LOAD_AVE_TYPE long | 194 | # define LOAD_AVE_TYPE long |
| 191 | #endif | 195 | # endif |
| 192 | 196 | ||
| 193 | #ifdef sgi | 197 | # ifdef sgi |
| 194 | #define LOAD_AVE_TYPE long | 198 | # define LOAD_AVE_TYPE long |
| 195 | #endif | 199 | # endif |
| 196 | 200 | ||
| 197 | #ifdef SVR4 | 201 | # ifdef SVR4 |
| 198 | #define LOAD_AVE_TYPE long | 202 | # define LOAD_AVE_TYPE long |
| 199 | #endif | 203 | # endif |
| 200 | 204 | ||
| 201 | #ifdef sony_news | 205 | # ifdef sony_news |
| 202 | #define LOAD_AVE_TYPE long | 206 | # define LOAD_AVE_TYPE long |
| 203 | #endif | 207 | # endif |
| 204 | 208 | ||
| 205 | #ifdef sequent | 209 | # ifdef sequent |
| 206 | #define LOAD_AVE_TYPE long | 210 | # define LOAD_AVE_TYPE long |
| 207 | #endif | 211 | # endif |
| 208 | 212 | ||
| 209 | #ifdef OSF_ALPHA | 213 | # ifdef OSF_ALPHA |
| 210 | #define LOAD_AVE_TYPE long | 214 | # define LOAD_AVE_TYPE long |
| 211 | #endif | 215 | # endif |
| 212 | 216 | ||
| 213 | #if defined (ardent) && defined (titan) | 217 | # if defined (ardent) && defined (titan) |
| 214 | #define LOAD_AVE_TYPE long | 218 | # define LOAD_AVE_TYPE long |
| 215 | #endif | 219 | # endif |
| 216 | 220 | ||
| 217 | #ifdef tek4300 | 221 | # ifdef tek4300 |
| 218 | #define LOAD_AVE_TYPE long | 222 | # define LOAD_AVE_TYPE long |
| 219 | #endif | 223 | # endif |
| 220 | 224 | ||
| 221 | #if defined(alliant) && defined(i860) /* Alliant FX/2800 */ | 225 | # if defined(alliant) && defined(i860) /* Alliant FX/2800 */ |
| 222 | #define LOAD_AVE_TYPE long | 226 | # define LOAD_AVE_TYPE long |
| 223 | #endif | 227 | # endif |
| 224 | 228 | ||
| 225 | #ifdef _AIX | 229 | # ifdef _AIX |
| 226 | #define LOAD_AVE_TYPE long | 230 | # define LOAD_AVE_TYPE long |
| 227 | #endif | 231 | # endif |
| 228 | 232 | ||
| 229 | #ifdef convex | 233 | # ifdef convex |
| 230 | #define LOAD_AVE_TYPE double | 234 | # define LOAD_AVE_TYPE double |
| 231 | #ifndef LDAV_CVT | 235 | # ifndef LDAV_CVT |
| 232 | #define LDAV_CVT(n) (n) | 236 | # define LDAV_CVT(n) (n) |
| 233 | #endif | 237 | # endif |
| 234 | #endif | 238 | # endif |
| 235 | 239 | ||
| 236 | #endif /* No LOAD_AVE_TYPE. */ | 240 | # endif /* No LOAD_AVE_TYPE. */ |
| 237 | 241 | ||
| 238 | #ifdef OSF_ALPHA | 242 | # ifdef OSF_ALPHA |
| 239 | /* <sys/param.h> defines an incorrect value for FSCALE on Alpha OSF/1, | 243 | /* <sys/param.h> defines an incorrect value for FSCALE on Alpha OSF/1, |
| 240 | according to ghazi@noc.rutgers.edu. */ | 244 | according to ghazi@noc.rutgers.edu. */ |
| 241 | #undef FSCALE | 245 | # undef FSCALE |
| 242 | #define FSCALE 1024.0 | 246 | # define FSCALE 1024.0 |
| 243 | #endif | 247 | # endif |
| 244 | 248 | ||
| 245 | #if defined(alliant) && defined(i860) /* Alliant FX/2800 */ | 249 | # if defined(alliant) && defined(i860) /* Alliant FX/2800 */ |
| 246 | /* <sys/param.h> defines an incorrect value for FSCALE on an | 250 | /* <sys/param.h> defines an incorrect value for FSCALE on an |
| 247 | Alliant FX/2800 Concentrix 2.2, according to ghazi@noc.rutgers.edu. */ | 251 | Alliant FX/2800 Concentrix 2.2, according to ghazi@noc.rutgers.edu. */ |
| 248 | #undef FSCALE | 252 | # undef FSCALE |
| 249 | #define FSCALE 100.0 | 253 | # define FSCALE 100.0 |
| 250 | #endif | 254 | # endif |
| 251 | 255 | ||
| 252 | 256 | ||
| 253 | #ifndef FSCALE | 257 | # ifndef FSCALE |
| 254 | 258 | ||
| 255 | /* SunOS and some others define FSCALE in sys/param.h. */ | 259 | /* SunOS and some others define FSCALE in sys/param.h. */ |
| 256 | 260 | ||
| 257 | #ifdef MORE_BSD | 261 | # ifdef MORE_BSD |
| 258 | #define FSCALE 2048.0 | 262 | # define FSCALE 2048.0 |
| 259 | #endif | 263 | # endif |
| 260 | 264 | ||
| 261 | #if defined(MIPS) || defined(SVR4) || defined(decstation) | 265 | # if defined(MIPS) || defined(SVR4) || defined(decstation) |
| 262 | #define FSCALE 256 | 266 | # define FSCALE 256 |
| 263 | #endif | 267 | # endif |
| 264 | 268 | ||
| 265 | #if defined (sgi) || defined (sequent) | 269 | # if defined (sgi) || defined (sequent) |
| 266 | /* Sometimes both MIPS and sgi are defined, so FSCALE was just defined | 270 | /* Sometimes both MIPS and sgi are defined, so FSCALE was just defined |
| 267 | above under #ifdef MIPS. But we want the sgi value. */ | 271 | above under #ifdef MIPS. But we want the sgi value. */ |
| 268 | #undef FSCALE | 272 | # undef FSCALE |
| 269 | #define FSCALE 1000.0 | 273 | # define FSCALE 1000.0 |
| 270 | #endif | 274 | # endif |
| 271 | 275 | ||
| 272 | #if defined (ardent) && defined (titan) | 276 | # if defined (ardent) && defined (titan) |
| 273 | #define FSCALE 65536.0 | 277 | # define FSCALE 65536.0 |
| 274 | #endif | 278 | # endif |
| 275 | 279 | ||
| 276 | #ifdef tek4300 | 280 | # ifdef tek4300 |
| 277 | #define FSCALE 100.0 | 281 | # define FSCALE 100.0 |
| 278 | #endif | 282 | # endif |
| 279 | 283 | ||
| 280 | #ifdef _AIX | 284 | # ifdef _AIX |
| 281 | #define FSCALE 65536.0 | 285 | # define FSCALE 65536.0 |
| 282 | #endif | 286 | # endif |
| 283 | 287 | ||
| 284 | #endif /* Not FSCALE. */ | 288 | # endif /* Not FSCALE. */ |
| 285 | 289 | ||
| 286 | #if !defined (LDAV_CVT) && defined (FSCALE) | 290 | # if !defined (LDAV_CVT) && defined (FSCALE) |
| 287 | #define LDAV_CVT(n) (((double) (n)) / FSCALE) | 291 | # define LDAV_CVT(n) (((double) (n)) / FSCALE) |
| 288 | #endif | 292 | # endif |
| 289 | 293 | ||
| 290 | /* VAX C can't handle multi-line #ifs, or lines longer that 256 characters. */ | 294 | /* VAX C can't handle multi-line #ifs, or lines longer that 256 characters. */ |
| 291 | #ifndef NLIST_STRUCT | 295 | # ifndef NLIST_STRUCT |
| 292 | 296 | ||
| 293 | #ifdef MORE_BSD | 297 | # ifdef MORE_BSD |
| 294 | #define NLIST_STRUCT | 298 | # define NLIST_STRUCT |
| 295 | #endif | 299 | # endif |
| 296 | 300 | ||
| 297 | #ifdef sun | 301 | # ifdef sun |
| 298 | #define NLIST_STRUCT | 302 | # define NLIST_STRUCT |
| 299 | #endif | 303 | # endif |
| 300 | 304 | ||
| 301 | #ifdef decstation | 305 | # ifdef decstation |
| 302 | #define NLIST_STRUCT | 306 | # define NLIST_STRUCT |
| 303 | #endif | 307 | # endif |
| 304 | 308 | ||
| 305 | #ifdef hpux | 309 | # ifdef hpux |
| 306 | #define NLIST_STRUCT | 310 | # define NLIST_STRUCT |
| 307 | #endif | 311 | # endif |
| 308 | 312 | ||
| 309 | #if defined (_SEQUENT_) || defined (sequent) | 313 | # if defined (_SEQUENT_) || defined (sequent) |
| 310 | #define NLIST_STRUCT | 314 | # define NLIST_STRUCT |
| 311 | #endif | 315 | # endif |
| 312 | 316 | ||
| 313 | #ifdef sgi | 317 | # ifdef sgi |
| 314 | #define NLIST_STRUCT | 318 | # define NLIST_STRUCT |
| 315 | #endif | 319 | # endif |
| 316 | 320 | ||
| 317 | #ifdef SVR4 | 321 | # ifdef SVR4 |
| 318 | #define NLIST_STRUCT | 322 | # define NLIST_STRUCT |
| 319 | #endif | 323 | # endif |
| 320 | 324 | ||
| 321 | #ifdef sony_news | 325 | # ifdef sony_news |
| 322 | #define NLIST_STRUCT | 326 | # define NLIST_STRUCT |
| 323 | #endif | 327 | # endif |
| 324 | 328 | ||
| 325 | #ifdef OSF_ALPHA | 329 | # ifdef OSF_ALPHA |
| 326 | #define NLIST_STRUCT | 330 | # define NLIST_STRUCT |
| 327 | #endif | 331 | # endif |
| 328 | 332 | ||
| 329 | #if defined (ardent) && defined (titan) | 333 | # if defined (ardent) && defined (titan) |
| 330 | #define NLIST_STRUCT | 334 | # define NLIST_STRUCT |
| 331 | #endif | 335 | # endif |
| 332 | 336 | ||
| 333 | #ifdef tek4300 | 337 | # ifdef tek4300 |
| 334 | #define NLIST_STRUCT | 338 | # define NLIST_STRUCT |
| 335 | #endif | 339 | # endif |
| 336 | 340 | ||
| 337 | #ifdef butterfly | 341 | # ifdef butterfly |
| 338 | #define NLIST_STRUCT | 342 | # define NLIST_STRUCT |
| 339 | #endif | 343 | # endif |
| 340 | 344 | ||
| 341 | #if defined(alliant) && defined(i860) /* Alliant FX/2800 */ | 345 | # if defined(alliant) && defined(i860) /* Alliant FX/2800 */ |
| 342 | #define NLIST_STRUCT | 346 | # define NLIST_STRUCT |
| 343 | #endif | 347 | # endif |
| 344 | 348 | ||
| 345 | #ifdef _AIX | 349 | # ifdef _AIX |
| 346 | #define NLIST_STRUCT | 350 | # define NLIST_STRUCT |
| 347 | #endif | 351 | # endif |
| 348 | 352 | ||
| 349 | #endif /* defined (NLIST_STRUCT) */ | 353 | # endif /* defined (NLIST_STRUCT) */ |
| 350 | 354 | ||
| 351 | 355 | ||
| 352 | #if defined(sgi) || (defined(mips) && !defined(BSD)) | 356 | # if defined(sgi) || (defined(mips) && !defined(BSD)) |
| 353 | #define FIXUP_KERNEL_SYMBOL_ADDR(nl) ((nl)[0].n_value &= ~(1 << 31)) | 357 | # define FIXUP_KERNEL_SYMBOL_ADDR(nl) ((nl)[0].n_value &= ~(1 << 31)) |
| 354 | #endif | 358 | # endif |
| 355 | 359 | ||
| 356 | 360 | ||
| 357 | #if !defined (KERNEL_FILE) && defined (sequent) | 361 | # if !defined (KERNEL_FILE) && defined (sequent) |
| 358 | #define KERNEL_FILE "/dynix" | 362 | # define KERNEL_FILE "/dynix" |
| 359 | #endif | 363 | # endif |
| 360 | 364 | ||
| 361 | #if !defined (KERNEL_FILE) && defined (hpux) | 365 | # if !defined (KERNEL_FILE) && defined (hpux) |
| 362 | #define KERNEL_FILE "/hp-ux" | 366 | # define KERNEL_FILE "/hp-ux" |
| 363 | #endif | 367 | # endif |
| 364 | 368 | ||
| 365 | #if !defined(KERNEL_FILE) && (defined(_SEQUENT_) || defined(MIPS) || defined(SVR4) || defined(ISC) || defined (sgi) || defined(SVR4) || (defined (ardent) && defined (titan))) | 369 | # if !defined(KERNEL_FILE) && (defined(_SEQUENT_) || defined(MIPS) || defined(SVR4) || defined(ISC) || defined (sgi) || (defined (ardent) && defined (titan))) |
| 366 | #define KERNEL_FILE "/unix" | 370 | # define KERNEL_FILE "/unix" |
| 367 | #endif | 371 | # endif |
| 368 | 372 | ||
| 369 | 373 | ||
| 370 | #if !defined (LDAV_SYMBOL) && defined (alliant) | 374 | # if !defined (LDAV_SYMBOL) && defined (alliant) |
| 371 | #define LDAV_SYMBOL "_Loadavg" | 375 | # define LDAV_SYMBOL "_Loadavg" |
| 372 | #endif | 376 | # endif |
| 373 | 377 | ||
| 374 | #if !defined(LDAV_SYMBOL) && ((defined(hpux) && !defined(hp9000s300)) || defined(_SEQUENT_) || defined(SVR4) || defined(ISC) || defined(sgi) || (defined (ardent) && defined (titan)) || defined (_AIX)) | 378 | # if !defined(LDAV_SYMBOL) && ((defined(hpux) && !defined(hp9000s300)) || defined(_SEQUENT_) || defined(SVR4) || defined(ISC) || defined(sgi) || (defined (ardent) && defined (titan)) || defined (_AIX)) |
| 375 | #define LDAV_SYMBOL "avenrun" | 379 | # define LDAV_SYMBOL "avenrun" |
| 376 | #endif | 380 | # endif |
| 377 | 381 | ||
| 378 | #ifdef HAVE_UNISTD_H | 382 | # ifdef HAVE_UNISTD_H |
| 379 | #include <unistd.h> | 383 | # include <unistd.h> |
| 380 | #endif | 384 | # endif |
| 381 | 385 | ||
| 382 | #include <stdio.h> | 386 | # include <stdio.h> |
| 383 | 387 | ||
| 384 | /* LOAD_AVE_TYPE should only get defined if we're going to use the | 388 | /* LOAD_AVE_TYPE should only get defined if we're going to use the |
| 385 | nlist method. */ | 389 | nlist method. */ |
| 386 | #if !defined(LOAD_AVE_TYPE) && (defined(BSD) || defined(LDAV_CVT) || defined(KERNEL_FILE) || defined(LDAV_SYMBOL)) | 390 | # if !defined(LOAD_AVE_TYPE) && (defined(BSD) || defined(LDAV_CVT) || defined(KERNEL_FILE) || defined(LDAV_SYMBOL)) |
| 387 | #define LOAD_AVE_TYPE double | 391 | # define LOAD_AVE_TYPE double |
| 388 | #endif | 392 | # endif |
| 389 | 393 | ||
| 390 | #ifdef LOAD_AVE_TYPE | 394 | # ifdef LOAD_AVE_TYPE |
| 391 | 395 | ||
| 392 | #ifndef VMS | 396 | # ifndef VMS |
| 393 | #ifndef NLIST_STRUCT | 397 | # ifndef __linux__ |
| 394 | #include <a.out.h> | 398 | # ifndef NLIST_STRUCT |
| 395 | #else /* NLIST_STRUCT */ | 399 | # include <a.out.h> |
| 396 | #include <nlist.h> | 400 | # else /* NLIST_STRUCT */ |
| 397 | #endif /* NLIST_STRUCT */ | 401 | # include <nlist.h> |
| 398 | 402 | # endif /* NLIST_STRUCT */ | |
| 399 | #ifdef SUNOS_5 | 403 | |
| 400 | #include <fcntl.h> | 404 | # ifdef SUNOS_5 |
| 401 | #include <kvm.h> | 405 | # include <fcntl.h> |
| 402 | #include <kstat.h> | 406 | # include <kvm.h> |
| 403 | #endif | 407 | # include <kstat.h> |
| 404 | 408 | # endif | |
| 405 | #ifndef KERNEL_FILE | 409 | |
| 406 | #define KERNEL_FILE "/vmunix" | 410 | # if defined (hpux) && defined (HAVE_PSTAT_GETDYNAMIC) |
| 407 | #endif /* KERNEL_FILE */ | 411 | # include <sys/pstat.h> |
| 408 | 412 | # endif | |
| 409 | #ifndef LDAV_SYMBOL | 413 | |
| 410 | #define LDAV_SYMBOL "_avenrun" | 414 | # ifndef KERNEL_FILE |
| 411 | #endif /* LDAV_SYMBOL */ | 415 | # define KERNEL_FILE "/vmunix" |
| 412 | 416 | # endif /* KERNEL_FILE */ | |
| 413 | #else /* VMS */ | 417 | |
| 414 | 418 | # ifndef LDAV_SYMBOL | |
| 415 | #ifndef eunice | 419 | # define LDAV_SYMBOL "_avenrun" |
| 416 | #include <iodef.h> | 420 | # endif /* LDAV_SYMBOL */ |
| 417 | #include <descrip.h> | 421 | # endif /* __linux__ */ |
| 418 | #else /* eunice */ | 422 | |
| 419 | #include <vms/iodef.h> | 423 | # else /* VMS */ |
| 420 | #endif /* eunice */ | 424 | |
| 421 | #endif /* VMS */ | 425 | # ifndef eunice |
| 422 | 426 | # include <iodef.h> | |
| 423 | #ifndef LDAV_CVT | 427 | # include <descrip.h> |
| 424 | #define LDAV_CVT(n) ((double) (n)) | 428 | # else /* eunice */ |
| 425 | #endif /* !LDAV_CVT */ | 429 | # include <vms/iodef.h> |
| 426 | 430 | # endif /* eunice */ | |
| 427 | #endif /* LOAD_AVE_TYPE */ | 431 | # endif /* VMS */ |
| 428 | 432 | ||
| 429 | #ifdef NeXT | 433 | # ifndef LDAV_CVT |
| 430 | #ifdef HAVE_MACH_MACH_H | 434 | # define LDAV_CVT(n) ((double) (n)) |
| 431 | #include <mach/mach.h> | 435 | # endif /* !LDAV_CVT */ |
| 432 | #else | 436 | |
| 433 | #include <mach.h> | 437 | # endif /* LOAD_AVE_TYPE */ |
| 434 | #endif | 438 | |
| 435 | #endif /* NeXT */ | 439 | # ifdef NeXT |
| 436 | 440 | # ifdef HAVE_MACH_MACH_H | |
| 437 | #ifdef sgi | 441 | # include <mach/mach.h> |
| 438 | #include <sys/sysmp.h> | 442 | # else |
| 439 | #endif /* sgi */ | 443 | # include <mach.h> |
| 440 | 444 | # endif | |
| 441 | #ifdef UMAX | 445 | # endif /* NeXT */ |
| 442 | #include <stdio.h> | 446 | |
| 443 | #include <signal.h> | 447 | # ifdef sgi |
| 444 | #include <sys/time.h> | 448 | # include <sys/sysmp.h> |
| 445 | #include <sys/wait.h> | 449 | # endif /* sgi */ |
| 446 | #include <sys/syscall.h> | 450 | |
| 447 | 451 | # ifdef UMAX | |
| 448 | #ifdef UMAX_43 | 452 | # include <stdio.h> |
| 449 | #include <machine/cpu.h> | 453 | # include <signal.h> |
| 450 | #include <inq_stats/statistics.h> | 454 | # include <sys/time.h> |
| 451 | #include <inq_stats/sysstats.h> | 455 | # include <sys/wait.h> |
| 452 | #include <inq_stats/cpustats.h> | 456 | # include <sys/syscall.h> |
| 453 | #include <inq_stats/procstats.h> | 457 | |
| 454 | #else /* Not UMAX_43. */ | 458 | # ifdef UMAX_43 |
| 455 | #include <sys/sysdefs.h> | 459 | # include <machine/cpu.h> |
| 456 | #include <sys/statistics.h> | 460 | # include <inq_stats/statistics.h> |
| 457 | #include <sys/sysstats.h> | 461 | # include <inq_stats/sysstats.h> |
| 458 | #include <sys/cpudefs.h> | 462 | # include <inq_stats/cpustats.h> |
| 459 | #include <sys/cpustats.h> | 463 | # include <inq_stats/procstats.h> |
| 460 | #include <sys/procstats.h> | 464 | # else /* Not UMAX_43. */ |
| 461 | #endif /* Not UMAX_43. */ | 465 | # include <sys/sysdefs.h> |
| 462 | #endif /* UMAX */ | 466 | # include <sys/statistics.h> |
| 463 | 467 | # include <sys/sysstats.h> | |
| 464 | #ifdef DGUX | 468 | # include <sys/cpudefs.h> |
| 465 | #include <sys/dg_sys_info.h> | 469 | # include <sys/cpustats.h> |
| 466 | #endif | 470 | # include <sys/procstats.h> |
| 467 | 471 | # endif /* Not UMAX_43. */ | |
| 468 | #if defined(HAVE_FCNTL_H) || defined(_POSIX_VERSION) | 472 | # endif /* UMAX */ |
| 469 | #include <fcntl.h> | 473 | |
| 470 | #else | 474 | # ifdef DGUX |
| 471 | #include <sys/file.h> | 475 | # include <sys/dg_sys_info.h> |
| 472 | #endif | 476 | # endif |
| 477 | |||
| 478 | # if defined(HAVE_FCNTL_H) || defined(_POSIX_VERSION) | ||
| 479 | # include <fcntl.h> | ||
| 480 | # else | ||
| 481 | # include <sys/file.h> | ||
| 482 | # endif | ||
| 473 | 483 | ||
| 474 | /* Avoid static vars inside a function since in HPUX they dump as pure. */ | 484 | /* Avoid static vars inside a function since in HPUX they dump as pure. */ |
| 475 | 485 | ||
| 476 | #ifdef NeXT | 486 | # ifdef NeXT |
| 477 | static processor_set_t default_set; | 487 | static processor_set_t default_set; |
| 478 | static int getloadavg_initialized; | 488 | static int getloadavg_initialized; |
| 479 | #endif /* NeXT */ | 489 | # endif /* NeXT */ |
| 480 | 490 | ||
| 481 | #ifdef UMAX | 491 | # ifdef UMAX |
| 482 | static unsigned int cpus = 0; | 492 | static unsigned int cpus = 0; |
| 483 | static unsigned int samples; | 493 | static unsigned int samples; |
| 484 | #endif /* UMAX */ | 494 | # endif /* UMAX */ |
| 485 | 495 | ||
| 486 | #ifdef DGUX | 496 | # ifdef DGUX |
| 487 | static struct dg_sys_info_load_info load_info; /* what-a-mouthful! */ | 497 | static struct dg_sys_info_load_info load_info; /* what-a-mouthful! */ |
| 488 | #endif /* DGUX */ | 498 | # endif /* DGUX */ |
| 489 | 499 | ||
| 490 | #ifdef LOAD_AVE_TYPE | 500 | # ifdef LOAD_AVE_TYPE |
| 491 | /* File descriptor open to /dev/kmem or VMS load ave driver. */ | 501 | /* File descriptor open to /dev/kmem or VMS load ave driver. */ |
| 492 | static int channel; | 502 | static int channel; |
| 493 | /* Nonzero iff channel is valid. */ | 503 | /* Nonzero iff channel is valid. */ |
| @@ -495,15 +505,15 @@ static int getloadavg_initialized; | |||
| 495 | /* Offset in kmem to seek to read load average, or 0 means invalid. */ | 505 | /* Offset in kmem to seek to read load average, or 0 means invalid. */ |
| 496 | static long offset; | 506 | static long offset; |
| 497 | 507 | ||
| 498 | #if !defined(VMS) && !defined(sgi) | 508 | # if !defined(VMS) && !defined(sgi) && !defined(__linux__) |
| 499 | static struct nlist nl[2]; | 509 | static struct nlist nl[2]; |
| 500 | #endif /* Not VMS or sgi */ | 510 | # endif /* Not VMS or sgi */ |
| 501 | 511 | ||
| 502 | #ifdef SUNOS_5 | 512 | # ifdef SUNOS_5 |
| 503 | static kvm_t *kd; | 513 | static kvm_t *kd; |
| 504 | #endif /* SUNOS_5 */ | 514 | # endif /* SUNOS_5 */ |
| 505 | 515 | ||
| 506 | #endif /* LOAD_AVE_TYPE */ | 516 | # endif /* LOAD_AVE_TYPE */ |
| 507 | 517 | ||
| 508 | /* Put the 1 minute, 5 minute and 15 minute load averages | 518 | /* Put the 1 minute, 5 minute and 15 minute load averages |
| 509 | into the first NELEM elements of LOADAVG. | 519 | into the first NELEM elements of LOADAVG. |
| @@ -517,26 +527,29 @@ getloadavg (loadavg, nelem) | |||
| 517 | { | 527 | { |
| 518 | int elem = 0; /* Return value. */ | 528 | int elem = 0; /* Return value. */ |
| 519 | 529 | ||
| 520 | #ifdef NO_GET_LOAD_AVG | 530 | # ifdef NO_GET_LOAD_AVG |
| 521 | #define LDAV_DONE | 531 | # define LDAV_DONE |
| 522 | /* Set errno to zero to indicate that there was no particular error; | 532 | /* Set errno to zero to indicate that there was no particular error; |
| 523 | this function just can't work at all on this system. */ | 533 | this function just can't work at all on this system. */ |
| 524 | errno = 0; | 534 | errno = 0; |
| 525 | elem = -1; | 535 | elem = -1; |
| 526 | #endif | 536 | # endif |
| 527 | 537 | ||
| 528 | #if !defined (LDAV_DONE) && defined (SUNOS_5) | 538 | # if !defined (LDAV_DONE) && defined (SUNOS_5) |
| 529 | /* Use libkstat because we don't have to be root. */ | 539 | /* Use libkstat because we don't have to be root. */ |
| 530 | #define LDAV_DONE | 540 | # define LDAV_DONE |
| 531 | kstat_ctl_t *kc; | 541 | kstat_ctl_t *kc; |
| 532 | kstat_t *ksp; | 542 | kstat_t *ksp; |
| 533 | kstat_named_t *kn; | 543 | kstat_named_t *kn; |
| 534 | 544 | ||
| 535 | kc = kstat_open (); | 545 | kc = kstat_open (); |
| 536 | if (kc == 0) return -1; | 546 | if (kc == 0) |
| 547 | return -1; | ||
| 537 | ksp = kstat_lookup (kc, "unix", 0, "system_misc"); | 548 | ksp = kstat_lookup (kc, "unix", 0, "system_misc"); |
| 538 | if (ksp == 0 ) return -1; | 549 | if (ksp == 0 ) |
| 539 | if (kstat_read (kc, ksp, 0) == -1) return -1; | 550 | return -1; |
| 551 | if (kstat_read (kc, ksp, 0) == -1) | ||
| 552 | return -1; | ||
| 540 | 553 | ||
| 541 | 554 | ||
| 542 | kn = kstat_data_lookup (ksp, "avenrun_1min"); | 555 | kn = kstat_data_lookup (ksp, "avenrun_1min"); |
| @@ -567,15 +580,32 @@ getloadavg (loadavg, nelem) | |||
| 567 | } | 580 | } |
| 568 | 581 | ||
| 569 | kstat_close (kc); | 582 | kstat_close (kc); |
| 570 | #endif /* SUNOS_5 */ | 583 | # endif /* SUNOS_5 */ |
| 571 | 584 | ||
| 572 | #if !defined (LDAV_DONE) && defined (__linux__) | 585 | # if !defined (LDAV_DONE) && defined (hpux) && defined (HAVE_PSTAT_GETDYNAMIC) |
| 573 | #define LDAV_DONE | 586 | /* Use pstat_getdynamic() because we don't have to be root. */ |
| 574 | #undef LOAD_AVE_TYPE | 587 | # define LDAV_DONE |
| 588 | # undef LOAD_AVE_TYPE | ||
| 575 | 589 | ||
| 576 | #ifndef LINUX_LDAV_FILE | 590 | struct pst_dynamic dyn_info; |
| 577 | #define LINUX_LDAV_FILE "/proc/loadavg" | 591 | if (pstat_getdynamic (&dyn_info, sizeof (dyn_info), 0, 0) < 0) |
| 578 | #endif | 592 | return -1; |
| 593 | if (nelem > 0) | ||
| 594 | loadavg[elem++] = dyn_info.psd_avg_1_min; | ||
| 595 | if (nelem > 1) | ||
| 596 | loadavg[elem++] = dyn_info.psd_avg_5_min; | ||
| 597 | if (nelem > 2) | ||
| 598 | loadavg[elem++] = dyn_info.psd_avg_15_min; | ||
| 599 | |||
| 600 | # endif /* hpux && HAVE_PSTAT_GETDYNAMIC */ | ||
| 601 | |||
| 602 | # if !defined (LDAV_DONE) && defined (__linux__) | ||
| 603 | # define LDAV_DONE | ||
| 604 | # undef LOAD_AVE_TYPE | ||
| 605 | |||
| 606 | # ifndef LINUX_LDAV_FILE | ||
| 607 | # define LINUX_LDAV_FILE "/proc/loadavg" | ||
| 608 | # endif | ||
| 579 | 609 | ||
| 580 | char ldavgbuf[40]; | 610 | char ldavgbuf[40]; |
| 581 | double load_ave[3]; | 611 | double load_ave[3]; |
| @@ -599,15 +629,15 @@ getloadavg (loadavg, nelem) | |||
| 599 | 629 | ||
| 600 | return elem; | 630 | return elem; |
| 601 | 631 | ||
| 602 | #endif /* __linux__ */ | 632 | # endif /* __linux__ */ |
| 603 | 633 | ||
| 604 | #if !defined (LDAV_DONE) && defined (__NetBSD__) | 634 | # if !defined (LDAV_DONE) && defined (__NetBSD__) |
| 605 | #define LDAV_DONE | 635 | # define LDAV_DONE |
| 606 | #undef LOAD_AVE_TYPE | 636 | # undef LOAD_AVE_TYPE |
| 607 | 637 | ||
| 608 | #ifndef NETBSD_LDAV_FILE | 638 | # ifndef NETBSD_LDAV_FILE |
| 609 | #define NETBSD_LDAV_FILE "/kern/loadavg" | 639 | # define NETBSD_LDAV_FILE "/kern/loadavg" |
| 610 | #endif | 640 | # endif |
| 611 | 641 | ||
| 612 | unsigned long int load_ave[3], scale; | 642 | unsigned long int load_ave[3], scale; |
| 613 | int count; | 643 | int count; |
| @@ -628,10 +658,10 @@ getloadavg (loadavg, nelem) | |||
| 628 | 658 | ||
| 629 | return elem; | 659 | return elem; |
| 630 | 660 | ||
| 631 | #endif /* __NetBSD__ */ | 661 | # endif /* __NetBSD__ */ |
| 632 | 662 | ||
| 633 | #if !defined (LDAV_DONE) && defined (NeXT) | 663 | # if !defined (LDAV_DONE) && defined (NeXT) |
| 634 | #define LDAV_DONE | 664 | # define LDAV_DONE |
| 635 | /* The NeXT code was adapted from iscreen 3.2. */ | 665 | /* The NeXT code was adapted from iscreen 3.2. */ |
| 636 | 666 | ||
| 637 | host_t host; | 667 | host_t host; |
| @@ -651,7 +681,7 @@ getloadavg (loadavg, nelem) | |||
| 651 | { | 681 | { |
| 652 | info_count = PROCESSOR_SET_BASIC_INFO_COUNT; | 682 | info_count = PROCESSOR_SET_BASIC_INFO_COUNT; |
| 653 | if (processor_set_info (default_set, PROCESSOR_SET_BASIC_INFO, &host, | 683 | if (processor_set_info (default_set, PROCESSOR_SET_BASIC_INFO, &host, |
| 654 | (processor_set_info_t) &info, &info_count) | 684 | (processor_set_info_t) &info, &info_count) |
| 655 | != KERN_SUCCESS) | 685 | != KERN_SUCCESS) |
| 656 | getloadavg_initialized = 0; | 686 | getloadavg_initialized = 0; |
| 657 | else | 687 | else |
| @@ -663,10 +693,10 @@ getloadavg (loadavg, nelem) | |||
| 663 | 693 | ||
| 664 | if (!getloadavg_initialized) | 694 | if (!getloadavg_initialized) |
| 665 | return -1; | 695 | return -1; |
| 666 | #endif /* NeXT */ | 696 | # endif /* NeXT */ |
| 667 | 697 | ||
| 668 | #if !defined (LDAV_DONE) && defined (UMAX) | 698 | # if !defined (LDAV_DONE) && defined (UMAX) |
| 669 | #define LDAV_DONE | 699 | # define LDAV_DONE |
| 670 | /* UMAX 4.2, which runs on the Encore Multimax multiprocessor, does not | 700 | /* UMAX 4.2, which runs on the Encore Multimax multiprocessor, does not |
| 671 | have a /dev/kmem. Information about the workings of the running kernel | 701 | have a /dev/kmem. Information about the workings of the running kernel |
| 672 | can be gathered with inq_stats system calls. | 702 | can be gathered with inq_stats system calls. |
| @@ -733,10 +763,10 @@ getloadavg (loadavg, nelem) | |||
| 733 | 763 | ||
| 734 | if (nelem > 0) | 764 | if (nelem > 0) |
| 735 | loadavg[elem++] = load / samples / cpus; | 765 | loadavg[elem++] = load / samples / cpus; |
| 736 | #endif /* UMAX */ | 766 | # endif /* UMAX */ |
| 737 | 767 | ||
| 738 | #if !defined (LDAV_DONE) && defined (DGUX) | 768 | # if !defined (LDAV_DONE) && defined (DGUX) |
| 739 | #define LDAV_DONE | 769 | # define LDAV_DONE |
| 740 | /* This call can return -1 for an error, but with good args | 770 | /* This call can return -1 for an error, but with good args |
| 741 | it's not supposed to fail. The first argument is for no | 771 | it's not supposed to fail. The first argument is for no |
| 742 | apparent reason of type `long int *'. */ | 772 | apparent reason of type `long int *'. */ |
| @@ -750,10 +780,10 @@ getloadavg (loadavg, nelem) | |||
| 750 | loadavg[elem++] = load_info.five_minute; | 780 | loadavg[elem++] = load_info.five_minute; |
| 751 | if (nelem > 2) | 781 | if (nelem > 2) |
| 752 | loadavg[elem++] = load_info.fifteen_minute; | 782 | loadavg[elem++] = load_info.fifteen_minute; |
| 753 | #endif /* DGUX */ | 783 | # endif /* DGUX */ |
| 754 | 784 | ||
| 755 | #if !defined (LDAV_DONE) && defined (apollo) | 785 | # if !defined (LDAV_DONE) && defined (apollo) |
| 756 | #define LDAV_DONE | 786 | # define LDAV_DONE |
| 757 | /* Apollo code from lisch@mentorg.com (Ray Lischner). | 787 | /* Apollo code from lisch@mentorg.com (Ray Lischner). |
| 758 | 788 | ||
| 759 | This system call is not documented. The load average is obtained as | 789 | This system call is not documented. The load average is obtained as |
| @@ -775,10 +805,10 @@ getloadavg (loadavg, nelem) | |||
| 775 | loadavg[elem++] = load_ave[1] / 65536.0; | 805 | loadavg[elem++] = load_ave[1] / 65536.0; |
| 776 | if (nelem > 2) | 806 | if (nelem > 2) |
| 777 | loadavg[elem++] = load_ave[2] / 65536.0; | 807 | loadavg[elem++] = load_ave[2] / 65536.0; |
| 778 | #endif /* apollo */ | 808 | # endif /* apollo */ |
| 779 | 809 | ||
| 780 | #if !defined (LDAV_DONE) && defined (OSF_MIPS) | 810 | # if !defined (LDAV_DONE) && defined (OSF_MIPS) |
| 781 | #define LDAV_DONE | 811 | # define LDAV_DONE |
| 782 | 812 | ||
| 783 | struct tbl_loadavg load_ave; | 813 | struct tbl_loadavg load_ave; |
| 784 | table (TBL_LOADAVG, 0, &load_ave, 1, sizeof (load_ave)); | 814 | table (TBL_LOADAVG, 0, &load_ave, 1, sizeof (load_ave)); |
| @@ -786,20 +816,20 @@ getloadavg (loadavg, nelem) | |||
| 786 | = (load_ave.tl_lscale == 0 | 816 | = (load_ave.tl_lscale == 0 |
| 787 | ? load_ave.tl_avenrun.d[0] | 817 | ? load_ave.tl_avenrun.d[0] |
| 788 | : (load_ave.tl_avenrun.l[0] / (double) load_ave.tl_lscale)); | 818 | : (load_ave.tl_avenrun.l[0] / (double) load_ave.tl_lscale)); |
| 789 | #endif /* OSF_MIPS */ | 819 | # endif /* OSF_MIPS */ |
| 790 | 820 | ||
| 791 | #if !defined (LDAV_DONE) && (defined (MSDOS) || defined (WIN32)) | 821 | # if !defined (LDAV_DONE) && (defined (MSDOS) || defined (WIN32)) |
| 792 | #define LDAV_DONE | 822 | # define LDAV_DONE |
| 793 | 823 | ||
| 794 | /* A faithful emulation is going to have to be saved for a rainy day. */ | 824 | /* A faithful emulation is going to have to be saved for a rainy day. */ |
| 795 | for ( ; elem < nelem; elem++) | 825 | for ( ; elem < nelem; elem++) |
| 796 | { | 826 | { |
| 797 | loadavg[elem] = 0.0; | 827 | loadavg[elem] = 0.0; |
| 798 | } | 828 | } |
| 799 | #endif /* MSDOS */ | 829 | # endif /* MSDOS */ |
| 800 | 830 | ||
| 801 | #if !defined (LDAV_DONE) && defined (OSF_ALPHA) | 831 | # if !defined (LDAV_DONE) && defined (OSF_ALPHA) |
| 802 | #define LDAV_DONE | 832 | # define LDAV_DONE |
| 803 | 833 | ||
| 804 | struct tbl_loadavg load_ave; | 834 | struct tbl_loadavg load_ave; |
| 805 | table (TBL_LOADAVG, 0, &load_ave, 1, sizeof (load_ave)); | 835 | table (TBL_LOADAVG, 0, &load_ave, 1, sizeof (load_ave)); |
| @@ -808,31 +838,31 @@ getloadavg (loadavg, nelem) | |||
| 808 | = (load_ave.tl_lscale == 0 | 838 | = (load_ave.tl_lscale == 0 |
| 809 | ? load_ave.tl_avenrun.d[elem] | 839 | ? load_ave.tl_avenrun.d[elem] |
| 810 | : (load_ave.tl_avenrun.l[elem] / (double) load_ave.tl_lscale)); | 840 | : (load_ave.tl_avenrun.l[elem] / (double) load_ave.tl_lscale)); |
| 811 | #endif /* OSF_ALPHA */ | 841 | # endif /* OSF_ALPHA */ |
| 812 | 842 | ||
| 813 | #if !defined (LDAV_DONE) && defined (VMS) | 843 | # if !defined (LDAV_DONE) && defined (VMS) |
| 814 | /* VMS specific code -- read from the Load Ave driver. */ | 844 | /* VMS specific code -- read from the Load Ave driver. */ |
| 815 | 845 | ||
| 816 | LOAD_AVE_TYPE load_ave[3]; | 846 | LOAD_AVE_TYPE load_ave[3]; |
| 817 | static int getloadavg_initialized = 0; | 847 | static int getloadavg_initialized = 0; |
| 818 | #ifdef eunice | 848 | # ifdef eunice |
| 819 | struct | 849 | struct |
| 820 | { | 850 | { |
| 821 | int dsc$w_length; | 851 | int dsc$w_length; |
| 822 | char *dsc$a_pointer; | 852 | char *dsc$a_pointer; |
| 823 | } descriptor; | 853 | } descriptor; |
| 824 | #endif | 854 | # endif |
| 825 | 855 | ||
| 826 | /* Ensure that there is a channel open to the load ave device. */ | 856 | /* Ensure that there is a channel open to the load ave device. */ |
| 827 | if (!getloadavg_initialized) | 857 | if (!getloadavg_initialized) |
| 828 | { | 858 | { |
| 829 | /* Attempt to open the channel. */ | 859 | /* Attempt to open the channel. */ |
| 830 | #ifdef eunice | 860 | # ifdef eunice |
| 831 | descriptor.dsc$w_length = 18; | 861 | descriptor.dsc$w_length = 18; |
| 832 | descriptor.dsc$a_pointer = "$$VMS_LOAD_AVERAGE"; | 862 | descriptor.dsc$a_pointer = "$$VMS_LOAD_AVERAGE"; |
| 833 | #else | 863 | # else |
| 834 | $DESCRIPTOR (descriptor, "LAV0:"); | 864 | $DESCRIPTOR (descriptor, "LAV0:"); |
| 835 | #endif | 865 | # endif |
| 836 | if (sys$assign (&descriptor, &channel, 0, 0) & 1) | 866 | if (sys$assign (&descriptor, &channel, 0, 0) & 1) |
| 837 | getloadavg_initialized = 1; | 867 | getloadavg_initialized = 1; |
| 838 | } | 868 | } |
| @@ -848,76 +878,76 @@ getloadavg (loadavg, nelem) | |||
| 848 | 878 | ||
| 849 | if (!getloadavg_initialized) | 879 | if (!getloadavg_initialized) |
| 850 | return -1; | 880 | return -1; |
| 851 | #endif /* VMS */ | 881 | # endif /* VMS */ |
| 852 | 882 | ||
| 853 | #if !defined (LDAV_DONE) && defined(LOAD_AVE_TYPE) && !defined(VMS) | 883 | # if !defined (LDAV_DONE) && defined(LOAD_AVE_TYPE) && !defined(VMS) |
| 854 | 884 | ||
| 855 | /* UNIX-specific code -- read the average from /dev/kmem. */ | 885 | /* UNIX-specific code -- read the average from /dev/kmem. */ |
| 856 | 886 | ||
| 857 | #define LDAV_PRIVILEGED /* This code requires special installation. */ | 887 | # define LDAV_PRIVILEGED /* This code requires special installation. */ |
| 858 | 888 | ||
| 859 | LOAD_AVE_TYPE load_ave[3]; | 889 | LOAD_AVE_TYPE load_ave[3]; |
| 860 | 890 | ||
| 861 | /* Get the address of LDAV_SYMBOL. */ | 891 | /* Get the address of LDAV_SYMBOL. */ |
| 862 | if (offset == 0) | 892 | if (offset == 0) |
| 863 | { | 893 | { |
| 864 | #ifndef sgi | 894 | # ifndef sgi |
| 865 | #ifndef NLIST_STRUCT | 895 | # ifndef NLIST_STRUCT |
| 866 | strcpy (nl[0].n_name, LDAV_SYMBOL); | 896 | strcpy (nl[0].n_name, LDAV_SYMBOL); |
| 867 | strcpy (nl[1].n_name, ""); | 897 | strcpy (nl[1].n_name, ""); |
| 868 | #else /* NLIST_STRUCT */ | 898 | # else /* NLIST_STRUCT */ |
| 869 | #ifdef NLIST_NAME_UNION | 899 | # ifdef NLIST_NAME_UNION |
| 870 | nl[0].n_un.n_name = LDAV_SYMBOL; | 900 | nl[0].n_un.n_name = LDAV_SYMBOL; |
| 871 | nl[1].n_un.n_name = 0; | 901 | nl[1].n_un.n_name = 0; |
| 872 | #else /* not NLIST_NAME_UNION */ | 902 | # else /* not NLIST_NAME_UNION */ |
| 873 | nl[0].n_name = LDAV_SYMBOL; | 903 | nl[0].n_name = LDAV_SYMBOL; |
| 874 | nl[1].n_name = 0; | 904 | nl[1].n_name = 0; |
| 875 | #endif /* not NLIST_NAME_UNION */ | 905 | # endif /* not NLIST_NAME_UNION */ |
| 876 | #endif /* NLIST_STRUCT */ | 906 | # endif /* NLIST_STRUCT */ |
| 877 | 907 | ||
| 878 | #ifndef SUNOS_5 | 908 | # ifndef SUNOS_5 |
| 879 | if ( | 909 | if ( |
| 880 | #if !(defined (_AIX) && !defined (ps2)) | 910 | # if !(defined (_AIX) && !defined (ps2)) |
| 881 | nlist (KERNEL_FILE, nl) | 911 | nlist (KERNEL_FILE, nl) |
| 882 | #else /* _AIX */ | 912 | # else /* _AIX */ |
| 883 | knlist (nl, 1, sizeof (nl[0])) | 913 | knlist (nl, 1, sizeof (nl[0])) |
| 884 | #endif | 914 | # endif |
| 885 | >= 0) | 915 | >= 0) |
| 886 | /* Omit "&& nl[0].n_type != 0 " -- it breaks on Sun386i. */ | 916 | /* Omit "&& nl[0].n_type != 0 " -- it breaks on Sun386i. */ |
| 887 | { | 917 | { |
| 888 | #ifdef FIXUP_KERNEL_SYMBOL_ADDR | 918 | # ifdef FIXUP_KERNEL_SYMBOL_ADDR |
| 889 | FIXUP_KERNEL_SYMBOL_ADDR (nl); | 919 | FIXUP_KERNEL_SYMBOL_ADDR (nl); |
| 890 | #endif | 920 | # endif |
| 891 | offset = nl[0].n_value; | 921 | offset = nl[0].n_value; |
| 892 | } | 922 | } |
| 893 | #endif /* !SUNOS_5 */ | 923 | # endif /* !SUNOS_5 */ |
| 894 | #else /* sgi */ | 924 | # else /* sgi */ |
| 895 | int ldav_off; | 925 | int ldav_off; |
| 896 | 926 | ||
| 897 | ldav_off = sysmp (MP_KERNADDR, MPKA_AVENRUN); | 927 | ldav_off = sysmp (MP_KERNADDR, MPKA_AVENRUN); |
| 898 | if (ldav_off != -1) | 928 | if (ldav_off != -1) |
| 899 | offset = (long) ldav_off & 0x7fffffff; | 929 | offset = (long) ldav_off & 0x7fffffff; |
| 900 | #endif /* sgi */ | 930 | # endif /* sgi */ |
| 901 | } | 931 | } |
| 902 | 932 | ||
| 903 | /* Make sure we have /dev/kmem open. */ | 933 | /* Make sure we have /dev/kmem open. */ |
| 904 | if (!getloadavg_initialized) | 934 | if (!getloadavg_initialized) |
| 905 | { | 935 | { |
| 906 | #ifndef SUNOS_5 | 936 | # ifndef SUNOS_5 |
| 907 | channel = open ("/dev/kmem", 0); | 937 | channel = open ("/dev/kmem", 0); |
| 908 | if (channel >= 0) | 938 | if (channel >= 0) |
| 909 | { | 939 | { |
| 910 | /* Set the channel to close on exec, so it does not | 940 | /* Set the channel to close on exec, so it does not |
| 911 | litter any child's descriptor table. */ | 941 | litter any child's descriptor table. */ |
| 912 | #ifdef FD_SETFD | 942 | # ifdef FD_SETFD |
| 913 | #ifndef FD_CLOEXEC | 943 | # ifndef FD_CLOEXEC |
| 914 | #define FD_CLOEXEC 1 | 944 | # define FD_CLOEXEC 1 |
| 915 | #endif | 945 | # endif |
| 916 | (void) fcntl (channel, F_SETFD, FD_CLOEXEC); | 946 | (void) fcntl (channel, F_SETFD, FD_CLOEXEC); |
| 917 | #endif | 947 | # endif |
| 918 | getloadavg_initialized = 1; | 948 | getloadavg_initialized = 1; |
| 919 | } | 949 | } |
| 920 | #else /* SUNOS_5 */ | 950 | # else /* SUNOS_5 */ |
| 921 | /* We pass 0 for the kernel, corefile, and swapfile names | 951 | /* We pass 0 for the kernel, corefile, and swapfile names |
| 922 | to use the currently running kernel. */ | 952 | to use the currently running kernel. */ |
| 923 | kd = kvm_open (0, 0, 0, O_RDONLY, 0); | 953 | kd = kvm_open (0, 0, 0, O_RDONLY, 0); |
| @@ -928,14 +958,14 @@ getloadavg (loadavg, nelem) | |||
| 928 | offset = nl[0].n_value; | 958 | offset = nl[0].n_value; |
| 929 | getloadavg_initialized = 1; | 959 | getloadavg_initialized = 1; |
| 930 | } | 960 | } |
| 931 | #endif /* SUNOS_5 */ | 961 | # endif /* SUNOS_5 */ |
| 932 | } | 962 | } |
| 933 | 963 | ||
| 934 | /* If we can, get the load average values. */ | 964 | /* If we can, get the load average values. */ |
| 935 | if (offset && getloadavg_initialized) | 965 | if (offset && getloadavg_initialized) |
| 936 | { | 966 | { |
| 937 | /* Try to read the load. */ | 967 | /* Try to read the load. */ |
| 938 | #ifndef SUNOS_5 | 968 | # ifndef SUNOS_5 |
| 939 | if (lseek (channel, offset, 0) == -1L | 969 | if (lseek (channel, offset, 0) == -1L |
| 940 | || read (channel, (char *) load_ave, sizeof (load_ave)) | 970 | || read (channel, (char *) load_ave, sizeof (load_ave)) |
| 941 | != sizeof (load_ave)) | 971 | != sizeof (load_ave)) |
| @@ -943,21 +973,21 @@ getloadavg (loadavg, nelem) | |||
| 943 | close (channel); | 973 | close (channel); |
| 944 | getloadavg_initialized = 0; | 974 | getloadavg_initialized = 0; |
| 945 | } | 975 | } |
| 946 | #else /* SUNOS_5 */ | 976 | # else /* SUNOS_5 */ |
| 947 | if (kvm_read (kd, offset, (char *) load_ave, sizeof (load_ave)) | 977 | if (kvm_read (kd, offset, (char *) load_ave, sizeof (load_ave)) |
| 948 | != sizeof (load_ave)) | 978 | != sizeof (load_ave)) |
| 949 | { | 979 | { |
| 950 | kvm_close (kd); | 980 | kvm_close (kd); |
| 951 | getloadavg_initialized = 0; | 981 | getloadavg_initialized = 0; |
| 952 | } | 982 | } |
| 953 | #endif /* SUNOS_5 */ | 983 | # endif /* SUNOS_5 */ |
| 954 | } | 984 | } |
| 955 | 985 | ||
| 956 | if (offset == 0 || !getloadavg_initialized) | 986 | if (offset == 0 || !getloadavg_initialized) |
| 957 | return -1; | 987 | return -1; |
| 958 | #endif /* LOAD_AVE_TYPE and not VMS */ | 988 | # endif /* LOAD_AVE_TYPE and not VMS */ |
| 959 | 989 | ||
| 960 | #if !defined (LDAV_DONE) && defined (LOAD_AVE_TYPE) /* Including VMS. */ | 990 | # if !defined (LDAV_DONE) && defined (LOAD_AVE_TYPE) /* Including VMS. */ |
| 961 | if (nelem > 0) | 991 | if (nelem > 0) |
| 962 | loadavg[elem++] = LDAV_CVT (load_ave[0]); | 992 | loadavg[elem++] = LDAV_CVT (load_ave[0]); |
| 963 | if (nelem > 1) | 993 | if (nelem > 1) |
| @@ -965,17 +995,17 @@ getloadavg (loadavg, nelem) | |||
| 965 | if (nelem > 2) | 995 | if (nelem > 2) |
| 966 | loadavg[elem++] = LDAV_CVT (load_ave[2]); | 996 | loadavg[elem++] = LDAV_CVT (load_ave[2]); |
| 967 | 997 | ||
| 968 | #define LDAV_DONE | 998 | # define LDAV_DONE |
| 969 | #endif /* !LDAV_DONE && LOAD_AVE_TYPE */ | 999 | # endif /* !LDAV_DONE && LOAD_AVE_TYPE */ |
| 970 | 1000 | ||
| 971 | #ifdef LDAV_DONE | 1001 | # ifdef LDAV_DONE |
| 972 | return elem; | 1002 | return elem; |
| 973 | #else | 1003 | # else |
| 974 | /* Set errno to zero to indicate that there was no particular error; | 1004 | /* Set errno to zero to indicate that there was no particular error; |
| 975 | this function just can't work at all on this system. */ | 1005 | this function just can't work at all on this system. */ |
| 976 | errno = 0; | 1006 | errno = 0; |
| 977 | return -1; | 1007 | return -1; |
| 978 | #endif | 1008 | # endif |
| 979 | } | 1009 | } |
| 980 | 1010 | ||
| 981 | #endif /* ! HAVE_GETLOADAVG */ | 1011 | #endif /* ! HAVE_GETLOADAVG */ |