xref: /illumos-gate/usr/src/cmd/lp/lib/msgs/mcreate.c (revision 8019f4e761252f7a9d2af104a4efe6419528dc21)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1996 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 # include	<unistd.h>
31 # include	<string.h>
32 # include	<stropts.h>
33 # include	<errno.h>
34 # include	<stdlib.h>
35 
36 # include	"lp.h"
37 # include	"msgs.h"
38 
39 #if	defined(__STDC__)
40 MESG * mcreate ( char * path )
41 #else
42 MESG * mcreate (path)
43     char	*path;
44 #endif
45 {
46     int			fds[2];
47     MESG		*md;
48 
49     if (pipe(fds) != 0)
50 	return(NULL);
51 
52 #if	!defined(NOCONNLD)
53     if (ioctl(fds[1], I_PUSH, "connld") != 0)
54 	return(NULL);
55 #endif
56 
57     if (fattach(fds[1], path) != 0)
58         return(NULL);
59 
60     if ((md = (MESG *)Malloc(MDSIZE)) == NULL)
61 	return(NULL);
62 
63     memset(md, 0, sizeof (MESG));
64     md->admin = 1;
65     md->file = Strdup(path);
66     md->gid = getgid();
67     md->readfd = fds[0];
68     md->state = MDS_IDLE;
69     md->type = MD_MASTER;
70     md->uid = getuid();
71 #if 1
72     md->writefd = fds[1];
73 #else
74     md->writefd = fds[0];
75     close(fds[1]);
76 #endif
77 
78     return(md);
79 }
80