From 608a68fba0caee7cb803c034957830d980a870c7 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Tue, 16 Jun 2015 20:35:24 +0200 Subject: started a small worker helper named 'birudaenv' doing a environemnt guessing and the executing it's arguments (something docker does). Will do a lot more in the future. --- .gitignore | 1 + src/GNUmakefile | 7 +++++-- src/birudaenv.c | 36 ++++++++++++++++++++++++++++++++++++ src/system.c | 1 - 4 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 src/birudaenv.c diff --git a/.gitignore b/.gitignore index fd61823..8a78253 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ src/biruda +src/birudaenv src/workertest src/3rdParty/xxd/xxd *.o diff --git a/src/GNUmakefile b/src/GNUmakefile index aefb70c..bec27f0 100644 --- a/src/GNUmakefile +++ b/src/GNUmakefile @@ -1,6 +1,6 @@ .PHONY: all clean install test -all: 3rdParty/xxd/xxd biruda workertest +all: 3rdParty/xxd/xxd biruda birudaenv workertest # gcc/clang CFLAGS = -g -O0 -std=c99 -Wall -pedantic -D_XOPEN_SOURCE=600 -D_DEFAULT_SOURCE @@ -25,6 +25,9 @@ LIBS += `pkg-config --libs-only-l glib-2.0` biruda: biruda.o biruda_cmdline.o master.o coordinator.o worker.o system.o webserver.o 3rdParty/linenoise/linenoise.o 3rdParty/http_tiny/http_lib.o cli.o $(CC) -o $@ $(LDFLAGS) $^ $(LIBS) +birudaenv: birudaenv.c system.c + $(CC) -static -o $@ $^ + biruda_cmdline.o: biruda_cmdline.c biruda.o: biruda.c biruda_cmdline.h master.h coordinator.h worker.h port.h system.h webserver.h 3rdParty/linenoise/linenoise.h cli.h biruda_conf.c master.o: master.c master.h port.h @@ -53,7 +56,7 @@ biruda_conf.c: biruda.conf 3rdParty/xxd/xxd clean: @-rm *.o - @-rm biruda + @-rm biruda birudaenv @-rm biruda_cmdline.[ch] @-rm workertest @-rm 3rdParty/http_tiny/*.o diff --git a/src/birudaenv.c b/src/birudaenv.c new file mode 100644 index 0000000..1fafd41 --- /dev/null +++ b/src/birudaenv.c @@ -0,0 +1,36 @@ +#include +#include +#include + +#include "system.h" + +int main( int argc, char *argv[] ) +{ + char hostname[100]; + system_hostname( hostname, sizeof( hostname ) ); + unsigned int nofCpus = system_available_cpus( ); + unsigned int nofPhysMem = system_phys_memory( ); + char os_name[100]; + system_os( os_name, sizeof( os_name ) ); + char machine_arch[100]; + system_arch( machine_arch, sizeof( machine_arch ) ); + + printf( + "{ " + "\"arch\": \"%s\", " + "\"os\": \"%s\", " + "\"host\": \"%s\", " + "\"cpus\": %d, " + "\"physical_memory\": %d " + "}\n", + machine_arch, + os_name, + hostname, + nofCpus, + nofPhysMem + ); + + execvp( argv[1], &argv[1] ); + + exit( EXIT_SUCCESS ); +} diff --git a/src/system.c b/src/system.c index 7d2e052..bd3df98 100644 --- a/src/system.c +++ b/src/system.c @@ -350,7 +350,6 @@ void system_os( char *name, size_t len ) fclose( f ) ; - #elif defined( __FreeBSD__ ) || defined( __NetBSD__ ) /* resort to uname */ struct utsname uts; -- cgit v1.2.3-54-g00ecf