xref: /titanic_51/usr/src/cmd/lp/lib/msgs/mcreate.c (revision a31148363f598def767ac48c5d82e1572e44b935)
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 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.7	*/
32 
33 # include	<unistd.h>
34 # include	<string.h>
35 # include	<stropts.h>
36 # include	<errno.h>
37 # include	<stdlib.h>
38 
39 # include	"lp.h"
40 # include	"msgs.h"
41 
42 #if	defined(__STDC__)
43 MESG * mcreate ( char * path )
44 #else
45 MESG * mcreate (path)
46     char	*path;
47 #endif
48 {
49     int			fds[2];
50     MESG		*md;
51 
52     if (pipe(fds) != 0)
53 	return(NULL);
54 
55 #if	!defined(NOCONNLD)
56     if (ioctl(fds[1], I_PUSH, "connld") != 0)
57 	return(NULL);
58 #endif
59 
60     if (fattach(fds[1], path) != 0)
61         return(NULL);
62 
63     if ((md = (MESG *)Malloc(MDSIZE)) == NULL)
64 	return(NULL);
65 
66     memset(md, 0, sizeof (MESG));
67     md->admin = 1;
68     md->file = Strdup(path);
69     md->gid = getgid();
70     md->readfd = fds[0];
71     md->state = MDS_IDLE;
72     md->type = MD_MASTER;
73     md->uid = getuid();
74 #if 1
75     md->writefd = fds[1];
76 #else
77     md->writefd = fds[0];
78     close(fds[1]);
79 #endif
80 
81     return(md);
82 }
83