Stuart Henderson <s...@spacehopper.org> writes: >> "Martijn Rijkeboer" <mart...@bunix.org> writes: >> >> > After quite some discussion here's take 4 of the update of >> > sysutils/cfengine. This version is based on Stuart's version which was >> > based on Jiri B's version. > .. >> > Please commit so other people can start testing it. > > Okan, these diffs change MAINTAINER to you but I haven't seen much > activity in the recent list posts, are you still interested in this? > > On 2013/04/25 07:29, Timo Myyrä wrote: >> >> #ifdef LINUX >> @@ -2100,6 +2106,17 @@ const char *GetWorkDir(void) >> >> static void GetCPUInfo() >> { >> +#if defined(__OpenBSD) > > This one should be __OpenBSD__, however it would probably be better > to use sysconf(_SC_NPROCESSORS_CONF) for this if available; it's more > portable and should be easier to feed upstream. sysconf(3) itself is > POSIX; _SC_NPROCESSORS_CONF is not POSIX but is fairly common. > >> + int mib[2], count; >> + size_t len; >> + char buf[CF_BUFSIZE]; >> + >> + mib[0] = CTL_HW; >> + mib[1] = HW_NCPU; >> + len = sizeof(count); >> + if (sysctl(mib, 2, &count, &len, NULL, 0) == -1) >> + err(1, "sysctl"); >> +#else >> FILE *fp; >> char buf[CF_BUFSIZE]; >> int count = 0;
Ok, here's a new patch to use sysconf where able instead of /proc: I used _SC_NPROCESSORS_ONLN to get the actually usable processors. Better? timo $OpenBSD$ --- src/sysinfo.c.orig Fri Mar 15 14:49:36 2013 +++ src/sysinfo.c Fri Apr 26 14:36:23 2013 @@ -36,6 +36,10 @@ # include <zone.h> #endif +#ifdef HAVE_SYSCONF +# include <unistd.h> +#endif + void CalculateDomainName(const char *nodename, const char *dnsname, char *fqname, char *uqname, char *domain); #ifdef LINUX @@ -2100,10 +2104,21 @@ const char *GetWorkDir(void) static void GetCPUInfo() { - FILE *fp; char buf[CF_BUFSIZE]; int count = 0; + +#ifdef HAVE_SYSCONF + count = sysconf(_SC_NPROCESSORS_ONLN); + if (count == -1) { + CfOut(cf_verbose, "", "Unable to get cpu data\n"); + return; + } + +#else + + FILE *fp; + if ((fp = fopen("/proc/stat", "r")) == NULL) { CfOut(cf_verbose, "", "Unable to find proc/cpu data\n"); @@ -2123,6 +2138,8 @@ static void GetCPUInfo() fclose(fp); count--; + +#endif if (count < 1) {