irods  4.2.8
About: iRODS (the integrated Rule Oriented Data System) is a distributed data-management system for creating data grids, digital libraries, persistent archives, and real-time data systems.
  Fossies Dox: irods-4.2.8.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

procLog.cpp
Go to the documentation of this file.
1 #include "procLog.h"
2 #include "miscUtil.h"
3 #include "rsGlobalExtern.hpp"
4 #include "rodsConnect.h"
5 #include "rsLog.hpp"
6 
7 #include "arpa/inet.h"
8 
9 #include <fstream>
10 #include <boost/lexical_cast.hpp>
11 
12 int
14  initProcLog();
15  int error_code = mkdir( ProcLogDir, DEFAULT_DIR_MODE );
16  int errsv = errno;
17  if ( error_code != 0 && errsv != EEXIST ) {
18  rodsLog( LOG_ERROR, "mkdir failed in initAndClearProcLog with error code %d", error_code );
19  }
21 
22  return 0;
23 }
24 
25 int
27  snprintf( ProcLogDir, MAX_NAME_LEN, "%s/%s",
29  return 0;
30 }
31 
32 int
33 logAgentProc( rsComm_t *rsComm ) {
34  FILE *fptr;
35  char procPath[MAX_NAME_LEN];
36  char *remoteAddr;
37  char *progName;
38  char *clientZone, *proxyZone;
39 
40  if ( rsComm->procLogFlag == PROC_LOG_DONE ) {
41  return 0;
42  }
43 
44  if ( *rsComm->clientUser.userName == '\0' ||
45  *rsComm->proxyUser.userName == '\0' ) {
46  return 0;
47  }
48 
49  if ( *rsComm->clientUser.rodsZone == '\0' ) {
50  if ( ( clientZone = getLocalZoneName() ) == NULL ) {
51  clientZone = "UNKNOWN";
52  }
53  }
54  else {
55  clientZone = rsComm->clientUser.rodsZone;
56  }
57 
58  if ( *rsComm->proxyUser.rodsZone == '\0' ) {
59  if ( ( proxyZone = getLocalZoneName() ) == NULL ) {
60  proxyZone = "UNKNOWN";
61  }
62  }
63  else {
64  proxyZone = rsComm->proxyUser.rodsZone;
65  }
66 
67  remoteAddr = inet_ntoa( rsComm->remoteAddr.sin_addr );
68  if ( remoteAddr == NULL || *remoteAddr == '\0' ) {
69  remoteAddr = "UNKNOWN";
70  }
71  if ( *rsComm->option == '\0' ) {
72  progName = "UNKNOWN";
73  }
74  else {
75  progName = rsComm->option;
76  }
77 
78  snprintf( procPath, MAX_NAME_LEN, "%s/%-d", ProcLogDir, getpid() );
79 
80  fptr = fopen( procPath, "w" );
81 
82  if ( fptr == NULL ) {
84  "logAgentProc: Cannot open input file %s. errno = %d",
85  procPath, errno );
86  return UNIX_FILE_OPEN_ERR - errno;
87  }
88 
89  fprintf( fptr, "%s %s %s %s %s %s %u\n",
90  rsComm->proxyUser.userName, clientZone,
91  rsComm->clientUser.userName, proxyZone,
92  progName, remoteAddr, ( unsigned int ) time( 0 ) );
93 
94  rsComm->procLogFlag = PROC_LOG_DONE;
95  fclose( fptr );
96  return 0;
97 }
98 
99 int
100 rmProcLog( int pid ) {
101  char procPath[MAX_NAME_LEN];
102 
103  snprintf( procPath, MAX_NAME_LEN, "%s/%-d", ProcLogDir, pid );
104  unlink( procPath );
105  return 0;
106 }
107 
108 int
109 readProcLog( int pid, procLog_t *procLog ) {
110 
111  if ( procLog == NULL ) {
112  return USER__NULL_INPUT_ERR;
113  }
114 
115  char procPath[MAX_NAME_LEN];
116  snprintf( procPath, MAX_NAME_LEN, "%s/%-d", ProcLogDir, pid );
117 
118  std::fstream procStream( procPath, std::ios::in );
119  std::vector<std::string> procTokens;
120  while ( !procStream.eof() && procTokens.size() < 7 ) {
121  std::string token;
122  procStream >> token;
123  procTokens.push_back( token );
124  }
125 
126  if ( procTokens.size() != 7 ) {
128  "readProcLog: error fscanf file %s. Number of param read = %d",
129  procPath, procTokens.size() );
130  return UNIX_FILE_READ_ERR;
131  }
132 
133  procLog->pid = pid;
134 
135  snprintf( procLog->clientName, sizeof( procLog->clientName ), "%s", procTokens[0].c_str() );
136  snprintf( procLog->clientZone, sizeof( procLog->clientZone ), "%s", procTokens[1].c_str() );
137  snprintf( procLog->proxyName, sizeof( procLog->proxyName ), "%s", procTokens[2].c_str() );
138  snprintf( procLog->proxyZone, sizeof( procLog->proxyZone ), "%s", procTokens[3].c_str() );
139  snprintf( procLog->progName, sizeof( procLog->progName ), "%s", procTokens[4].c_str() );
140  snprintf( procLog->remoteAddr, sizeof( procLog->remoteAddr ), "%s", procTokens[5].c_str() );
141  try {
142  procLog->startTime = boost::lexical_cast<unsigned int>( procTokens[6].c_str() );
143  }
144  catch ( ... ) {
145  rodsLog( LOG_ERROR, "Could not convert %s to unsigned int.", procTokens[6].c_str() );
146  return INVALID_LEXICAL_CAST;
147  }
148 
149  return 0;
150 }
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
NULL
#define NULL
Definition: rodsDef.h:70
rsComm_t
Definition: rcConnect.h:145
procLog_t::proxyName
char proxyName[64]
Definition: rodsDef.h:366
procLog_t::clientZone
char clientZone[64]
Definition: rodsDef.h:365
rsLog.hpp
userInfo_t::userName
char userName[64]
Definition: rodsUser.h:66
procLog_t::remoteAddr
char remoteAddr[64]
Definition: rodsDef.h:368
logAgentProc
int logAgentProc(rsComm_t *rsComm)
Definition: procLog.cpp:33
procLog_t::pid
int pid
Definition: rodsDef.h:362
rmProcLog
int rmProcLog(int pid)
Definition: procLog.cpp:100
rsComm_t::option
char option[256]
Definition: rcConnect.h:156
PROC_LOG_DONE
@ PROC_LOG_DONE
Definition: rcConnect.h:90
INVALID_LEXICAL_CAST
@ INVALID_LEXICAL_CAST
Definition: rodsErrorTable.h:768
token
Definition: restructs.hpp:293
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
rodsConnect.h
initProcLog
int initProcLog()
Definition: procLog.cpp:26
rsGlobalExtern.hpp
rmFilesInDir
int rmFilesInDir(char *mydir)
Definition: miscUtil.cpp:2149
UNIX_FILE_OPEN_ERR
@ UNIX_FILE_OPEN_ERR
Definition: rodsErrorTable.h:300
procLog_t::proxyZone
char proxyZone[64]
Definition: rodsDef.h:367
rsComm_t::proxyUser
userInfo_t proxyUser
Definition: rcConnect.h:152
pid_age.pid
pid
Definition: pid_age.py:12
procLog_t::clientName
char clientName[64]
Definition: rodsDef.h:364
rsComm_t::remoteAddr
struct sockaddr_in remoteAddr
Definition: rcConnect.h:150
MAX_NAME_LEN
#define MAX_NAME_LEN
Definition: rodsDef.h:61
getLogDir
char * getLogDir()
Definition: rsLog.cpp:12
userInfo_t::rodsZone
char rodsZone[64]
Definition: rodsUser.h:67
procLog_t::startTime
unsigned int startTime
Definition: rodsDef.h:363
rsComm_t::clientUser
userInfo_t clientUser
Definition: rcConnect.h:153
getLocalZoneName
char * getLocalZoneName()
Definition: rodsConnect.cpp:685
procLog_t::progName
char progName[64]
Definition: rodsDef.h:370
readProcLog
int readProcLog(int pid, procLog_t *procLog)
Definition: procLog.cpp:109
UNIX_FILE_READ_ERR
@ UNIX_FILE_READ_ERR
Definition: rodsErrorTable.h:302
ProcLogDir
char ProcLogDir[(1024+64)]
Definition: irods_server_globals.cpp:18
procLog.h
PROC_LOG_DIR_NAME
#define PROC_LOG_DIR_NAME
Definition: rsLog.hpp:17
procLog_t
Definition: rodsDef.h:361
initAndClearProcLog
int initAndClearProcLog()
Definition: procLog.cpp:13
miscUtil.h
DEFAULT_DIR_MODE
#define DEFAULT_DIR_MODE
Definition: objInfo.h:241
rsComm_t::procLogFlag
procLogFlag_t procLogFlag
Definition: rcConnect.h:157
USER__NULL_INPUT_ERR
@ USER__NULL_INPUT_ERR
Definition: rodsErrorTable.h:247