[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#448406: Patch to implement a racy_pselect



tags 448406 + patch
kthxbye

A patch is attached which implements a function racy_pselect, which is used if pselect returns EINVAL or ENOSYS. This bug should probably be cloned to the kernel as a request to implement pselect on certain (unspecified) architectures, since pselect is required by POSIX.

Indentation may leave something to be desired, but I tried hard to make it look reasonable.

--
brian m. carlson / brian with sandals: Houston, Texas, US
+1 713 440 7475 | http://crustytoothpaste.ath.cx/~bmc | My opinion only
a typesetting engine: http://crustytoothpaste.ath.cx/~bmc/code/thwack
OpenPGP: RSA v4 4096b 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187
--- apt-pkg/deb/dpkgpm.cc.old	2007-10-29 14:27:41.000000000 +0000
+++ apt-pkg/deb/dpkgpm.cc	2007-10-29 14:42:24.000000000 +0000
@@ -543,7 +543,26 @@
    return true;
 }
 
-
+/*{{{*/
+// This implements a racy version of pselect for those architectures
+// that don't have a working implementation.
+static int racy_pselect(int nfds, fd_set *readfds, fd_set *writefds,
+   fd_set *exceptfds, const struct timespec *timeout,
+   const sigset_t *sigmask)
+{
+   sigset_t origmask;
+   struct timeval tv;
+   int retval;
+
+   tv.tv_sec = timeout->tv.tv_sec;
+   tv.tv_usec = timeout->tv.tv_nsec/1000;
+
+   sigprocmask(SIG_SETMASK, &sigmask, &origmask);
+   retval = select(nfds, readfds, writefds, exceptfds, &tv);
+   sigprocmask(SIG_SETMASK, &origmask, 0);
+   return retval;
+}
+/*}}}*/
 // DPkgPM::Go - Run the sequence					/*{{{*/
 // ---------------------------------------------------------------------
 /* This globs the operations and calls dpkg 
@@ -855,6 +874,9 @@
 	 tv.tv_nsec = 0;
 	 select_ret = pselect(max(master, _dpkgin)+1, &rfds, NULL, NULL, 
 			      &tv, &original_sigmask);
+	 if (select_ret < 0 && (errno == EINVAL || errno == ENOSYS))
+	    select_ret = racy_pselect(max(master, _dpkgin)+1, &rfds, NULL,
+				      NULL, &tv, &original_sigmask);
 	 if (select_ret == 0) 
   	    continue;
   	 else if (select_ret < 0 && errno == EINTR)

Attachment: signature.asc
Description: Digital signature


Reply to: