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