summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODOS3
-rw-r--r--src/GNUmakefile3
-rw-r--r--src/biruda.conf7
-rw-r--r--src/system.c29
4 files changed, 30 insertions, 12 deletions
diff --git a/TODOS b/TODOS
index 087efc5..a38bc85 100644
--- a/TODOS
+++ b/TODOS
@@ -13,4 +13,5 @@ http://xmodulo.com/alternatives-skype-linux.html
-which embedded web server
microhttpd (GNU) or swill
-
+- platform/compiler macros
+http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_system
diff --git a/src/GNUmakefile b/src/GNUmakefile
index f6db48e..5e531c8 100644
--- a/src/GNUmakefile
+++ b/src/GNUmakefile
@@ -3,7 +3,8 @@
all: biruda
CFLAGS = -g -std=c99 -Wall -pedantic -D_XOPEN_SOURCE=600
-LDFLAGS =
+CFLAGS += -I/usr/local/include
+LDFLAGS = -L/usr/local/lib
LIBS = -lconfuse -lpthread -lnanomsg -ljson-c -lmicrohttpd
%.o : %.c
diff --git a/src/biruda.conf b/src/biruda.conf
index 51da929..df78a0f 100644
--- a/src/biruda.conf
+++ b/src/biruda.conf
@@ -27,10 +27,3 @@ worker worker2
# control = "inproc://control"
control = "tcp://localhost:5555"
}
-
-webserver
-{
- threads = 4
- host = localhost
- port = 8080
-}
diff --git a/src/system.c b/src/system.c
index 7ce5f83..5a62242 100644
--- a/src/system.c
+++ b/src/system.c
@@ -6,9 +6,15 @@
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#else
+#ifdef __FreeBSD__
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <sys/utsname.h>
+#else /* __FreeBSD__ */
#include <unistd.h>
#include <sys/utsname.h>
-#endif
+#endif /* __FreeBSD__ */
+#endif /* _WIN32 */
#include <stdio.h>
#include <string.h>
@@ -16,11 +22,27 @@
unsigned int system_available_cpus( void )
{
+ // operating specific cases
#ifdef _WIN32
SYSTEM_INFO info;
GetSystemInfo( &info );
return info.dwNumberOfProcessors;
#else
+#ifdef __FreeBSD__
+ int req[2];
+ req[0] = CTL_HW;
+ req[1] = HW_NCPU;
+ int nprocs;
+ size_t len = sizeof( nprocs );
+ if( sysctl( req, 2, &nprocs, &len, NULL, 0 ) < 0 ) {
+ // assuming one CPU in case of error
+ // (safe fallback)
+ return 1;
+ }
+ return nprocs;
+#else // __FreeBSD__
+
+ // generic POSIX case
#ifdef _SC_NPROCESSORS_ONLN
long nprocs = sysconf( _SC_NPROCESSORS_ONLN );
if( nprocs < -1 ) {
@@ -31,8 +53,9 @@ unsigned int system_available_cpus( void )
return nprocs;
#else
#error No _SC_NPROCESSORS_ONLN, must port first!
-#endif
-#endif
+#endif // _SC_NPROCESSORS_ONLN
+#endif // __FreeBSD__
+#endif // _WIN32
}
void system_os( char *name, size_t len )