00001
00002
00003
00004
00005
00006
00007
00008 #include <string.h>
00009 #include <time.h>
00010 #include "reGlobalsExtern.h"
00011 #include "icatHighLevelRoutines.h"
00012 #include "execMyRule.h"
00013 #include "region.h"
00014 #include "rules.h"
00015 #include "conversion.h"
00016
00017 int
00018 fillSubmitConditions (char *action, char *inDelayCondition, bytesBuf_t *packedReiAndArgBBuf,
00019 ruleExecSubmitInp_t *ruleSubmitInfo, ruleExecInfo_t *rei);
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 #define evaluateExpression(expr, eaVal, rei) \
00057 computeExpression(expr, NULL,rei, 0, eaVal)
00058
00059 #if 0
00060 int assign(msParam_t* var, msParam_t* value, ruleExecInfo_t *rei)
00061 {
00062 char *varName;
00063 char *varMap;
00064 char *varValue;
00065 char aVal[MAX_COND_LEN * 2];
00066 int i;
00067 char eaVal[MAX_COND_LEN * 2];
00068 varName = (char *)var->label;
00069 varValue = (char *) var->inOutStruct;
00070 if ( varValue != NULL && varValue[0] == '$') {
00071 i = getVarMap("", var->inOutStruct, &varMap, 0);
00072 if (i < 0) return(i);
00073 rstrcpy(aVal,value->inOutStruct,MAX_COND_LEN * 2);
00074 i = evaluateExpression(aVal, eaVal,rei);
00075 if (i < 0 )
00076 return(i);
00077
00078 rodsLog (LOG_NOTICE,"BEFORE:uioc=%s,uiop=%s:cp=%d,pp=%d,eaval=%s\n",rei->uoic->userName,rei->uoip->userName, rei->uoic,rei->uoip,eaVal);
00079 i = setVarValue(varMap,rei, eaVal);
00080 rodsLog (LOG_NOTICE,"AFTER:uioc=%s,uiop=%s:cp=%d,pp=%d\n",rei->uoic->userName,rei->uoip->userName, rei->uoic,rei->uoip);
00081 }
00082 else {
00083 if ((value->type == NULL && value->label != NULL) ||
00084 strcmp (value->type, STR_MS_T) == 0 ||
00085 strcmp (value->type, STR_PI) == 0 ) {
00086 if (value->inOutStruct != NULL)
00087 rstrcpy(aVal,value->inOutStruct,MAX_COND_LEN * 2);
00088 else
00089 rstrcpy(aVal,value->label,MAX_COND_LEN * 2);
00090 i = evaluateExpression(aVal, eaVal,rei);
00091 if (i < 0)
00092 fillMsParam (var, NULL, value->type, value->inOutStruct, value->inpOutBuf);
00093 else if (!strcmp(eaVal,aVal)) {
00094 var->inOutStruct = strdup(aVal);
00095 var->type = strdup(STR_MS_T);
00096 }
00097 else {
00098
00099 var->inOutStruct = strdup(eaVal);
00100 var->type = strdup(STR_MS_T);
00101 }
00102 }
00103 else
00104 fillMsParam (var, NULL, value->type, value->inOutStruct, value->inpOutBuf);
00105 }
00106 return(0);
00107 }
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146 int whileExec(msParam_t* condition, msParam_t* whileBody,
00147 msParam_t* recoverWhileBody, ruleExecInfo_t *rei)
00148 {
00149 int i,done;
00150 char *cond, *ruleBody;
00151 msParamArray_t *inMsParamArray = NULL;
00152 char eaVal[MAX_COND_LEN * 2];
00153 done = 0;
00154 inMsParamArray = rei->msParamArray;
00155
00156 cond = (char *) malloc(strlen(condition->inOutStruct) + 10 + MAX_COND_LEN * 2);
00157 ruleBody = (char *) malloc ( strlen(whileBody->inOutStruct) +
00158 strlen(recoverWhileBody->inOutStruct) + 10 + MAX_COND_LEN * 2);
00159 sprintf(ruleBody,"%s|%s",(char *) whileBody->inOutStruct,
00160 (char *) recoverWhileBody->inOutStruct + MAX_COND_LEN * 8);
00161
00162 while (done == 0) {
00163
00164 strcpy(cond , condition->inOutStruct);
00165 i = evaluateExpression(cond, eaVal, rei);
00166 if (i < 0)
00167 return(i);
00168 if (i == 0) {
00169 done = 1;
00170 break;
00171 }
00172 i = execMyRuleWithSaveFlag(ruleBody, inMsParamArray, rei, 0);
00173 if (i == BREAK_ACTION_ENCOUNTERED_ERR)
00174 return(0);
00175 if (i != 0)
00176 return(i);
00177
00178 }
00179 return(0);
00180 }
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220 int forExec(msParam_t* initial, msParam_t* condition, msParam_t* step,
00221 msParam_t* forBody, msParam_t* recoverForBody, ruleExecInfo_t *rei)
00222 {
00223
00224 int i,done;
00225 char *cond, *ruleBody, *stepStr;
00226 char eaVal[MAX_COND_LEN * 2];
00227 done = 0;
00228
00229 i = execMyRuleWithSaveFlag(initial->inOutStruct,rei->msParamArray, rei,0);
00230 if (i != 0)
00231 return(i);
00232
00233 cond = (char *) malloc(strlen(condition->inOutStruct) + 10 + MAX_COND_LEN * 2);
00234
00235 stepStr = (char *) malloc(strlen(step->inOutStruct) + 10 + MAX_COND_LEN * 2);
00236 ruleBody = (char *) malloc ( strlen(forBody->inOutStruct) +
00237 strlen(recoverForBody->inOutStruct) + 10 + MAX_COND_LEN * 8);
00238
00239 while (done == 0) {
00240
00241 strcpy(cond , condition->inOutStruct);
00242 i = evaluateExpression(cond, eaVal, rei);
00243 if (i < 0)
00244 return(i);
00245 if (i == 0) {
00246 done = 1;
00247 break;
00248 }
00249 sprintf(ruleBody,"%s|%s",(char *) forBody->inOutStruct,
00250 (char *) recoverForBody->inOutStruct);
00251 i = execMyRuleWithSaveFlag(ruleBody, rei->msParamArray, rei, 0);
00252 if (i == BREAK_ACTION_ENCOUNTERED_ERR)
00253 return(0);
00254 if (i != 0)
00255 return(i);
00256
00257 strcpy(stepStr,step->inOutStruct);
00258 i = execMyRuleWithSaveFlag(stepStr,rei->msParamArray, rei,0);
00259 if (i != 0)
00260 return(i);
00261 }
00262 return(0);
00263 }
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308 int ifExec(msParam_t* condition, msParam_t* thenC, msParam_t* recoverThen,
00309 msParam_t* elseC, msParam_t* recoverElse, ruleExecInfo_t *rei)
00310 {
00311 int i;
00312 char *cond, *thenStr, *elseStr;
00313 char eaVal[MAX_COND_LEN * 2];
00314
00315 if (condition->inOutStruct == NULL) {
00316
00317
00318 cond = (char *) malloc(strlen(condition->inOutStruct) + 10 + MAX_COND_LEN * 2);
00319 strcpy(cond , condition->inOutStruct);
00320 }
00321 else {
00322 cond = (char *) malloc(strlen(condition->inOutStruct) + 10 + MAX_COND_LEN * 2);
00323 strcpy(cond , condition->inOutStruct);
00324 }
00325
00326 i = evaluateExpression(cond, eaVal, rei);
00327 free(cond);
00328 if (i < 0)
00329 return(i);
00330 if (i == 1) {
00331 thenStr = (char *) malloc(strlen(thenC->inOutStruct) + strlen(recoverThen->inOutStruct) + 10 + MAX_COND_LEN * 8);
00332 sprintf(thenStr,"%s|%s",(char *) thenC->inOutStruct,
00333 (char *) recoverThen->inOutStruct);
00334 i = execMyRuleWithSaveFlag(thenStr, rei->msParamArray, rei, 0);
00335 free(thenStr);
00336 }
00337 else {
00338 elseStr = (char *) malloc(strlen(elseC->inOutStruct) + strlen(recoverElse->inOutStruct) + 10 + MAX_COND_LEN * 8);
00339 sprintf(elseStr,"%s|%s",(char *) elseC->inOutStruct,
00340 (char *) recoverElse->inOutStruct);
00341 i = execMyRuleWithSaveFlag(elseStr, rei->msParamArray, rei, 0);
00342 free(elseStr);
00343 }
00344 return(i);
00345 }
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377 int breakExec(ruleExecInfo_t *rei)
00378 {
00379 return (BREAK_ACTION_ENCOUNTERED_ERR);
00380 }
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427 int forEachExec(msParam_t* inlist, msParam_t* body, msParam_t* recoverBody,
00428 ruleExecInfo_t *rei)
00429 {
00430
00431 char *label ;
00432 int i;
00433 msParamArray_t *inMsParamArray;
00434 void *value, *restPtr, *inPtr, *buf, *inStructPtr, *msParamStruct ;
00435 char *typ;
00436 char *bodyStr;
00437 msParam_t *msParam, *list;
00438 bytesBuf_t *inBufPtr, *msParamBuf;
00439 int first = 1;
00440 int inx;
00441 char *outtyp;
00442 execCmdOut_t *myExecCmdOut;
00443
00444 list = (msParam_t *) malloc (sizeof (msParam_t));
00445 memset (list, 0, sizeof (msParam_t));
00446 replMsParam (inlist,list);
00447 typ = strdup(list->type);
00448 label = list->label;
00449 inPtr = list->inOutStruct;
00450 if (!strcmp(typ,ExecCmdOut_MS_T)) {
00451 free(typ);
00452 typ = strdup(STR_MS_T);
00453 myExecCmdOut = (execCmdOut_t *) inPtr;
00454 inPtr = myExecCmdOut->stdoutBuf.buf;
00455 }
00456 inStructPtr = inPtr;
00457 inBufPtr = list->inpOutBuf;
00458 outtyp = typ;
00459 buf = inBufPtr;
00460 value = NULL;
00461
00462 inMsParamArray = rei->msParamArray;
00463 msParam = getMsParamByLabel(inMsParamArray, label);
00464 if (msParam != NULL) {
00465 msParamStruct = msParam->inOutStruct;
00466 msParamBuf = msParam->inpOutBuf;
00467
00468 }
00469 else
00470 msParamStruct = NULL;
00471
00472 i = 0;
00473
00474 bodyStr = (char *) malloc ( strlen(body->inOutStruct) +
00475 strlen(recoverBody->inOutStruct) + 10 + MAX_COND_LEN * 8);
00476 sprintf(bodyStr,"%s|%s",(char *) body->inOutStruct,
00477 (char *) recoverBody->inOutStruct);
00478
00479 restPtr = NULL;
00480 inx = 0;
00481 while (inPtr != NULL) {
00482 i = getNextValueAndBufFromListOrStruct(typ, inPtr, &value, (bytesBuf_t **) &buf, &restPtr, &inx, &outtyp);
00483 if ( i != 0)
00484 break;
00485
00486 if (first == 1 && msParam == NULL) {
00487 addMsParam(inMsParamArray, label, outtyp ,value, buf);
00488 msParam = getMsParamByLabel(inMsParamArray, label);
00489 first = 0;
00490 }
00491 else {
00492 msParam->inOutStruct = value;
00493 msParam->inpOutBuf = buf;
00494 msParam->type = outtyp;
00495 }
00496
00497
00498 i = execMyRuleWithSaveFlag(bodyStr, inMsParamArray, rei, 0);
00499 if ( i != 0)
00500 break;
00501
00502
00503 inPtr = restPtr;
00504 }
00505
00506 if (msParamStruct != NULL) {
00507
00508 msParam->inOutStruct = msParamStruct;
00509 msParam->inpOutBuf = msParamBuf;
00510 msParam->type = typ;
00511 }
00512
00513
00514 free(list);
00515
00516 if (i == BREAK_ACTION_ENCOUNTERED_ERR)
00517 return(0);
00518 if (i == NO_VALUES_FOUND)
00519 return(0);
00520 return(i);
00521 }
00522 #endif
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596 int delayExec(msParam_t *mPA, msParam_t *mPB, msParam_t *mPC, ruleExecInfo_t *rei)
00597 {
00598 int i;
00599 char actionCall[MAX_ACTION_SIZE];
00600 char recoveryActionCall[MAX_ACTION_SIZE];
00601 char delayCondition[MAX_ACTION_SIZE];
00602
00603 rstrcpy(delayCondition, (char *) mPA->inOutStruct,MAX_ACTION_SIZE);
00604 rstrcpy(actionCall, (char *) mPB->inOutStruct,MAX_ACTION_SIZE);
00605 rstrcpy(recoveryActionCall, (char *) mPC->inOutStruct,MAX_ACTION_SIZE);
00606 i = _delayExec(actionCall, recoveryActionCall, delayCondition, rei);
00607 return(i);
00608 }
00609
00610 int _delayExec(char *inActionCall, char *recoveryActionCall,
00611 char *delayCondition, ruleExecInfo_t *rei)
00612 {
00613
00614 char *args[MAX_NUM_OF_ARGS_IN_ACTION];
00615 int i, argc;
00616 ruleExecSubmitInp_t *ruleSubmitInfo;
00617
00618 char tmpStr[NAME_LEN];
00619 bytesBuf_t *packedReiAndArgBBuf = NULL;
00620 char *ruleExecId;
00621 char *actionCall;
00622
00623
00624 RE_TEST_MACRO (" Calling _delayExec");
00625
00626 actionCall = inActionCall;
00627
00628 actionCall = (char *) malloc(strlen(inActionCall) + strlen(recoveryActionCall) + 3);
00629 sprintf(actionCall,"%s|%s",inActionCall,recoveryActionCall);
00630 args[1] = NULL;
00631 argc = 0;
00632
00633 i = packReiAndArg (rei->rsComm, rei, args, argc, &packedReiAndArgBBuf);
00634 if (i < 0) {
00635 if (actionCall != inActionCall)
00636 free (actionCall);
00637 return(i);
00638 }
00639
00640 ruleSubmitInfo = (ruleExecSubmitInp_t *) mallocAndZero(sizeof(ruleExecSubmitInp_t));
00641 i = fillSubmitConditions (actionCall, delayCondition, packedReiAndArgBBuf, ruleSubmitInfo, rei);
00642 if (actionCall != inActionCall)
00643 free (actionCall);
00644 if (i < 0) {
00645 free(ruleSubmitInfo);
00646 return(i);
00647 }
00648
00649
00650 i = rsRuleExecSubmit(rei->rsComm, ruleSubmitInfo, &ruleExecId);
00651 if (packedReiAndArgBBuf != NULL) {
00652 clearBBuf (packedReiAndArgBBuf);
00653 free (packedReiAndArgBBuf);
00654 }
00655
00656 free(ruleSubmitInfo);
00657 if (i < 0)
00658 return(i);
00659 free (ruleExecId);
00660 snprintf(tmpStr,NAME_LEN, "%d",i);
00661 i = pushStack(&delayStack,tmpStr);
00662 return(i);
00663 }
00664
00665 int recover_delayExec(msParam_t *actionCall, msParam_t *delayCondition, ruleExecInfo_t *rei)
00666 {
00667
00668 int i;
00669 ruleExecDelInp_t ruleExecDelInp;
00670
00671 RE_TEST_MACRO (" Calling recover_delayExec");
00672
00673 i = popStack(&delayStack,ruleExecDelInp.ruleExecId);
00674 if (i < 0)
00675 return(i);
00676
00677 i = rsRuleExecDel(rei->rsComm, &ruleExecDelInp);
00678 return(i);
00679
00680 }
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723 int remoteExec(msParam_t *mPD, msParam_t *mPA, msParam_t *mPB, msParam_t *mPC, ruleExecInfo_t *rei)
00724 {
00725 int i;
00726 execMyRuleInp_t execMyRuleInp;
00727 msParamArray_t *tmpParamArray, *aParamArray;
00728 msParamArray_t *outParamArray = NULL;
00729 char tmpStr[LONG_NAME_LEN];
00730 char tmpStr1[LONG_NAME_LEN];
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742 memset (&execMyRuleInp, 0, sizeof (execMyRuleInp));
00743 execMyRuleInp.condInput.len=0;
00744 rstrcpy (execMyRuleInp.outParamDesc, ALL_MS_PARAM_KW, LONG_NAME_LEN);
00745
00746 rstrcpy (tmpStr, (char *) mPD->inOutStruct, LONG_NAME_LEN);
00747 #if 0
00748 i = evaluateExpression(tmpStr, execMyRuleInp.addr.hostAddr, rei);
00749 if (i < 0)
00750 return(i);
00751 #else
00752 i = evaluateExpression(tmpStr, tmpStr1, rei);
00753 if (i < 0)
00754 return(i);
00755 parseHostAddrStr (tmpStr1, &execMyRuleInp.addr);
00756
00757 #endif
00758 if(strlen((char*)mPC->inOutStruct)!=0) {
00759 snprintf(execMyRuleInp.myRule, META_STR_LEN, "remExec||%s|%s", (char*)mPB->inOutStruct,(char*)mPC->inOutStruct);
00760 } else {
00761 snprintf(execMyRuleInp.myRule, META_STR_LEN, "remExec{%s}", (char*)mPB->inOutStruct);
00762 }
00763 addKeyVal(&execMyRuleInp.condInput,"execCondition",(char *) mPA->inOutStruct);
00764
00765 tmpParamArray = (msParamArray_t *) malloc (sizeof (msParamArray_t));
00766 memset (tmpParamArray, 0, sizeof (msParamArray_t));
00767 i = replMsParamArray (rei->msParamArray,tmpParamArray);
00768 if (i < 0) {
00769 free(tmpParamArray);
00770 return(i);
00771 }
00772 aParamArray = rei->msParamArray;
00773 rei->msParamArray = tmpParamArray;
00774 execMyRuleInp.inpParamArray = rei->msParamArray;
00775 i = rsExecMyRule (rei->rsComm, &execMyRuleInp, &outParamArray);
00776 carryOverMsParam(outParamArray, aParamArray);
00777 rei->msParamArray = aParamArray;
00778 clearMsParamArray(tmpParamArray,0);
00779 free(tmpParamArray);
00780 return(i);
00781 }
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849 int recover_remoteExec(msParam_t *actionCall, msParam_t *delayCondition, char *hostName, ruleExecInfo_t *rei)
00850 {
00851
00852 int i;
00853 ruleExecDelInp_t ruleExecDelInp;
00854
00855 RE_TEST_MACRO (" Calling recover_delayExec");
00856
00857 i = popStack(&delayStack,ruleExecDelInp.ruleExecId);
00858 if (i < 0)
00859 return(i);
00860
00861
00862
00863 return(i);
00864
00865 }
00866
00867
00868 int
00869 doForkExec(char *prog, char *arg1)
00870 {
00871 int pid, i;
00872
00873 i = checkFilePerms(prog);
00874 if (i) return(i);
00875
00876 i = checkFilePerms(arg1);
00877 if (i) return(i);
00878
00879 #ifndef windows_platform
00880 pid = fork();
00881 if (pid == -1) return -1;
00882
00883 if (pid) {
00884
00885 }
00886 else {
00887
00888 for (i=0;i<100;i++) {
00889 close(i);
00890 }
00891 i = execl(prog, prog, arg1, (char *) 0);
00892 printf("execl failed %d\n",i);
00893 return(0);
00894 }
00895 #else
00896
00897 if(_spawnl(_P_NOWAIT, prog, prog, arg1) == -1)
00898 {
00899 return -1;
00900 }
00901 #endif
00902
00903 return(0);
00904 }
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942 int
00943 msiGoodFailure(ruleExecInfo_t *rei)
00944 {
00945
00946
00947 if (reTestFlag > 0) {
00948 if (reTestFlag == LOG_TEST_1)
00949 rodsLog (LOG_NOTICE," Calling msiGoodFailure So that It will Retry Other Rules Without Recovery\n");
00950 return(RETRY_WITHOUT_RECOVERY_ERR);
00951 }
00952
00953 return(RETRY_WITHOUT_RECOVERY_ERR);
00954 }
00955
00956
00957
00958
00959 int
00960 checkFilePerms(char *fileName) {
00961 struct stat buf;
00962 if (stat (fileName, &buf) == -1) {
00963 printf ("Stat failed for file %s\n",
00964 fileName);
00965 return(-1);
00966 }
00967
00968 if (buf.st_mode & 022) {
00969 printf ("File is writable by group or other: %s.\n",
00970 fileName);
00971 return(-2);
00972 }
00973 return(0);
00974 }
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007 int
01008 msiFreeBuffer(msParam_t* memoryParam, ruleExecInfo_t *rei)
01009 {
01010
01011 msParamArray_t *inMsParamArray;
01012 msParam_t *mP;
01013 execCmdOut_t *myExecCmdOut;
01014
01015 RE_TEST_MACRO ("Loopback on msiFreeBuffer");
01016
01017 if (!strcmp(memoryParam->type,"STR_PI") &&
01018 ( !strcmp((char*)memoryParam->inOutStruct,"stdout") ||
01019 !strcmp((char*)memoryParam->inOutStruct,"stderr")
01020 )
01021 )
01022 {
01023 mP = NULL;
01024 inMsParamArray = rei->msParamArray;
01025 if (((mP = getMsParamByLabel (inMsParamArray, "ruleExecOut")) != NULL) &&
01026 (mP->inOutStruct != NULL)) {
01027 myExecCmdOut = (execCmdOut_t *) mP->inOutStruct;
01028 if (!strcmp((char*)memoryParam->inOutStruct,"stdout")) {
01029 if ( myExecCmdOut->stdoutBuf.buf != NULL) {
01030 free ( myExecCmdOut->stdoutBuf.buf);
01031 myExecCmdOut->stdoutBuf.buf=NULL;
01032 myExecCmdOut->stdoutBuf.len = 0;
01033 }
01034 }
01035 if (!strcmp((char*)memoryParam->inOutStruct,"stderr")) {
01036 if ( myExecCmdOut->stderrBuf.buf != NULL) {
01037 free ( myExecCmdOut->stderrBuf.buf);
01038 myExecCmdOut->stderrBuf.buf = NULL;
01039 myExecCmdOut->stderrBuf.len = 0;
01040 }
01041 }
01042 }
01043 return(0);
01044 }
01045
01046 if (memoryParam->inpOutBuf != NULL)
01047 free(memoryParam->inpOutBuf);
01048 memoryParam->inpOutBuf = NULL;
01049 return(0);
01050
01051 }
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084
01085 int
01086 msiSleep(msParam_t* secPtr, msParam_t* microsecPtr, ruleExecInfo_t *rei)
01087 {
01088
01089 int sec, microsec;
01090
01091 sec = atoi((char *) secPtr->inOutStruct);
01092 microsec = atoi((char *) microsecPtr->inOutStruct);
01093
01094 rodsSleep (sec, microsec);
01095 return(0);
01096 }
01097
01098
01099
01100
01101
01102
01103
01104
01105
01106
01107
01108
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138
01139
01140
01141
01142
01143 int
01144 msiApplyAllRules(msParam_t *actionParam, msParam_t* reiSaveFlagParam,
01145 msParam_t* allRuleExecFlagParam, ruleExecInfo_t *rei)
01146 {
01147 int i;
01148 char *action;
01149 int reiSaveFlag;
01150 int allRuleExecFlag;
01151
01152 action = (char *) actionParam->inOutStruct;
01153 reiSaveFlag = atoi((char *) reiSaveFlagParam->inOutStruct);
01154 allRuleExecFlag = atoi((char *) allRuleExecFlagParam->inOutStruct);
01155 i = applyAllRules(action, rei->msParamArray, rei, reiSaveFlag,allRuleExecFlag);
01156 return(i);
01157
01158 }
01159
01160
01161
01162
01163
01164
01165
01166
01167
01168
01169
01170
01171
01172
01173
01174
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193
01194
01195
01196
01197
01198 int
01199 msiGetDiffTime(msParam_t* inpParam1, msParam_t* inpParam2, msParam_t* inpParam3, msParam_t* outParam, ruleExecInfo_t *rei)
01200 {
01201 long hours, minutes, seconds;
01202 char timeStr[TIME_LEN];
01203 char *format;
01204 int status;
01205
01206
01207
01208 RE_TEST_MACRO (" Calling msiGetDiffTime")
01209
01210
01211 if (rei == NULL || rei->rsComm == NULL) {
01212 rodsLog (LOG_ERROR, "msiGetDiffTime: input rei or rsComm is NULL");
01213 return (SYS_INTERNAL_NULL_INPUT_ERR);
01214 }
01215
01216
01217
01218 if ((parseMspForStr(inpParam1) == NULL)) {
01219 rodsLog (LOG_ERROR, "msiGetDiffTime: input inpParam1 is NULL");
01220 return (USER__NULL_INPUT_ERR);
01221 }
01222
01223 if ((parseMspForStr (inpParam2) == NULL)) {
01224 rodsLog (LOG_ERROR, "msiGetDiffTime: input inpParam2 is NULL");
01225 return (USER__NULL_INPUT_ERR);
01226 }
01227
01228
01229
01230 seconds = atol((char *) inpParam2->inOutStruct) - atol((char *)inpParam1->inOutStruct);
01231
01232
01233 format = (char *) inpParam3->inOutStruct;
01234
01235
01236
01237 if (format && !strcmp(format, "human")) {
01238
01239 hours = seconds / 3600;
01240 seconds = seconds % 3600;
01241 minutes = seconds / 60;
01242 seconds = seconds % 60;
01243
01244 snprintf(timeStr, TIME_LEN, "%ldh %ldm %lds", hours, minutes, seconds);
01245 }
01246 else {
01247 snprintf(timeStr, TIME_LEN, "%011ld", seconds);
01248 }
01249
01250
01251
01252 status = fillStrInMsParam (outParam, timeStr);
01253
01254 return(status);
01255 }
01256
01257
01258
01259
01260
01261
01262
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272
01273
01274
01275
01276
01277
01278
01279
01280
01281
01282
01283
01284
01285
01286
01287
01288
01289
01290
01291
01292 int
01293 msiGetSystemTime(msParam_t* outParam, msParam_t* inpParam, ruleExecInfo_t *rei)
01294 {
01295 char *format;
01296 char tStr0[TIME_LEN],tStr[TIME_LEN];
01297 int status;
01298
01299
01300 RE_TEST_MACRO (" Calling msiGetSystemTime")
01301
01302
01303 if (rei == NULL || rei->rsComm == NULL) {
01304 rodsLog (LOG_ERROR, "msiGetSystemTime: input rei or rsComm is NULL");
01305 return (SYS_INTERNAL_NULL_INPUT_ERR);
01306 }
01307
01308
01309 format = (char *) inpParam->inOutStruct;
01310
01311 if (!format || strcmp(format, "human")) {
01312 getNowStr(tStr);
01313 }
01314 else {
01315 getNowStr(tStr0);
01316 getLocalTimeFromRodsTime(tStr0,tStr);
01317 }
01318
01319 status = fillStrInMsParam (outParam,tStr);
01320
01321 return(status);
01322 }
01323
01324
01325
01326
01327
01328
01329
01330
01331
01332
01333
01334
01335
01336
01337
01338
01339
01340
01341
01342
01343
01344
01345
01346
01347
01348
01349
01350
01351
01352
01353
01354
01355
01356
01357
01358
01359 int
01360 msiHumanToSystemTime(msParam_t* inpParam, msParam_t* outParam, ruleExecInfo_t *rei)
01361 {
01362 char sys_time[TIME_LEN], *hr_time;
01363 int status;
01364
01365
01366 RE_TEST_MACRO (" Calling msiHumanToSystemTime")
01367
01368
01369
01370 if (rei == NULL || rei->rsComm == NULL) {
01371 rodsLog (LOG_ERROR, "msiHumanToSystemTime: input rei or rsComm is NULL");
01372 return (SYS_INTERNAL_NULL_INPUT_ERR);
01373 }
01374
01375
01376
01377 if ((hr_time = parseMspForStr (inpParam)) == NULL) {
01378 rodsLog (LOG_ERROR, "msiHumanToSystemTime: parseMspForStr error for input param.");
01379 return (rei->status);
01380 }
01381
01382
01383
01384 memset(sys_time, '\0', TIME_LEN);
01385 sys_time[0] = '0';
01386
01387
01388
01389 if ((status = localToUnixTime (hr_time, &sys_time[1])) == 0) {
01390 status = fillStrInMsParam (outParam, sys_time);
01391 }
01392
01393
01394 return(status);
01395 }
01396
01397
01398
01399
01400
01401
01402
01403
01404
01405
01406
01407
01408
01409
01410
01411
01412
01413
01414
01415
01416
01417
01418
01419
01420
01421
01422
01423
01424
01425
01426
01427
01428
01429
01430
01431
01432
01433 int
01434 msiStrToBytesBuf(msParam_t* str_msp, msParam_t* buf_msp, ruleExecInfo_t *rei)
01435 {
01436 char *inStr;
01437 bytesBuf_t *outBuf;
01438
01439
01440 if ((inStr = parseMspForStr(str_msp)) == NULL)
01441 {
01442 rodsLog (LOG_ERROR, "msiStrToBytesBuf: input str_msp is NULL.");
01443 return (USER__NULL_INPUT_ERR);
01444 }
01445
01446
01447 outBuf = (bytesBuf_t *)malloc(sizeof(bytesBuf_t));
01448 memset (outBuf, 0, sizeof (bytesBuf_t));
01449
01450
01451 outBuf->len = strlen(inStr);
01452 outBuf->buf = inStr;
01453
01454
01455 fillBufLenInMsParam (buf_msp, outBuf->len, outBuf);
01456
01457 return 0;
01458 }
01459
01460
01461
01462
01463
01464
01465
01466
01467
01468
01469
01470
01471
01472
01473
01474
01475
01476
01477
01478
01479
01480
01481
01482
01483
01484
01485
01486
01487
01488
01489
01490
01491
01492
01493
01494
01495
01496
01497
01498
01499
01500 int
01501 msiBytesBufToStr(msParam_t* buf_msp, msParam_t* str_msp, ruleExecInfo_t *rei)
01502 {
01503 char *outStr;
01504 bytesBuf_t *inBuf;
01505
01506
01507 if ( buf_msp == NULL && buf_msp->inOutStruct == NULL)
01508 {
01509 rodsLog (LOG_ERROR, "msiBytesBufToStr: input buf_msp is NULL.");
01510 return (USER__NULL_INPUT_ERR);
01511 }
01512 inBuf = buf_msp->inpOutBuf;
01513 if (inBuf->len < 0 || inBuf->len > (MAX_SZ_FOR_SINGLE_BUF-10)) {
01514 rodsLog (LOG_ERROR, "msiBytesBufToStr: input buf_msp is NULL.");
01515 return (USER_INPUT_FORMAT_ERR);
01516 }
01517 outStr = (char *) malloc((inBuf->len + 1));
01518 outStr[inBuf->len] = '\0';
01519 strncpy(outStr, (char *) inBuf->buf, inBuf->len);
01520 fillStrInMsParam(str_msp, outStr);
01521 free(outStr);
01522
01523 return 0;
01524 }
01525
01526
01527
01528
01529
01530
01531
01532
01533
01534
01535
01536
01537
01538
01539
01540
01541
01542
01543
01544
01545
01546
01547
01548
01549
01550
01551
01552
01553
01554
01555
01556
01557
01558
01559
01560
01561
01562
01563
01564
01565 int
01566 msiListEnabledMS(msParam_t *outKVPairs, ruleExecInfo_t *rei)
01567 {
01568 FILE *radh;
01569
01570 keyValPair_t *results;
01571
01572 char lineStr[LONG_NAME_LEN];
01573 char modName[NAME_LEN];
01574 char *begPtr, *endPtr;
01575
01576
01577
01578 RE_TEST_MACRO (" Calling msiEnabledMS")
01579
01580
01581
01582 if (rei == NULL || rei->rsComm == NULL) {
01583 rodsLog (LOG_ERROR, "msiListEnabledMS: input rei or rsComm is NULL.");
01584 return (SYS_INTERNAL_NULL_INPUT_ERR);
01585 }
01586
01587
01588
01589 radh = fopen ("../re/include/reAction.h", "r");
01590 if(!radh) {
01591 rodsLog (LOG_ERROR, "msiListEnabledMS: unable to open reAction.h for reading.");
01592 return (UNIX_FILE_READ_ERR);
01593 }
01594
01595
01596
01597 while (fgets(lineStr, LONG_NAME_LEN, radh) != NULL)
01598 {
01599 if (strstr(lineStr, "microsdef_t MicrosTable[]") == lineStr)
01600 {
01601 break;
01602 }
01603 }
01604
01605
01606
01607 strncpy(modName, "core", NAME_LEN);
01608
01609
01610
01611 results = (keyValPair_t*)malloc(sizeof(keyValPair_t));
01612 memset (results, 0, sizeof (keyValPair_t));
01613
01614
01615
01616 while (fgets(lineStr, LONG_NAME_LEN, radh) != NULL)
01617 {
01618
01619 if (strstr(lineStr, "};") == lineStr)
01620 {
01621 break;
01622 }
01623
01624
01625 if ( (begPtr = strchr(lineStr, '\"')) && (endPtr = strrchr(lineStr, '\"')) )
01626 {
01627 endPtr[0] = '\0';
01628 addKeyVal(results, &begPtr[1], modName);
01629 }
01630 else
01631 {
01632
01633 if (strstr(lineStr, "module microservices") )
01634 {
01635
01636 begPtr = strchr(lineStr, ' ');
01637 endPtr = strchr(++begPtr, ' ');
01638 endPtr[0] = '\0';
01639
01640 strncpy(modName, begPtr, NAME_LEN-1);
01641 }
01642 }
01643 }
01644
01645
01646
01647 fclose(radh);
01648
01649
01650
01651 fillMsParam (outKVPairs, NULL, KeyValPair_MS_T, results, NULL);
01652
01653
01654 return 0;
01655 }
01656
01657
01658
01659
01660
01661
01662
01663
01664
01665
01666
01667
01668
01669
01670
01671
01672
01673
01674
01675
01676
01677
01678
01679
01680
01681
01682
01683
01684
01685
01686
01687
01688
01689
01690
01691
01692
01693
01694
01695 int
01696 msiGetFormattedSystemTime(msParam_t* outParam, msParam_t* inpParam,
01697 msParam_t* inpFormatParam, ruleExecInfo_t *rei)
01698 {
01699 char *format;
01700 char *dateFormat;
01701 char tStr[TIME_LEN];
01702 time_t myTime;
01703 struct tm *mytm;
01704 int status;
01705
01706
01707 RE_TEST_MACRO (" Calling msiGetFormattedSystemTime");
01708
01709
01710 if (rei == NULL || rei->rsComm == NULL) {
01711 rodsLog (LOG_ERROR,
01712 "msiGetFormattedSystemTime: input rei or rsComm is NULL");
01713 return (SYS_INTERNAL_NULL_INPUT_ERR);
01714 }
01715 format = (char*)inpParam->inOutStruct;
01716 dateFormat = (char*)inpFormatParam->inOutStruct;
01717
01718 if (!format || strcmp(format, "human")) {
01719 getNowStr(tStr);
01720 }
01721 else {
01722 myTime = time(NULL);
01723 mytm = localtime(&myTime);
01724
01725 snprintf (tStr, TIME_LEN, dateFormat,
01726 mytm->tm_year + 1900, mytm->tm_mon + 1, mytm->tm_mday,
01727 mytm->tm_hour, mytm->tm_min, mytm->tm_sec);
01728 }
01729 status = fillStrInMsParam (outParam,tStr);
01730 return(status);
01731 }
01732
01733
01734
01735