Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
  • Loading branch information
netblue30 committed Nov 21, 2016
1 parent 13ef7fb commit 10990a9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 72 deletions.
4 changes: 2 additions & 2 deletions gcov.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 9 additions & 10 deletions src/lib/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
46 changes: 6 additions & 40 deletions src/lib/libnetlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
34 changes: 14 additions & 20 deletions src/lib/pid.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -93,10 +91,9 @@ void pid_get_cpu_time(unsigned pid, unsigned *utime, unsigned *stime) {
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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 10990a9

Please sign in to comment.