comparison src/getloadavg.c @ 771:943eaba38521

[xemacs-hg @ 2002-03-13 08:51:24 by ben] The big ben-mule-21-5 check-in! Various files were added and deleted. See CHANGES-ben-mule. There are still some test suite failures. No crashes, though. Many of the failures have to do with problems in the test suite itself rather than in the actual code. I'll be addressing these in the next day or so -- none of the test suite failures are at all critical. Meanwhile I'll be trying to address the biggest issues -- i.e. build or run failures, which will almost certainly happen on various platforms. All comments should be sent to ben@xemacs.org -- use a Cc: if necessary when sending to mailing lists. There will be pre- and post- tags, something like pre-ben-mule-21-5-merge-in, and post-ben-mule-21-5-merge-in.
author ben
date Wed, 13 Mar 2002 08:54:06 +0000
parents b39c14581166
children 13e47461d509
comparison
equal deleted inserted replaced
770:336a418893b5 771:943eaba38521
572 572
573 char ldavgbuf[40]; 573 char ldavgbuf[40];
574 double load_ave[3]; 574 double load_ave[3];
575 int fd, count; 575 int fd, count;
576 576
577 fd = open (LINUX_LDAV_FILE, O_RDONLY); 577 fd = retry_open (LINUX_LDAV_FILE, O_RDONLY);
578 if (fd == -1) 578 if (fd == -1)
579 return -1; 579 return -1;
580 count = read (fd, ldavgbuf, 40); 580 count = retry_read (fd, ldavgbuf, 40);
581 (void) close (fd); 581 (void) retry_close (fd);
582 if (count <= 0) 582 if (count <= 0)
583 return -1; 583 return -1;
584 584
585 count = sscanf (ldavgbuf, "%lf %lf %lf", 585 count = sscanf (ldavgbuf, "%lf %lf %lf",
586 &load_ave[0], &load_ave[1], &load_ave[2]); 586 &load_ave[0], &load_ave[1], &load_ave[2]);
601 601
602 unsigned long int load_ave[3], scale; 602 unsigned long int load_ave[3], scale;
603 int count; 603 int count;
604 FILE *fp; 604 FILE *fp;
605 605
606 fp = fopen (NETBSD_LDAV_FILE, "r"); 606 fp = retry_fopen (NETBSD_LDAV_FILE, "r");
607 if (fp == NULL) 607 if (fp == NULL)
608 return -1; 608 return -1;
609 count = fscanf (fp, "%lu %lu %lu %lu\n", 609 count = fscanf (fp, "%lu %lu %lu %lu\n",
610 &load_ave[0], &load_ave[1], &load_ave[2], 610 &load_ave[0], &load_ave[1], &load_ave[2],
611 &scale); 611 &scale);
612 (void) fclose (fp); 612 (void) retry_fclose (fp);
613 if (count != 4) 613 if (count != 4)
614 return -1; 614 return -1;
615 615
616 for (elem = 0; elem < nelem; elem++) 616 for (elem = 0; elem < nelem; elem++)
617 loadavg[elem] = (double) load_ave[elem] / (double) scale; 617 loadavg[elem] = (double) load_ave[elem] / (double) scale;
824 824
825 /* Make sure we have /dev/kmem open. */ 825 /* Make sure we have /dev/kmem open. */
826 if (!getloadavg_initialized) 826 if (!getloadavg_initialized)
827 { 827 {
828 #ifndef SUNOS_5 828 #ifndef SUNOS_5
829 channel = open ("/dev/kmem", 0); 829 channel = retry_open ("/dev/kmem", 0);
830 if (channel >= 0) 830 if (channel >= 0)
831 { 831 {
832 /* Set the channel to close on exec, so it does not 832 /* Set the channel to close on exec, so it does not
833 litter any child's descriptor table. */ 833 litter any child's descriptor table. */
834 #ifdef FD_SETFD 834 #ifdef FD_SETFD
857 if (offset && getloadavg_initialized) 857 if (offset && getloadavg_initialized)
858 { 858 {
859 /* Try to read the load. */ 859 /* Try to read the load. */
860 #ifndef SUNOS_5 860 #ifndef SUNOS_5
861 if (lseek (channel, offset, 0) == -1L 861 if (lseek (channel, offset, 0) == -1L
862 || read (channel, (char *) load_ave, sizeof (load_ave)) 862 || retry_read (channel, (char *) load_ave, sizeof (load_ave))
863 != sizeof (load_ave)) 863 != sizeof (load_ave))
864 { 864 {
865 close (channel); 865 retry_close (channel);
866 getloadavg_initialized = 0; 866 getloadavg_initialized = 0;
867 } 867 }
868 #else /* SUNOS_5 */ 868 #else /* SUNOS_5 */
869 if (kvm_read (kd, offset, (char *) load_ave, sizeof (load_ave)) 869 if (kvm_read (kd, offset, (char *) load_ave, sizeof (load_ave))
870 != sizeof (load_ave)) 870 != sizeof (load_ave))