Purpose: Open a LogChannel to use a private logserver file

Return TypeFunction nameArguments
hzEcodehzLogger::OpenPrivate(const char*,hzLogRotate,uint32_t,)

Declared in file: hzProcess.h
Defined in file : hzLogger.cpp

Function Logic:

0:START 1:unknown 2:Return E_HOSTFAIL 3:21 4:nSize nProcID nUsr nGrp u u items nSize u items items items nProcID u items items items nUsr u items items items nGrp u items items items nPerms u u items 5:unknown 6:Return E_SENDFAIL 7:unknown 8:Return E_RECVFAIL 9:unknown 10:m_nSessID m_nSessID m_nSessID m_nSessID m_cvData m_pDataPtr 11:Return E_OK 12:Return E_PROTOCOL

Function body:

hzEcode hzLogger::OpenPrivate (const char* fpath)hzLogRotate eRotate, uint32_t nPerms, 
{
   //  Purpose: Open a LogChannel to use a private logserver file
   //  
   //  Arguments: 1) fpath The base pathname of the logfile
   //     2) eRotate The log rotate edict
   //     3) nPerms Access permissions to be applied to the file. This will be ignored by the logserver if the file already exists and the calling
   //        process has write permission.
   //  
   //  Returns: E_HOSTFAIL If no connection to the logserver could be established
   //     E_SENDFAIL If the open command could not be sent to the logserver
   //     E_RECVFAIL If the logserver's response could not be received
   //     E_WRITEFAIL If the logserver fails to find the named public logfile
   //     E_PROTOCOL If the uid of the calling process is not permitted to write to the file
   //     E_OK  If the logserver has opened a channel to the named public logfile
   _hzfunc("hzLogger::OpenPrivate") ;
   uint32_t    nSize ;     //  Size of logserver client request
   uint32_t    nUsr ;      //  UNIX user id
   uint32_t    nGrp ;      //  UNIX group id
   uint32_t    nProcID ;   //  Caller process id
   uchar*      u ;         //  Pointer into message buffer
   //  Connect to the logserver
   if (m_pConnection->ConnectStd(s_LocalHost, PORT_LOGSERVER) != E_OK)
       return E_HOSTFAIL ;
   //  Prepare header
   nSize = 21+strlen(fpath) ;
   nProcID = getpid() ;
   nUsr = geteuid() ;
   nGrp = getegid() ;
   u = (uchar*) m_cvData ;
   //  Command
   u[ 0]= LS_OPEN_PUB ;
   //  Size of message
   u[ 1]= (nSize & 0xff00)>>8;
   u[ 2]= (nSize & 0xff);
   //  Process ID
   u[ 3]= (nProcID & 0xff000000)>>24;
   u[ 4]= (nProcID & 0xff0000)>>16;
   u[ 5]= (nProcID & 0xff00)>>8;
   u[ 6]= (nProcID & 0xff);
   //  User ID
   u[ 7]= (nUsr & 0xff000000)>>24;
   u[ 8]= (nUsr & 0xff0000)>>16;
   u[ 9]= (nUsr & 0xff00)>>8;
   u[10]=(nUsr & 0xff);
   //  Group ID
   u[11]=(nGrp & 0xff000000)>>24;
   u[12]=(nGrp & 0xff0000)>>16;
   u[13]=(nGrp & 0xff00)>>8;
   u[14]=(nGrp & 0xff);
   //  Permissions
   u[15]=(nPerms & 0xff000000)>>24;
   u[16]=(nPerms & 0xff0000)>>16;
   u[17]=(nPerms & 0xff00)>>8;
   u[18]=(nPerms & 0xff);
   //  Rotate edict
   u[19]=eRotate ;
   //  Filename
   strncpy(m_cvData + 20,fpath,HZ_MAXPATHLEN) ;
   //  Send message and recv response
   if (m_pConnection->Send(m_cvData, nSize) != E_OK)
       return E_SENDFAIL ;
   if (m_pConnection->Recv(m_cvData, nSize, 64)!=E_OK)
       return E_RECVFAIL ;
   if (nSize == 4&& m_cvData[0]== LS_OK)
   {
       m_nSessID = 0;
       m_nSessID |= (u[1]<< 16);
       m_nSessID |= (u[2]<< 8);
       m_nSessID |= u[3];
       //  Set data pointer
       m_pDataPtr = m_cvData + 10;
       return E_OK ;
   }
   return E_PROTOCOL ;
}