arch/net/charmrun/daemon.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * $Source: /cvsroot/charm/src/arch/net/charmrun/daemon.h,v $
00003  * $Author: gzheng $
00004  * $Date: 2003-10-29 21:46:31 $
00005  * $Revision: 1.1 $
00006  *****************************************************************************/
00007 
00008 #define DAEMON_IP_PORT 12396
00009 
00010 /*This is the structure that is passed to the Daemon when
00011 you want it to start a process.
00012 */
00013 #define DAEMON_MAXPATHLEN 512
00014 #define DAEMON_MAXENV 256
00015 typedef struct {
00016         char pgm[DAEMON_MAXPATHLEN]; /*Name of executable to run (no ".exe" needed)*/
00017         char cwd[DAEMON_MAXPATHLEN];/*Directory in which to start program*/
00018 
00019         char env[DAEMON_MAXENV];/*Environment variables*/
00020 
00021 #define DAEMON_MAGIC 0x7AF2893C
00022         ChMessageInt_t magic;/*Magic number for daemon (a weak security measure)*/
00023         /*Length (bytes) of the program arguments to follow*/
00024         ChMessageInt_t argLength;
00025 } taskStruct;
00026 
00027 /*This table is used to look up the Windows error code
00028 returned by CreateProcess and convert it into a "status code"
00029 character (returned to conv-host) and an error message
00030 (logged and printed by conv-host).
00031 */
00032 #ifndef _WIN32
00033 /*UNIX equivalents to Win32 errors*/
00034 #define ERROR_FILE_NOT_FOUND EACCES
00035 #define ERROR_NOT_ENOUGH_MEMORY ENOMEM
00036 #define ERROR_OUTOFMEMORY E2BIG
00037 #define ERROR_ACCESS_DENIED -1000 /*No equivalent*/
00038 #define ERROR_SHARING_VIOLATION -1000
00039 #define ERROR_BAD_EXE_FORMAT ENOEXEC
00040 #endif
00041 const static struct {
00042                                 int errorCode;
00043                                 char statusCode;/*'G'->sucess; all others failure*/
00044                                 char *reason;
00045 } daemon_errtab[]= {
00046                                 {ERROR_FILE_NOT_FOUND,'F',"executable not found."},
00047                                 {-1,'D',"directory not found."},
00048                                 {ERROR_NOT_ENOUGH_MEMORY,'M',"not enough memory."},
00049                                 {ERROR_OUTOFMEMORY,'M',"not enough memory."},
00050                                 {ERROR_ACCESS_DENIED,'A',"access denied."},
00051                                 {ERROR_SHARING_VIOLATION,'S',"sharing violation."},
00052                                 {ERROR_BAD_EXE_FORMAT,'E',"not an executable."},
00053                                 {-1,'N',"could not contact daemon-- is it running?"},
00054                                 {0,0,NULL}
00055 };
00056 
00057 /*Convert a windows error code into a status character*/
00058 char daemon_err2status(int err)
00059 {
00060         int i;
00061         for (i=0;daemon_errtab[i].reason;i++)
00062                 if (daemon_errtab[i].errorCode==err)
00063                         return daemon_errtab[i].statusCode;
00064         return 'U';/*If it's not in the table, it's an unknown error*/
00065 }
00066 
00067 /*Convert a status character into a human-readable error code*/
00068 const char *daemon_status2msg(char statusCode)
00069 {
00070         int i;
00071         for (i=0;daemon_errtab[i].reason;i++)
00072                 if (daemon_errtab[i].statusCode==statusCode)
00073                         return daemon_errtab[i].reason;
00074         return "unknown error.";
00075 }
00076 
00077 
00078 
00079 
00080 

Generated on Sun Jun 29 13:29:06 2008 for Charm++ by  doxygen 1.5.1