Ticket #1417: unix-pty.patch

File unix-pty.patch, 8.6 KB (added by bos@…, 8 years ago)
Line 
1
2New patches:
3
4[Add basic pseudoterminal support.
5Bryan O'Sullivan <[email protected]>**20070607005323] {
6hunk ./System/Posix/Terminal.hsc 63
7-  getControllingTerminalName
8+  getControllingTerminalName,
9hunk ./System/Posix/Terminal.hsc 65
10+  -- ** Pseudoterminal operations
11+  openPseudoTerminal,
12+  getSlaveTerminalName
13hunk ./System/Posix/Terminal.hsc 74
14-import Foreign.C.Error ( throwErrnoIfMinus1, throwErrnoIfMinus1_, throwErrnoIfNull )
15-import Foreign.C.String ( CString, peekCString )
16+import Foreign.C.Error ( errnoToIOError, throwErrnoIfMinus1,
17+                         throwErrnoIfMinus1_, throwErrnoIfNull )
18+import Foreign.C.String ( CString, peekCString, withCString )
19hunk ./System/Posix/Terminal.hsc 79
20+import Foreign.Marshal.Alloc ( alloca )
21hunk ./System/Posix/Terminal.hsc 83
22+import System.IO.Error ( ioError )
23hunk ./System/Posix/Terminal.hsc 85
24+import System.Posix.IO ( OpenFileFlags(..), OpenMode(..), defaultFileFlags,
25+                         openFd )
26hunk ./System/Posix/Terminal.hsc 526
27+-- | @getSlaveTerminalName@ calls @ptsname@ to obtain the name of the
28+-- slave terminal associated with a pseudoterminal pair.  The file
29+-- descriptor to pass in must be that of the master.
30+getSlaveTerminalName :: Fd -> IO FilePath
31+
32+#ifdef HAVE_PTSNAME
33+getSlaveTerminalName (Fd fd) = do
34+  s <- throwErrnoIfNull "getSlaveTerminalName" (c_ptsname fd)
35+  peekCString s
36+
37+foreign import ccall unsafe "__hsunix_ptsname"
38+  c_ptsname :: CInt -> IO CString
39+#else
40+getSlaveTerminalName =
41+    ioError (errnoToIOError "getSlaveTerminalName" eNOSYS Nothing Nothing)
42+#endif
43+
44+-- | @openPseudoTerminal@ creates a pseudoterminal (pty) pair, and
45+-- returns the newly created pair as a (@master@, @slave@) tuple.
46+openPseudoTerminal :: IO (Fd, Fd)
47+
48+#ifdef HAVE_OPENPTY
49+openPseudoTerminal =
50+  alloca $ \p_master ->
51+    alloca $ \p_slave -> do
52+      throwErrnoIfMinus1_ "openPty"
53+          (c_openpty p_master p_slave nullPtr nullPtr nullPtr)
54+      master <- peek p_master
55+      slave <- peek p_slave
56+      return (Fd master, Fd slave)
57+
58+foreign import ccall unsafe "openpty"
59+  c_openpty :: Ptr CInt -> Ptr CInt -> CString -> Ptr CTermios -> Ptr a
60+            -> IO CInt
61+#else
62+openPseudoTerminal = do
63+  (Fd master) <- openFd "/dev/ptmx" ReadWrite Nothing
64+                        defaultFileFlags{noctty=True}
65+  throwErrnoIfMinus1_ "openPseudoTerminal" (c_grantpt master)
66+  throwErrnoIfMinus1_ "openPseudoTerminal" (c_unlockpt master)
67+  slaveName <- getSlaveTerminalName (Fd master)
68+  slave <- openFd slaveName ReadWrite Nothing defaultFileFlags{noctty=True}
69+  pushModule slave "ptem"
70+  pushModule slave "ldterm"
71+# ifndef __hpux
72+  pushModule slave "ttcompat"
73+# endif /* __hpux */
74+  return (Fd master, slave)
75+
76+-- Push a STREAMS module, for System V systems.
77+pushModule :: Fd -> String -> IO ()
78+pushModule (Fd fd) name =
79+  withCString name $ \p_name ->
80+    throwErrnoIfMinus1_ "openPseudoTerminal"
81+                        (c_push_module fd p_name)
82+
83+foreign import ccall unsafe "__hsunix_push_module"
84+  c_push_module :: CInt -> CString -> IO CInt
85+
86+foreign import ccall unsafe "__hsunix_grantpt"
87+  c_grantpt :: CInt -> IO CInt
88+
89+foreign import ccall unsafe "__hsunix_unlockpt"
90+  c_unlockpt :: CInt -> IO CInt
91+#endif /* !HAVE_OPENPTY */
92+
93hunk ./configure.ac 17
94+AC_CHECK_HEADERS([libutil.h pty.h utmp.h])
95hunk ./configure.ac 24
96+AC_CHECK_FUNCS([ptsname])
97hunk ./configure.ac 142
98+AC_CHECK_FUNCS(openpty,,
99+   AC_CHECK_LIB(util,openpty,
100+     [AC_DEFINE(HAVE_OPENPTY) EXTRA_LIBS="$EXTRA_LIBS util"],
101+     AC_CHECK_LIB(bsd,openpty, [AC_DEFINE(HAVE_OPENPTY) EXTRA_LIBS="$EXTRA_LIBS bsd"])
102+   )
103+)
104+
105+AC_MSG_CHECKING(for /dev/ptmx)
106+if test -r /dev/ptmx
107+then
108+  AC_MSG_RESULT(yes)
109+  AC_DEFINE(HAVE_DEV_PTMX, 1,
110+  [Define if we have /dev/ptmx.])
111+else
112+  AC_MSG_RESULT(no)
113+fi
114+
115+AC_MSG_CHECKING(for /dev/ptc)
116+if test -r /dev/ptc
117+then
118+  AC_MSG_RESULT(yes)
119+  AC_DEFINE(HAVE_DEV_PTC, 1,
120+  [Define if we have /dev/ptc.])
121+else
122+  AC_MSG_RESULT(no)
123+fi
124+
125hunk ./configure.ac 170
126-AC_CHECK_LIB(dl, dlopen, [EXTRA_LIBS=dl], [EXTRA_LIBS=])
127+AC_CHECK_LIB(dl, dlopen, [EXTRA_LIBS="$EXTRA_LIBS dl"])
128hunk ./include/HsUnix.h 77
129+#ifdef HAVE_LIBUTIL_H
130+#include <libutil.h>
131+#endif
132+#ifdef HAVE_PTY_H
133+#include <pty.h>
134+#endif
135+#ifdef HAVE_UTMP_H
136+#include <utmp.h>
137+#endif
138+
139hunk ./include/HsUnix.h 142
140+
141+#ifdef HAVE_PTSNAME
142+// I cannot figure out how to make the definitions of the following
143+// functions visible in <stdlib.h> on Linux.  But these definitions
144+// follow the POSIX specs, and everything links and runs.
145+
146+INLINE char *__hsunix_ptsname(int fd)
147+{
148+    extern char *ptsname(int);
149+    return ptsname(fd);
150+}
151+
152+INLINE int __hsunix_grantpt(int fd)
153+{
154+    extern int grantpt(int);
155+    return grantpt(fd);
156+}
157+
158+INLINE int __hsunix_unlockpt(int fd)
159+{
160+    extern int unlockpt(int);
161+    return unlockpt(fd);
162+}
163+#endif
164+
165+// push a SVR4 STREAMS module; do nothing if STREAMS not available
166+INLINE int __hsunix_push_module(int fd, const char *module)
167+{
168+#if defined(I_PUSH) && !defined(__CYGWIN__) && !defined(HAVE_DEV_PTC)
169+    return ioctl(fd, I_PUSH, module);
170+#else
171+    return 0;
172+#endif
173+}
174}
175
176Context:
177
178[--configure-option and --ghc-option are now provided by Cabal
179Ross Paterson <[email protected]>**20070604115617]
180[Add support for named semaphores and shared memory objects
181Daniel Franke <[email protected]>**20070503220003]
182[Remove Makefile and package.conf.in (used in the old build system)
183Ian Lynagh <[email protected]>**20070524142637]
184[We now depend on process
185Ian Lynagh <[email protected]>**20070523181544]
186[We now depend on directory
187Ian Lynagh <[email protected]>**20070519160513]
188[add includes: field
189Simon Marlow <[email protected]>**20070517095025]
190[Fix calling getAllUserEntries twice (trac #1279).
191Ian Lynagh <[email protected]>**20070504104956
192 It used to return [] on all but the first call.
193 Patch from an unidentified guest.
194]
195[Make it more obvious that the forkprocess01 test is really working
196Ian Lynagh <[email protected]>**20070418114542]
197[Follow Cabal changes in Setup.hs
198Ian Lynagh <[email protected]>**20070418114510]
199[Handle sysconf(3) return value -1 when checking _SC_GETGR_R_SIZE_MAX and _SC_GETPW_R_SIZE_MAX.
200[email protected]**20070416214837
201 sysconf(3) returns -1 on failure, but this was not handled when checking _SC_GETGR_R_SIZE_MAX and _SC_GETPW_R_SIZE_MAX in System.Posix.User. This made getUserEntryForID, getUserEntryForName, getGroupEntryForID and getGroupEntryForName fail on OS X 10.4.9 on i386. Just checking that unistd.h defines _SC_GETGR_R_SIZE_MAX and _SC_GETPW_R_SIZE_MAX as was done before does not guarantee that sysconf(3) will succeed.
202 
203 sysconf(3) failure is now handled by using the same default values as were already used when sysconf(3) is not available, or the parameter names are not defined.
204]
205[Added tests/user001.hs which tests all the get* functions in System.Posix.User.
206[email protected]**20070416220012
207 I added this since I noticed that getUserEntryForID, getUserEntryForName,
208 getGroupEntryForID and getGroupEntryForName failed on OS X 10.4.9 on i386.
209]
210[Fix -Wall warnings
211Ian Lynagh <[email protected]>**20070411005028]
212[Add missing case in removePrefix
213Ian Lynagh <[email protected]>**20070411002604]
214[parse (but don't pass on) options for ./configure
215Ian Lynagh <[email protected]>**20070406153756]
216[make Setup suitable for building the libraries with GHC
217Ian Lynagh <[email protected]>**20061112214741]
218[Don't use Fd/FD in foreign decls
219Ian Lynagh <[email protected]>**20070404155930
220 Using CInt makes it much easier to verify that it is right, and we won't
221 get caught out by possible newtype switches between CInt/Int.
222]
223[Fix C/Haskell type mismatches
224Ian Lynagh <[email protected]>**20070404003625]
225[Follow type changes in base
226Ian Lynagh <[email protected]>**20070403195237
227 (of the dubiously exported c_access and c_fcntl_write)
228]
229[fix cut-and-pasto in error message
230Simon Marlow <[email protected]>**20070308134418]
231[add tests from GHC testsuite
232Simon Marlow <[email protected]>**20070305145258]
233[export the file-type modes, so that createDevice can be used
234Simon Marlow <[email protected]>**20070305113316]
235[Provide nanosleep if we have it, and use it to implement usleep
236Simon Marlow <[email protected]>**20070302132818
237 Fixes #1156
238]
239[don't retry usleep() on EINTR (see #850/#1156)
240Simon Marlow <[email protected]>**20070302114118]
241[expand docs for forkProcess
242Simon Marlow <[email protected]>**20070301151220]
243[add C wrappers for lstat() and mknod().  Fixes #1086.
244Simon Marlow <[email protected]>**20070226110311]
245[README about building from darcs
246Ross Paterson <[email protected]>**20070218110201]
247[TAG 6.6 release
248Ian Lynagh <[email protected]>**20061011124740]
249Patch bundle hash:
250741ba2e3e3ebdf13ef4cb8a78ac96f0a689b00c9