summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <abaumann@yahoo.com>2015-06-11 20:59:00 +0200
committerAndreas Baumann <abaumann@yahoo.com>2015-06-11 20:59:00 +0200
commitc86834d40fa6b07828b10e2c6d8d2c6bd35fe116 (patch)
treeafca67b9f4287e07c12e076a96f359e0210edf6f
parent365d5c59d76831b7ec0d6c3ebe49ef1e3793ac7c (diff)
downloadbiruda-c86834d40fa6b07828b10e2c6d8d2c6bd35fe116.tar.gz
biruda-c86834d40fa6b07828b10e2c6d8d2c6bd35fe116.tar.bz2
replaced gethostname on Windows with GetComputerNameEx
-rw-r--r--src/NMakefile1
-rw-r--r--src/cli.c2
-rw-r--r--src/coordinator.c6
-rw-r--r--src/system.c12
-rw-r--r--src/system.h2
-rw-r--r--src/worker.c2
6 files changed, 20 insertions, 5 deletions
diff --git a/src/NMakefile b/src/NMakefile
index e7fb64a..ede3e98 100644
--- a/src/NMakefile
+++ b/src/NMakefile
@@ -90,4 +90,5 @@ run: all
@-copy "$(GTK3_BUNDLE_DIR)\bin\pthreadGC2.dll" .
@-copy "$(GTK3_BUNDLE_DIR)\bin\gspawn-win32-helper-console.exe .
@-biruda -c biruda.conf -p
+ @-biruda --guess-env --human-readable
diff --git a/src/cli.c b/src/cli.c
index f5bdcd1..3f8f903 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -398,7 +398,7 @@ int start_interactive( bool colors, const char *host, unsigned short port, FILE
void print_guessed_env( bool human_readable )
{
char hostname[100];
- gethostname( hostname, sizeof( hostname ) );
+ system_hostname( hostname, sizeof( hostname ) );
unsigned int nofCpus = system_available_cpus( );
unsigned int nofPhysMem = system_phys_memory( );
char os_name[100];
diff --git a/src/coordinator.c b/src/coordinator.c
index 356a402..c74c822 100644
--- a/src/coordinator.c
+++ b/src/coordinator.c
@@ -42,7 +42,7 @@ static char *create_worker_started_answer( const char *name, bool worker_found )
* or additionally the MAC of the first interface or hostid?)
*/
char hostname[100];
- gethostname( hostname, sizeof( hostname ) );
+ system_hostname( hostname, sizeof( hostname ) );
json_object *host = json_object_new_string( hostname );
json_object_object_add( obj, "host", host );
@@ -75,7 +75,7 @@ static char *create_worker_stopped_answer( const char *name, bool worker_found )
* or additionally the MAC of the first interface or hostid?)
*/
char hostname[100];
- gethostname( hostname, sizeof( hostname ) );
+ system_hostname( hostname, sizeof( hostname ) );
json_object *host = json_object_new_string( hostname );
json_object_object_add( obj, "host", host );
@@ -108,7 +108,7 @@ static char *create_register_answer( )
* or additionally the MAC of the first interface or hostid?)
*/
char hostname[100];
- gethostname( hostname, sizeof( hostname ) );
+ system_hostname( hostname, sizeof( hostname ) );
json_object *host = json_object_new_string( hostname );
json_object_object_add( obj, "host", host );
diff --git a/src/system.c b/src/system.c
index 766e264..7d2e052 100644
--- a/src/system.c
+++ b/src/system.c
@@ -20,6 +20,7 @@
#ifdef __NetBSD__
#include <unistd.h>
#else /* __NetBSD__ */
+#include <unistd.h>
#endif /* __NetBSD__ */
#endif /* __FreeBSD__ */
#endif /* _WIN32 */
@@ -391,6 +392,17 @@ void system_arch( char *name, size_t len )
#endif
}
+int system_hostname( char *name, size_t len )
+{
+#ifdef _WIN32
+ DWORD dwSize = len;
+ int res = GetComputerNameExA( ComputerNamePhysicalDnsFullyQualified, name, &dwSize );
+ return ( res > 0 ) ? 0 : -1;
+#else
+ return gethostname( name, len );
+#endif
+}
+
unsigned int system_phys_memory( )
{
#ifdef _WIN32
diff --git a/src/system.h b/src/system.h
index 3ff2ebb..dee8669 100644
--- a/src/system.h
+++ b/src/system.h
@@ -9,6 +9,8 @@ void system_os( char *name, size_t len );
void system_arch( char *name, size_t len );
+int system_hostname( char *name, size_t len );
+
/* in kilobytes */
unsigned int system_phys_memory( );
diff --git a/src/worker.c b/src/worker.c
index 4360432..733718c 100644
--- a/src/worker.c
+++ b/src/worker.c
@@ -335,7 +335,7 @@ static char *expand_system_variables( const char *s )
state = COPYING;
} else if( strncmp( var, "HOST", 4 ) == 0 ) {
char hostname[100];
- gethostname( hostname, sizeof( hostname ) );
+ system_hostname( hostname, sizeof( hostname ) );
strncpy( d, hostname, strlen( hostname ) );
d += strlen( hostname );
state = COPYING;