From: Sangho Park Date: Mon, 15 Feb 2016 03:38:07 +0000 (+0900) Subject: util: remove/replace unnecessary system(3) call X-Git-Tag: Tizen_Studio_1.3_Release_p2.3.2~63 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e0d3b7050df84ae0fcf69ef693dde718b1d82f92;p=sdk%2Femulator%2Fqemu.git util: remove/replace unnecessary system(3) call * Mac OS X ** use uname(3) instead of system("uname") ** remove system("java -version") * Linux ** Try to read /etc/lsb-release ** Add get_number_of_processors() ** Remove redundant codes Change-Id: I0a73b27ab35a6ab9dd774455b33182abb15ad481 Signed-off-by: Sangho Park --- diff --git a/tizen/src/util/osutil-darwin.c b/tizen/src/util/osutil-darwin.c index cdf492c13b..b27ed7ca24 100644 --- a/tizen/src/util/osutil-darwin.c +++ b/tizen/src/util/osutil-darwin.c @@ -6,6 +6,7 @@ * Contact: * SeokYeon Hwang * MunKyu Im + * Sangho Park * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -32,6 +33,7 @@ */ #include +#include #include "png.h" @@ -102,15 +104,18 @@ int get_number_of_processors(void) void print_system_info_os(void) { + struct utsname utsname; + LOG_INFO("* Mac\n"); LOG_INFO("* LibPNG Version : %s\n", PNG_LIBPNG_VER_STRING); /* uname */ LOG_INFO("* Host machine uname :\n"); - char const *const uname_cmd = "uname -a"; - if(system(uname_cmd) < 0) { - LOG_INFO("system function command '%s' \ - returns error !", uname_cmd); + if (uname(&utsname) == 0) { + LOG_INFO("* Host machine uname : %s %s %s %s %s\n", + utsname.sysname, utsname.nodename, + utsname.release, utsname.version, + utsname.machine); } /* hw information */ @@ -153,16 +158,6 @@ void print_system_info_os(void) if (sysctl(mib, 2, &sys_num, &len, NULL, 0) >= 0) { LOG_INFO("* Total memory : %llu bytes\n", sys_num); } - - /* java version */ - LOG_INFO("* Java version :\n"); - char const *const lspci_cmd = "java -version"; - - fflush(stdout); - if(system(lspci_cmd) < 0) { - LOG_INFO("system function command '%s' \ - returns error !", lspci_cmd); - } } bool make_sdcard_lock_os(char *sdcard) diff --git a/tizen/src/util/osutil-linux.c b/tizen/src/util/osutil-linux.c index 9dc506382a..8e432f990b 100644 --- a/tizen/src/util/osutil-linux.c +++ b/tizen/src/util/osutil-linux.c @@ -6,6 +6,7 @@ * Contact: * SeokYeon Hwang * MunKyu Im + * Sangho Park * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -34,11 +35,13 @@ #include #include #include +#include #include "png.h" #include "osutil.h" #include "emul_state.h" +#include "qemu/osdep.h" #ifndef CONFIG_LINUX #error @@ -82,11 +85,48 @@ int get_number_of_processors(void) if (num_processors < 1) { num_processors = 1; } - LOG_TRACE("Number of processors : %d\n", num_processors); + LOG_INFO("Number of processors : %d\n", num_processors); return num_processors; } +static void _system(const char *buf) +{ + if (system(buf) < 0) { + LOG_INFO("system function command '%s' \ + returns error !", buf); + } +} + +static void get_lsb(void) +{ + int fd; + + /* + * lsb_release(1) is defined at LSB spec + * while the spec does not define /etc/lsb-release. + * At first, try to read from /etc/lsb-release in order to avoid system(3). + * If open(2) to the file is failed, try to system(lsb_release). + */ + LOG_INFO("* Linux distribution infomation :\n"); + fd = qemu_open("/etc/lsb-release", O_RDONLY); + if (fd >= 0) { + char buf[4096]; + int ret; + do { + ret = read(fd, buf, sizeof(buf)); + if (ret > 0) + LOG_INFO("%.*s\n", ret, buf); + } while (ret == sizeof(buf)); + if (ret < 0) { + LOG_INFO("Failed to read file for lsb: %s\n", strerror(errno)); + } + qemu_close(fd); + } else { + _system("lsb_release -d -r -c"); + } +} + void print_system_info_os(void) { LOG_INFO("* Linux\n"); @@ -98,7 +138,7 @@ void print_system_info_os(void) (LINUX_VERSION_CODE >> 8) & 0xff, LINUX_VERSION_CODE & 0xff); - /* depends on launching */ + /* depends on launching */ struct utsname host_uname_buf; if (uname(&host_uname_buf) == 0) { LOG_INFO("* Host machine uname : %s %s %s %s %s\n", @@ -107,6 +147,11 @@ void print_system_info_os(void) host_uname_buf.machine); } + /* get linux distribution information */ + get_lsb(); + + get_number_of_processors(); + struct sysinfo sys_info; if (sysinfo(&sys_info) == 0) { LOG_INFO("* Total Ram : %llu kB, Free: %llu kB\n", @@ -114,37 +159,9 @@ void print_system_info_os(void) sys_info.freeram * (unsigned long long)sys_info.mem_unit / 1024); } - /* get linux distribution information */ - LOG_INFO("* Linux distribution infomation :\n"); - char const *const lsb_release_cmd = "lsb_release -d -r -c"; - gchar *buffer = NULL; - gint buffer_size = strlen(lsb_release_cmd) + 1; - - buffer = g_malloc(buffer_size); - - g_snprintf(buffer, buffer_size, "%s", lsb_release_cmd); - - if (system(buffer) < 0) { - LOG_INFO("system function command '%s' \ - returns error !", buffer); - } - g_free(buffer); - /* pci device description */ LOG_INFO("* Host PCI devices :\n"); - char const *const lspci_cmd = "lspci"; - buffer_size = strlen(lspci_cmd) + 1; - - buffer = g_malloc(buffer_size); - - g_snprintf(buffer, buffer_size, "%s", lspci_cmd); - - fflush(stdout); - if (system(buffer) < 0) { - LOG_INFO("system function command '%s' \ - returns error !", buffer); - } - g_free(buffer); + _system("lspci"); } bool make_sdcard_lock_os(char *sdcard)