1N/A/***********************************************************************
1N/A* *
1N/A* This software is part of the ast package *
1N/A* Copyright (c) 1985-2011 AT&T Intellectual Property *
1N/A* and is licensed under the *
1N/A* Common Public License, Version 1.0 *
1N/A* by AT&T Intellectual Property *
1N/A* *
1N/A* A copy of the License is available at *
1N/A* http://www.opensource.org/licenses/cpl1.0.txt *
1N/A* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
1N/A* *
1N/A* Information and Software Systems Research *
1N/A* AT&T Research *
1N/A* Florham Park NJ *
1N/A* *
1N/A* Glenn Fowler <gsf@research.att.com> *
1N/A* David Korn <dgk@research.att.com> *
1N/A* Phong Vo <kpv@research.att.com> *
1N/A* *
1N/A***********************************************************************/
1N/A#pragma prototyped
1N/A
1N/A/*
1N/A * process library interface
1N/A */
1N/A
1N/A#ifndef _PROC_H
1N/A#define _PROC_H
1N/A
1N/A#include <ast.h>
1N/A
1N/A#define PROC_ARGMOD (1<<0) /* argv[-1],argv[0] can be modified */
1N/A#define PROC_BACKGROUND (1<<1) /* shell background (&) setup */
1N/A#define PROC_CHECK (1<<17) /* check that command exists */
1N/A#define PROC_CLEANUP (1<<2) /* close parent redirect fds on error */
1N/A#define PROC_DAEMON (1<<3) /* daemon setup */
1N/A#define PROC_ENVCLEAR (1<<4) /* clear environment */
1N/A#define PROC_FOREGROUND (1<<14) /* system(3) setup */
1N/A#define PROC_GID (1<<5) /* setgid(getgid()) */
1N/A#define PROC_IGNORE (1<<6) /* ignore parent pipe errors */
1N/A#define PROC_IGNOREPATH (1<<16) /* procrun() intercept to ignore path */
1N/A#define PROC_ORPHAN (1<<18) /* create orphaned process */
1N/A#define PROC_OVERLAY (1<<7) /* overlay current process if possible */
1N/A#define PROC_PARANOID (1<<8) /* restrict everything */
1N/A#define PROC_PRIVELEGED (1<<9) /* setuid(0), setgid(getegid()) */
1N/A#define PROC_READ (1<<10) /* proc pipe fd 1 returned */
1N/A#define PROC_SESSION (1<<11) /* session leader */
1N/A#define PROC_UID (1<<12) /* setuid(getuid()) */
1N/A#define PROC_WRITE (1<<13) /* proc pipe fd 0 returned */
1N/A#define PROC_ZOMBIE (1<<15) /* proc may leave a zombie behind */
1N/A
1N/A#define PROC_ARG_BIT 14 /* bits per op arg */
1N/A#define PROC_OP_BIT 4 /* bits per op */
1N/A
1N/A#define PROC_ARG_NULL ((1<<PROC_ARG_BIT)-1)
1N/A
1N/A#define PROC_fd_dup 0x4
1N/A#define PROC_FD_CHILD 0x1
1N/A#define PROC_FD_PARENT 0x2
1N/A
1N/A#define PROC_sig_dfl 0x8
1N/A#define PROC_sig_ign 0x9
1N/A
1N/A#define PROC_sys_pgrp 0xa
1N/A#define PROC_sys_umask 0xb
1N/A
1N/A#define PROC_fd_ctty 0xc
1N/A
1N/A#define PROC_op1(o,a) (((o)<<(2*PROC_ARG_BIT))|((a)&((PROC_ARG_NULL<<PROC_ARG_BIT)|PROC_ARG_NULL)))
1N/A#define PROC_op2(o,a,b) (((o)<<(2*PROC_ARG_BIT))|(((b)&PROC_ARG_NULL)<<PROC_ARG_BIT)|((a)&PROC_ARG_NULL))
1N/A
1N/A#define PROC_FD_CLOSE(p,f) PROC_op2(PROC_fd_dup|(f),p,PROC_ARG_NULL)
1N/A#define PROC_FD_CTTY(f) PROC_op1(PROC_fd_ctty,f)
1N/A#define PROC_FD_DUP(p,c,f) PROC_op2(PROC_fd_dup|(f),p,c)
1N/A#define PROC_SIG_DFL(s) PROC_op1(PROC_sig_dfl,s,0)
1N/A#define PROC_SIG_IGN(s) PROC_op1(PROC_sig_ign,s,0)
1N/A#define PROC_SYS_PGRP(g) PROC_op1(PROC_sys_pgrp,g)
1N/A#define PROC_SYS_UMASK(m) PROC_op1(PROC_sys_umask,m,0)
1N/A
1N/A#define PROC_OP(x) (((x)>>(2*PROC_ARG_BIT))&((1<<PROC_OP_BIT)-1))
1N/A#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)))
1N/A
1N/Atypedef struct
1N/A{
1N/A pid_t pid; /* process id */
1N/A pid_t pgrp; /* process group id */
1N/A int rfd; /* read fd if applicable */
1N/A int wfd; /* write fd if applicable */
1N/A
1N/A#ifdef _PROC_PRIVATE_
1N/A_PROC_PRIVATE_
1N/A#endif
1N/A
1N/A} Proc_t;
1N/A
1N/A#if _BLD_ast && defined(__EXPORT__)
1N/A#define extern __EXPORT__
1N/A#endif
1N/A
1N/Aextern int procclose(Proc_t*);
1N/Aextern int procfree(Proc_t*);
1N/Aextern Proc_t* procopen(const char*, char**, char**, long*, int);
1N/Aextern int procrun(const char*, char**, int);
1N/A
1N/A#undef extern
1N/A
1N/A#endif