Commit 4869da17 authored by Pavel Emelyanov's avatar Pavel Emelyanov

net: Read ns' sysfs file helper

Just a small helper, that reads string from ns' sysfs mount.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 8d2e0d5d
......@@ -23,5 +23,6 @@ extern struct ns_desc net_ns_desc;
#include "protobuf/netdev.pb-c.h"
int write_netdev_img(NetDeviceEntry *nde, struct cr_fdset *fds);
int read_ns_sys_file(char *path, char *buf, int len);
#endif /* __CR_NET_H__ */
......@@ -22,6 +22,27 @@
static int ns_fd = -1;
static int ns_sysfs_fd = -1;
int read_ns_sys_file(char *path, char *buf, int len)
{
int fd, rlen;
BUG_ON(ns_sysfs_fd == -1);
fd = openat(ns_sysfs_fd, path, O_RDONLY, 0);
if (fd < 0) {
pr_perror("Can't open ns' %s", path);
return -1;
}
rlen = read(fd, buf, len);
close(fd);
if (rlen >= 0)
buf[rlen] = '\0';
return rlen;
}
void show_netdevices(int fd)
{
pb_show_plain_pretty(fd, PB_NETDEV, "2:%d");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment