linux uname系统调用

uname系统调用入口

<kernel/sys.c>
SYSCALL_DEFINE1(newuname, struct new_utsname __user *, name)
{
	int errno = 0;

	down_read(&uts_sem);
	if (copy_to_user(name, utsname(), sizeof *name))
		errno = -EFAULT;
	up_read(&uts_sem);

	if (!errno && override_release(name->release, sizeof(name->release)))
		errno = -EFAULT;
	if (!errno && override_architecture(name))
		errno = -EFAULT;
	return errno;
}
其中调用utsname,定义如下:

<include/linux/utsname.h>
static inline struct new_utsname *utsname(void)
{
	return &current->nsproxy->uts_ns->name;
}
uts_ns的定义来自init_uts_ns

struct uts_namespace init_uts_ns = {
	.kref = {
		.refcount	= ATOMIC_INIT(2),
	},
	.name = {
		.sysname	= UTS_SYSNAME,
		.nodename	= UTS_NODENAME,
		.release	= UTS_RELEASE,
		.version	= UTS_VERSION,
		.machine	= UTS_MACHINE,
		.domainname	= UTS_DOMAINNAME,
	},
	.user_ns = &init_user_ns,
};
而UTS_VERSION定义在

<include/generated/compile.h>
#define UTS_VERSION "#1 PREEMPT Thu Aug 22 10:10:49 CST 2013"
compile.h是在kernel/scripts/mkcompile_h这个脚本生成






你可能感兴趣的:(linux uname系统调用)