mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-22 18:07:57 +00:00
pb: Switch uts namespace image file to protobuf format
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
parent
4806e1395f
commit
0c54b67b88
@ -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
|
||||||
|
|
||||||
|
4
protobuf/utsns.proto
Normal file
4
protobuf/utsns.proto
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
message utsns_entry {
|
||||||
|
required string nodename = 1;
|
||||||
|
required string domainname = 2;
|
||||||
|
}
|
105
uts_ns.c
105
uts_ns.c
@ -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)
|
|||||||
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);
|
return pb_write(fdset_fd(fdset, CR_FD_UTSNS), &ue, utsns_entry);
|
||||||
if (!ret)
|
|
||||||
ret = dump_uts_string(fd, ubuf.domainname);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|||||||
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)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
u32 len;
|
|
||||||
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);
|
|
||||||
if (ret < 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
str[len] = '\0';
|
|
||||||
pr_msg("%s: [%s]\n", n, str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void show_utsns(int fd, struct cr_options *o)
|
void show_utsns(int fd, struct cr_options *o)
|
||||||
{
|
{
|
||||||
pr_img_head(CR_FD_UTSNS);
|
int ret;
|
||||||
show_uts_string(fd, "hostname");
|
UtsnsEntry *ue;
|
||||||
show_uts_string(fd, "domainname");
|
|
||||||
pr_img_tail(CR_FD_UTSNS);
|
ret = pb_read(fd, &ue, utsns_entry);
|
||||||
|
if (ret < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
pr_msg("nodename: %s\n", ue->nodename);
|
||||||
|
pr_msg("domainname: %s\n", ue->domainname);
|
||||||
|
|
||||||
|
utsns_entry__free_unpacked(ue, NULL);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user