From bcd0e950a774338237f666894e625201973bee34 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Thu, 9 Apr 2015 14:30:35 +0200 Subject: added printing of environment --- src/biruda.c | 7 ++++++- src/biruda.ggo | 7 +++++++ src/cli.c | 41 ++++++++++++++++++++++++++++++++++++++++- src/cli.h | 6 ++++++ 4 files changed, 59 insertions(+), 2 deletions(-) diff --git a/src/biruda.c b/src/biruda.c index 7c0f1b4..788bc13 100644 --- a/src/biruda.c +++ b/src/biruda.c @@ -335,10 +335,15 @@ int main( int argc, char *argv[] ) { struct gengetopt_args_info args_info; cfg_t *cfg = NULL; - + if( parse_options_and_arguments( argc, argv, &args_info ) ) { exit( EXIT_FAILURE ); } + + if( args_info.guess_env_given ) { + print_guessed_env( args_info.human_readable_given ); + exit( EXIT_SUCCESS ); + } if( !( args_info.cli_given || args_info.filename_given ) || args_info.config_file_given ) { if( read_config( args_info.config_file_given ? diff --git a/src/biruda.ggo b/src/biruda.ggo index 9b2fdc6..7df88ba 100644 --- a/src/biruda.ggo +++ b/src/biruda.ggo @@ -56,4 +56,11 @@ section "Command Line Interface" "filename to read commands from and execute them" string typestr="filename" optional + + option "human-readable" - + "try to display output in for humans and not for computers" + optional + option "guess-env" - + "guess environment (used also internally)" + optional diff --git a/src/cli.c b/src/cli.c index 194abd1..66bc5b6 100644 --- a/src/cli.c +++ b/src/cli.c @@ -13,6 +13,7 @@ int start_interactive( bool colors, const char *host, unsigned short port, FILE #include #include "linenoise.h" #include "http_lib.h" +#include "json-c/json.h" #include #include @@ -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 ); + } +} + diff --git a/src/cli.h b/src/cli.h index 4c1d48f..e6ac44c 100644 --- a/src/cli.h +++ b/src/cli.h @@ -5,6 +5,12 @@ #include +#ifdef _WIN32 + int start_interactive( bool colors, const char *host, unsigned short port, FILE *in ); #endif + +#endif + +void print_guessed_env( bool human_readable ); -- cgit v1.2.3-54-g00ecf