about summary refs log tree commit diff
path: root/sysdeps/pthread/sem_open.c
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2021-05-05 17:15:57 +0200
committerFlorian Weimer <fweimer@redhat.com>2021-05-05 17:19:38 +0200
commit0b7d48d1062e4383b4a78e0bb78c5f0f29479780 (patch)
tree7f68d1ddf402078c5ba49416a076b7875fb18b75 /sysdeps/pthread/sem_open.c
parent19cc20ef2e8b9e09429741a3108e55c50758a273 (diff)
downloadglibc-0b7d48d1062e4383b4a78e0bb78c5f0f29479780.tar.gz
glibc-0b7d48d1062e4383b4a78e0bb78c5f0f29479780.tar.xz
glibc-0b7d48d1062e4383b4a78e0bb78c5f0f29479780.zip
nptl: Move sem_close, sem_open into libc
The symbols were moved using move-symbol-to-libc.py.

Both functions are moved at the same time because they depend
on internal functions in sysdeps/pthread/sem_routines.c, which
are moved in this commit as well.  Additional hidden prototypes
are required to avoid check-localplt failures.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
Diffstat (limited to 'sysdeps/pthread/sem_open.c')
-rw-r--r--sysdeps/pthread/sem_open.c40
1 files changed, 27 insertions, 13 deletions
diff --git a/sysdeps/pthread/sem_open.c b/sysdeps/pthread/sem_open.c
index 0265abc45b..770ab17cdb 100644
--- a/sysdeps/pthread/sem_open.c
+++ b/sysdeps/pthread/sem_open.c
@@ -27,8 +27,14 @@
 #include <futex-internal.h>
 #include <libc-lock.h>
 
+#if !PTHREAD_IN_LIBC
+/* The private names are not exported from libc.  */
+# define __link link
+# define __unlink unlink
+#endif
+
 sem_t *
-sem_open (const char *name, int oflag, ...)
+__sem_open (const char *name, int oflag, ...)
 {
   int fd;
   sem_t *result;
@@ -59,8 +65,8 @@ sem_open (const char *name, int oflag, ...)
   if ((oflag & O_CREAT) == 0 || (oflag & O_EXCL) == 0)
     {
     try_again:
-      fd = open (dirname.name,
-		 (oflag & ~(O_CREAT|O_ACCMODE)) | O_NOFOLLOW | O_RDWR);
+      fd = __open (dirname.name,
+		   (oflag & ~(O_CREAT|O_ACCMODE)) | O_NOFOLLOW | O_RDWR);
 
       if (fd == -1)
 	{
@@ -127,7 +133,7 @@ sem_open (const char *name, int oflag, ...)
 	    }
 
 	  /* Open the file.  Make sure we do not overwrite anything.  */
-	  fd = open (tmpfname, O_RDWR | O_CREAT | O_EXCL, mode);
+	  fd = __open (tmpfname, O_RDWR | O_CREAT | O_EXCL, mode);
 	  if (fd == -1)
 	    {
 	      if (errno == EEXIST)
@@ -154,15 +160,15 @@ sem_open (const char *name, int oflag, ...)
       if (TEMP_FAILURE_RETRY (write (fd, &sem.initsem, sizeof (sem_t)))
 	  == sizeof (sem_t)
 	  /* Map the sem_t structure from the file.  */
-	  && (result = (sem_t *) mmap (NULL, sizeof (sem_t),
-				       PROT_READ | PROT_WRITE, MAP_SHARED,
-				       fd, 0)) != MAP_FAILED)
+	  && (result = (sem_t *) __mmap (NULL, sizeof (sem_t),
+					 PROT_READ | PROT_WRITE, MAP_SHARED,
+					 fd, 0)) != MAP_FAILED)
 	{
 	  /* Create the file.  Don't overwrite an existing file.  */
-	  if (link (tmpfname, dirname.name) != 0)
+	  if (__link (tmpfname, dirname.name) != 0)
 	    {
 	      /* Undo the mapping.  */
-	      (void) munmap (result, sizeof (sem_t));
+	      __munmap (result, sizeof (sem_t));
 
 	      /* Reinitialize 'result'.  */
 	      result = SEM_FAILED;
@@ -172,10 +178,10 @@ sem_open (const char *name, int oflag, ...)
 	      if ((oflag & O_EXCL) == 0 && errno == EEXIST)
 		{
 		  /* Remove the file.  */
-		  (void) unlink (tmpfname);
+		  __unlink (tmpfname);
 
 		  /* Close the file.  */
-		  close (fd);
+		  __close (fd);
 
 		  goto try_again;
 		}
@@ -189,7 +195,7 @@ sem_open (const char *name, int oflag, ...)
 
       /* Now remove the temporary name.  This should never fail.  If
 	 it fails we leak a file name.  Better fix the kernel.  */
-      (void) unlink (tmpfname);
+      __unlink (tmpfname);
     }
 
   /* Map the mmap error to the error we need.  */
@@ -201,7 +207,7 @@ sem_open (const char *name, int oflag, ...)
     {
       /* Do not disturb errno.  */
       int save = errno;
-      close (fd);
+      __close (fd);
       errno = save;
     }
 
@@ -212,3 +218,11 @@ out:
 
   return result;
 }
+#if PTHREAD_IN_LIBC
+versioned_symbol (libc, __sem_open, sem_open, GLIBC_2_34);
+# if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_1_1, GLIBC_2_34)
+compat_symbol (libpthread, __sem_open, sem_open, GLIBC_2_1_1);
+# endif
+#else /* !PTHREAD_IN_LIBC */
+strong_alias (__sem_open, sem_open)
+#endif