pkgsrc-Bugs archive

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

pkg/34763: rxvt-unicode: Fix compilation for systems without SCM_RIGHTS



>Number:         34763
>Category:       pkg
>Synopsis:       rxvt-unicode: Fix compilation for systems without SCM_RIGHTS
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    pkg-manager
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Mon Oct 09 01:10:01 +0000 2006
>Originator:     Christian Biere
>Release:        NetBSD 4.99.3
>Description:
The following patch fixes rxvt-unicode so that it compiles on systems
which don't support file descriptor passing with SCM_RIGHTS and
msg_controllen but use msg_msgaccrights instead. I offered this patch
to the author of rxvt-unicode but he rejected it suggesting to set
_XOPEN_SOURCE appropriately. Indeed, that would make msg_controllen and
SCM_RIGHTS available at least on IRIX. However, it would break compilation
on Solaris for example. Setting _XOPEN_SOURCE has usually tons of
side-effects and is inherently non-portable as you never no which system
breaks when you fiddle with it and there's no guarantee that you can make
SCM_RIGHTS etc. available on any given system anyway.

In contrast, using msg_accrights just works and my patch definitely breaks
nothing.

>How-To-Repeat:
Try to compile rxvt-unicode on IRIX 6.5.
>Fix:

$NetBSD$

--- configure   2006-02-08 23:48:51.000000000 +0100
+++ configure   2006-10-09 01:15:28.000000000 +0200
@@ -11787,7 +11787,6 @@
 {
   msghdr msg;
   iovec iov;
-  char buf [100];
   char data = 0;
 
   iov.iov_base = &data;
@@ -11795,6 +11794,9 @@
 
   msg.msg_iov        = &iov;
   msg.msg_iovlen     = 1;
+
+#ifdef SCM_RIGHTS
+  char buf [100];
   msg.msg_control    = buf;
   msg.msg_controllen = sizeof buf;
 
@@ -11804,6 +11806,10 @@
   cmsg->cmsg_len   = 100;
 
   *(int *)CMSG_DATA (cmsg) = 5;
+#else  /* !SCM_RIGHTS */
+  msg.msg_accrights    = (void *)&fd;
+  msg.msg_accrightslen = sizeof fd;
+#endif /* SCM_RIGHTS */
 
   return sendmsg (3, &msg, 0);
 }
--- ptytty.m4   2006-02-07 06:31:56.000000000 +0100
+++ ptytty.m4   2006-10-09 01:15:20.000000000 +0200
@@ -465,7 +465,6 @@
 {
   msghdr msg;
   iovec iov;
-  char buf [100];
   char data = 0;
 
   iov.iov_base = &data;
@@ -473,6 +472,9 @@
 
   msg.msg_iov        = &iov;
   msg.msg_iovlen     = 1;
+
+#ifdef SCM_RIGHTS
+  char buf [100];
   msg.msg_control    = buf;
   msg.msg_controllen = sizeof buf;
 
@@ -482,6 +484,10 @@
   cmsg->cmsg_len   = 100;
 
   *(int *)CMSG_DATA (cmsg) = 5;
+#else  /* !SCM_RIGHTS */
+  msg.msg_accrights    = (void *)&fd;
+  msg.msg_accrightslen = sizeof fd;
+#endif /* SCM_RIGHTS */
 
   return sendmsg (3, &msg, 0);
 }
--- src/fdpass.C        2006-06-06 01:01:00.000000000 +0200
+++ src/fdpass.C        2006-10-09 02:12:33.000000000 +0200
@@ -33,7 +33,8 @@
 
 #include "libptytty.h"
 
-#ifndef CMSG_LEN // CMSG_SPACe && CMSG_LEN are rfc2292 extensions to unix
+#if defined(SCM_RIGHTS) && !defined(CMSG_LEN)
+// CMSG_SPACe && CMSG_LEN are rfc2292 extensions to unix
 # define CMSG_LEN(len) (sizeof (cmsghdr) + len)
 #endif
 
@@ -42,7 +43,6 @@
 {
   msghdr msg;
   iovec iov;
-  char buf [CMSG_LEN (sizeof (int))];
   char data = 0;
 
   iov.iov_base = &data;
@@ -52,6 +52,9 @@
   msg.msg_namelen    = 0;
   msg.msg_iov        = &iov;
   msg.msg_iovlen     = 1;
+
+#ifdef SCM_RIGHTS
+  char buf [CMSG_LEN (sizeof (int))];
   msg.msg_control    = (void *)buf;
   msg.msg_controllen = sizeof buf;
 
@@ -63,6 +66,10 @@
   *(int *)CMSG_DATA (cmsg) = fd;
 
   msg.msg_controllen = cmsg->cmsg_len;
+#else  /* SCM_RIGHTS */
+  msg.msg_accrights  = (void *)&fd;
+  msg.msg_accrightslen = sizeof fd;
+#endif /* !SCM_RIGHTS */
 
   return sendmsg (socket, &msg, 0) >= 0;
 }
@@ -72,8 +79,8 @@
 {
   msghdr msg;
   iovec iov;
-  char buf [CMSG_LEN (sizeof (int))];  /* ancillary data buffer */
   char data = 1;
+  int fd;
 
   iov.iov_base = &data;
   iov.iov_len  = 1;
@@ -82,6 +89,9 @@
   msg.msg_namelen    = 0;
   msg.msg_iov        = &iov;
   msg.msg_iovlen     = 1;
+
+#ifdef SCM_RIGHTS
+  char buf [CMSG_LEN (sizeof (int))];  /* ancillary data buffer */
   msg.msg_control    = buf;
   msg.msg_controllen = sizeof buf;
 
@@ -91,15 +101,26 @@
   cmsg->cmsg_len   = CMSG_LEN (sizeof (int));
 
   msg.msg_controllen = cmsg->cmsg_len;
+#else /* !SCM_RIGHTS */
+  msg.msg_accrights  = (void *)&fd;
+  msg.msg_accrightslen = sizeof fd;
+#endif /* SCM_RIGHTS */
+
+  if (recvmsg (socket, &msg, 0) <= 0 || data != 0)
+     return -1;
 
-  if (recvmsg (socket, &msg, 0) <= 0
-      || data               != 0
-      || msg.msg_controllen < CMSG_LEN (sizeof (int))
+#ifdef SCM_RIGHTS
+  if (msg.msg_controllen < CMSG_LEN (sizeof (int))
       || cmsg->cmsg_level   != SOL_SOCKET
       || cmsg->cmsg_type    != SCM_RIGHTS
       || cmsg->cmsg_len     < CMSG_LEN (sizeof (int)))
     return -1;
 
-  return *(int *)CMSG_DATA (cmsg);
-}
+  fd = *(int *)CMSG_DATA (cmsg);
+#else /* SCM_RIGHTS */
+  if (!msg.msg_accrights || msg.msg_accrightslen != sizeof fd)
+    return -1;
+#endif /* !SCM_RIGHTS */
 
+  return fd;
+}




Home | Main Index | Thread Index | Old Index