2012-01-31 11:29:23 +03:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/utsname.h>
|
2012-05-29 20:11:00 +04:00
|
|
|
#include <string.h>
|
2012-01-31 23:25:36 +04:00
|
|
|
|
2012-01-31 11:29:23 +03:00
|
|
|
#include "util.h"
|
|
|
|
#include "crtools.h"
|
|
|
|
#include "syscall.h"
|
|
|
|
#include "namespaces.h"
|
2012-02-02 19:55:48 +04:00
|
|
|
#include "sysctl.h"
|
2012-01-31 11:29:23 +03:00
|
|
|
|
2012-07-19 14:52:30 +04:00
|
|
|
#include "protobuf.h"
|
|
|
|
#include "protobuf/utsns.pb-c.h"
|
2012-01-31 11:29:23 +03:00
|
|
|
|
|
|
|
int dump_uts_ns(int ns_pid, struct cr_fdset *fdset)
|
|
|
|
{
|
2012-07-19 14:52:30 +04:00
|
|
|
int ret;
|
2012-01-31 11:29:23 +03:00
|
|
|
struct utsname ubuf;
|
2012-07-19 14:52:30 +04:00
|
|
|
UtsnsEntry ue = UTSNS_ENTRY__INIT;
|
2012-01-31 11:29:23 +03:00
|
|
|
|
2012-08-02 07:55:05 +04:00
|
|
|
ret = switch_ns(ns_pid, CLONE_NEWUTS, "uts", NULL);
|
2012-01-31 11:29:23 +03:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = uname(&ubuf);
|
|
|
|
if (ret < 0) {
|
2012-01-31 15:13:05 +04:00
|
|
|
pr_perror("Error calling uname");
|
2012-01-31 11:29:23 +03:00
|
|
|
return ret;
|
|
|
|
}
|
2012-08-11 21:34:35 +04:00
|
|
|
|
2012-07-19 14:52:30 +04:00
|
|
|
ue.nodename = ubuf.nodename;
|
|
|
|
ue.domainname = ubuf.domainname;
|
2012-01-31 11:29:23 +03:00
|
|
|
|
2012-08-07 02:26:50 +04:00
|
|
|
return pb_write_one(fdset_fd(fdset, CR_FD_UTSNS), &ue, PB_UTSNS);
|
2012-01-31 11:29:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int prepare_utsns(int pid)
|
|
|
|
{
|
|
|
|
int fd, ret;
|
2012-07-19 14:52:30 +04:00
|
|
|
UtsnsEntry *ue;
|
|
|
|
struct sysctl_req req[3] = {
|
|
|
|
{ "kernel/hostname" },
|
|
|
|
{ "kernel/domainname" },
|
2012-02-02 19:55:48 +04:00
|
|
|
{ },
|
|
|
|
};
|
2012-01-31 11:29:23 +03:00
|
|
|
|
|
|
|
fd = open_image_ro(CR_FD_UTSNS, pid);
|
|
|
|
if (fd < 0)
|
|
|
|
return -1;
|
|
|
|
|
2012-08-07 02:42:58 +04:00
|
|
|
ret = pb_read_one(fd, &ue, PB_UTSNS);
|
2012-02-02 19:55:48 +04:00
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
|
2012-07-19 14:52:30 +04:00
|
|
|
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));
|
2012-01-31 11:29:23 +03:00
|
|
|
|
2012-02-02 19:55:48 +04:00
|
|
|
ret = sysctl_op(req, CTL_WRITE);
|
2012-07-19 14:52:30 +04:00
|
|
|
utsns_entry__free_unpacked(ue, NULL);
|
2012-02-02 19:55:48 +04:00
|
|
|
out:
|
2012-01-31 11:29:23 +03:00
|
|
|
close(fd);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-07-19 14:52:30 +04:00
|
|
|
void show_utsns(int fd, struct cr_options *o)
|
2012-01-31 11:29:23 +03:00
|
|
|
{
|
2012-08-07 02:51:34 +04:00
|
|
|
pb_show_vertical(fd, PB_UTSNS);
|
2012-01-31 11:29:23 +03:00
|
|
|
}
|