14887Schin /*********************************************************************** 24887Schin * * 34887Schin * This software is part of the ast package * 4*12068SRoger.Faulkner@Oracle.COM * Copyright (c) 1985-2010 AT&T Intellectual Property * 54887Schin * and is licensed under the * 64887Schin * Common Public License, Version 1.0 * 78462SApril.Chin@Sun.COM * by AT&T Intellectual Property * 84887Schin * * 94887Schin * A copy of the License is available at * 104887Schin * http://www.opensource.org/licenses/cpl1.0.txt * 114887Schin * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * 124887Schin * * 134887Schin * Information and Software Systems Research * 144887Schin * AT&T Research * 154887Schin * Florham Park NJ * 164887Schin * * 174887Schin * Glenn Fowler <gsf@research.att.com> * 184887Schin * David Korn <dgk@research.att.com> * 194887Schin * Phong Vo <kpv@research.att.com> * 204887Schin * * 214887Schin ***********************************************************************/ 224887Schin #pragma prototyped 234887Schin 244887Schin /* 254887Schin * process library interface 264887Schin */ 274887Schin 284887Schin #ifndef _PROC_H 294887Schin #define _PROC_H 304887Schin 314887Schin #include <ast.h> 324887Schin 334887Schin #define PROC_ARGMOD (1<<0) /* argv[-1],argv[0] can be modified */ 344887Schin #define PROC_BACKGROUND (1<<1) /* shell background (&) setup */ 358462SApril.Chin@Sun.COM #define PROC_CHECK (1<<17) /* check that command exists */ 364887Schin #define PROC_CLEANUP (1<<2) /* close parent redirect fds on error */ 374887Schin #define PROC_DAEMON (1<<3) /* daemon setup */ 384887Schin #define PROC_ENVCLEAR (1<<4) /* clear environment */ 394887Schin #define PROC_FOREGROUND (1<<14) /* system(3) setup */ 404887Schin #define PROC_GID (1<<5) /* setgid(getgid()) */ 414887Schin #define PROC_IGNORE (1<<6) /* ignore parent pipe errors */ 428462SApril.Chin@Sun.COM #define PROC_IGNOREPATH (1<<16) /* procrun() intercept to ignore path */ 434887Schin #define PROC_OVERLAY (1<<7) /* overlay current process if possible */ 444887Schin #define PROC_PARANOID (1<<8) /* restrict everything */ 454887Schin #define PROC_PRIVELEGED (1<<9) /* setuid(0), setgid(getegid()) */ 464887Schin #define PROC_READ (1<<10) /* proc pipe fd 1 returned */ 474887Schin #define PROC_SESSION (1<<11) /* session leader */ 484887Schin #define PROC_UID (1<<12) /* setuid(getuid()) */ 494887Schin #define PROC_WRITE (1<<13) /* proc pipe fd 0 returned */ 504887Schin #define PROC_ZOMBIE (1<<15) /* proc may leave a zombie behind */ 514887Schin 524887Schin #define PROC_ARG_BIT 14 /* bits per op arg */ 534887Schin #define PROC_OP_BIT 4 /* bits per op */ 544887Schin 554887Schin #define PROC_ARG_NULL ((1<<PROC_ARG_BIT)-1) 564887Schin 574887Schin #define PROC_fd_dup 0x4 584887Schin #define PROC_FD_CHILD 0x1 594887Schin #define PROC_FD_PARENT 0x2 604887Schin 614887Schin #define PROC_sig_dfl 0x8 624887Schin #define PROC_sig_ign 0x9 634887Schin 644887Schin #define PROC_sys_pgrp 0xa 654887Schin #define PROC_sys_umask 0xb 664887Schin 674887Schin #define PROC_op1(o,a) (((o)<<(2*PROC_ARG_BIT))|((a)&((PROC_ARG_NULL<<PROC_ARG_BIT)|PROC_ARG_NULL))) 684887Schin #define PROC_op2(o,a,b) (((o)<<(2*PROC_ARG_BIT))|(((b)&PROC_ARG_NULL)<<PROC_ARG_BIT)|((a)&PROC_ARG_NULL)) 694887Schin 704887Schin #define PROC_FD_CLOSE(p,f) PROC_op2(PROC_fd_dup|(f),p,PROC_ARG_NULL) 714887Schin #define PROC_FD_DUP(p,c,f) PROC_op2(PROC_fd_dup|(f),p,c) 724887Schin #define PROC_SIG_DFL(s) PROC_op1(PROC_sig_dfl,s,0) 734887Schin #define PROC_SIG_IGN(s) PROC_op1(PROC_sig_ign,s,0) 744887Schin #define PROC_SYS_PGRP(g) PROC_op1(PROC_sys_pgrp,g) 754887Schin #define PROC_SYS_UMASK(m) PROC_op1(PROC_sys_umask,m,0) 764887Schin 774887Schin #define PROC_OP(x) (((x)>>(2*PROC_ARG_BIT))&((1<<PROC_OP_BIT)-1)) 784887Schin #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))) 794887Schin 804887Schin typedef struct 814887Schin { 824887Schin pid_t pid; /* process id */ 834887Schin pid_t pgrp; /* process group id */ 844887Schin int rfd; /* read fd if applicable */ 854887Schin int wfd; /* write fd if applicable */ 864887Schin 874887Schin #ifdef _PROC_PRIVATE_ 884887Schin _PROC_PRIVATE_ 894887Schin #endif 904887Schin 914887Schin } Proc_t; 924887Schin 934887Schin #if _BLD_ast && defined(__EXPORT__) 944887Schin #define extern __EXPORT__ 954887Schin #endif 964887Schin 974887Schin extern int procclose(Proc_t*); 984887Schin extern int procfree(Proc_t*); 998462SApril.Chin@Sun.COM extern Proc_t* procopen(const char*, char**, char**, long*, int); 1008462SApril.Chin@Sun.COM extern int procrun(const char*, char**, int); 1014887Schin 1024887Schin #undef extern 1034887Schin 1044887Schin #endif 105