ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libptytty/ptytty.m4
Revision: 1.30
Committed: Wed Nov 23 19:29:27 2011 UTC (12 years, 6 months ago) by sf-exg
Branch: MAIN
Changes since 1.29: +15 -30 lines
Log Message:
Simplify.

File Contents

# User Rev Content
1 root 1.2 dnl this file is part of libptytty, do not make local modifications
2     dnl http://software.schmorp.de/pkg/libptytty
3    
4 sf-exg 1.24 AC_DEFUN([PT_FIND_FILE],
5     [AC_CACHE_CHECK(where $1 is located, pt_cv_path_$1,
6     [AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <stdio.h>
7     #include <stdlib.h>
8 sf-exg 1.25 #include <sys/stat.h>
9 sf-exg 1.30 #include <sys/types.h>
10     #ifdef HAVE_UTMPX_H
11     #include <utmpx.h>
12     #endif
13     #ifdef HAVE_UTMP_H
14     #include <utmp.h>
15     #endif
16     #ifdef HAVE_LASTLOG_H
17     #include <lastlog.h>
18     #endif
19 sf-exg 1.24 int main()
20     {
21 sf-exg 1.27 const char **path, *list[] = { $4, NULL };
22 sf-exg 1.25 FILE *f = fopen("conftestval", "w");
23     if (!f) return 1;
24 sf-exg 1.24 #ifdef $2
25     fprintf(f, "%s\n", $2);
26 sf-exg 1.25 #elif defined($3)
27 sf-exg 1.24 fprintf(f, "%s\n", $3);
28 sf-exg 1.25 #else
29 sf-exg 1.24 for (path = list; *path; path++) {
30 sf-exg 1.25 struct stat st;
31     if (stat(*path, &st) == 0) {
32 sf-exg 1.24 fprintf(f, "%s\n", *path);
33 sf-exg 1.25 break;
34 sf-exg 1.24 }
35     }
36 sf-exg 1.25 #endif
37     return fclose(f) != 0;
38 sf-exg 1.24 }]])],[pt_cv_path_$1=`cat conftestval`],[pt_cv_path_$1=],
39     [AC_MSG_WARN(Define $2 in config.h manually)])])
40     if test x$pt_cv_path_$1 != x; then
41     AC_DEFINE_UNQUOTED($2, "$pt_cv_path_$1", Define location of $1)
42     fi])
43    
44 ayin 1.1 AC_DEFUN([PTY_CHECK],
45     [
46     AC_CHECK_HEADERS( \
47     pty.h \
48     util.h \
49     libutil.h \
50     sys/ioctl.h \
51     sys/stropts.h \
52 root 1.17 stropts.h \
53 ayin 1.1 )
54    
55     AC_CHECK_FUNCS( \
56     revoke \
57     _getpty \
58     getpt \
59     posix_openpt \
60     isastream \
61 root 1.7 setuid \
62     seteuid \
63     setreuid \
64     setresuid \
65 ayin 1.1 )
66    
67 sf-exg 1.29 AC_MSG_CHECKING(for UNIX98 ptys)
68     AC_LINK_IFELSE(
69     [AC_LANG_PROGRAM(
70     [[#include <stdlib.h>]],
71     [[grantpt(0);unlockpt(0);ptsname(0);]])],
72     [unix98_pty=yes
73     AC_DEFINE(UNIX98_PTY, 1, "")
74     AC_MSG_RESULT(yes)],
75     [AC_MSG_RESULT(no)])
76 ayin 1.1
77     if test -z "$unix98_pty"; then
78 sf-exg 1.21 AC_SEARCH_LIBS(openpty, util, AC_DEFINE(HAVE_OPENPTY, 1, ""))
79 ayin 1.1 fi
80     ])
81    
82     AC_DEFUN([UTMP_CHECK],
83     [
84 ayin 1.5 support_utmp=yes
85     support_wtmp=yes
86     support_lastlog=yes
87    
88 ayin 1.4 AC_ARG_ENABLE(utmp,
89 ayin 1.11 [AS_HELP_STRING([--enable-utmp],[enable utmp (utmpx) support])],
90 ayin 1.4 [if test x$enableval = xyes -o x$enableval = xno; then
91     support_utmp=$enableval
92     fi])
93    
94     AC_ARG_ENABLE(wtmp,
95 ayin 1.11 [AS_HELP_STRING([--enable-wtmp],[enable wtmp (wtmpx) support (requires --enable-utmp)])],
96 ayin 1.4 [if test x$enableval = xyes -o x$enableval = xno; then
97     support_wtmp=$enableval
98     fi])
99    
100     AC_ARG_ENABLE(lastlog,
101 ayin 1.11 [AS_HELP_STRING([--enable-lastlog],[enable lastlog support (requires --enable-utmp)])],
102 ayin 1.4 [if test x$enableval = xyes -o x$enableval = xno; then
103     support_lastlog=$enableval
104     fi])
105    
106     if test x$support_utmp = xyes; then
107     AC_DEFINE(UTMP_SUPPORT, 1, Define if you want to have utmp/utmpx support)
108     fi
109     if test x$support_wtmp = xyes; then
110     AC_DEFINE(WTMP_SUPPORT, 1, Define if you want to have wtmp support when utmp/utmpx is enabled)
111     fi
112     if test x$support_lastlog = xyes; then
113     AC_DEFINE(LASTLOG_SUPPORT, 1, Define if you want to have lastlog support when utmp/utmpx is enabled)
114     fi
115    
116 ayin 1.1 AC_CHECK_FUNCS( \
117     updwtmp \
118     updwtmpx \
119 ayin 1.12 updlastlogx \
120 ayin 1.1 )
121    
122 ayin 1.15 AC_CHECK_HEADERS(lastlog.h)
123 ayin 1.1
124     dnl# --------------------------------------------------------------------------
125     dnl# DO ALL UTMP AND WTMP CHECKING
126     dnl# --------------------------------------------------------------------------
127     dnl# check for host field in utmp structure
128    
129     dnl# --------------------------------------------
130 ayin 1.15 AC_CHECK_HEADERS(utmp.h,
131 sf-exg 1.26 AC_CHECK_TYPES([struct utmp], [], [], [
132     #include <sys/types.h>
133     #include <utmp.h>
134     ])
135 ayin 1.1
136 sf-exg 1.26 AC_CHECK_MEMBER([struct utmp.ut_host],
137     [AC_DEFINE(HAVE_UTMP_HOST, 1, Define if struct utmp contains ut_host)], [], [
138     #include <sys/types.h>
139     #include <utmp.h>
140     ])
141 ayin 1.1
142 sf-exg 1.26 AC_CHECK_MEMBER([struct utmp.ut_pid],
143     [AC_DEFINE(HAVE_UTMP_PID, 1, Define if struct utmp contains ut_pid)], [], [
144     #include <sys/types.h>
145     #include <utmp.h>
146     ])
147 ayin 1.15 ) dnl# AC_CHECK_HEADERS(utmp.h
148 ayin 1.1
149     dnl# --------------------------------------------
150    
151 ayin 1.15 AC_CHECK_HEADERS(utmpx.h,
152 sf-exg 1.26 AC_CHECK_TYPES([struct utmpx], [], [], [
153     #include <sys/types.h>
154     #include <utmpx.h>
155     ])
156 ayin 1.1
157 sf-exg 1.26 AC_CHECK_MEMBER([struct utmpx.ut_host],
158     [AC_DEFINE(HAVE_UTMPX_HOST, 1, Define if struct utmpx contains ut_host)], [], [
159     #include <sys/types.h>
160     #include <utmpx.h>
161     ])
162 ayin 1.1
163 sf-exg 1.26 AC_CHECK_MEMBER([struct utmpx.ut_session],
164     [AC_DEFINE(HAVE_UTMPX_SESSION, 1, Define if struct utmpx contains ut_session)], [], [
165     #include <sys/types.h>
166     #include <utmpx.h>
167     ])
168 ayin 1.15 ) dnl# AC_CHECK_HEADERS(utmpx.h
169 ayin 1.1
170     dnl# --------------------------------------------------------------------------
171     dnl# check for struct lastlog
172 sf-exg 1.26 AC_CHECK_TYPES([struct lastlog], [], [], [
173     #include <sys/types.h>
174 ayin 1.1 #include <utmp.h>
175     #ifdef HAVE_LASTLOG_H
176     #include <lastlog.h>
177     #endif
178 sf-exg 1.26 ])
179 ayin 1.1
180     dnl# check for struct lastlogx
181 sf-exg 1.26 AC_CHECK_TYPES([struct lastlogx], [], [], [
182     #include <sys/types.h>
183 ayin 1.1 #include <utmpx.h>
184     #ifdef HAVE_LASTLOG_H
185     #include <lastlog.h>
186     #endif
187 sf-exg 1.26 ])
188 ayin 1.1
189     dnl# --------------------------------------------------------------------------
190     dnl# FIND FILES
191     dnl# --------------------------------------------------------------------------
192    
193     dnl# find utmp
194 sf-exg 1.24 PT_FIND_FILE([utmp], [UTMP_FILE], [_PATH_UTMP],
195 sf-exg 1.30 ["/var/run/utmp", "/var/adm/utmp", "/etc/utmp", "/usr/etc/utmp", "/usr/adm/utmp"])
196 ayin 1.1
197     dnl# --------------------------------------------------------------------------
198    
199     dnl# find wtmp
200 sf-exg 1.24 PT_FIND_FILE([wtmp], [WTMP_FILE], [_PATH_WTMP],
201 sf-exg 1.30 ["/var/log/wtmp", "/var/adm/wtmp", "/etc/wtmp", "/usr/etc/wtmp", "/usr/adm/wtmp"])
202 ayin 1.1 dnl# --------------------------------------------------------------------------
203    
204     dnl# find wtmpx
205 sf-exg 1.24 PT_FIND_FILE([wtmpx], [WTMPX_FILE], [_PATH_WTMPX],
206 sf-exg 1.30 ["/var/log/wtmpx", "/var/adm/wtmpx"])
207 ayin 1.1 dnl# --------------------------------------------------------------------------
208    
209     dnl# find lastlog
210 sf-exg 1.24 PT_FIND_FILE([lastlog], [LASTLOG_FILE], [_PATH_LASTLOG],
211 sf-exg 1.30 ["/var/log/lastlog"])
212 ayin 1.1 dnl# --------------------------------------------------------------------------
213    
214     dnl# find lastlogx
215 sf-exg 1.24 PT_FIND_FILE([lastlogx], [LASTLOGX_FILE], [_PATH_LASTLOGX],
216 sf-exg 1.30 ["/var/log/lastlogx", "/var/adm/lastlogx"])
217 ayin 1.1 ])
218    
219     AC_DEFUN([SCM_RIGHTS_CHECK],
220     [
221 sf-exg 1.18 AC_CACHE_CHECK(for unix-compliant filehandle passing ability, pt_cv_can_pass_fds,
222 ayin 1.16 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
223 root 1.6 #include <cstddef> // broken bsds (is that redundant?) need this
224 ayin 1.1 #include <sys/types.h>
225     #include <sys/socket.h>
226     #include <sys/uio.h>
227 ayin 1.16 ]], [[
228 ayin 1.1 {
229     msghdr msg;
230     iovec iov;
231     char buf [100];
232     char data = 0;
233    
234     iov.iov_base = &data;
235     iov.iov_len = 1;
236    
237     msg.msg_iov = &iov;
238     msg.msg_iovlen = 1;
239     msg.msg_control = buf;
240     msg.msg_controllen = sizeof buf;
241    
242     cmsghdr *cmsg = CMSG_FIRSTHDR (&msg);
243     cmsg->cmsg_level = SOL_SOCKET;
244     cmsg->cmsg_type = SCM_RIGHTS;
245     cmsg->cmsg_len = 100;
246    
247     *(int *)CMSG_DATA (cmsg) = 5;
248    
249     return sendmsg (3, &msg, 0);
250     }
251 sf-exg 1.18 ]])],[pt_cv_can_pass_fds=yes],[pt_cv_can_pass_fds=no])])
252     if test x$pt_cv_can_pass_fds = xyes; then
253 ayin 1.1 AC_DEFINE(HAVE_UNIX_FDPASS, 1, Define if sys/socket.h defines the necessary macros/functions for file handle passing)
254     else
255     AC_MSG_ERROR([libptytty requires unix-compliant filehandle passing ability])
256     fi
257     ])
258 ayin 1.3
259     AC_DEFUN([TTY_GROUP_CHECK],
260     [
261 sf-exg 1.18 AC_CACHE_CHECK([for tty group], pt_cv_tty_group,
262 ayin 1.16 [AC_RUN_IFELSE([AC_LANG_SOURCE([[
263 ayin 1.3 #include <sys/types.h>
264     #include <sys/stat.h>
265     #include <unistd.h>
266     #include <grp.h>
267    
268 sf-exg 1.22 int main()
269 ayin 1.3 {
270     struct stat st;
271     struct group *gr;
272     char *tty;
273     gr = getgrnam("tty");
274     tty = ttyname(0);
275     if (gr != 0
276     && tty != 0
277     && (stat(tty, &st)) == 0
278     && st.st_gid == gr->gr_gid)
279     return 0;
280     else
281     return 1;
282 sf-exg 1.18 }]])],[pt_cv_tty_group=yes],[pt_cv_tty_group=no],[pt_cv_tty_group=no])])
283     if test x$pt_cv_tty_group = xyes; then
284 ayin 1.3 AC_DEFINE(TTY_GID_SUPPORT, 1, "")
285     fi])
286