aboutsummaryrefslogtreecommitdiffstats
path: root/src/fns.c
diff options
context:
space:
mode:
authorJim Blandy1992-06-24 05:09:26 +0000
committerJim Blandy1992-06-24 05:09:26 +0000
commitdaa3760289bd389e8c174c8d24b375cd875cd911 (patch)
tree0abe3e6108e0e5a7c98f4c4aa68a495b0ecef09a /src/fns.c
parenta4275ad1c8f60239b0bad43cef97ca86d35a51a3 (diff)
downloademacs-daa3760289bd389e8c174c8d24b375cd875cd911.tar.gz
emacs-daa3760289bd389e8c174c8d24b375cd875cd911.zip
*** empty log message ***
Diffstat (limited to 'src/fns.c')
-rw-r--r--src/fns.c209
1 files changed, 15 insertions, 194 deletions
diff --git a/src/fns.c b/src/fns.c
index 8562f142dce..b30a2422f7f 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -20,41 +20,6 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
20 20
21#include "config.h" 21#include "config.h"
22 22
23#ifdef LOAD_AVE_TYPE
24#ifdef BSD
25/* It appears param.h defines BSD and BSD4_3 in 4.3
26 and is not considerate enough to avoid bombing out
27 if they are already defined. */
28#undef BSD
29#ifdef BSD4_3
30#undef BSD4_3
31#define XBSD4_3 /* XBSD4_3 says BSD4_3 is supposed to be defined. */
32#endif
33#include <sys/param.h>
34/* Now if BSD or BSD4_3 was defined and is no longer,
35 define it again. */
36#ifndef BSD
37#define BSD
38#endif
39#ifdef XBSD4_3
40#ifndef BSD4_3
41#define BSD4_3
42#endif
43#endif /* XBSD4_3 */
44#endif /* BSD */
45#ifndef VMS
46#ifndef NLIST_STRUCT
47#include <a.out.h>
48#else /* NLIST_STRUCT */
49#include <nlist.h>
50#endif /* NLIST_STRUCT */
51#endif /* not VMS */
52#endif /* LOAD_AVE_TYPE */
53
54#ifdef DGUX
55#include <sys/dg_sys_info.h> /* for load average info - DJB */
56#endif
57
58/* Note on some machines this defines `vector' as a typedef, 23/* Note on some machines this defines `vector' as a typedef,
59 so make sure we don't use that name in this file. */ 24 so make sure we don't use that name in this file. */
60#undef vector 25#undef vector
@@ -1226,171 +1191,27 @@ and can rub it out if not confirmed.")
1226 UNGCPRO; 1191 UNGCPRO;
1227} 1192}
1228 1193
1229/* Avoid static vars inside a function since in HPUX they dump as pure. */
1230#ifdef DGUX
1231static struct dg_sys_info_load_info load_info; /* what-a-mouthful! */
1232
1233#else /* Not DGUX */
1234
1235static int ldav_initialized;
1236static int ldav_channel;
1237#ifdef LOAD_AVE_TYPE
1238#ifndef VMS
1239static struct nlist ldav_nl[2];
1240#endif /* VMS */
1241#endif /* LOAD_AVE_TYPE */
1242
1243#define channel ldav_channel
1244#define initialized ldav_initialized
1245#define nl ldav_nl
1246#endif /* Not DGUX */
1247
1248DEFUN ("load-average", Fload_average, Sload_average, 0, 0, 0, 1194DEFUN ("load-average", Fload_average, Sload_average, 0, 0, 0,
1249 "Return list of 1 minute, 5 minute and 15 minute load averages.\n\ 1195 "Return list of 1 minute, 5 minute and 15 minute load averages.\n\
1250Each of the three load averages is multiplied by 100,\n\ 1196Each of the three load averages is multiplied by 100,\n\
1251then converted to integer.") 1197then converted to integer.\n\
1198If the 5-minute or 15-minute load averages are not available, return a\n\
1199shortened list, containing only those averages which are available.")
1252 () 1200 ()
1253{ 1201{
1254#ifdef DGUX 1202 double load_ave[3];
1255 /* perhaps there should be a "sys_load_avg" call in sysdep.c?! - DJB */ 1203 int loads = getloadavg (load_ave, 3);
1256 load_info.one_minute = 0.0; /* just in case there is an error */ 1204 Lisp_Object ret;
1257 load_info.five_minute = 0.0;
1258 load_info.fifteen_minute = 0.0;
1259 dg_sys_info (&load_info, DG_SYS_INFO_LOAD_INFO_TYPE,
1260 DG_SYS_INFO_LOAD_VERSION_0);
1261
1262 return Fcons (make_number ((int)(load_info.one_minute * 100.0)),
1263 Fcons (make_number ((int)(load_info.five_minute * 100.0)),
1264 Fcons (make_number ((int)(load_info.fifteen_minute * 100.0)),
1265 Qnil)));
1266#else /* not DGUX */
1267#ifndef LOAD_AVE_TYPE
1268 error ("load-average not implemented for this operating system");
1269
1270#else /* LOAD_AVE_TYPE defined */
1271
1272 LOAD_AVE_TYPE load_ave[3];
1273#ifdef VMS
1274#ifndef eunice
1275#include <iodef.h>
1276#include <descrip.h>
1277#else
1278#include <vms/iodef.h>
1279 struct {int dsc$w_length; char *dsc$a_pointer;} descriptor;
1280#endif /* eunice */
1281#endif /* VMS */
1282
1283 /* If this fails for any reason, we can return (0 0 0) */
1284 load_ave[0] = 0.0; load_ave[1] = 0.0; load_ave[2] = 0.0;
1285
1286#ifdef VMS
1287 /*
1288 * VMS specific code -- read from the Load Ave driver
1289 */
1290
1291 /*
1292 * Ensure that there is a channel open to the load ave device
1293 */
1294 if (initialized == 0)
1295 {
1296 /* Attempt to open the channel */
1297#ifdef eunice
1298 descriptor.size = 18;
1299 descriptor.ptr = "$$VMS_LOAD_AVERAGE";
1300#else
1301 $DESCRIPTOR(descriptor, "LAV0:");
1302#endif
1303 if (sys$assign (&descriptor, &channel, 0, 0) & 1)
1304 initialized = 1;
1305 }
1306 /*
1307 * Read the load average vector
1308 */
1309 if (initialized)
1310 {
1311 if (!(sys$qiow (0, channel, IO$_READVBLK, 0, 0, 0,
1312 load_ave, 12, 0, 0, 0, 0)
1313 & 1))
1314 {
1315 sys$dassgn (channel);
1316 initialized = 0;
1317 }
1318 }
1319#else /* not VMS */
1320 /*
1321 * 4.2BSD UNIX-specific code -- read _avenrun from /dev/kmem
1322 */
1323
1324 /*
1325 * Make sure we have the address of _avenrun
1326 */
1327 if (nl[0].n_value == 0)
1328 {
1329 /*
1330 * Get the address of _avenrun
1331 */
1332#ifndef NLIST_STRUCT
1333 strcpy (nl[0].n_name, LDAV_SYMBOL);
1334 nl[1].n_zeroes = 0;
1335#else /* NLIST_STRUCT */
1336#ifdef convex
1337 nl[0].n_un.n_name = LDAV_SYMBOL;
1338 nl[1].n_un.n_name = 0;
1339#else /* not convex */
1340 nl[0].n_name = LDAV_SYMBOL;
1341 nl[1].n_name = 0;
1342#endif /* not convex */
1343#endif /* NLIST_STRUCT */
1344
1345 nlist (KERNEL_FILE, nl);
1346
1347#ifdef FIXUP_KERNEL_SYMBOL_ADDR
1348 FIXUP_KERNEL_SYMBOL_ADDR (nl);
1349#endif /* FIXUP_KERNEL_SYMBOL_ADDR */
1350 }
1351 /*
1352 * Make sure we have /dev/kmem open
1353 */
1354 if (initialized == 0)
1355 {
1356 /*
1357 * Open /dev/kmem
1358 */
1359 channel = open ("/dev/kmem", 0);
1360 if (channel >= 0) initialized = 1;
1361 }
1362 /*
1363 * If we can, get the load ave values
1364 */
1365 if ((nl[0].n_value != 0) && (initialized != 0))
1366 {
1367 /*
1368 * Seek to the correct address
1369 */
1370 lseek (channel, (long) nl[0].n_value, 0);
1371 if (read (channel, load_ave, sizeof load_ave)
1372 != sizeof(load_ave))
1373 {
1374 close (channel);
1375 initialized = 0;
1376 }
1377 }
1378#endif /* not VMS */
1379
1380 /*
1381 * Return the list of load average values
1382 */
1383 return Fcons (make_number (LOAD_AVE_CVT (load_ave[0])),
1384 Fcons (make_number (LOAD_AVE_CVT (load_ave[1])),
1385 Fcons (make_number (LOAD_AVE_CVT (load_ave[2])),
1386 Qnil)));
1387#endif /* LOAD_AVE_TYPE */
1388#endif /* not DGUX */
1389}
1390 1205
1391#undef channel 1206 if (loads < 0)
1392#undef initialized 1207 error ("load-average not implemented for this operating system");
1393#undef nl 1208
1209 ret = Qnil;
1210 while (loads > 0)
1211 ret = Fcons (make_number ((int) (load_ave[--loads] * 100.0)), ret);
1212
1213 return ret;
1214}
1394 1215
1395Lisp_Object Vfeatures; 1216Lisp_Object Vfeatures;
1396 1217