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