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 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 /* $Id: lpd-misc.c 155 2006-04-26 02:34:54Z ktou $ */
30 #define __EXTENSIONS__ /* for strtok_r() */
34 #include <sys/types.h>
39 #include <sys/socket.h>
43 #include <papi_impl.h>
45 #include <config-site.h>
48 fdgets(char *buf
, size_t len
, int fd
)
54 while ((count
< len
) && (read(fd
, &tmp
, 1) > 0))
55 if ((buf
[count
++] = tmp
) == '\n') break;
63 queue_name_from_uri(uri_t
*uri
)
67 if ((uri
!= NULL
) && (uri
->path
!= NULL
)) {
68 char *ptr
= strrchr(uri
->path
, '/');
83 #if defined(sun) && defined(unix) && defined(I_RECVFD)
84 struct strrecvfd recv_fd
;
86 memset(&recv_fd
, NULL
, sizeof (recv_fd
));
87 if (ioctl(sockfd
, I_RECVFD
, &recv_fd
) == 0)
94 struct cmsghdr cmp
[1];
95 char buf
[24]; /* send/recv 2 byte protocol */
97 memset(buf
, 0, sizeof (buf
));
99 iov
[0].iov_base
= buf
;
100 iov
[0].iov_len
= sizeof (buf
);
102 msg
.msg_control
= cmp
;
103 msg
.msg_controllen
= sizeof (struct cmsghdr
) + sizeof (int);
105 iov
[0].iov_base
= NULL
;
107 msg
.msg_accrights
= (caddr_t
)&fd
;
108 msg
.msg_accrights
= sizeof (fd
);
115 if (recvmsg(sockfd
, &msg
, 0) < 0)
119 fd
= * (int *)CMSG_DATA(cmp
);
126 lpd_open(service_t
*svc
, char type
, char **args
, int timeout
)
128 int ac
, rc
= -1, fds
[2];
130 char *av
[64], *tmp
, buf
[BUFSIZ
];
132 if ((svc
== NULL
) || (svc
->uri
== NULL
))
135 #ifndef SUID_LPD_PORT
136 #define SUID_LPD_PORT "/usr/lib/print/lpd-port"
139 av
[0] = SUID_LPD_PORT
; ac
= 1;
143 av
[ac
++] = svc
->uri
->host
;
147 snprintf(buf
, sizeof (buf
), "%d", timeout
);
149 av
[ac
++] = strdup(buf
);
153 snprintf(buf
, sizeof (buf
), "-%c", type
);
157 if (svc
->uri
->path
== NULL
) {
160 if ((tmp
= strrchr(svc
->uri
->path
, '/')) == NULL
)
161 tmp
= svc
->uri
->path
;
169 while ((*args
!= NULL
) && (ac
< 62))
174 #if defined(sun) && defined(unix) && defined(I_RECVFD)
177 socketpair(AF_UNIX
, SOCK_STREAM
, 0, fds
);
180 switch (pid
= fork()) {
181 case -1: /* failed */
185 execv(av
[0], &av
[0]);
189 default: { /* parent */
192 while ((waitpid(pid
, &status
, 0) < 0) && (errno
== EINTR
));
193 errno
= WEXITSTATUS(status
);