Commit 0c54b67b authored by Pavel Emelyanov's avatar Pavel Emelyanov

pb: Switch uts namespace image file to protobuf format

Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 4806e139
...@@ -47,6 +47,7 @@ PROTO_FILES += ipc-desc.proto ...@@ -47,6 +47,7 @@ PROTO_FILES += ipc-desc.proto
PROTO_FILES += ipc-shm.proto PROTO_FILES += ipc-shm.proto
PROTO_FILES += ipc-msg.proto PROTO_FILES += ipc-msg.proto
PROTO_FILES += ipc-sem.proto PROTO_FILES += ipc-sem.proto
PROTO_FILES += utsns.proto
PROTO_FILES += creds.proto PROTO_FILES += creds.proto
PROTO_FILES += vma.proto PROTO_FILES += vma.proto
......
message utsns_entry {
required string nodename = 1;
required string domainname = 2;
}
...@@ -9,23 +9,14 @@ ...@@ -9,23 +9,14 @@
#include "namespaces.h" #include "namespaces.h"
#include "sysctl.h" #include "sysctl.h"
static int dump_uts_string(int fd, const char *str) #include "protobuf.h"
{ #include "protobuf/utsns.pb-c.h"
int ret;
u32 len;
len = strlen(str);
ret = write_img(fd, &len);
if (!ret)
ret = write_img_buf(fd, str, len);
return ret;
}
int dump_uts_ns(int ns_pid, struct cr_fdset *fdset) int dump_uts_ns(int ns_pid, struct cr_fdset *fdset)
{ {
int fd, ret; int ret;
struct utsname ubuf; struct utsname ubuf;
UtsnsEntry ue = UTSNS_ENTRY__INIT;
ret = switch_ns(ns_pid, CLONE_NEWUTS, "uts"); ret = switch_ns(ns_pid, CLONE_NEWUTS, "uts");
if (ret < 0) if (ret < 0)
...@@ -37,46 +28,19 @@ int dump_uts_ns(int ns_pid, struct cr_fdset *fdset) ...@@ -37,46 +28,19 @@ int dump_uts_ns(int ns_pid, struct cr_fdset *fdset)
return ret; return ret;
} }
fd = fdset_fd(fdset, CR_FD_UTSNS); ue.nodename = ubuf.nodename;
ue.domainname = ubuf.domainname;
ret = dump_uts_string(fd, ubuf.nodename);
if (!ret)
ret = dump_uts_string(fd, ubuf.domainname);
return ret; return pb_write(fdset_fd(fdset, CR_FD_UTSNS), &ue, utsns_entry);
}
static int read_uts_str(int fd, char *n, int size)
{
int ret;
u32 len;
ret = read_img(fd, &len);
if (ret < 0)
return -1;
if (len >= size) {
pr_err("Corrupted %s\n", n);
return -1;
}
ret = read_img_buf(fd, n, len);
if (ret < 0)
return -1;
n[len] = '\0';
return 0;
} }
int prepare_utsns(int pid) int prepare_utsns(int pid)
{ {
int fd, ret; int fd, ret;
char hostname[65]; UtsnsEntry *ue;
char domainname[65]; struct sysctl_req req[3] = {
{ "kernel/hostname" },
struct sysctl_req req[] = { { "kernel/domainname" },
{ "kernel/hostname", hostname, CTL_STR(sizeof(hostname)) },
{ "kernel/domainname", domainname, CTL_STR(sizeof(hostname)) },
{ }, { },
}; };
...@@ -84,46 +48,33 @@ int prepare_utsns(int pid) ...@@ -84,46 +48,33 @@ int prepare_utsns(int pid)
if (fd < 0) if (fd < 0)
return -1; return -1;
ret = read_uts_str(fd, hostname, sizeof(hostname)); ret = pb_read(fd, &ue, utsns_entry);
if (ret < 0) if (ret < 0)
goto out; goto out;
ret = read_uts_str(fd, domainname, sizeof(domainname)); req[0].arg = ue->nodename;
if (ret < 0) req[0].type = CTL_STR(strlen(ue->nodename));
goto out; req[1].arg = ue->domainname;
req[1].type = CTL_STR(strlen(ue->domainname));
ret = sysctl_op(req, CTL_WRITE); ret = sysctl_op(req, CTL_WRITE);
utsns_entry__free_unpacked(ue, NULL);
out: out:
close(fd); close(fd);
return ret; return ret;
} }
static void show_uts_string(int fd, char *n) void show_utsns(int fd, struct cr_options *o)
{ {
int ret; int ret;
u32 len; UtsnsEntry *ue;
char str[65];
ret = read_img_eof(fd, &len);
if (ret > 0) {
if (len >= sizeof(str)) {
pr_err("Corrupted hostname\n");
return;
}
ret = read_img_buf(fd, str, len); ret = pb_read(fd, &ue, utsns_entry);
if (ret < 0) if (ret < 0)
return; return;
str[len] = '\0'; pr_msg("nodename: %s\n", ue->nodename);
pr_msg("%s: [%s]\n", n, str); pr_msg("domainname: %s\n", ue->domainname);
}
}
void show_utsns(int fd, struct cr_options *o) utsns_entry__free_unpacked(ue, NULL);
{
pr_img_head(CR_FD_UTSNS);
show_uts_string(fd, "hostname");
show_uts_string(fd, "domainname");
pr_img_tail(CR_FD_UTSNS);
} }
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