source: trunk/doc/lossage @ 8769

Revision 8769, 4.0 KB checked in by ghudson, 28 years ago (diff)
First cut at source tree documentation.
Line 
1This file describes cases where platforms we care about do not
2correctly implement the ANSI C and POSIX specifications.  The cases
3described are:
4
5        setsid() and Ultrix 4.2
6        getpgrp() and Ultrix, SunOS 4.x
7        Pseudo-ttys and Ultrix 4.2
8        strerror() and SunOS
9
10setsid() and Ultrix 4.2
11-----------------------
12
13Under Ultrix 4.2, setsid() does not dissociate a process from its
14controlling tty.
15
16For a program using imake, an appropriate way to detect the problem
17is:
18
19        #define HAVE_SETSID
20        #ifdef ultrix
21        /* Under Ultrix 4.2, setsid() doesn't dissociate the calling process
22         * from its controlling tty.  Use setpgid() and the TIOCNOTTY
23         * ioctl instead. */
24        #undef HAVE_SETSID
25        #endif
26
27For a program using Autoconf, you should put the following test in
28your aclocal.m4:
29
30        AC_DEFUN(ATHENA_FUNC_SETSID,
31        [AC_MSG_CHECKING(for working setsid)
32        AC_CACHE_VAL(athena_cv_func_setsid,
33        [AC_TRY_RUN([
34        #include <sys/types.h>
35        #include <sys/stat.h>
36        #include <fcntl.h>
37        #include <unistd.h>
38        int main()
39        {
40            setsid();
41            return (open("/dev/tty", O_RDWR, 0666) < 0) ? 0 : 1;
42        }
43        ], athena_cv_func_setsid=yes, athena_cv_func_setsid=no,
44           athena_cv_func_setsid=no)])dnl
45        AC_MSG_RESULT($athena_cv_func_regcomp)
46        if test $athena_cv_func_regcomp = yes; then
47          AC_DEFINE(HAVE_SETSID)
48        fi])
49
50and then put ATHENA_FUNC_SETSID in your configure.in.
51
52In either case, an appropriate workaround is:
53
54        #ifndef HAVE_SETSID
55        #include <sys/ioctl.h>
56        static int bsd_emulate_setsid()
57        {
58            int fd, status;
59
60            status = setpgid(getpid(), getpid());
61            if (status < 0)
62                return status;
63            fd = open("/dev/tty", O_RDWR, 0666);
64            if (fd >= 0) {
65                status = ioctl(fd, TIOCNOTTY, (char *) 0);
66                close(fd);
67            }
68            return status;
69        }
70        #define setsid bsd_emulate_setsid
71        #endif
72
73getpgrp() and Ultrix, SunOS 4.x
74-------------------------------
75
76The BSD 4.3 getpgrp() interface takes a process ID argument indicating
77which process one wants the process group of.  POSIX "simplified" the
78getpgrp() interface by eliminating the argument and assuming the
79calling process's ID.  Ultrix and SunOS both have "POSIX" or "System
80V" environments which have the correct getpgrp() interface, but we
81don't use those environments.
82
83For a program using imake, an appropriate way to detect the problem
84is:
85
86        #define GETPGRP_VOID
87        #if defined(ultrix) || (defined(sun) && !defined(__svr4__))
88        /* Ultrix 4.2 and SunOS 4.1.3_U1 use the old BSD interface for
89         * getpgrp(), which takes an argument.  Use the BSD getpgrp()
90         * interface instead of the POSIX interface. */
91        #undef GETPGRP_VOID
92        #endif
93
94For a program which uses Autoconf, put AC_FUNC_GETPGRP in your
95configure.in file.
96
97In either case, an appropriate workaround is:
98
99        #ifndef GETPGRP_VOID
100        #include <sys/types.h>
101        static pid_t bsd_emulate_getpgrp()
102        {
103            return getpgrp(getpid());
104        }
105        #define getpgrp bsd_emulate_getpgrp
106        #endif
107
108Pseudo-ttys and Ultrix 4.2
109--------------------------
110
111Opening a slave pty under Ultrix without opening the parent causes the
112pty to become unusable until a reboot.  The best workaround is to
113always open the parent side of pseudo-ttys first.  See the section on
114pseudo-ttys in the "nonstd" file in this directory for more
115information about obtaining a pseudo-tty.
116
117strerror() and SunOS
118--------------------
119
120The standard way of getting the error message for an error value in
121ANSI C is the function strerror().  SunOS does not define strerror().
122
123An incorrect solution is to declare sys_nerr and sys_errlist and use
124them directly.  Not only is this solution nonstandard, but modern
125operating systems often have their own declarations of those
126variables, which may conflict with your declarations.
127
128For a program using imake, an appropriate way to detect the problem
129is:
130
131        #define HAVE_STRERROR
132        #if defined(sun) && !defined(__svr4__)
133        /* SunOS 4.1.3_U1 doesn't have strerror().  Use sys_errlist
134         * instead. */
135        #undef HAVE_STRERROR
136        #endif
137
138For a program using autoconf, put AC_CHECK_FUNC(strerror) in your
139configure.in.
140
141In either case, an appropriate workaround is:
142
143        #ifndef HAVE_STRERROR
144        extern const char *const sys_errlist[];
145        #define strerror(x) (sys_errlist[x])
146        #endif
Note: See TracBrowser for help on using the repository browser.