1/*********************************************************************** 2* * 3* This software is part of the ast package * 4* Copyright (c) 1990-2011 AT&T Intellectual Property * 5* and is licensed under the * 6* Common Public License, Version 1.0 * 7* by AT&T Intellectual Property * 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* * 19***********************************************************************/ 20#pragma prototyped 21/* 22 * Glenn Fowler 23 * AT&T Research 24 * 25 * coshell library interface 26 */ 27 28#ifndef _COSHELL_H 29#define _COSHELL_H 30 31#include <ast.h> 32 33#if !_BLD_coshell 34 35#undef procrun 36#define procrun(a,b,c) coprocrun(a,b,c) 37#undef system 38#define system(a) cosystem(a) 39 40#endif 41 42struct Coshell_s; typedef struct Coshell_s Coshell_t; 43struct Cojob_s; typedef struct Cojob_s Cojob_t; 44 45/* 46 * DEPRECATED names for compatibility 47 */ 48 49#define COSHELL Coshell_t 50#define COJOB Cojob_t 51 52#define CO_ID "coshell" /* library/command id */ 53 54#define CO_ENV_ATTRIBUTES "COATTRIBUTES"/* coshell attributes env var */ 55#define CO_ENV_EXPORT "COEXPORT" /* coshell env var export list */ 56#define CO_ENV_HOST "HOSTNAME" /* coshell host name env var */ 57#define CO_ENV_MSGFD "_COSHELL_msgfd"/* msg fd */ 58#define CO_ENV_OPTIONS "COSHELL_OPTIONS"/* options environment var */ 59#define CO_ENV_PROC "NPROC" /* concurrency environment var */ 60#define CO_ENV_SHELL "COSHELL" /* coshell path environment var */ 61#define CO_ENV_TEMP "COTEMP" /* 10 char temp file base */ 62#define CO_ENV_TYPE "HOSTTYPE" /* coshell host type env var */ 63 64#define CO_OPT_ACK "ack" /* wait for server coexec() ack */ 65#define CO_OPT_INDIRECT "indirect" /* indirect server connection */ 66#define CO_OPT_SERVER "server" /* server connection */ 67 68#define CO_QUANT 100 /* time quanta per sec */ 69 70#define CO_ANY 0x000001 /* return any open coshell */ 71#define CO_DEBUG 0x000002 /* library debug trace */ 72#define CO_EXPORT 0x000004 /* export everything */ 73#define CO_IGNORE 0x000008 /* ignore command errors */ 74#define CO_LOCAL 0x000010 /* local affinity */ 75#define CO_NONBLOCK 0x000020 /* don't block coexec if Q full */ 76#define CO_SHELL 0x000040 /* shell using coshell! */ 77#define CO_SILENT 0x000080 /* don't trace commands */ 78 79#define CO_KSH 0x000100 /* coshell is ksh (readonly) */ 80#define CO_SERVER 0x000200 /* coshell is server (readonly) */ 81#define CO_OSH 0x000400 /* coshell is OLD (readonly) */ 82 83#define CO_CROSS 0x000800 /* don't prepend local dirs */ 84#define CO_DEVFD 0x001000 /* coshell handles /dev/fd/# */ 85 86#define CO_SERIALIZE 0x002000 /* serialize stdout and stderr */ 87#define CO_SERVICE 0x004000 /* service callouts */ 88 89#define CO_APPEND 0x008000 /* append coexec() out/err */ 90#define CO_SEPARATE 0x010000 /* 1 shell+wait per coexec() */ 91#define CO_ORPHAN 0x020000 /* PROC_ORPHAN */ 92 93#define CO_USER 0x100000 /* first user flag */ 94 95struct Cojob_s /* coshell job info */ 96{ 97 Coshell_t* coshell; /* running in this coshell */ 98 int id; /* job id */ 99 int status; /* exit status */ 100 int flags; /* CO_* flags */ 101 void* local; /* local info */ 102 unsigned long user; /* user time in 1/CO_QUANT secs */ 103 unsigned long sys; /* sys time in 1/CO_QUANT secs */ 104#ifdef _CO_JOB_PRIVATE_ 105 _CO_JOB_PRIVATE_ /* library private additions */ 106#endif 107}; 108 109struct Coshell_s /* coshell connection info */ 110{ 111 void* data; /* user data, initially 0 */ 112 int flags; /* flags */ 113 int outstanding; /* number of outstanding jobs */ 114 int running; /* number of running jobs */ 115 int total; /* number of coexec() jobs */ 116 unsigned long user; /* user time in 1/CO_QUANT secs */ 117 unsigned long sys; /* sys time in 1/CO_QUANT secs */ 118 Sfio_t* msgfp; /* message stream for sfpoll() */ 119#ifdef _CO_SHELL_PRIVATE_ 120 _CO_SHELL_PRIVATE_ /* library private additions */ 121#endif 122}; 123 124extern int coclose(Coshell_t*); 125extern Cojob_t* coexec(Coshell_t*, const char*, int, const char*, const char*, const char*); 126extern char* coinit(int); 127extern int coexport(Coshell_t*, const char*, const char*); 128extern int cokill(Coshell_t*, Cojob_t*, int); 129extern Coshell_t* coopen(const char*, int, const char*); 130extern void coquote(Sfio_t*, const char*, int); 131extern int cosync(Coshell_t*, const char*, int, int); 132extern Cojob_t* cowait(Coshell_t*, Cojob_t*, int); 133 134extern int cojobs(Coshell_t*); 135extern int copending(Coshell_t*); 136extern int cozombie(Coshell_t*); 137 138extern int coattr(Coshell_t*, const char*); 139 140extern int coprocrun(const char*, char**, int); 141extern int cosystem(const char*); 142 143#endif 144