1 /*************************************************
2 * Exim - an Internet mail transport agent *
3 *************************************************/
5 /* Copyright (c) University of Cambridge 1995 - 2018 */
6 /* Copyright (c) The Exim Maintainers 2021 */
7 /* See the file NOTICE for conditions of use and distribution. */
17 # define US (unsigned char *)
20 /* This source file contains "default" system-dependent functions which
21 provide functionality (or lack of it) in cases where the OS-specific os.c
22 file has not. Some of them are tailored by macros defined in os.h files. */
25 #ifndef OS_RESTARTING_SIGNAL
26 /*************************************************
27 * Set up restarting signal *
28 *************************************************/
30 /* This function has the same functionality as the ANSI C signal() function,
31 except that it arranges that, if the signal happens during a system call, the
32 system call gets restarted. (Also, it doesn't return a result.) Different
33 versions of Unix have different defaults, and different ways of setting up a
34 restarting signal handler. If the functionality is not available, the signal
35 should be set to be ignored. This function is used only for catching SIGUSR1.
39 os_restarting_signal(int sig, void (*handler)(int))
41 /* Many systems have the SA_RESTART sigaction for specifying that a signal
42 should restart system calls. These include SunOS5, AIX, BSDI, IRIX, FreeBSD,
43 OSF1, Linux and HP-UX 10 (but *not* HP-UX 9). */
47 act.sa_handler = handler;
48 sigemptyset(&(act.sa_mask));
49 act.sa_flags = SA_RESTART;
50 sigaction(sig, &act, NULL);
53 printf("Used SA_RESTART\n");
56 /* SunOS4 and Ultrix default to non-interruptable signals, with SV_INTERRUPT
57 for making them interruptable. This seems to be a dying fashion. */
59 #elif defined SV_INTERRUPT
63 printf("Used default signal()\n");
67 /* If neither SA_RESTART nor SV_INTERRUPT is available we don't know how to
68 set up a restarting signal, so simply suppress the facility. */
74 printf("Used SIG_IGN\n");
80 #endif /* OS_RESTARTING_SIGNAL */
83 #ifndef OS_NON_RESTARTING_SIGNAL
84 /*************************************************
85 * Set up non-restarting signal *
86 *************************************************/
88 /* This function has the same functionality as the ANSI C signal() function,
89 except that it arranges that, if the signal happens during a system call, the
90 system call gets interrupted. (Also, it doesn't return a result.) Different
91 versions of Unix have different defaults, and different ways of setting up a
92 non-restarting signal handler. For systems for which we don't know what to do,
93 just use the normal signal() function and hope for the best. */
96 os_non_restarting_signal(int sig, void (*handler)(int))
98 /* Many systems have the SA_RESTART sigaction for specifying that a signal
99 should restart system calls. These include SunOS5, AIX, BSDI, IRIX, FreeBSD,
100 OSF1, Linux and HP-UX 10 (but *not* HP-UX 9). */
103 struct sigaction act;
104 act.sa_handler = handler;
105 sigemptyset(&(act.sa_mask));
107 sigaction(sig, &act, NULL);
110 printf("Used sigaction() with flags = 0\n");
113 /* SunOS4 and Ultrix default to non-interruptable signals, with SV_INTERRUPT
114 for making them interruptable. This seems to be a dying fashion. */
116 #elif defined SV_INTERRUPT
118 sv.sv_handler = handler;
119 sv.sv_flags = SV_INTERRUPT;
121 sigvec(sig, &sv, NULL);
124 printf("Used sigvec() with flags = SV_INTERRUPT\n");
127 /* If neither SA_RESTART nor SV_INTERRUPT is available we don't know how to
128 set up a restarting signal, so just use the standard signal() function. */
131 signal(sig, handler);
134 printf("Used default signal()\n");
140 #endif /* OS_NON_RESTARTING_SIGNAL */
144 #ifdef STRERROR_FROM_ERRLIST
145 /*************************************************
146 * Provide strerror() for non-ANSI libraries *
147 *************************************************/
149 /* Some old-fashioned systems still around (e.g. SunOS4) don't have strerror()
150 in their libraries, but can provide the same facility by this simple
151 alternative function. */
156 if (n < 0 || n >= sys_nerr) return "unknown error number";
157 return sys_errlist[n];
159 #endif /* STRERROR_FROM_ERRLIST */
164 /*************************************************
165 * Provide strsignal() for systems without *
166 *************************************************/
168 /* Some systems have strsignal() to turn signal numbers into names; others
169 may have other means of doing this. This function is used for those systems
170 that have nothing. It provides a basic translation for the common standard
171 signal numbers. I've been extra cautious with the ifdef's here. Probably more
172 than is necessary... */
175 os_strsignal(const int n)
180 case SIGHUP: return "hangup";
184 case SIGINT: return "interrupt";
188 case SIGQUIT: return "quit";
192 case SIGILL: return "illegal instruction";
196 case SIGTRAP: return "trace trap";
200 case SIGABRT: return "abort";
204 case SIGEMT: return "EMT instruction";
208 case SIGFPE: return "arithmetic exception";
212 case SIGKILL: return "killed";
216 case SIGBUS: return "bus error";
220 case SIGSEGV: return "segmentation fault";
224 case SIGSYS: return "bad system call";
228 case SIGPIPE: return "broken pipe";
232 case SIGALRM: return "alarm";
236 case SIGTERM: return "terminated";
240 case SIGUSR1: return "user signal 1";
244 case SIGUSR2: return "user signal 2";
248 case SIGCHLD: return "child stop or exit";
252 case SIGPWR: return "power fail/restart";
256 case SIGURG: return "urgent condition on I/O channel";
260 case SIGSTOP: return "stop";
264 case SIGTSTP: return "stop from tty";
268 case SIGXCPU: return "exceeded CPU limit";
272 case SIGXFSZ: return "exceeded file size limit";
275 default: return "unrecognized signal number";
278 #endif /* OS_STRSIGNAL */
283 /*************************************************
284 * Provide strexit() for systems without *
285 *************************************************/
287 /* Actually, I don't know of any system that has a strexit() function to turn
288 exit codes into text, but this function is implemented this way so that if any
289 OS does have such a thing, it could be used instead of this build-in one. */
292 os_strexit(const int n)
296 /* On systems without sysexits.h we can assume only those exit codes
297 that are given a default value in exim.h. */
300 case EX_USAGE: return "(could mean usage or syntax error)";
301 case EX_DATAERR: return "(could mean error in input data)";
302 case EX_NOINPUT: return "(could mean input data missing)";
303 case EX_NOUSER: return "(could mean user nonexistent)";
304 case EX_NOHOST: return "(could mean host nonexistent)";
305 case EX_SOFTWARE: return "(could mean internal software error)";
306 case EX_OSERR: return "(could mean internal operating system error)";
307 case EX_OSFILE: return "(could mean system file missing)";
308 case EX_IOERR: return "(could mean input/output error)";
309 case EX_PROTOCOL: return "(could mean protocol error)";
310 case EX_NOPERM: return "(could mean permission denied)";
313 case EX_EXECFAILED: return "(could mean unable to exec or command does not exist)";
314 case EX_UNAVAILABLE: return "(could mean service or program unavailable)";
315 case EX_CANTCREAT: return "(could mean can't create output file)";
316 case EX_TEMPFAIL: return "(could mean temporary error)";
317 case EX_CONFIG: return "(could mean configuration error)";
321 #endif /* OS_STREXIT */
326 /***********************************************************
327 * Load average function *
328 ***********************************************************/
330 /* Although every Unix seems to have a different way of getting the load
331 average, a number of them have things in common. Some common variants are
332 provided below, but if an OS has unique requirements it can be handled in
333 a specific os.c file. What is required is a function called os_getloadavg
334 which takes no arguments and passes back the load average * 1000 as an int,
335 or -1 if no data is available. */
338 /* ----------------------------------------------------------------------- */
339 /* If the OS has got a BSD getloadavg() function, life is very easy. */
341 #if !defined(OS_LOAD_AVERAGE) && defined(HAVE_BSD_GETLOADAVG)
342 #define OS_LOAD_AVERAGE
348 int loads = getloadavg (&avg, 1);
349 if (loads != 1) return -1;
350 return (int)(avg * 1000.0);
353 /* ----------------------------------------------------------------------- */
357 /* ----------------------------------------------------------------------- */
358 /* Only SunOS5 has the kstat functions as far as I know, but put the code
359 here as there is the -hal variant, and other systems might follow this road one
362 #if !defined(OS_LOAD_AVERAGE) && defined(HAVE_KSTAT)
363 #define OS_LOAD_AVERAGE
375 if ((kc = kstat_open()) == NULL ||
376 (ksp = kstat_lookup(kc, LOAD_AVG_KSTAT_MODULE, 0, LOAD_AVG_KSTAT))
378 kstat_read(kc, ksp, NULL) < 0 ||
379 (kn = kstat_data_lookup(ksp, LOAD_AVG_SYMBOL)) == NULL)
382 avg = (int)(((double)(kn->LOAD_AVG_FIELD)/FSCALE) * 1000.0);
389 /* ----------------------------------------------------------------------- */
393 /* ----------------------------------------------------------------------- */
394 /* Handle OS where a kernel symbol has to be read from /dev/kmem */
396 #if !defined(OS_LOAD_AVERAGE) && defined(HAVE_DEV_KMEM)
397 #define OS_LOAD_AVERAGE
401 static int avg_kd = -1;
402 static long avg_offset;
412 nl[0].n_name = LOAD_AVG_SYMBOL;
414 nlist (KERNEL_PATH, nl);
415 avg_offset = (long)nl[0].n_value;
416 avg_kd = open ("/dev/kmem", 0);
417 if (avg_kd < 0) return -1;
418 (void) fcntl(avg_kd, F_SETFD, FD_CLOEXEC);
421 if (lseek (avg_kd, avg_offset, 0) == -1L
422 || read (avg_kd, CS (&avg), sizeof (avg)) != sizeof(avg))
425 return (int)(((double)avg/FSCALE)*1000.0);
429 /* ----------------------------------------------------------------------- */
433 /* ----------------------------------------------------------------------- */
434 /* If nothing is known about this OS, then the load average facility is
437 #ifndef OS_LOAD_AVERAGE
447 /* ----------------------------------------------------------------------- */
451 #if !defined FIND_RUNNING_INTERFACES
452 /*************************************************
453 * Find all the running network interfaces *
454 *************************************************/
456 /* Finding all the running interfaces is something that has os-dependent
457 tweaks, even in the IPv4 case, and it gets worse for IPv6, which is why this
458 code is now in the os-dependent source file. There is a common function which
459 works on most OS (except IRIX) for IPv4 interfaces, and, with some variations
460 controlled by macros, on at least one OS for IPv6 and IPv4 interfaces. On Linux
461 with IPv6, the common function is used for the IPv4 interfaces and additional
462 code used for IPv6. Consequently, the real function is called
463 os_common_find_running_interfaces() so that it can be called from the Linux
464 function. On non-Linux systems, the macro for os_find_running_interfaces just
465 calls the common function; on Linux it calls the Linux function.
467 This function finds the addresses of all the running interfaces on the machine.
468 A chain of blocks containing the textual form of the addresses is returned.
470 getifaddrs() provides a sane consistent way to query this on modern OSs,
471 otherwise fall back to a maze of twisty ioctl() calls
474 Returns: a chain of ip_address_items, each pointing to a textual
475 version of an IP address, with the port field set to zero
479 #ifndef NO_FIND_INTERFACES
481 #ifdef HAVE_GETIFADDRS
486 os_common_find_running_interfaces(void)
488 struct ifaddrs *ifalist = NULL;
489 ip_address_item *yield = NULL;
490 ip_address_item *last = NULL;
491 ip_address_item *next;
493 if (getifaddrs(&ifalist) != 0)
494 log_write(0, LOG_PANIC_DIE, "Unable to call getifaddrs: %d %s",
495 errno, strerror(errno));
497 for (struct ifaddrs * ifa = ifalist; ifa; ifa = ifa->ifa_next)
499 struct sockaddr * ifa_addr = ifa->ifa_addr;
500 if (!ifa_addr) continue;
501 if (ifa_addr->sa_family != AF_INET
503 && ifa_addr->sa_family != AF_INET6
504 #endif /* HAVE_IPV6 */
508 if ( !(ifa->ifa_flags & IFF_UP) ) /* Only want 'UP' interfaces */
511 /* Create a data block for the address, fill in the data, and put it on the
514 next = store_get(sizeof(ip_address_item), GET_UNTAINTED);
517 (void)host_ntoa(-1, ifa_addr, next->address, NULL);
527 DEBUG(D_interface) debug_printf("Actual local interface address is %s (%s)\n",
528 last->address, ifa->ifa_name);
531 /* free the list of addresses, and return the chain of data blocks. */
533 freeifaddrs (ifalist);
537 #else /* HAVE_GETIFADDRS */
542 (1) Solaris 2 has the SIOGIFNUM call to get the number of interfaces, but
543 other OS (including Solaris 1) appear not to. So just screw in a largeish
544 fixed number, defined by MAX_INTERFACES. This is in the config.h file and
545 can be changed in Local/Makefile. Unfortunately, the www addressing scheme
546 means that some hosts have a very large number of virtual interfaces. Such
547 hosts are recommended to set local_interfaces to avoid problems with this.
549 (2) If the standard code is run on IRIX, it does not return any alias
550 interfaces. There is special purpose code for that operating system, which
551 uses the sysctl() function. The code is in OS/os.c-IRIX, and this code isn't
554 (3) Some experimental/developing OS (e.g. GNU/Hurd) do not have any means
555 of finding the interfaces. If NO_FIND_INTERFACES is set, a fudge-up is used
558 (4) Some operating systems set the IP address in what SIOCGIFCONF returns;
559 others do not, and require SIOCGIFADDR to be called to get it. For most of
560 the former, calling the latter does no harm, but it causes grief on Linux and
561 BSD systems in the case of IP aliasing, so a means of cutting it out is
565 /* If there is IPv6 support, and SIOCGLIFCONF is defined, define macros to
566 use these new, longer versions of the old IPv4 interfaces. Otherwise, define
567 the macros to use the historical versions. */
569 #if HAVE_IPV6 && defined SIOCGLIFCONF
570 #define V_ifconf lifconf
571 #define V_ifreq lifreq
572 #define V_GIFADDR SIOCGLIFADDR
573 #define V_GIFCONF SIOCGLIFCONF
574 #define V_GIFFLAGS SIOCGLIFFLAGS
575 #define V_ifc_buf lifc_buf
576 #define V_ifc_family lifc_family
577 #define V_ifc_flags lifc_flags
578 #define V_ifc_len lifc_len
579 #define V_ifr_addr lifr_addr
580 #define V_ifr_flags lifr_flags
581 #define V_ifr_name lifr_name
582 #define V_FAMILY_QUERY AF_UNSPEC
583 #define V_family ss_family
585 #define V_ifconf ifconf
586 #define V_ifreq ifreq
587 #define V_GIFADDR SIOCGIFADDR
588 #define V_GIFCONF SIOCGIFCONF
589 #define V_GIFFLAGS SIOCGIFFLAGS
590 #define V_ifc_buf ifc_buf
591 #define V_ifc_family ifc_family
592 #define V_ifc_flags ifc_flags
593 #define V_ifc_len ifc_len
594 #define V_ifr_addr ifr_addr
595 #define V_ifr_flags ifr_flags
596 #define V_ifr_name ifr_name
597 #define V_family sa_family
600 /* In all cases of IPv6 support, use an IPv6 socket. Otherwise (at least on
601 Solaris 8) the call to read the flags doesn't work for IPv6 interfaces. If
602 we find we can't actually make an IPv6 socket, the code will revert to trying
606 #define FAMILY AF_INET6
608 #define FAMILY AF_INET
611 /* OK, after all that preliminary stuff, here's the code. */
614 os_common_find_running_interfaces(void)
617 struct V_ifreq ifreq;
619 ip_address_item *yield = NULL;
620 ip_address_item *last = NULL;
621 ip_address_item *next;
622 char buf[MAX_INTERFACES*sizeof(struct V_ifreq)];
623 struct sockaddr *addrp;
627 /* We have to create a socket in order to do ioctls on it to find out
628 what we want to know. */
630 if ((vs = socket(FAMILY, SOCK_DGRAM, 0)) < 0)
634 debug_printf("Unable to create IPv6 socket to find interface addresses:\n "
635 "error %d %s\nTrying for an IPv4 socket\n", errno, strerror(errno));
636 vs = socket(AF_INET, SOCK_DGRAM, 0);
639 log_write(0, LOG_PANIC_DIE, "Unable to create IPv4 socket to find interface "
640 "addresses: %d %s", errno, strerror(errno));
643 /* Get the interface configuration. Some additional data is required when the
644 new structures are in use. */
646 ifc.V_ifc_len = sizeof(buf);
649 #ifdef V_FAMILY_QUERY
650 ifc.V_ifc_family = V_FAMILY_QUERY;
654 if (ioctl(vs, V_GIFCONF, CS &ifc) < 0)
655 log_write(0, LOG_PANIC_DIE, "Unable to get interface configuration: %d %s",
656 errno, strerror(errno));
658 /* If the buffer is big enough, the ioctl sets the value of ifc.V_ifc_len to
659 the amount actually used. If the buffer isn't big enough, at least on some
660 operating systems, ifc.V_ifc_len still gets set to correspond to the total
661 number of interfaces, even though they don't all fit in the buffer. */
663 if (ifc.V_ifc_len > sizeof(buf))
665 ifc.V_ifc_len = sizeof(buf);
667 debug_printf("more than %d interfaces found: remainder not used\n"
668 "(set MAX_INTERFACES in Local/Makefile and rebuild if you want more)\n",
672 /* For each interface, check it is an IP interface, get its flags, and see if
673 it is up; if not, skip.
675 BSD systems differ from others in what SIOCGIFCONF returns. Other systems
676 return a vector of ifreq structures whose size is as defined by the structure.
677 BSD systems allow sockaddrs to be longer than their sizeof, which in turn makes
678 the ifreq structures longer than their sizeof. The code below has its origins
679 in amd and ifconfig; it uses the sa_len field of each sockaddr to determine
682 This is complicated by the fact that, at least on BSD systems, the data in the
683 buffer is not guaranteed to be aligned. Thus, we must first copy the basic
684 struct to some aligned memory before looking at the field in the fixed part to
685 find its length, and then recopy the correct length. */
687 for (char * cp = buf; cp < buf + ifc.V_ifc_len; cp += len)
689 memcpy(CS &ifreq, cp, sizeof(ifreq));
692 len = sizeof(struct V_ifreq);
695 len = ((ifreq.ifr_addr.sa_len > sizeof(ifreq.ifr_addr))?
696 ifreq.ifr_addr.sa_len : sizeof(ifreq.ifr_addr)) +
697 sizeof(ifreq.V_ifr_name);
698 if (len > sizeof(addrbuf))
699 log_write(0, LOG_PANIC_DIE, "Address for %s interface is absurdly long",
704 /* If not an IP interface, skip */
706 if (ifreq.V_ifr_addr.V_family != AF_INET
708 && ifreq.V_ifr_addr.V_family != AF_INET6
712 /* Get the interface flags, and if the interface is down, continue. Formerly,
713 we treated the inability to get the flags as a panic-die error. However, it
714 seems that on some OS (Solaris 9 being the case noted), it is possible to
715 have an interface in this list for which this call fails because the
716 interface hasn't been "plumbed" to any protocol (IPv4 or IPv6). Therefore,
717 we now just treat this case as "down" as well. */
719 if (ioctl(vs, V_GIFFLAGS, CS &ifreq) < 0)
723 log_write(0, LOG_PANIC_DIE, "Unable to get flags for %s interface: %d %s",
724 ifreq.V_ifr_name, errno, strerror(errno));
727 if ((ifreq.V_ifr_flags & IFF_UP) == 0) continue;
729 /* On some operating systems we have to get the IP address of the interface
730 by another call. On others, it's already there, but we must copy the full
731 length because we only copied the basic length above, and anyway,
732 GIFFLAGS may have wrecked the data. */
734 #ifndef SIOCGIFCONF_GIVES_ADDR
735 if (ioctl(vs, V_GIFADDR, CS &ifreq) < 0)
736 log_write(0, LOG_PANIC_DIE, "Unable to get IP address for %s interface: "
737 "%d %s", ifreq.V_ifr_name, errno, strerror(errno));
738 addrp = &ifreq.V_ifr_addr;
741 memcpy(addrbuf, cp + offsetof(struct V_ifreq, V_ifr_addr),
742 len - sizeof(ifreq.V_ifr_name));
743 addrp = (struct sockaddr *)addrbuf;
746 /* Create a data block for the address, fill in the data, and put it on the
749 next = store_get(sizeof(ip_address_item), GET_UNTAINTED);
752 (void)host_ntoa(-1, addrp, next->address, NULL);
754 if (yield == NULL) yield = last = next; else
760 DEBUG(D_interface) debug_printf("Actual local interface address is %s (%s)\n",
761 last->address, ifreq.V_ifr_name);
764 /* Close the socket, and return the chain of data blocks. */
770 #endif /* HAVE_GETIFADDRS */
772 #else /* NO_FIND_INTERFACES */
774 /* Some experimental or developing OS (e.g. GNU/Hurd) do not have the ioctls,
775 and there is no other way to get a list of the (IP addresses of) local
776 interfaces. We just return the loopback address(es). */
779 os_common_find_running_interfaces(void)
781 ip_address_item *yield = store_get(sizeof(address_item), GET_UNTAINTED);
782 yield->address = US"127.0.0.1";
787 yield->next = store_get(sizeof(address_item), GET_UNTAINTED);
788 yield->next->address = US"::1";
789 yield->next->port = 0;
790 yield->next->next = NULL;
793 DEBUG(D_interface) debug_printf("Unable to find local interface addresses "
794 "on this OS: returning loopback address(es)\n");
798 #endif /* NO_FIND_INTERFACES */
799 #endif /* FIND_RUNNING_INTERFACES */
804 /* ----------------------------------------------------------------------- */
806 /***********************************************************
807 * DNS Resolver Base Finder *
808 ***********************************************************/
810 /* We need to be able to set options for the system resolver(5), historically
811 made available as _res. At least one OS (NetBSD) now no longer provides this
812 directly, instead making you call a function per thread to get a handle.
813 Other OSs handle thread-safe resolver differently, in ways which fail if the
814 programmer creates their own structs. */
816 #if !defined(OS_GET_DNS_RESOLVER_RES) && !defined(COMPILE_UTILITY)
820 /* confirmed that res_state is typedef'd as a struct* on BSD and Linux, will
821 find out how unportable it is on other OSes, but most resolver implementations
822 should be descended from ISC's bind.
825 define _res (*__res_state())
826 identically. We just can't rely on __foo functions. It's surprising that use
827 of _res has been as portable as it has, for so long.
829 So, since _res works everywhere, and everything can decode the struct, I'm
830 going to gamble that res_state is a typedef everywhere and use that as the
835 os_get_dns_resolver_res(void)
840 #endif /* OS_GET_DNS_RESOLVER_RES */
842 /* ----------------------------------------------------------------------- */
844 /***********************************************************
846 ***********************************************************/
848 /* Most modern systems define int unsetenv(const char*),
851 #if !defined(OS_UNSETENV)
853 os_unsetenv(const unsigned char * name)
855 return unsetenv(CS name);
859 /* ----------------------------------------------------------------------- */
861 /***********************************************************
863 ***********************************************************/
865 /* Glibc allows getcwd(NULL, 0) to do auto-allocation. Some systems
866 do auto-allocation, but need the size of the buffer, and others
867 may not even do this. If the OS supports getcwd(NULL, 0) we'll use
868 this, for all other systems we provide our own getcwd() */
870 #if !defined(OS_GETCWD)
872 os_getcwd(unsigned char * buffer, size_t size)
874 return US getcwd(CS buffer, size);
878 # define PATH_MAX 4096
881 os_getcwd(unsigned char * buffer, size_t size)
883 char * b = CS buffer;
885 if (!size) size = PATH_MAX;
886 if (!b && !(b = malloc(size))) return NULL;
887 if (!(b = getcwd(b, size))) return NULL;
888 return buffer ? buffer : realloc(b, strlen(b) + 1);
892 /* ----------------------------------------------------------------------- */
897 /*************************************************
898 **************************************************
899 * Stand-alone test program *
900 **************************************************
901 *************************************************/
906 #ifdef CLOCKS_PER_SEC
907 #define REAL_CLOCK_TICK CLOCKS_PER_SEC
910 #define REAL_CLOCK_TICK CLK_TCK
912 #define REAL_CLOCK_TICK 1000000 /* SunOS4 */
917 int main(int argc, char **argv)
920 int fd = fileno(stdin);
923 printf("Testing restarting signal; wait for handler message, then type a line\n");
924 strcpy(buffer, "*** default ***\n");
925 os_restarting_signal(SIGALRM, sigalrm_handler);
927 if ((rc = read(fd, buffer, sizeof(buffer))) < 0)
928 printf("No data read\n");
932 printf("Read: %s", buffer);
936 printf("Testing non-restarting signal; should read no data after handler message\n");
937 strcpy(buffer, "*** default ***\n");
938 os_non_restarting_signal(SIGALRM, sigalrm_handler);
940 if ((rc = read(fd, buffer, sizeof(buffer))) < 0)
941 printf("No data read\n");
945 printf("Read: %s", buffer);
949 printf("Testing load averages (last test - ^C to kill)\n");
954 clock_t before = clock();
955 avg = os_getloadavg();
956 used = clock() - before;
957 printf("cpu time = %.2f ", (double)used/REAL_CLOCK_TICK);
960 printf("load average not available\n");
963 printf("load average = %.2f\n", (double)avg/1000.0);