diff --git a/include/sys/syscall_lookup.h b/include/sys/syscall_lookup.h index a5f1d0e6660..f07906a6b3a 100644 --- a/include/sys/syscall_lookup.h +++ b/include/sys/syscall_lookup.h @@ -45,7 +45,7 @@ SYSCALL_LOOKUP(nxsched_get_stackinfo, 2) SYSCALL_LOOKUP(sched_setaffinity, 3) #endif -SYSCALL_LOOKUP(uname, 1) +SYSCALL_LOOKUP(gethostname, 2) SYSCALL_LOOKUP(sethostname, 2) /* User identity */ diff --git a/libs/libc/misc/lib_utsname.c b/libs/libc/misc/lib_utsname.c index 03c91b3bdc3..181af54b01f 100644 --- a/libs/libc/misc/lib_utsname.c +++ b/libs/libc/misc/lib_utsname.c @@ -46,18 +46,6 @@ #include #include -/* In the protected and kernel build modes where kernel and application code - * are separated, some of these common system property must reside only in - * the kernel. In that case, uname() can only be called from user space via - * a kernel system call. - */ - -#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__) - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -100,11 +88,7 @@ int uname(FAR struct utsname *name) /* Get the hostname */ - if (-1 == gethostname(name->nodename, HOST_NAME_MAX)) - { - ret = -1; - } - + ret = gethostname(name->nodename, HOST_NAME_MAX); name->nodename[HOST_NAME_MAX - 1] = '\0'; strncpy(name->release, CONFIG_VERSION_STRING, SYS_NAMELEN); @@ -123,5 +107,3 @@ int uname(FAR struct utsname *name) return ret; } - -#endif /* CONFIG_BUILD_FLAT || __KERNEL__ */ diff --git a/libs/libc/unistd/lib_gethostname.c b/libs/libc/unistd/lib_gethostname.c index 9ed6f44ad1b..c02b2d9858f 100644 --- a/libs/libc/unistd/lib_gethostname.c +++ b/libs/libc/unistd/lib_gethostname.c @@ -41,12 +41,19 @@ #include -#include #include #include #include +/* Further, in the protected and kernel build modes where kernel and + * application code are separated, the hostname is a common system property + * and must reside only in the kernel. In that case, this accessor + * function only be called from user space is only via a kernel system call. + */ + +#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__) + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -96,17 +103,6 @@ char g_hostname[HOST_NAME_MAX + 1] = CONFIG_LIB_HOSTNAME; int gethostname(FAR char *name, size_t namelen) { -/* In the protected and kernel build modes where kernel and application code - * are separated, the hostname is a common system property and must reside - * only in the kernel. In that case, we need to do things differently. - * - * uname() is implemented as a system call and can be called from user space. - * So, in these configurations we will get the hostname via the uname - * function. - */ - -#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__) - irqstate_t flags; /* Return the host name, truncating to fit into the user provided buffer. @@ -119,24 +115,6 @@ int gethostname(FAR char *name, size_t namelen) leave_critical_section(flags); return 0; - -#else - - struct utsname info; - int ret; - - /* Get uname data */ - - ret = uname(&info); - if (ret < 0) - { - return ret; - } - - /* Return the nodename from the uname data */ - - strncpy(name, info.nodename, namelen); - return 0; - -#endif } + +#endif /* CONFIG_BUILD_FLAT || __KERNEL__ */ diff --git a/syscall/syscall.csv b/syscall/syscall.csv index 475d2870df5..3389ac89d6d 100644 --- a/syscall/syscall.csv +++ b/syscall/syscall.csv @@ -30,6 +30,7 @@ "ftruncate","unistd.h","!defined(CONFIG_DISABLE_MOUNTPOINT)","int","int","off_t" "getenv","stdlib.h","!defined(CONFIG_DISABLE_ENVIRON)","FAR char *","FAR const char *" "getgid","unistd.h","defined(CONFIG_SCHED_USER_IDENTITY)","gid_t" +"gethostname","unistd.h","","int","FAR char *","size_t" "getitimer","sys/time.h","!defined(CONFIG_DISABLE_POSIX_TIMERS)","int","int","FAR struct itimerval *" "getpeername","sys/socket.h","defined(CONFIG_NET)","int","int","FAR struct sockaddr *","FAR socklen_t *" "getpid","unistd.h","","pid_t" @@ -176,7 +177,6 @@ "tls_alloc","nuttx/tls.h","CONFIG_TLS_NELEM > 0","int" "tls_free","nuttx/tls.h","CONFIG_TLS_NELEM > 0","int","int" "umount2","sys/mount.h","!defined(CONFIG_DISABLE_MOUNTPOINT)","int","FAR const char *","unsigned int" -"uname","sys/utsname.h","","int","FAR struct utsname *" "unlink","unistd.h","!defined(CONFIG_DISABLE_MOUNTPOINT)","int","FAR const char *" "unsetenv","stdlib.h","!defined(CONFIG_DISABLE_ENVIRON)","int","FAR const char *" "up_assert","nuttx/arch.h","","void","FAR const char *","int"