NetBSD Problem Report #34763

From christianbiere@gmx.de  Mon Oct  9 01:07:37 2006
Return-Path: <christianbiere@gmx.de>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by narn.NetBSD.org (Postfix) with ESMTP id A1BA363BC6A
	for <gnats-bugs@gnats.NetBSD.org>; Mon,  9 Oct 2006 01:07:37 +0000 (UTC)
Message-Id: <20061009010724.GA8703@cyclonus>
Date: Mon, 9 Oct 2006 03:07:24 +0200
From: Christian Biere <christianbiere@gmx.de>
To: gnats-bugs@NetBSD.org
Subject: rxvt-unicode: Fix compilation for systems without SCM_RIGHTS
X-Send-Pr-Version: 3.95

>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
>Last-Modified:  Mon Oct 09 17:40:00 +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;
+}

>Audit-Trail:
From: Christian Biere <christianbiere@gmx.de>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: pkg/34763: rxvt-unicode: Fix compilation for systems without SCM_RIGHTS
Date: Mon, 9 Oct 2006 19:36:16 +0200

 gnats-admin@netbsd.org wrote:
 > >Synopsis:       rxvt-unicode: Fix compilation for systems without SCM_RIGHTS

 After testing my patch on IRIX 6.5, I found some obvious mistakes in the
 patch and another issue i.e., TIOCSCTTY is undefined on IRIX and definitely
 nowhere found in any header files. This ioctl() or another method is apparently
 not necessary on IRIX as far as I interpret the manpages and the test results.
 I've verified that other terminal emulators use such a #ifdef for TIOCSTTY as
 well.


 --- configure	2006-02-08 23:48:51.000000000 +0100
 +++ configure	2006-10-09 18:49:02.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,11 @@
    cmsg->cmsg_len   = 100;

    *(int *)CMSG_DATA (cmsg) = 5;
 +#else	/* !SCM_RIGHTS */
 +  int fd;
 +  msg.msg_accrights    = (caddr_t)&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 18:49:53.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,11 @@
    cmsg->cmsg_len   = 100;

    *(int *)CMSG_DATA (cmsg) = 5;
 +#else	/* !SCM_RIGHTS */
 +  int fd;
 +  msg.msg_accrights    = (caddr_t)&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 18:47:25.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  = (caddr_t)&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  = (caddr_t)&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;
 +}
 --- src/ptytty.C	2006-02-20 23:41:16.000000000 +0100
 +++ src/ptytty.C	2006-10-09 19:10:17.000000000 +0200
 @@ -233,7 +233,9 @@
      }
  #endif

 +#ifdef TIOCSCTTY
    ioctl (fd_tty, TIOCSCTTY, NULL);
 +#endif

    int fd = open ("/dev/tty", O_WRONLY);
    if (fd < 0)

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.