00001
00002
00003
00004
00005
00006
00007
00008 #include "rsApiHandler.h"
00009 #include "modDataObjMeta.h"
00010 #include "rcMisc.h"
00011 #include "miscServerFunct.h"
00012 #include "regReplica.h"
00013 #include "unregDataObj.h"
00014 #include "modAVUMetadata.h"
00015
00016 #ifdef USE_BOOST
00017 #include <boost/thread.hpp>
00018 #include <boost/thread/mutex.hpp>
00019 #include <boost/thread/condition.hpp>
00020 #include <setjmp.h>
00021 jmp_buf Jenv;
00022 #else
00023 #ifndef windows_platform
00024 #include <pthread.h>
00025 #include <setjmp.h>
00026 jmp_buf Jenv;
00027 #endif
00028 #endif
00029
00030 int
00031 rsApiHandler (rsComm_t *rsComm, int apiNumber, bytesBuf_t *inputStructBBuf,
00032 bytesBuf_t *bsBBuf)
00033 {
00034 int apiInx;
00035 int status = 0;
00036 char *myInStruct = NULL;
00037 funcPtr myHandler = NULL;
00038 void *myOutStruct = NULL;
00039 bytesBuf_t myOutBsBBuf;
00040 int retVal = 0;
00041 int numArg = 0;
00042 void *myArgv[4];
00043
00044 memset (&myOutBsBBuf, 0, sizeof (bytesBuf_t));
00045 memset (&rsComm->rError, 0, sizeof (rError_t));
00046
00047 apiInx = apiTableLookup (apiNumber);
00048 if (apiInx < 0) {
00049 rodsLog (LOG_ERROR,
00050 "rsApiHandler: apiTableLookup of apiNumber %d failed", apiNumber);
00051
00052 sendRodsMsg (rsComm->sock, RODS_API_REPLY_T, NULL, NULL, NULL,
00053 apiInx, rsComm->irodsProt);
00054 return (apiInx);
00055 }
00056
00057 rsComm->apiInx = apiInx;
00058
00059 status = chkApiVersion (rsComm, apiInx);
00060 if (status < 0) {
00061 sendApiReply (rsComm, apiInx, status, myOutStruct, &myOutBsBBuf);
00062 return (status);
00063 }
00064
00065 status = chkApiPermission (rsComm, apiInx);
00066 if (status < 0) {
00067 rodsLog (LOG_NOTICE,
00068 "rsApiHandler: User has no permission for apiNumber %d", apiNumber);
00069 sendApiReply (rsComm, apiInx, status, myOutStruct, &myOutBsBBuf);
00070 return (status);
00071 }
00072
00073
00074
00075 if (inputStructBBuf->len > 0 && RsApiTable[apiInx].inPackInstruct == NULL) {
00076 rodsLog (LOG_NOTICE,
00077 "rsApiHandler: input struct error for apiNumber %d", apiNumber);
00078 sendApiReply (rsComm, apiInx, SYS_API_INPUT_ERR, myOutStruct,
00079 &myOutBsBBuf);
00080 return (SYS_API_INPUT_ERR);
00081 }
00082
00083 if (inputStructBBuf->len <= 0 && RsApiTable[apiInx].inPackInstruct != NULL){
00084 rodsLog (LOG_NOTICE,
00085 "rsApiHandler: input struct error for apiNumber %d", apiNumber);
00086 sendApiReply (rsComm, apiInx, SYS_API_INPUT_ERR, myOutStruct,
00087 &myOutBsBBuf);
00088 return (SYS_API_INPUT_ERR);
00089 }
00090
00091 if (bsBBuf->len > 0 && RsApiTable[apiInx].inBsFlag <= 0) {
00092 rodsLog (LOG_NOTICE,
00093 "rsApiHandler: input byte stream error for apiNumber %d", apiNumber);
00094 sendApiReply (rsComm, apiInx, SYS_API_INPUT_ERR, myOutStruct,
00095 &myOutBsBBuf);
00096 return (SYS_API_INPUT_ERR);
00097 }
00098
00099 if (inputStructBBuf->len > 0) {
00100 status = unpackStruct (inputStructBBuf->buf, (void **) &myInStruct,
00101 RsApiTable[apiInx].inPackInstruct, RodsPackTable, rsComm->irodsProt);
00102 if (status < 0) {
00103 rodsLog (LOG_NOTICE,
00104 "rsApiHandler: unpackStruct error for apiNumber %d, status = %d",
00105 apiNumber, status);
00106 sendApiReply (rsComm, apiInx, status, myOutStruct,
00107 &myOutBsBBuf);
00108 return (status);
00109 }
00110 }
00111
00112
00113
00114 myHandler = RsApiTable[apiInx].svrHandler;
00115
00116 if (RsApiTable[apiInx].inPackInstruct != NULL) {
00117 myArgv[numArg] = myInStruct;
00118 numArg++;
00119 };
00120
00121 if (RsApiTable[apiInx].inBsFlag != 0) {
00122 myArgv[numArg] = bsBBuf;
00123 numArg++;
00124 };
00125
00126 if (RsApiTable[apiInx].outPackInstruct != NULL) {
00127 myArgv[numArg] = (void *) &myOutStruct;
00128 numArg++;
00129 };
00130
00131 if (RsApiTable[apiInx].outBsFlag != 0) {
00132 myArgv[numArg] = (void *) &myOutBsBBuf;
00133 numArg++;
00134 };
00135
00136 if (numArg == 0) {
00137 retVal = (*myHandler) (rsComm);
00138 } else if (numArg == 1) {
00139 retVal = (*myHandler) (rsComm, myArgv[0]);
00140 } else if (numArg == 2) {
00141 retVal = (*myHandler) (rsComm, myArgv[0], myArgv[1]);
00142 } else if (numArg == 3) {
00143 retVal = (*myHandler) (rsComm, myArgv[0], myArgv[1], myArgv[2]);
00144 } else if (numArg == 4) {
00145 retVal = (*myHandler) (rsComm, myArgv[0], myArgv[1], myArgv[2],
00146 myArgv[3]);
00147 }
00148
00149 if (myInStruct != NULL) {
00150
00151
00152 if (strcmp (RsApiTable[apiInx].inPackInstruct, "GenQueryInp_PI") == 0) {
00153 clearGenQueryInp ((genQueryInp_t *) myInStruct);
00154 } else if (strcmp (RsApiTable[apiInx].inPackInstruct,
00155 "ModDataObjMeta_PI") == 0) {
00156 clearModDataObjMetaInp ((modDataObjMeta_t *) myInStruct);
00157 } else if (strcmp (RsApiTable[apiInx].inPackInstruct,
00158 "RegReplica_PI") == 0) {
00159 clearRegReplicaInp ((regReplica_t *) myInStruct);
00160 } else if (strcmp (RsApiTable[apiInx].inPackInstruct,
00161 "UnregDataObj_PI") == 0) {
00162 clearUnregDataObj ((unregDataObj_t *) myInStruct);
00163 } else if (strcmp (RsApiTable[apiInx].inPackInstruct,
00164 "DataObjInp_PI") == 0) {
00165 #if 0
00166 if (apiNumber == QUERY_SPEC_COLL_AN &&
00167 ((dataObjInp_t *) myInStruct)->specColl != NULL) {
00168 #endif
00169 clearDataObjInp ((dataObjInp_t *) myInStruct);
00170 } else if (strcmp (RsApiTable[apiInx].inPackInstruct,
00171 "DataObjCopyInp_PI") == 0) {
00172 clearDataObjCopyInp ((dataObjCopyInp_t *) myInStruct);
00173 } else if (strcmp (RsApiTable[apiInx].inPackInstruct,
00174 "GenQueryOut_PI") == 0) {
00175 clearGenQueryOut ((genQueryOut_t *) myInStruct);
00176 } else if (strcmp (RsApiTable[apiInx].inPackInstruct,
00177 "CollInpNew_PI") == 0) {
00178 clearCollInp ((collInp_t *) myInStruct);
00179 } else if (strcmp (RsApiTable[apiInx].inPackInstruct,
00180 "BulkOprInp_PI") == 0) {
00181 clearBulkOprInp ((bulkOprInp_t *) myInStruct);
00182 } else if (strcmp (RsApiTable[apiInx].inPackInstruct,
00183 "ModAVUMetadataInp_PI") == 0) {
00184 clearModAVUMetadataInp ((modAVUMetadataInp_t *) myInStruct);
00185 } else if (strcmp (RsApiTable[apiInx].inPackInstruct,
00186 "authResponseInp_PI") == 0) {
00187
00188 clearAuthResponseInp ((void *) myInStruct);
00189 }
00190 free (myInStruct);
00191 myInStruct = NULL;
00192 }
00193
00194 if (apiNumber == GSI_AUTH_REQUEST_AN && retVal >= 0) {
00195
00196
00197
00198 logAgentProc (rsComm);
00199 }
00200 if (retVal != SYS_NO_HANDLER_REPLY_MSG) {
00201 status = sendAndProcApiReply
00202 (rsComm, apiInx, retVal, myOutStruct, &myOutBsBBuf);
00203 }
00204
00205 if (retVal >= 0 && status < 0) {
00206 return (status);
00207 } else {
00208 return (retVal);
00209 }
00210 }
00211
00212 int
00213 sendAndProcApiReply ( rsComm_t *rsComm, int apiInx, int status,
00214 void *myOutStruct, bytesBuf_t *myOutBsBBuf)
00215 {
00216 int retval;
00217
00218 retval = sendApiReply (rsComm, apiInx, status, myOutStruct, myOutBsBBuf);
00219
00220 clearBBuf (myOutBsBBuf);
00221 if (myOutStruct != NULL) {
00222 free (myOutStruct);
00223 }
00224 freeRErrorContent (&rsComm->rError);
00225
00226
00227
00228 if (rsComm->portalOpr != NULL) {
00229 handlePortalOpr (rsComm);
00230 clearKeyVal (&rsComm->portalOpr->dataOprInp.condInput);
00231 free (rsComm->portalOpr);
00232 rsComm->portalOpr = NULL;
00233 }
00234
00235 return (retval);
00236 }
00237
00238 int
00239 sendApiReply (rsComm_t *rsComm, int apiInx, int retVal,
00240 void *myOutStruct, bytesBuf_t *myOutBsBBuf)
00241 {
00242 int status;
00243 bytesBuf_t *outStructBBuf = NULL;
00244 bytesBuf_t *myOutStructBBuf;
00245 bytesBuf_t *rErrorBBuf = NULL;
00246 bytesBuf_t *myRErrorBBuf;
00247
00248
00249 svrChkReconnAtSendStart (rsComm);
00250
00251
00252 if (retVal == SYS_HANDLER_DONE_NO_ERROR) {
00253
00254 retVal = 0;
00255 }
00256
00257 if (RsApiTable[apiInx].outPackInstruct != NULL && myOutStruct != NULL) {
00258
00259 status = packStruct ((char *) myOutStruct, &outStructBBuf,
00260 RsApiTable[apiInx].outPackInstruct, RodsPackTable, FREE_POINTER,
00261 rsComm->irodsProt);
00262
00263 if (status < 0) {
00264 rodsLog (LOG_NOTICE,
00265 "sendApiReply: packStruct error, status = %d", status);
00266 sendRodsMsg (rsComm->sock, RODS_API_REPLY_T, NULL,
00267 NULL, NULL, status, rsComm->irodsProt);
00268
00269 svrChkReconnAtSendEnd (rsComm);
00270
00271 return status;
00272 }
00273
00274 myOutStructBBuf = outStructBBuf;
00275 } else {
00276 myOutStructBBuf = NULL;
00277 }
00278
00279 if (RsApiTable[apiInx].outBsFlag == 0) {
00280 myOutBsBBuf = NULL;
00281 }
00282
00283 if (rsComm->rError.len > 0) {
00284 status = packStruct ((char *) &rsComm->rError, &rErrorBBuf,
00285 "RError_PI", RodsPackTable, 0, rsComm->irodsProt);
00286
00287 if (status < 0) {
00288 rodsLog (LOG_NOTICE,
00289 "sendApiReply: packStruct error, status = %d", status);
00290 sendRodsMsg (rsComm->sock, RODS_API_REPLY_T, NULL,
00291 NULL, NULL, status, rsComm->irodsProt);
00292
00293 svrChkReconnAtSendEnd (rsComm);
00294
00295 return status;
00296 }
00297
00298 myRErrorBBuf = rErrorBBuf;
00299 } else {
00300 myRErrorBBuf = NULL;
00301 }
00302
00303 status = sendRodsMsg (rsComm->sock, RODS_API_REPLY_T, myOutStructBBuf,
00304 myOutBsBBuf, myRErrorBBuf, retVal, rsComm->irodsProt);
00305
00306 if (status < 0) {
00307 int status1;
00308 rodsLog (LOG_NOTICE,
00309 "sendApiReply: sendRodsMsg error, status = %d", status);
00310
00311 if (rsComm->reconnSock > 0) {
00312 int savedStatus = status;
00313 #ifdef USE_BOOST
00314 boost::unique_lock< boost::mutex > boost_lock( *rsComm->lock );
00315 rodsLog (LOG_DEBUG,
00316 "sendApiReply: svrSwitchConnect. cliState = %d,agState=%d",
00317 rsComm->clientState, rsComm->agentState);
00318 status1 = svrSwitchConnect (rsComm);
00319 boost_lock.unlock();
00320 #else
00321 pthread_mutex_lock (&rsComm->lock);
00322 rodsLog (LOG_DEBUG,
00323 "sendApiReply: svrSwitchConnect. cliState = %d,agState=%d",
00324 rsComm->clientState, rsComm->agentState);
00325 status1 = svrSwitchConnect (rsComm);
00326 pthread_mutex_unlock (&rsComm->lock);
00327 #endif
00328 if (status1 > 0) {
00329
00330 rodsLog (LOG_NOTICE,
00331 "sendApiReply: Switch connection and retry sendRodsMsg");
00332 status = sendRodsMsg (rsComm->sock, RODS_API_REPLY_T,
00333 myOutStructBBuf, myOutBsBBuf, myRErrorBBuf, retVal,
00334 rsComm->irodsProt);
00335 if (status >= 0) {
00336 rodsLog (LOG_NOTICE,
00337 "sendApiReply: retry sendRodsMsg succeeded");
00338 } else {
00339 status = savedStatus;
00340 }
00341 }
00342 }
00343
00344 }
00345
00346
00347 svrChkReconnAtSendEnd (rsComm);
00348
00349
00350 freeBBuf (outStructBBuf);
00351 freeBBuf (rErrorBBuf);
00352
00353 return (status);
00354 }
00355
00356 int
00357 chkApiVersion (rsComm_t *rsComm, int apiInx)
00358 {
00359 char *cliApiVersion;
00360
00361 if ((cliApiVersion = getenv (SP_API_VERSION)) != NULL) {
00362 if (strcmp (cliApiVersion, RsApiTable[apiInx].apiVersion) != 0) {
00363 rodsLog (LOG_ERROR,
00364 "chkApiVersion:Client's API Version %s does not match Server's %s",
00365 cliApiVersion, RsApiTable[apiInx].apiVersion);
00366 return (USER_API_VERSION_MISMATCH);
00367 }
00368 }
00369 return (0);
00370 }
00371
00372 int
00373 chkApiPermission (rsComm_t *rsComm, int apiInx)
00374 {
00375 int clientUserAuth;
00376 int proxyUserAuth;
00377 int xmsgSvrOnly;
00378 int xmsgSvrAlso;
00379
00380 clientUserAuth = RsApiTable[apiInx].clientUserAuth;
00381
00382 xmsgSvrOnly = clientUserAuth & XMSG_SVR_ONLY;
00383 xmsgSvrAlso = clientUserAuth & XMSG_SVR_ALSO;
00384
00385 if (ProcessType == XMSG_SERVER_PT) {
00386 if ((xmsgSvrOnly + xmsgSvrAlso) == 0) {
00387 rodsLog (LOG_ERROR,
00388 "chkApiPermission: xmsgServer not allowed to handle api %d",
00389 RsApiTable[apiInx].apiNumber);
00390 return (SYS_NO_API_PRIV);
00391 }
00392 } else if (xmsgSvrOnly != 0) {
00393 rodsLog (LOG_ERROR,
00394 "chkApiPermission: non xmsgServer not allowed to handle api %d",
00395 RsApiTable[apiInx].apiNumber);
00396 return (SYS_NO_API_PRIV);
00397 }
00398
00399 clientUserAuth = clientUserAuth & 0xfff;
00400
00401 if (clientUserAuth > rsComm->clientUser.authInfo.authFlag) {
00402 return (SYS_NO_API_PRIV);
00403 }
00404
00405 proxyUserAuth = RsApiTable[apiInx].proxyUserAuth & 0xfff;
00406 if (proxyUserAuth > rsComm->proxyUser.authInfo.authFlag) {
00407 return (SYS_NO_API_PRIV);
00408 }
00409 return (0);
00410 }
00411
00412 int
00413 handlePortalOpr (rsComm_t *rsComm)
00414 {
00415 int oprType;
00416 int status;
00417
00418 if (rsComm == NULL || rsComm->portalOpr == NULL)
00419 return (0);
00420
00421 oprType = rsComm->portalOpr->oprType;
00422
00423 switch (oprType) {
00424 case PUT_OPR:
00425 case GET_OPR:
00426 status = svrPortalPutGet (rsComm);
00427 break;
00428 default:
00429 rodsLog (LOG_NOTICE,
00430 "handlePortalOpr: Invalid portal oprType: %d", oprType);
00431 status = SYS_INVALID_PORTAL_OPR;
00432 break;
00433 }
00434 return (status);
00435 }
00436
00437 int
00438 readAndProcClientMsg (rsComm_t *rsComm, int flags)
00439 {
00440 int status = 0;
00441 msgHeader_t myHeader;
00442 bytesBuf_t inputStructBBuf, bsBBuf, errorBBuf;
00443
00444
00445 svrChkReconnAtReadStart (rsComm);
00446
00447
00448
00449 memset (&bsBBuf, 0, sizeof (bsBBuf));
00450
00451
00452
00453
00454
00455
00456 if ((flags & READ_HEADER_TIMEOUT) != 0) {
00457 int retryCnt = 0;
00458 #if 0
00459 int retVal = 0;
00460 while (1) {
00461 signal (SIGALRM, readTimeoutHandler);
00462 if ((retVal = setjmp (Jenv)) == 0) {
00463 alarm(READ_HEADER_TIMEOUT_IN_SEC);
00464 status = readMsgHeader (rsComm->sock, &myHeader, NULL);
00465 alarm(0);
00466 break;
00467 } else {
00468 if (retVal == L1DESC_INUSE &&
00469 retryCnt < MAX_READ_HEADER_RETRY) {
00470 retryCnt++;
00471 continue;
00472 }
00473 rodsLog (LOG_ERROR,
00474 "readAndProcClientMsg: readMsgHeader by pid %d hs timedout.",
00475 getpid ());
00476 return USER_SOCK_CONNECT_TIMEDOUT;
00477 }
00478 }
00479 #else
00480 struct timeval tv;
00481 tv.tv_sec = READ_HEADER_TIMEOUT_IN_SEC;
00482 tv.tv_usec = 0;
00483 while (1) {
00484 status = readMsgHeader (rsComm->sock, &myHeader, &tv);
00485 if (status < 0) {
00486 if (isL1descInuse () && retryCnt < MAX_READ_HEADER_RETRY) {
00487 rodsLogError (LOG_ERROR, status,
00488 "readAndProcClientMsg:readMsgHeader error. status = %d",
00489 status);
00490 retryCnt++;
00491 continue;
00492 }
00493 if (status == USER_SOCK_CONNECT_TIMEDOUT) {
00494 rodsLog (LOG_ERROR,
00495 "readAndProcClientMsg: readMsgHeader by pid %d timedout",
00496 getpid ());
00497 return status;
00498 }
00499 }
00500 break;
00501 }
00502 #endif
00503 } else {
00504 status = readMsgHeader (rsComm->sock, &myHeader, NULL);
00505 }
00506
00507
00508 if (status < 0) {
00509
00510 rodsLog (LOG_DEBUG,
00511 "readAndProcClientMsg: readMsgHeader error. status = %d", status);
00512
00513
00514 if (rsComm->reconnSock > 0) {
00515 int savedStatus = status;
00516
00517 #ifdef USE_BOOST
00518 boost::unique_lock< boost::mutex > boost_lock( *rsComm->lock );
00519 rodsLog (LOG_DEBUG,
00520 "readAndProcClientMsg: svrSwitchConnect. cliState = %d,agState=%d",
00521 rsComm->clientState, rsComm->agentState);
00522 svrSwitchConnect (rsComm);
00523 boost_lock.unlock();
00524 #else
00525 pthread_mutex_lock (&rsComm->lock);
00526 rodsLog (LOG_DEBUG,
00527 "readAndProcClientMsg: svrSwitchConnect. cliState = %d,agState=%d",
00528 rsComm->clientState, rsComm->agentState);
00529 svrSwitchConnect (rsComm);
00530 pthread_mutex_unlock (&rsComm->lock);
00531 #endif
00532 status = readMsgHeader (rsComm->sock, &myHeader, NULL);
00533 if (status < 0) {
00534 svrChkReconnAtReadEnd (rsComm);
00535 return (savedStatus);
00536 }
00537 } else {
00538 svrChkReconnAtReadEnd (rsComm);
00539 return (status);
00540 }
00541
00542
00543
00544 }
00545
00546 #ifdef SYS_TIMING
00547 if (strcmp (myHeader.type, RODS_API_REQ_T) == 0) {
00548
00549 if (myHeader.intInfo != AUTH_RESPONSE_AN)
00550 initSysTiming ("irodsAgent", "recv request", 0);
00551 }
00552 #endif
00553 status = readMsgBody (rsComm->sock, &myHeader, &inputStructBBuf,
00554 &bsBBuf, &errorBBuf, rsComm->irodsProt, NULL);
00555 if (status < 0) {
00556 rodsLog (LOG_NOTICE,
00557 "agentMain: readMsgBody error. status = %d", status);
00558
00559 svrChkReconnAtReadEnd (rsComm);
00560
00561 return (status);
00562 }
00563
00564
00565 svrChkReconnAtReadEnd (rsComm);
00566
00567
00568
00569
00570 if (strcmp (myHeader.type, RODS_API_REQ_T) == 0) {
00571 status = rsApiHandler (rsComm, myHeader.intInfo, &inputStructBBuf,
00572 &bsBBuf);
00573 #ifdef SYS_TIMING
00574 char tmpStr[NAME_LEN];
00575 snprintf (tmpStr, NAME_LEN, "handle API %d", myHeader.intInfo);
00576 printSysTiming ("irodsAgent", tmpStr, 0);
00577 #endif
00578 clearBBuf (&inputStructBBuf);
00579 clearBBuf (&bsBBuf);
00580 clearBBuf (&errorBBuf);
00581 if ((flags & RET_API_STATUS) != 0) {
00582 return (status);
00583 } else {
00584 return (0);
00585 }
00586 } else if (strcmp (myHeader.type, RODS_DISCONNECT_T) == 0) {
00587 rodsLog (LOG_NOTICE,
00588 "readAndProcClientMsg: received disconnect msg from client");
00589 return (DISCONN_STATUS);
00590 } else if (strcmp (myHeader.type, RODS_RECONNECT_T) == 0) {
00591 rodsLog (LOG_NOTICE,
00592 "readAndProcClientMsg: received reconnect msg from client");
00593
00594 status = readAndProcClientMsg (rsComm, flags);
00595 return status;
00596 } else {
00597 rodsLog (LOG_NOTICE,
00598 "agentMain: msg type %s not support by server",
00599 myHeader.type);
00600 return (USER_MSG_TYPE_NO_SUPPORT);
00601 }
00602 }
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618 int
00619 sendAndRecvBranchMsg (rsComm_t *rsComm, int apiInx, int status,
00620 void *myOutStruct, bytesBuf_t *myOutBsBBuf)
00621 {
00622 int retval;
00623 int savedApiInx;
00624
00625 savedApiInx = rsComm->apiInx;
00626 retval = sendAndProcApiReply (rsComm, apiInx, status,
00627 myOutStruct, myOutBsBBuf);
00628 if (retval < 0) {
00629 rodsLog (LOG_ERROR,
00630 "sendAndRecvBranchMsg: sendAndProcApiReply error. status = %d", retval);
00631 rsComm->apiInx = savedApiInx;
00632 return (retval);
00633 }
00634
00635 while (1) {
00636 retval = readAndProcClientMsg (rsComm, RET_API_STATUS);
00637 if (retval >= 0 || retval == SYS_NO_HANDLER_REPLY_MSG) {
00638
00639 continue;
00640 } else {
00641 rsComm->apiInx = savedApiInx;
00642 if (retval == SYS_HANDLER_DONE_NO_ERROR) {
00643 return 0;
00644 } else {
00645 return (retval);
00646 }
00647 }
00648 }
00649 }
00650
00651 int
00652 svrSendCollOprStat (rsComm_t *rsComm, collOprStat_t *collOprStat)
00653 {
00654 int status;
00655
00656 status = _svrSendCollOprStat (rsComm, collOprStat);
00657
00658 if (status != SYS_CLI_TO_SVR_COLL_STAT_REPLY) {
00659 rodsLog (LOG_ERROR,
00660 "svrSendCollOprStat: client reply %d != %d.",
00661 status, SYS_CLI_TO_SVR_COLL_STAT_REPLY);
00662 return (UNMATCHED_KEY_OR_INDEX);
00663 } else {
00664 return (0);
00665 }
00666 }
00667
00668 int
00669 _svrSendCollOprStat (rsComm_t *rsComm, collOprStat_t *collOprStat)
00670 {
00671 int myBuf;
00672 int status;
00673
00674 status = sendAndProcApiReply (rsComm, rsComm->apiInx,
00675 SYS_SVR_TO_CLI_COLL_STAT, collOprStat, NULL);
00676 if (status < 0) {
00677 rodsLogError (LOG_ERROR, status,
00678 "svrSendCollOprStat: sendAndProcApiReply failed. status = %d",
00679 status);
00680 return status;
00681 }
00682
00683
00684 status = myRead (rsComm->sock, &myBuf, sizeof (myBuf), SOCK_TYPE, NULL,
00685 NULL);
00686 if (status < 0) {
00687 rodsLogError (LOG_ERROR, status,
00688 "svrSendCollOprStat: read handshake failed. status = %d", status);
00689 }
00690 return (ntohl (myBuf));
00691 }
00692
00693 int
00694 svrSendZoneCollOprStat (rsComm_t *rsComm, rcComm_t *conn,
00695 collOprStat_t *collOprStat, int retval)
00696 {
00697 int status = retval;
00698
00699 while (status == SYS_SVR_TO_CLI_COLL_STAT) {
00700 status = _svrSendCollOprStat (rsComm, collOprStat);
00701 if (status == SYS_CLI_TO_SVR_COLL_STAT_REPLY) {
00702 status = _cliGetCollOprStat (conn, &collOprStat);
00703 } else {
00704 int myBuf = htonl (status);
00705 myWrite (conn->sock, (void *) &myBuf, 4, SOCK_TYPE, NULL);
00706 break;
00707 }
00708 }
00709 return (status);
00710 }
00711
00712
00713 void
00714 readTimeoutHandler (int sig)
00715 {
00716 alarm(0);
00717 if (isL1descInuse ()) {
00718 rodsLog (LOG_ERROR,
00719 "readTimeoutHandler: read header by %d timed out. Lidesc is busy.",
00720 getpid ());
00721 longjmp (Jenv, L1DESC_INUSE);
00722 } else {
00723 rodsLog (LOG_ERROR,
00724 "readTimeoutHandler: read header by %d has timed out.",
00725 getpid ());
00726 longjmp (Jenv, READ_HEADER_TIMED_OUT);
00727 }
00728 }
00729
00730