From 44558f8ec38c39712a90def11d0e3de248fa04c4 Mon Sep 17 00:00:00 2001 From: "Samuel J. Greear" Date: Thu, 26 Jan 2012 16:34:01 -0700 Subject: [PATCH] linux - Add native sethostname implementation * Fixes Linux vector in the absence of COMPAT_43 --- sys/emulation/linux/i386/linux_syscall.h | 2 +- sys/emulation/linux/i386/linux_sysent.c | 2 +- sys/emulation/linux/i386/syscalls.master | 4 +- sys/emulation/linux/linux_misc.c | 31 ++++++++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/sys/emulation/linux/i386/linux_syscall.h b/sys/emulation/linux/i386/linux_syscall.h index 94e8019..ffa3199 100644 --- a/sys/emulation/linux/i386/linux_syscall.h +++ b/sys/emulation/linux/i386/linux_syscall.h @@ -69,7 +69,7 @@ #define LINUX_SYS_linux_setregid16 71 #define LINUX_SYS_linux_sigsuspend 72 #define LINUX_SYS_linux_sigpending 73 -#define LINUX_SYS_osethostname 74 +#define LINUX_SYS_sethostname 74 #define LINUX_SYS_linux_setrlimit 75 #define LINUX_SYS_linux_old_getrlimit 76 #define LINUX_SYS_getrusage 77 diff --git a/sys/emulation/linux/i386/linux_sysent.c b/sys/emulation/linux/i386/linux_sysent.c index 06ffaf7..b3cdbae 100644 --- a/sys/emulation/linux/i386/linux_sysent.c +++ b/sys/emulation/linux/i386/linux_sysent.c @@ -92,7 +92,7 @@ struct sysent linux_sysent[] = { { AS(linux_setregid16_args), (sy_call_t *)sys_linux_setregid16 }, /* 71 = linux_setregid16 */ { AS(linux_sigsuspend_args), (sy_call_t *)sys_linux_sigsuspend }, /* 72 = linux_sigsuspend */ { AS(linux_sigpending_args), (sy_call_t *)sys_linux_sigpending }, /* 73 = linux_sigpending */ - { AS(sethostname_args), (sy_call_t *)sys_osethostname }, /* 74 = osethostname */ + { AS(sethostname_args), (sy_call_t *)sys_linux_sethostname }, /* 74 = linux_sethostname */ { AS(linux_setrlimit_args), (sy_call_t *)sys_linux_setrlimit }, /* 75 = linux_setrlimit */ { AS(linux_old_getrlimit_args), (sy_call_t *)sys_linux_old_getrlimit }, /* 76 = linux_old_getrlimit */ { AS(getrusage_args), (sy_call_t *)sys_getrusage }, /* 77 = getrusage */ diff --git a/sys/emulation/linux/i386/syscalls.master b/sys/emulation/linux/i386/syscalls.master index 31c8d0d..00dfaec 100644 --- a/sys/emulation/linux/i386/syscalls.master +++ b/sys/emulation/linux/i386/syscalls.master @@ -126,8 +126,8 @@ 72 STD LINUX { int linux_sigsuspend(l_int hist0, l_int hist1, \ l_osigset_t mask); } 73 STD LINUX { int linux_sigpending(l_osigset_t *mask); } -74 NOPROTO LINUX { int osethostname(char *hostname, u_int len); } \ - osethostname sethostname_args int +74 NOPROTO LINUX { int sethostname(char *hostname, u_int len); } \ + sethostname sethostname_args int 75 STD LINUX { int linux_setrlimit(l_uint resource, \ struct l_rlimit *rlim); } 76 STD LINUX { int linux_old_getrlimit(l_uint resource, \ diff --git a/sys/emulation/linux/linux_misc.c b/sys/emulation/linux/linux_misc.c index beff37b..335ab54 100644 --- a/sys/emulation/linux/linux_misc.c +++ b/sys/emulation/linux/linux_misc.c @@ -1933,3 +1933,34 @@ sys_linux_getcpu(struct linux_getcpu_args *args) error = copyout(&node, args->pnode, sizeof(node)); return (error); } + +int +sys_linux_sethostname(struct sethostname_args *uap) +{ + struct thread *td = curthread; + size_t len; + char *hostname; + int name[2]; + int error; + + name[0] = CTL_KERN; + name[1] = KERN_HOSTNAME; + error = priv_check_cred(td->td_ucred, PRIV_SETHOSTNAME, 0); + if (error) + return (error); + len = MIN(uap->len, MAXHOSTNAMELEN); + hostname = kmalloc(MAXHOSTNAMELEN, M_TEMP, M_WAITOK); + + error = copyin(uap->hostname, hostname, len); + if (error) { + kfree(hostname, M_TEMP); + return (error); + } + + get_mplock(); + error = kernel_sysctl(name, 2, NULL, 0, hostname, len, NULL); + rel_mplock(); + + kfree(hostname, M_TEMP); + return (error); +} -- 1.7.6.3