4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
30 #pragma ident "%Z%%M% %I% %E% SMI"
36 # include <sys/utsname.h>
38 # include <sys/types.h>
39 # include <sys/stat.h>
44 #define TURN_OFF(X,F) (void)Fcntl(X, F_SETFL, (Fcntl(X, F_GETFL, 0) & ~(F)))
47 static int checklock ( void );
49 static int checklock();
53 ** mconnect() - OPEN A MESSAGE PATH
57 MESG
* mconnect ( char * path
, int id1
, int id2
)
72 ** invoked as mconnect(path, 0, 0)
74 ** Open <path>, if isastream() is true for the returned file
75 ** descriptor, then we're done.
81 ** Verify that the spooler is running and that the
82 ** <path> identifies a pipe.
83 ** This prevents us from getting hung in the open
84 ** and from thinking the <path> is a non-streams pipe.
86 if (checklock() == -1)
88 Again
: if (stat(path
, &stbuf
) == -1)
90 if ((stbuf
.st_mode
& S_IFMT
) != S_IFIFO
) {
97 if ((fd
= Open(path
, O_RDWR
, 0)) == -1)
98 if ((fd
= Open(path
, O_WRONLY
, 0)) == -1)
103 if (isastream(fd
) && !wronly
)
105 #if defined(NOCONNLD)
111 if (ioctl(fd
, I_SENDFD
, fds
[1]) != 0)
117 (void)_Close(fds
[1]);
120 if ((md
= (MESG
*)Malloc(MDSIZE
)) == NULL
)
126 memset(md
, 0, sizeof (MESG
));
128 md
->on_discon
= NULL
;
130 md
->state
= MDS_IDLE
;
131 md
->type
= MD_STREAM
;
135 ResetFifoBuffer (md
->readfd
);
142 if (id1
> 0 && id2
> 0)
144 if ((md
= (MESG
*)Malloc(MDSIZE
)) == NULL
)
150 memset(md
, 0, sizeof (MESG
));
152 md
->on_discon
= NULL
;
154 md
->state
= MDS_IDLE
;
159 ResetFifoBuffer (md
->readfd
);
168 #if defined(__STDC__)
169 static int checklock ( void )
171 static int checklock()
177 if ((fd
= Open(Lp_Schedlock
, O_RDONLY
, 0666)) == -1)
181 * Now, we try to read-lock the lock file. This can only succeed if
182 * the Spooler (lpsched) is down.
185 lock
.l_type
= F_RDLCK
;
188 lock
.l_len
= 0; /* till end of file */
190 if (Fcntl(fd
, F_SETLK
, &lock
) != -1 || errno
!= EAGAIN
)
197 * We can get here only when fcntl() == -1 && errno == EAGAIN,
198 * i.e., spooler (lpsched) is running.