diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2015-04-09 14:30:35 +0200 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2015-04-09 14:30:35 +0200 |
commit | bcd0e950a774338237f666894e625201973bee34 (patch) | |
tree | ba55dd105690bdaa864604b01e1eaf52cf8dc1fe /src/cli.c | |
parent | b36d9c7c9044f0252a38c401877e8ea29d49da03 (diff) | |
download | biruda-bcd0e950a774338237f666894e625201973bee34.tar.gz biruda-bcd0e950a774338237f666894e625201973bee34.tar.bz2 |
added printing of environment
Diffstat (limited to 'src/cli.c')
-rw-r--r-- | src/cli.c | 41 |
1 files changed, 40 insertions, 1 deletions
@@ -13,6 +13,7 @@ int start_interactive( bool colors, const char *host, unsigned short port, FILE #include <stdarg.h> #include "linenoise.h" #include "http_lib.h" +#include "json-c/json.h" #include <stdlib.h> #include <string.h> @@ -22,7 +23,7 @@ int start_interactive( bool colors, const char *host, unsigned short port, FILE #include "coordinator.h" #include "worker.h" - +#include "system.h" typedef enum { COMMAND, // command parsing START_WORKER, // worker command expecting a worker parameter @@ -382,3 +383,41 @@ int start_interactive( bool colors, const char *host, unsigned short port, FILE } #endif + +void print_guessed_env( bool human_readable ) +{ + char hostname[100]; + gethostname( hostname, sizeof( hostname ) ); + unsigned int nofCpus = system_available_cpus( ); + char os_name[100]; + system_os( os_name, sizeof( os_name ) ); + char machine_arch[100]; + system_arch( machine_arch, sizeof( machine_arch ) ); + + if( human_readable) { + printf( "Architecture: %s\n", machine_arch ); + printf( "Operating system: %s\n", os_name ); + printf( "Hostname: %s\n", hostname ); + printf( "Number of CPUs: %d\n", nofCpus ); + } else { + json_object *obj = json_object_new_object( ); + + json_object *arch = json_object_new_string( machine_arch ); + json_object_object_add( obj, "arch", arch ); + json_object *os = json_object_new_string( os_name ); + json_object_object_add( obj, "os", os ); + json_object *host = json_object_new_string( hostname ); + json_object_object_add( obj, "host", host ); + json_object *cpus = json_object_new_int( nofCpus ); + json_object_object_add( obj, "cpus", cpus ); + + const char *msg = json_object_to_json_string( obj ); + char *res = strdup( msg ); + + puts( res ); + + free( res ); + json_object_put( obj ); + } +} + |