diff --git a/libs/libc/unistd/lib_gethostname.c b/libs/libc/unistd/lib_gethostname.c index 9e0cf5b9e09..ba601aef9fe 100644 --- a/libs/libc/unistd/lib_gethostname.c +++ b/libs/libc/unistd/lib_gethostname.c @@ -46,6 +46,7 @@ #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 @@ -74,6 +75,7 @@ /* This is the system hostname */ char g_hostname[HOST_NAME_MAX + 1] = CONFIG_LIBC_HOSTNAME; +spinlock_t g_hostname_lock = SP_UNLOCKED; /**************************************************************************** * Public Functions @@ -111,9 +113,9 @@ int gethostname(FAR char *name, size_t namelen) * that it could change while we are copying it. */ - flags = enter_critical_section(); + flags = spin_lock_irqsave(&g_hostname_lock); strlcpy(name, g_hostname, namelen); - leave_critical_section(flags); + spin_unlock_irqrestore(&g_hostname_lock, flags); return 0; } diff --git a/libs/libc/unistd/lib_sethostname.c b/libs/libc/unistd/lib_sethostname.c index e80a2417df4..5b362214d88 100644 --- a/libs/libc/unistd/lib_sethostname.c +++ b/libs/libc/unistd/lib_sethostname.c @@ -47,6 +47,7 @@ #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 @@ -67,6 +68,7 @@ /* This is the system hostname (defined in lib_gethostname). */ extern char g_hostname[HOST_NAME_MAX + 1]; +extern spinlock_t g_hostname_lock; /**************************************************************************** * Public Functions @@ -105,9 +107,9 @@ int sethostname(FAR const char *name, size_t namelen) * are setting it. */ - flags = enter_critical_section(); + flags = spin_lock_irqsave(&g_hostname_lock); strlcpy(g_hostname, name, sizeof(g_hostname)); - leave_critical_section(flags); + spin_unlock_irqrestore(&g_hostname_lock, flags); return 0; }