aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruce A. Mah <bmah@es.net>2014-01-30 15:15:53 -0800
committerBruce A. Mah <bmah@es.net>2014-01-30 15:15:53 -0800
commit9a829841eb49e3d773111ba58a4239a61e3dd2a4 (patch)
treee1a1b625cc670ace3c440738bde98380ab132141 /src
parent441d8b75a0c8f3ab3b95c88376ff153a5a569d99 (diff)
downloadiperf3-9a829841eb49e3d773111ba58a4239a61e3dd2a4.tar.gz
Replace system("uname -a") with call to uname(3).
Slightly reworked version of a patch that was... Submitted by: Susant Sahani <ssahani@redhat.com>
Diffstat (limited to 'src')
-rw-r--r--src/iperf_api.c3
-rw-r--r--src/iperf_client_api.c2
-rw-r--r--src/iperf_server_api.c2
-rw-r--r--src/iperf_util.c26
4 files changed, 17 insertions, 16 deletions
diff --git a/src/iperf_api.c b/src/iperf_api.c
index 47b011a..193916f 100644
--- a/src/iperf_api.c
+++ b/src/iperf_api.c
@@ -588,8 +588,7 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
test->json_output = 1;
break;
case 'v':
- printf("%s\n", version);
- system("uname -a");
+ printf("%s\n%s\n", version, get_system_info());
exit(0);
case 's':
if (test->role == 'c') {
diff --git a/src/iperf_client_api.c b/src/iperf_client_api.c
index 1e72c42..0e0f1ad 100644
--- a/src/iperf_client_api.c
+++ b/src/iperf_client_api.c
@@ -356,7 +356,7 @@ iperf_run_client(struct iperf_test * test)
iprintf(test, "%s\n", version);
iprintf(test, "%s", "");
fflush(stdout);
- system("uname -a");
+ printf("%s\n", get_system_info());
}
/* Start the client and connect to the server */
diff --git a/src/iperf_server_api.c b/src/iperf_server_api.c
index d52efce..b21e042 100644
--- a/src/iperf_server_api.c
+++ b/src/iperf_server_api.c
@@ -450,7 +450,7 @@ iperf_run_server(struct iperf_test *test)
iprintf(test, "%s\n", version);
iprintf(test, "%s", "");
fflush(stdout);
- system("uname -a");
+ printf("%s\n", get_system_info());
}
// Open socket and listen
diff --git a/src/iperf_util.c b/src/iperf_util.c
index 93c6cb1..5a04cda 100644
--- a/src/iperf_util.c
+++ b/src/iperf_util.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009-2011, The Regents of the University of California,
+ * Copyright (c) 2009-2014, The Regents of the University of California,
* through Lawrence Berkeley National Laboratory (subject to receipt of any
* required approvals from the U.S. Dept. of Energy). All rights reserved.
*
@@ -22,6 +22,7 @@
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
+#include <sys/utsname.h>
#include <time.h>
#include <errno.h>
@@ -193,19 +194,20 @@ cpu_util(double pcpu[3])
pcpu[2] = (systemdiff / timediff) * 100;
}
-char*
+char *
get_system_info(void)
- {
- FILE* fp;
- static char buf[1000];
-
- fp = popen("uname -a", "r");
- if (fp == NULL)
- return NULL;
- fgets(buf, sizeof(buf), fp);
- pclose(fp);
+{
+ static char buf[1024];
+ struct utsname uts;
+
+ memset(buf, 0, 1024);
+ uname(&uts);
+
+ snprintf(buf, sizeof(buf), "%s %s %s %s %s", uts.sysname, uts.nodename,
+ uts.release, uts.version, uts.machine);
+
return buf;
- }
+}
/* Helper routine for building cJSON objects in a printf-like manner.