From 9a829841eb49e3d773111ba58a4239a61e3dd2a4 Mon Sep 17 00:00:00 2001 From: "Bruce A. Mah" Date: Thu, 30 Jan 2014 15:15:53 -0800 Subject: [PATCH] Replace system("uname -a") with call to uname(3). Slightly reworked version of a patch that was... Submitted by: Susant Sahani --- src/iperf_api.c | 3 +-- src/iperf_client_api.c | 2 +- src/iperf_server_api.c | 2 +- src/iperf_util.c | 24 +++++++++++++----------- 4 files changed, 16 insertions(+), 15 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 #include #include +#include #include #include @@ -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]; +{ + 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); - fp = popen("uname -a", "r"); - if (fp == NULL) - return NULL; - fgets(buf, sizeof(buf), fp); - pclose(fp); return buf; - } +} /* Helper routine for building cJSON objects in a printf-like manner.