]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/kern/bsd_stubs.c
xnu-6153.81.5.tar.gz
[apple/xnu.git] / bsd / kern / bsd_stubs.c
index fb33955de5cac4019429234a6d7c7df6bd2788e0..f738345987418d3c0695399828f2186967cc7331 100644 (file)
@@ -348,16 +348,21 @@ cdevsw_setkqueueok(int maj, struct cdevsw * csw, int extra_flags)
 int
 bsd_hostname(char * buf, int bufsize, int * len)
 {
+       int ret, hnlen;
        /*
-        * "hostname" is null-terminated, and "hostnamelen" is equivalent to strlen(hostname).
+        * "hostname" is null-terminated
         */
-       if (hostnamelen < bufsize) {
+       lck_mtx_lock(&hostname_lock);
+       hnlen = strlen(hostname);
+       if (hnlen < bufsize) {
                strlcpy(buf, hostname, bufsize);
-               *len = hostnamelen;
-               return 0;
+               *len = hnlen;
+               ret = 0;
        } else {
-               return ENAMETOOLONG;
+               ret = ENAMETOOLONG;
        }
+       lck_mtx_unlock(&hostname_lock);
+       return ret;
 }
 
 void