summaryrefslogtreecommitdiff
path: root/src/cli.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cli.c')
-rw-r--r--src/cli.c41
1 files changed, 40 insertions, 1 deletions
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 <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 );
+ }
+}
+