Replace system("uname -a") with call to uname(3).

Slightly reworked version of a patch that was...

Submitted by:	Susant Sahani <ssahani@redhat.com>
This commit is contained in:
Bruce A. Mah 2014-01-30 15:15:53 -08:00
parent 441d8b75a0
commit 9a829841eb
4 changed files with 16 additions and 15 deletions

View File

@ -588,8 +588,7 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
test->json_output = 1; test->json_output = 1;
break; break;
case 'v': case 'v':
printf("%s\n", version); printf("%s\n%s\n", version, get_system_info());
system("uname -a");
exit(0); exit(0);
case 's': case 's':
if (test->role == 'c') { if (test->role == 'c') {

View File

@ -356,7 +356,7 @@ iperf_run_client(struct iperf_test * test)
iprintf(test, "%s\n", version); iprintf(test, "%s\n", version);
iprintf(test, "%s", ""); iprintf(test, "%s", "");
fflush(stdout); fflush(stdout);
system("uname -a"); printf("%s\n", get_system_info());
} }
/* Start the client and connect to the server */ /* Start the client and connect to the server */

View File

@ -450,7 +450,7 @@ iperf_run_server(struct iperf_test *test)
iprintf(test, "%s\n", version); iprintf(test, "%s\n", version);
iprintf(test, "%s", ""); iprintf(test, "%s", "");
fflush(stdout); fflush(stdout);
system("uname -a"); printf("%s\n", get_system_info());
} }
// Open socket and listen // Open socket and listen

View File

@ -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 * through Lawrence Berkeley National Laboratory (subject to receipt of any
* required approvals from the U.S. Dept. of Energy). All rights reserved. * required approvals from the U.S. Dept. of Energy). All rights reserved.
* *
@ -22,6 +22,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/resource.h> #include <sys/resource.h>
#include <sys/utsname.h>
#include <time.h> #include <time.h>
#include <errno.h> #include <errno.h>
@ -193,19 +194,20 @@ cpu_util(double pcpu[3])
pcpu[2] = (systemdiff / timediff) * 100; pcpu[2] = (systemdiff / timediff) * 100;
} }
char* char *
get_system_info(void) get_system_info(void)
{ {
FILE* fp; static char buf[1024];
static char buf[1000]; 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; return buf;
} }
/* Helper routine for building cJSON objects in a printf-like manner. /* Helper routine for building cJSON objects in a printf-like manner.