mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-07-04 02:56:52 +00:00
tools: acrnlog: Deprecate binary "ls" with GPLv3+
The tools currently rely on the availability of binary "ls" to be available in the $PATH on the Service OS. This create an obscure dependency. The patch changes the code to use standard C APIs to perform the same functionality which makes the code more self-contained. Signed-off-by: Kaige Fu <kaige.fu@intel.com> Reviewed-by: Yan, Like <like.yan@intel.com>
This commit is contained in:
parent
0ccd74b947
commit
8869c862d6
@ -12,6 +12,7 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <dirent.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
@ -49,53 +50,32 @@ struct hvlog_dev {
|
|||||||
struct hvlog_msg latched_msg; /* latch for parsed msg */
|
struct hvlog_msg latched_msg; /* latch for parsed msg */
|
||||||
};
|
};
|
||||||
|
|
||||||
static int shell_cmd(const char *cmd, char *outbuf, int len)
|
|
||||||
{
|
|
||||||
FILE *ptr;
|
|
||||||
char cmd_buf[256];
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (!outbuf)
|
|
||||||
return system(cmd);
|
|
||||||
|
|
||||||
memset(cmd_buf, 0, sizeof(cmd_buf));
|
|
||||||
memset(outbuf, 0, len);
|
|
||||||
snprintf(cmd_buf, sizeof(cmd_buf), "%s 2>&1", cmd);
|
|
||||||
ptr = popen(cmd_buf, "re");
|
|
||||||
if (!ptr)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
ret = fread(outbuf, 1, len, ptr);
|
|
||||||
pclose(ptr);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* get pcpu_num, which is equal to num of acrnlog dev
|
* get pcpu_num, which is equal to num of acrnlog dev
|
||||||
*/
|
*/
|
||||||
static int get_cpu_num(void)
|
static int get_cpu_num(void)
|
||||||
{
|
{
|
||||||
|
char prefix[32] = "acrn_hvlog_cur_"; /* acrnlog dev prefix */
|
||||||
|
struct dirent *pdir;
|
||||||
|
int cpu_num = 0;
|
||||||
|
char *ret;
|
||||||
|
DIR *dir;
|
||||||
|
|
||||||
char cmd[128];
|
dir = opendir("/dev");
|
||||||
char buf[16];
|
if (!dir) {
|
||||||
int ret;
|
printf("Error opening /dev: %s\n", strerror(errno));
|
||||||
|
return -1;
|
||||||
snprintf(cmd, sizeof(cmd), "ls /dev/acrn_hvlog_cur_* | wc -l");
|
|
||||||
|
|
||||||
ret = shell_cmd(cmd, buf, sizeof(buf));
|
|
||||||
if (ret <= 0) {
|
|
||||||
printf("Faile to get cpu number, use default 4\n");
|
|
||||||
return PCPU_NUM;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = atoi(buf);
|
while (pdir = readdir(dir)) {
|
||||||
if (ret <= 0) {
|
ret = strstr(pdir->d_name, prefix);
|
||||||
printf("Wrong cpu number, use default 4\n");
|
if (ret)
|
||||||
return PCPU_NUM;
|
cpu_num++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
closedir(dir);
|
||||||
|
|
||||||
|
return cpu_num;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user