2 * Copyright (C) 2004 IBM Corporation
4 * Author: Serge Hallyn <serue@us.ibm.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2 of the
12 #include <linux/module.h>
13 #include <linux/uts.h>
14 #include <linux/utsname.h>
15 #include <linux/version.h>
18 * Clone a new ns copying an original utsname, setting refcount to 1
19 * @old_ns: namespace to clone
20 * Return NULL on error (failure to kmalloc), new ns otherwise
22 static struct uts_namespace
*clone_uts_ns(struct uts_namespace
*old_ns
)
24 struct uts_namespace
*ns
;
26 ns
= kmalloc(sizeof(struct uts_namespace
), GFP_KERNEL
);
28 memcpy(&ns
->name
, &old_ns
->name
, sizeof(ns
->name
));
35 * unshare the current process' utsname namespace.
36 * called only in sys_unshare()
38 int unshare_utsname(unsigned long unshare_flags
, struct uts_namespace
**new_uts
)
40 if (unshare_flags
& CLONE_NEWUTS
) {
41 if (!capable(CAP_SYS_ADMIN
))
44 *new_uts
= clone_uts_ns(current
->nsproxy
->uts_ns
);
53 * Copy task tsk's utsname namespace, or clone it if flags
54 * specifies CLONE_NEWUTS. In latter case, changes to the
55 * utsname of this process won't be seen by parent, and vice
58 int copy_utsname(int flags
, struct task_struct
*tsk
)
60 struct uts_namespace
*old_ns
= tsk
->nsproxy
->uts_ns
;
61 struct uts_namespace
*new_ns
;
69 if (!(flags
& CLONE_NEWUTS
))
72 if (!capable(CAP_SYS_ADMIN
)) {
77 new_ns
= clone_uts_ns(old_ns
);
82 tsk
->nsproxy
->uts_ns
= new_ns
;
89 void free_uts_ns(struct kref
*kref
)
91 struct uts_namespace
*ns
;
93 ns
= container_of(kref
, struct uts_namespace
, kref
);
This page took 0.031957 seconds and 5 git commands to generate.