Просмотр исходного кода

dpkgpm: Use ptsname_r() instead of ptsname() to be thread-safe

This function only exists on a limited number of platforms, so
we add a configure check to make sure it exists.

Gbp-Dch: ignore
Julian Andres Klode лет назад: 10
Родитель
Сommit
2a0cae347a
3 измененных файлов с 11 добавлено и 0 удалено
  1. 5 0
      apt-pkg/deb/dpkgpm.cc
  2. 3 0
      buildlib/config.h.in
  3. 3 0
      configure.ac

+ 5 - 0
apt-pkg/deb/dpkgpm.cc

@@ -1082,8 +1082,13 @@ void pkgDPkgPM::StartPtyMagic()
       _error->Errno("unlockpt", "Unlocking the slave of master fd %d failed!", d->master);
    else
    {
+#ifdef HAVE_PTS_NAME_R
+      char slave_name[64];	// 64 is used by bionic
+      if (ptsname_r(d->master, slave_name, sizeof(slave_name)) != 0)
+#else
       char const * const slave_name = ptsname(d->master);
       if (slave_name == NULL)
+#endif
 	 _error->Errno("ptsname", "Getting name for slave of master fd %d failed!", d->master);
       else
       {

+ 3 - 0
buildlib/config.h.in

@@ -34,6 +34,9 @@
 #undef HAVE_SETRESUID
 #undef HAVE_SETRESGID
 
+/* Check for ptsname_r() */
+#undef HAVE_PTSNAME_R
+
 /* Define to the size of the filesize containing structures */
 #undef _FILE_OFFSET_BITS
 

+ 3 - 0
configure.ac

@@ -180,6 +180,9 @@ AC_SUBST(HAVE_GETRESGID)
 AC_SUBST(HAVE_SETRESUID)
 AC_SUBST(HAVE_SETRESGID)
 
+AC_CHECK_FUNC(ptsname_r)
+AC_SUBST(HAVE_PTSNAME_R)
+
 dnl Check for doxygen
 AC_PATH_PROG(DOXYGEN, doxygen)