From a4cc41565b3a1314a1086178529c0f937830532c Mon Sep 17 00:00:00 2001 From: nocjj <1250062498@qq.com> Date: Mon, 7 Sep 2020 10:07:40 +0800 Subject: [PATCH] build: add configure option enable-debug and secure-build Add enable-debug option ad secure-build option to configure.ac. enable-debug: add "-g -O0" to CFLAGS secure-build: add secure compile option Signed-off-by: Jiajun Chen <1250062498@qq.com> --- configure.ac | 13 +++++++++++++ src/domain.c | 4 ++-- src/proc.c | 10 ++++++---- src/vcpu_stat.c | 2 +- src/vmtop.c | 2 +- 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/configure.ac b/configure.ac index ebb289c..a968ae8 100644 --- a/configure.ac +++ b/configure.ac @@ -10,6 +10,7 @@ AC_CONFIG_HEADERS([config.h]) AC_PROG_CC AC_PROG_RANLIB AM_INIT_AUTOMAKE([subdir-objects]) +CC="$CC -std=gnu11" # Checks for libraries. AC_CHECK_LIB(ncurses, initscr, [], [echo "missing ncurses support!";exit -1]) @@ -26,6 +27,18 @@ AC_TYPE_PID_T AC_FUNC_MALLOC AC_CHECK_FUNCS([memset realpath strstr strtoul]) +# AC_ARGS_ENABLES +AC_ARG_ENABLE([debug], + [AS_HELP_STRING([--enable-debug], [debug program(default is disable)])], + [CFLAGS="-g -O0"], + [CFLAGS="-g -O2"] +) + +AC_ARG_ENABLE([secure-build], + [AS_HELP_STRING([--enable-secure-build], [build project with secure flags])], + [CFLAGS="${CFLAGS} -Wl,-z,relro,-z,now -fPIE -fPIC -pie -Werror -Wall -ftrapv -fstack-protector-all -D_FORTIFY_SOURCE=2 -O2"],[] +) + AC_CONFIG_FILES([Makefile src/Makefile]) AC_OUTPUT diff --git a/src/domain.c b/src/domain.c index 274ede5..6b4ac2b 100644 --- a/src/domain.c +++ b/src/domain.c @@ -123,7 +123,7 @@ static int get_id_from_cgroup(pid_t pid) char *tmp = NULL; int id = -1; - if (snprintf(path, CGROUP_PATH_SIZE, "/proc/%lu/cgroup", pid) < 0) { + if (snprintf(path, CGROUP_PATH_SIZE, "/proc/%u/cgroup", pid) < 0) { return id; } fp = fopen(path, "r"); @@ -156,7 +156,7 @@ static int get_child_pid(struct domain *dom) char *end = NULL; int i = 0; - if (snprintf(path, TASK_STRING_SIZE, "/proc/%lu/task", dom->pid) < 0) { + if (snprintf(path, TASK_STRING_SIZE, "/proc/%u/task", dom->pid) < 0) { return -1; } dirptr = opendir(path); diff --git a/src/proc.c b/src/proc.c index 9cb2d8e..2200bf0 100644 --- a/src/proc.c +++ b/src/proc.c @@ -76,11 +76,11 @@ int get_proc_stat(struct domain *dom) int i = 0; if (dom->type == ISDOMAIN) { - if (snprintf(path, STAT_PATH_SIZE, "/proc/%lu/stat", dom->pid) < 0) { + if (snprintf(path, STAT_PATH_SIZE, "/proc/%u/stat", dom->pid) < 0) { return -1; } } else { - if (snprintf(path, STAT_PATH_SIZE, "/proc/%lu/task/%lu/stat", + if (snprintf(path, STAT_PATH_SIZE, "/proc/%u/task/%u/stat", dom->ppid, dom->pid) < 0) { return -1; } @@ -117,11 +117,13 @@ int get_proc_comm(struct domain *dom) char path[STAT_PATH_SIZE]; int len; - if (snprintf(path, STAT_PATH_SIZE, "/proc/%lu/comm", dom->pid) < 0) { + if (snprintf(path, STAT_PATH_SIZE, "/proc/%u/comm", dom->pid) < 0) { return -1; } len = read_file(dom->vmname, DOMAIN_NAME_MAX, path); - dom->vmname[len - 1] = '\0'; + if (len > 1) { + dom->vmname[len - 1] = '\0'; + } return len; } diff --git a/src/vcpu_stat.c b/src/vcpu_stat.c index 39e0e98..2076563 100644 --- a/src/vcpu_stat.c +++ b/src/vcpu_stat.c @@ -60,7 +60,7 @@ int get_vcpu_stat(struct domain *dom) char pid[PID_STRING_SIZE]; FILE *fp = NULL; - if (snprintf(pid, PID_STRING_SIZE, "%lu", dom->pid) < 0) { + if (snprintf(pid, PID_STRING_SIZE, "%u", dom->pid) < 0) { return -1; } fp = fopen(KVM_VCPU_STAT_PATH, "r"); diff --git a/src/vmtop.c b/src/vmtop.c index 5c5e340..2682f27 100644 --- a/src/vmtop.c +++ b/src/vmtop.c @@ -276,7 +276,7 @@ static void print_field(int high_light) { int x = 3; /* display x local */ int y = 4; /* display y local */ - int attr_flag; + unsigned int attr_flag; for (int i = 0; i < FD_END; i++) { attr_flag = A_NORMAL; -- GitLab