| 1 |
/*--------------------------------------------------------------------- |
| 2 |
* $Date: 2007-05-14 07:27:59 $ $Revision: 1.3 $ |
| 3 |
*--------------------------------------------------------------------- |
| 4 |
* Copyright (c) 1992, Visual Edge Software Ltd. |
| 5 |
* |
| 6 |
* ALL RIGHTS RESERVED. Permission to use, copy, modify, and |
| 7 |
* distribute this software and its documentation for any purpose |
| 8 |
* and without fee is hereby granted, provided that the above |
| 9 |
* copyright notice appear in all copies and that both that |
| 10 |
* copyright notice and this permission notice appear in supporting |
| 11 |
* documentation, and that the name of Visual Edge Software not be |
| 12 |
* used in advertising or publicity pertaining to distribution of |
| 13 |
* the software without specific, written prior permission. The year |
| 14 |
* included in the notice is the year of the creation of the work. |
| 15 |
*--------------------------------------------------------------------- |
| 16 |
* File_Description_Section |
| 17 |
|
| 18 |
070514 last modif |
| 19 |
|
| 20 |
*--------------------------------------------------------------------*/ |
| 21 |
|
| 22 |
#ifndef SP_SPMD_H |
| 23 |
#define SP_SPMD_H |
| 24 |
|
| 25 |
/*--- include files ---*/ |
| 26 |
#include "uxproto.h" |
| 27 |
#include <sys/ipc.h> |
| 28 |
|
| 29 |
#ifndef __USE_GNU |
| 30 |
#define __USE_GNU |
| 31 |
#endif |
| 32 |
|
| 33 |
/* include file sysglue.h not there anymore in OSX 10.4 ... |
| 34 |
#if defined(__Darwin__) |
| 35 |
#include <netat/sysglue.h> |
| 36 |
#endif |
| 37 |
*/ |
| 38 |
|
| 39 |
#if defined(__Darwin__) || defined(__FreeBSD__) || defined(Cygwin) |
| 40 |
#include <sys/types.h> |
| 41 |
#include <sys/errno.h> |
| 42 |
|
| 43 |
#include "msg.h" /* #include <sys/msg.h> */ |
| 44 |
|
| 45 |
#ifndef Cygwin |
| 46 |
#include <sys/msgbuf.h> |
| 47 |
#endif |
| 48 |
|
| 49 |
#else |
| 50 |
#include <sys/msg.h> |
| 51 |
#endif |
| 52 |
|
| 53 |
|
| 54 |
#include <sys/stat.h> /* For S_IWUSR, S_IRUSR permission mode masks. */ |
| 55 |
|
| 56 |
#ifdef __cplusplus |
| 57 |
extern "C" { /* C++ compatability */ |
| 58 |
#endif /* __cplusplus */ |
| 59 |
|
| 60 |
|
| 61 |
/*--- macro symbolic constants ---*/ |
| 62 |
/* |
| 63 |
* message types: |
| 64 |
* for protocol between application and Sub-Process Manager Daemon |
| 65 |
*/ |
| 66 |
#define SPMD_CREATE 0x1 |
| 67 |
#define SPMD_INPUT 0x2 /* input (to sub-process, from application) */ |
| 68 |
#define SPMD_OUTPUT 0x4 /* output (from sub-process, to application) */ |
| 69 |
#define SPMD_DIED 0x8 |
| 70 |
#define SPMD_RSP 0x20 /* used to ACK or NACK _CREATE and/or _INPUT */ |
| 71 |
#define SPMD_EXIT 0x40 /* used when SPMD must exit */ |
| 72 |
|
| 73 |
#define SIZEOFTEXTMSG (MSGMAX - 10) /* subtract 10 for safety */ |
| 74 |
#define SIZEOFMAXMSGBUF (MSGMAX + sizeof(long)) |
| 75 |
|
| 76 |
#define ACK 3 |
| 77 |
#define NACK 12 |
| 78 |
|
| 79 |
/* We can't select() on the msg queue, so we can't use XtAddInput (). |
| 80 |
* Instead we schedule a check every SpmdInterval millisecs. |
| 81 |
* See spmd_read_msg() |
| 82 |
*/ |
| 83 |
#define SHORT_INTERVAL 100 |
| 84 |
#define LONG_INTERVAL 500 |
| 85 |
|
| 86 |
#define UX_PREPARE_COMMAND UxSubprocMgr.prepare_command_m |
| 87 |
#define UX_SET_PARENT_SIDE UxSubprocMgr.set_parent_side_m |
| 88 |
#define UX_SETUP_PARENT_COMMUNICATION UxSubprocMgr.setup_parent_communication_m |
| 89 |
#define UX_START_CHILD UxSubprocMgr.start_child_m |
| 90 |
#define UX_SET_CHILD_SIDE UxSubprocMgr.set_child_side_m |
| 91 |
#define UX_SETUP_CHILD_COMMUNICATION UxSubprocMgr.setup_child_communication_m |
| 92 |
#define UX_SPMD_EXEC_SUBPROCESS UxSubprocMgr.exec_subprocess_m |
| 93 |
#define UX_CLOSE_COMMUNICATION UxSubprocMgr.close_communication_m |
| 94 |
|
| 95 |
|
| 96 |
/*--- macro functions ---*/ |
| 97 |
#ifdef DEBUG |
| 98 |
#if defined(__STDC__) && !defined(apollo) |
| 99 |
#define ASSERT(EX) if (!(EX)) \ |
| 100 |
fprintf(stderr, \ |
| 101 |
"Assert %s failed, File %s, Line %d\n", #EX, \ |
| 102 |
__FILE__, __LINE__) |
| 103 |
#else |
| 104 |
# define ASSERT(EX) if (!(EX)) \ |
| 105 |
fprintf(stderr, \ |
| 106 |
"Assert %s failed, File %s, Line %d\n", "EX", \ |
| 107 |
__FILE__, __LINE__) |
| 108 |
#endif /* (__STDC__) && !(apollo) */ |
| 109 |
|
| 110 |
#else /*DEBUG*/ |
| 111 |
#define ASSERT(EX) |
| 112 |
#endif /*DEBUG*/ |
| 113 |
|
| 114 |
|
| 115 |
/*--- types ---*/ |
| 116 |
typedef struct { /* Sub-Process Manager Daemon description */ |
| 117 |
int spmd_pid; /* process id */ |
| 118 |
int spmd_cp_msqid; /* daemon (child) -> app (parent) msg queue */ |
| 119 |
int spmd_pc_msqid; /* app (parent) -> daemon (child) msg queue */ |
| 120 |
struct { /* last message received from daemon */ |
| 121 |
int msgsiz; |
| 122 |
char *msgrp; /* SPMD_OUTPUT ptr into spmd_output_t msg */ |
| 123 |
|
| 124 |
#if defined(FreeBSD) || defined(__Darwin__) || defined(Cygwin) |
| 125 |
struct mymsg *msgp; |
| 126 |
#else |
| 127 |
struct msgbuf *msgp; |
| 128 |
#endif |
| 129 |
} spmd_rcv_msg; |
| 130 |
|
| 131 |
#define spmd_rmsgtyp spmd_rcv_msg.msgp->mtype |
| 132 |
#define spmd_rmsgtxt spmd_rcv_msg.msgp->mtext |
| 133 |
#define spmd_rmsgsiz spmd_rcv_msg.msgsiz |
| 134 |
#define spmd_rmsgrp spmd_rcv_msg.msgrp |
| 135 |
#define spmd_rmsgp spmd_rcv_msg.msgp |
| 136 |
} spmd_info_t; |
| 137 |
|
| 138 |
typedef struct |
| 139 |
{ |
| 140 |
int pid; |
| 141 |
int pty; |
| 142 |
int exit_status; |
| 143 |
} spmd_pid_pty_t; |
| 144 |
|
| 145 |
|
| 146 |
/* |
| 147 |
* message structures: these are the actual message formats used. |
| 148 |
* If fields are added to these structures, check that the size of the |
| 149 |
* message sent with msgsnd is changed accordingly. |
| 150 |
*/ |
| 151 |
typedef struct |
| 152 |
{ long mtype; int pid; char output[SIZEOFTEXTMSG]; } spmd_output_t; |
| 153 |
|
| 154 |
typedef struct |
| 155 |
{ long mtype; int pid; char input[SIZEOFTEXTMSG]; } spmd_input_t; |
| 156 |
|
| 157 |
typedef struct |
| 158 |
{ long mtype; int echo; char cmd[SIZEOFTEXTMSG]; } spmd_create_req; |
| 159 |
|
| 160 |
typedef struct |
| 161 |
{ long mtype; int pid; int handle; int response; } spmd_create_rsp; |
| 162 |
|
| 163 |
typedef struct { long mtype; int pid; int status; } spmd_dead_msg; |
| 164 |
|
| 165 |
|
| 166 |
/*--- external functions ---*/ |
| 167 |
extern int UxSpmdReadMsg UXPROTO(( long msgtyp )); |
| 168 |
extern int UxSpmdCreateDaemon UXPROTO(( void )); |
| 169 |
extern int UxExecSubprocess UXPROTO((SubprocInfo_t *sp, char *args)); |
| 170 |
extern int UxWhatSpIsDead UXPROTO((int *status)); |
| 171 |
extern void UxDestroySpmd UXPROTO((void)); |
| 172 |
|
| 173 |
/*--- external variables ---*/ |
| 174 |
extern spmd_info_t UxSpmd; |
| 175 |
|
| 176 |
#ifdef __cplusplus |
| 177 |
} /* Close scope of 'extern "C"' declaration which encloses file. */ |
| 178 |
#endif /* __cplusplus */ |
| 179 |
|
| 180 |
#endif |