为什么 oldolduname 和 uname 之间有区别?

Why is the difference between oldolduname and uname?

为什么 oldolduname 和 uname 有区别?

我一直在阅读手册页,但没有理解其中的微妙之处。

首先,如果你从用户空间调用uname,你不需要关心区别,应该不需要使用olduname或oldolduname。从用户空间,您使用 struct utsname 并调用 uname() 函数。

来自手册页:

Over time, increases in the size of the utsname structure have led to three successive versions of uname(): sys_olduname() (slot __NR_oldolduname), sys_uname() (slot __NR_olduname), and sys_newuname() (slot __NR_uname). The first one used length 9 for all fields; the second used 65; the third also uses 65 but adds the domainname field. The glibc uname() wrapper function hides these details from applications, invoking the most recent version of the system call provided by the kernel.

因此,纵观历史,struct utsname 的大小和内容略有变化,内核保留了 3 个不同的版本以保持与用户空间的兼容性,您可以在此处查看内核处理的不同版本: http://lxr.free-electrons.com/source/include/linux/utsname.h?v=2.6.38#L24。然而,glibc 或 linux 上的任何 C 库都对你隐藏了所有这些。

uname是用户代码调用的函数。

它调用内核函数 sys_newunamesys_unamesys_olduname 之一,具体取决于 Linux 内核的版本。它们之间的区别在于名称字段的长度(sys_olduname 中的 9 个字符,其他两个中的 65 个字符),sys_newuname 向结构添加了一个额外的 domainname 字段。