criu/uts_ns.c
Pavel Emelyanov b18fb09eb9 show: Replace one-line show_foo calls with args array
We have generic do_pb_show() call and tons of show_foo
routines, that just call one with proper args. Compact
the code by putting the args into array and calling
the do_pb_show() in one place.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-24 04:00:32 +04:00

68 lines
1.3 KiB
C

#include <unistd.h>
#include <fcntl.h>
#include <sys/utsname.h>
#include <string.h>
#include "util.h"
#include "crtools.h"
#include "syscall.h"
#include "namespaces.h"
#include "sysctl.h"
#include "uts_ns.h"
#include "protobuf.h"
#include "protobuf/utsns.pb-c.h"
int dump_uts_ns(int ns_pid, struct cr_fdset *fdset)
{
int ret;
struct utsname ubuf;
UtsnsEntry ue = UTSNS_ENTRY__INIT;
ret = switch_ns(ns_pid, &uts_ns_desc, NULL);
if (ret < 0)
return ret;
ret = uname(&ubuf);
if (ret < 0) {
pr_perror("Error calling uname");
return ret;
}
ue.nodename = ubuf.nodename;
ue.domainname = ubuf.domainname;
return pb_write_one(fdset_fd(fdset, CR_FD_UTSNS), &ue, PB_UTSNS);
}
int prepare_utsns(int pid)
{
int fd, ret;
UtsnsEntry *ue;
struct sysctl_req req[3] = {
{ "kernel/hostname" },
{ "kernel/domainname" },
{ },
};
fd = open_image(CR_FD_UTSNS, O_RSTR, pid);
if (fd < 0)
return -1;
ret = pb_read_one(fd, &ue, PB_UTSNS);
if (ret < 0)
goto out;
req[0].arg = ue->nodename;
req[0].type = CTL_STR(strlen(ue->nodename));
req[1].arg = ue->domainname;
req[1].type = CTL_STR(strlen(ue->domainname));
ret = sysctl_op(req, CTL_WRITE);
utsns_entry__free_unpacked(ue, NULL);
out:
close(fd);
return ret;
}
struct ns_desc uts_ns_desc = NS_DESC_ENTRY(CLONE_NEWUTS, "uts");