1 /*
2  * BEGIN illumos section
3  *   This is an unstable interface; changes may be made
4  *   without notice.
5  * END illumos section
6  */
7 /***********************************************************************
8 *                                                                      *
9 *               This software is part of the ast package               *
10 *          Copyright (c) 1985-2011 AT&T Intellectual Property          *
11 *                      and is licensed under the                       *
12 *                 Eclipse Public License, Version 1.0                  *
13 *                    by AT&T Intellectual Property                     *
14 *                                                                      *
15 *                A copy of the License is available at                 *
16 *          http://www.eclipse.org/org/documents/epl-v10.html           *
17 *         (with md5 checksum b35adb5213ca9657e911e9befb180842)         *
18 *                                                                      *
19 *              Information and Software Systems Research               *
20 *                            AT&T Research                             *
21 *                           Florham Park NJ                            *
22 *                                                                      *
23 *                 Glenn Fowler <gsf@research.att.com>                  *
24 *                  David Korn <dgk@research.att.com>                   *
25 *                   Phong Vo <kpv@research.att.com>                    *
26 *                                                                      *
27 ***********************************************************************/
28 #pragma prototyped
29 
30 /*
31  * process library interface
32  */
33 
34 #ifndef _PROC_H
35 #define _PROC_H
36 
37 #include <ast.h>
38 
39 #define PROC_ARGMOD	(1<<0)	/* argv[-1],argv[0] can be modified	*/
40 #define PROC_BACKGROUND	(1<<1)	/* shell background (&) setup		*/
41 #define PROC_CHECK	(1<<17)	/* check that command exists		*/
42 #define PROC_CLEANUP	(1<<2)	/* close parent redirect fds on error	*/
43 #define PROC_DAEMON	(1<<3)	/* daemon setup				*/
44 #define PROC_ENVCLEAR	(1<<4)	/* clear environment			*/
45 #define PROC_FOREGROUND	(1<<14)	/* system(3) setup			*/
46 #define PROC_GID	(1<<5)	/* setgid(getgid())			*/
47 #define PROC_IGNORE	(1<<6)	/* ignore parent pipe errors		*/
48 #define PROC_IGNOREPATH	(1<<16)	/* procrun() intercept to ignore path	*/
49 #define PROC_ORPHAN	(1<<18)	/* create orphaned process		*/
50 #define PROC_OVERLAY	(1<<7)	/* overlay current process if possible	*/
51 #define PROC_PARANOID	(1<<8)	/* restrict everything			*/
52 #define PROC_PRIVELEGED	(1<<9)	/* setuid(0), setgid(getegid())		*/
53 #define PROC_READ	(1<<10)	/* proc pipe fd 1 returned		*/
54 #define PROC_SESSION	(1<<11)	/* session leader			*/
55 #define PROC_UID	(1<<12)	/* setuid(getuid())			*/
56 #define PROC_WRITE	(1<<13)	/* proc pipe fd 0 returned		*/
57 #define PROC_ZOMBIE	(1<<15)	/* proc may leave a zombie behind	*/
58 
59 #define PROC_ARG_BIT	14	/* bits per op arg			*/
60 #define PROC_OP_BIT	4	/* bits per op				*/
61 
62 #define PROC_ARG_NULL	((1<<PROC_ARG_BIT)-1)
63 
64 #define PROC_fd_dup	0x4
65 #define PROC_FD_CHILD	0x1
66 #define PROC_FD_PARENT	0x2
67 
68 #define PROC_sig_dfl	0x8
69 #define PROC_sig_ign	0x9
70 
71 #define PROC_sys_pgrp	0xa
72 #define PROC_sys_umask	0xb
73 
74 #define PROC_fd_ctty	0xc
75 
76 #define PROC_op1(o,a)	(((o)<<(2*PROC_ARG_BIT))|((a)&((PROC_ARG_NULL<<PROC_ARG_BIT)|PROC_ARG_NULL)))
77 #define PROC_op2(o,a,b)	(((o)<<(2*PROC_ARG_BIT))|(((b)&PROC_ARG_NULL)<<PROC_ARG_BIT)|((a)&PROC_ARG_NULL))
78 
79 #define PROC_FD_CLOSE(p,f)	PROC_op2(PROC_fd_dup|(f),p,PROC_ARG_NULL)
80 #define PROC_FD_CTTY(f)		PROC_op1(PROC_fd_ctty,f)
81 #define PROC_FD_DUP(p,c,f)	PROC_op2(PROC_fd_dup|(f),p,c)
82 #define PROC_SIG_DFL(s)		PROC_op1(PROC_sig_dfl,s,0)
83 #define PROC_SIG_IGN(s)		PROC_op1(PROC_sig_ign,s,0)
84 #define PROC_SYS_PGRP(g)	PROC_op1(PROC_sys_pgrp,g)
85 #define PROC_SYS_UMASK(m)	PROC_op1(PROC_sys_umask,m,0)
86 
87 #define PROC_OP(x)	(((x)>>(2*PROC_ARG_BIT))&((1<<PROC_OP_BIT)-1))
88 #define PROC_ARG(x,n)	((n)?(((x)>>(((n)-1)*PROC_ARG_BIT))&PROC_ARG_NULL):(((x)&~((1<<(2*PROC_ARG_BIT))-1))==~((1<<(2*PROC_ARG_BIT))-1))?(-1):((x)&~((1<<(2*PROC_ARG_BIT))-1)))
89 
90 typedef struct
91 {
92 	pid_t	pid;			/* process id			*/
93 	pid_t	pgrp;			/* process group id		*/
94 	int	rfd;			/* read fd if applicable	*/
95 	int	wfd;			/* write fd if applicable	*/
96 
97 #ifdef _PROC_PRIVATE_
98 _PROC_PRIVATE_
99 #endif
100 
101 } Proc_t;
102 
103 #if _BLD_ast && defined(__EXPORT__)
104 #define extern		__EXPORT__
105 #endif
106 
107 extern int	procclose(Proc_t*);
108 extern int	procfree(Proc_t*);
109 extern Proc_t*	procopen(const char*, char**, char**, long*, int);
110 extern int	procrun(const char*, char**, int);
111 
112 #undef	extern
113 
114 #endif
115