From 10990a9da34bd360e48818608f46d9e9f544d0d9 Mon Sep 17 00:00:00 2001 From: netblue30 Date: Mon, 21 Nov 2016 08:47:33 -0500 Subject: testing --- gcov.sh | 4 ++-- src/lib/common.c | 19 +++++++++---------- src/lib/libnetlink.c | 46 ++++++---------------------------------------- src/lib/pid.c | 34 ++++++++++++++-------------------- 4 files changed, 31 insertions(+), 72 deletions(-) diff --git a/gcov.sh b/gcov.sh index 660aad7a1..c5c385dd3 100755 --- a/gcov.sh +++ b/gcov.sh @@ -13,9 +13,9 @@ gcov_init() { } generate() { - lcov --capture -d src/firejail -d src/firemon -d src/fcopy -d src/fseccomp -d src/fnet -d src/ftee -d src/lib -d src/firecfg --output-file gcov-file + lcov -q --capture -d src/firejail -d src/firemon -d src/fcopy -d src/fseccomp -d src/fnet -d src/ftee -d src/lib -d src/firecfg --output-file gcov-file rm -fr gcov-dir - genhtml gcov-file --output-directory gcov-dir + genhtml -q gcov-file --output-directory gcov-dir } gcov_init diff --git a/src/lib/common.c b/src/lib/common.c index 2f2340963..add4ff087 100644 --- a/src/lib/common.c +++ b/src/lib/common.c @@ -39,22 +39,23 @@ int join_namespace(pid_t pid, char *type) { errExit("asprintf"); int fd = open(path, O_RDONLY); - if (fd < 0) { - free(path); - fprintf(stderr, "Error: cannot open /proc/%u/ns/%s.\n", pid, type); - return -1; - } + if (fd < 0) + goto errout; if (syscall(__NR_setns, fd, 0) < 0) { - free(path); - fprintf(stderr, "Error: cannot join namespace %s.\n", type); close(fd); - return -1; + goto errout; } close(fd); free(path); return 0; + +errout: + free(path); + fprintf(stderr, "Error: cannot join namespace %s\\n", type); + return -1; + } // return 1 if error @@ -187,8 +188,6 @@ char *pid_proc_cmdline(const pid_t pid) { for (i = 0; i < len; i++) { if (buffer[i] == '\0') buffer[i] = ' '; -// if (buffer[i] >= 0x80) // execv in progress!!! -// return NULL; } // return a malloc copy of the command line diff --git a/src/lib/libnetlink.c b/src/lib/libnetlink.c index 836cf417d..417ef2c5f 100644 --- a/src/lib/libnetlink.c +++ b/src/lib/libnetlink.c @@ -105,6 +105,7 @@ int rtnl_open(struct rtnl_handle *rth, unsigned subscriptions) return rtnl_open_byproto(rth, subscriptions, NETLINK_ROUTE); } +#if 0 int rtnl_wilddump_request(struct rtnl_handle *rth, int family, int type) { return rtnl_wilddump_req_filter(rth, family, type, RTEXT_FILTER_VF); @@ -303,6 +304,7 @@ int rtnl_dump_filter(struct rtnl_handle *rth, return rtnl_dump_filter_l(rth, a); } +#endif int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer, unsigned groups, struct nlmsghdr *answer) @@ -422,6 +424,7 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer, } } +#if 0 int rtnl_listen(struct rtnl_handle *rtnl, rtnl_filter_t handler, void *jarg) @@ -580,7 +583,7 @@ int addattrstrz(struct nlmsghdr *n, int maxlen, int type, const char *str) { return addattr_l(n, maxlen, type, str, strlen(str)+1); } - +#endif int addattr_l(struct nlmsghdr *n, int maxlen, int type, const void *data, @@ -632,46 +635,8 @@ printf("\tdata length: %d\n", alen); return 0; } -#if 0 -int addattr_l(struct nlmsghdr *n, int maxlen, int type, const void *data, - int alen) -{ -printf("%s: adding type %d, length %d ", __FUNCTION__, type, alen); -if (type == IFLA_INFO_KIND) { -if (alen) - printf("(IFLA_INFO_KIND %s)\n", (char *)data); -else -printf("(VETH_INFO_PEER)\n"); -} -else if (type == IFLA_IFNAME) { -printf("(IFLA_IFNAME %s)\n", (char *) data); -} -else if (type == IFLA_NET_NS_PID) { -printf("(IFLA_NET_NS_PID %u)\n", *((unsigned *) data)); -} -else if (type == IFLA_LINKINFO) -printf("(IFLA_LINKINFO)\n"); -else if (type == IFLA_INFO_DATA) -printf("(IFLA_INFO_DATA)\n"); -else - printf("\n"); - - int len = RTA_LENGTH(alen); - struct rtattr *rta; - - if (NLMSG_ALIGN(n->nlmsg_len) + RTA_ALIGN(len) > maxlen) { - fprintf(stderr, "addattr_l ERROR: message exceeded bound of %d\n",maxlen); - return -1; - } - rta = NLMSG_TAIL(n); - rta->rta_type = type; - rta->rta_len = len; - memcpy(RTA_DATA(rta), data, alen); - n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + RTA_ALIGN(len); - return 0; -} -#endif +#if 0 int addraw_l(struct nlmsghdr *n, int maxlen, const void *data, int len) { if ((int)(NLMSG_ALIGN(n->nlmsg_len) + NLMSG_ALIGN(len)) > maxlen) { @@ -802,3 +767,4 @@ int __parse_rtattr_nested_compat(struct rtattr *tb[], int max, struct rtattr *rt memset(tb, 0, sizeof(struct rtattr *) * (max + 1)); return 0; } +#endif diff --git a/src/lib/pid.c b/src/lib/pid.c index ed583c51d..42687274e 100644 --- a/src/lib/pid.c +++ b/src/lib/pid.c @@ -34,10 +34,9 @@ int max_pids=32769; void pid_getmem(unsigned pid, unsigned *rss, unsigned *shared) { // open stat file char *file; - if (asprintf(&file, "/proc/%u/statm", pid) == -1) { - perror("asprintf"); - exit(1); - } + if (asprintf(&file, "/proc/%u/statm", pid) == -1) + errExit("asprintf"); + FILE *fp = fopen(file, "r"); if (!fp) { free(file); @@ -59,10 +58,9 @@ void pid_getmem(unsigned pid, unsigned *rss, unsigned *shared) { void pid_get_cpu_time(unsigned pid, unsigned *utime, unsigned *stime) { // open stat file char *file; - if (asprintf(&file, "/proc/%u/stat", pid) == -1) { - perror("asprintf"); - exit(1); - } + if (asprintf(&file, "/proc/%u/stat", pid) == -1) + errExit("asprintf"); + FILE *fp = fopen(file, "r"); if (!fp) { free(file); @@ -93,10 +91,9 @@ myexit: unsigned long long pid_get_start_time(unsigned pid) { // open stat file char *file; - if (asprintf(&file, "/proc/%u/stat", pid) == -1) { - perror("asprintf"); - exit(1); - } + if (asprintf(&file, "/proc/%u/stat", pid) == -1) + errExit("asprintf"); + FILE *fp = fopen(file, "r"); if (!fp) { free(file); @@ -138,10 +135,8 @@ uid_t pid_get_uid(pid_t pid) { // open status file char *file; - if (asprintf(&file, "/proc/%u/status", pid) == -1) { - perror("asprintf"); - exit(1); - } + if (asprintf(&file, "/proc/%u/status", pid) == -1) + errExit("asprintf"); FILE *fp = fopen(file, "r"); if (!fp) { @@ -316,10 +311,9 @@ void pid_read(pid_t mon_pid) { // open stat file char *file; - if (asprintf(&file, "/proc/%u/status", pid) == -1) { - perror("asprintf"); - exit(1); - } + if (asprintf(&file, "/proc/%u/status", pid) == -1) + errExit("asprintf"); + FILE *fp = fopen(file, "r"); if (!fp) { free(file); -- cgit v1.2.3-54-g00ecf