diff --git a/configure.ac b/configure.ac index ebb289c2648376eda77507de0bfc1e33eb1f33e6..a968ae8561a00102100e8f0e9a017300e9e512db 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 274ede5bce25a7a0da211c469ecf998abcfa7fc8..6b4ac2b2d14e062b05613f692fbf2f6ad03e80b8 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 9cb2d8e2776934c50e51162023cf2246fc5cf72f..2200bf0658ae26ad4110ee8de8f2efdef8c0d480 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 39e0e982994c0e7682cd84cb02ab56c049cb1455..207656339cbb08e6d6a46b1888f1250c25344218 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 5c5e3405fd81b259289352f9653ff11a1d682863..2682f2700c71b53f43fa8bfc401da22c90e18f75 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;