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 #endif
00757 if(strlen((char*)mPC->inOutStruct)!=0) {
00758 snprintf(execMyRuleInp.myRule, META_STR_LEN, "remExec||%s|%s", (char*)mPB->inOutStruct,(char*)mPC->inOutStruct);
00759 } else {
00760 snprintf(execMyRuleInp.myRule, META_STR_LEN, "remExec{%s}", (char*)mPB->inOutStruct);
00761 }
00762 addKeyVal(&execMyRuleInp.condInput,"execCondition",(char *) mPA->inOutStruct);
00763
00764 tmpParamArray = (msParamArray_t *) malloc (sizeof (msParamArray_t));
00765 memset (tmpParamArray, 0, sizeof (msParamArray_t));
00766 i = replMsParamArray (rei->msParamArray,tmpParamArray);
00767 if (i < 0) {
00768 free(tmpParamArray);
00769 return(i);
00770 }
00771 aParamArray = rei->msParamArray;
00772 rei->msParamArray = tmpParamArray;
00773 execMyRuleInp.inpParamArray = rei->msParamArray;
00774 i = rsExecMyRule (rei->rsComm, &execMyRuleInp, &outParamArray);
00775 carryOverMsParam(outParamArray, aParamArray);
00776 rei->msParamArray = aParamArray;
00777 clearMsParamArray(tmpParamArray,0);
00778 free(tmpParamArray);
00779 return(i);
00780 }
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 int recover_remoteExec(msParam_t *actionCall, msParam_t *delayCondition, char *hostName, ruleExecInfo_t *rei)
00849 {
00850
00851 int i;
00852 ruleExecDelInp_t ruleExecDelInp;
00853
00854 RE_TEST_MACRO (" Calling recover_delayExec");
00855
00856 i = popStack(&delayStack,ruleExecDelInp.ruleExecId);
00857 if (i < 0)
00858 return(i);
00859
00860
00861
00862 return(i);
00863
00864 }
00865
00866
00867 int
00868 doForkExec(char *prog, char *arg1)
00869 {
00870 int pid, i;
00871
00872 i = checkFilePerms(prog);
00873 if (i) return(i);
00874
00875 i = checkFilePerms(arg1);
00876 if (i) return(i);
00877
00878 #ifndef windows_platform
00879 pid = fork();
00880 if (pid == -1) return -1;
00881
00882 if (pid) {
00883
00884 }
00885 else {
00886
00887 for (i=0;i<100;i++) {
00888 close(i);
00889 }
00890 i = execl(prog, prog, arg1, (char *) 0);
00891 printf("execl failed %d\n",i);
00892 return(0);
00893 }
00894 #else
00895
00896 if(_spawnl(_P_NOWAIT, prog, prog, arg1) == -1)
00897 {
00898 return -1;
00899 }
00900 #endif
00901
00902 return(0);
00903 }
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 int
00942 msiGoodFailure(ruleExecInfo_t *rei)
00943 {
00944
00945
00946 if (reTestFlag > 0) {
00947 if (reTestFlag == LOG_TEST_1)
00948 rodsLog (LOG_NOTICE," Calling msiGoodFailure So that It will Retry Other Rules Without Recovery\n");
00949 return(RETRY_WITHOUT_RECOVERY_ERR);
00950 }
00951
00952 return(RETRY_WITHOUT_RECOVERY_ERR);
00953 }
00954
00955
00956
00957
00958 int
00959 checkFilePerms(char *fileName) {
00960 struct stat buf;
00961 if (stat (fileName, &buf) == -1) {
00962 printf ("Stat failed for file %s\n",
00963 fileName);
00964 return(-1);
00965 }
00966
00967 if (buf.st_mode & 022) {
00968 printf ("File is writable by group or other: %s.\n",
00969 fileName);
00970 return(-2);
00971 }
00972 return(0);
00973 }
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 int
01007 msiFreeBuffer(msParam_t* memoryParam, ruleExecInfo_t *rei)
01008 {
01009
01010 msParamArray_t *inMsParamArray;
01011 msParam_t *mP;
01012 execCmdOut_t *myExecCmdOut;
01013
01014 RE_TEST_MACRO ("Loopback on msiFreeBuffer");
01015
01016 if (!strcmp(memoryParam->type,"STR_PI") &&
01017 ( !strcmp((char*)memoryParam->inOutStruct,"stdout") ||
01018 !strcmp((char*)memoryParam->inOutStruct,"stderr")
01019 )
01020 )
01021 {
01022 mP = NULL;
01023 inMsParamArray = rei->msParamArray;
01024 if (((mP = getMsParamByLabel (inMsParamArray, "ruleExecOut")) != NULL) &&
01025 (mP->inOutStruct != NULL)) {
01026 myExecCmdOut = (execCmdOut_t *) mP->inOutStruct;
01027 if (!strcmp((char*)memoryParam->inOutStruct,"stdout")) {
01028 if ( myExecCmdOut->stdoutBuf.buf != NULL) {
01029 free ( myExecCmdOut->stdoutBuf.buf);
01030 myExecCmdOut->stdoutBuf.buf=NULL;
01031 myExecCmdOut->stdoutBuf.len = 0;
01032 }
01033 }
01034 if (!strcmp((char*)memoryParam->inOutStruct,"stderr")) {
01035 if ( myExecCmdOut->stderrBuf.buf != NULL) {
01036 free ( myExecCmdOut->stderrBuf.buf);
01037 myExecCmdOut->stderrBuf.buf = NULL;
01038 myExecCmdOut->stderrBuf.len = 0;
01039 }
01040 }
01041 }
01042 return(0);
01043 }
01044
01045 if (memoryParam->inpOutBuf != NULL)
01046 free(memoryParam->inpOutBuf);
01047 memoryParam->inpOutBuf = NULL;
01048 return(0);
01049
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 int
01085 msiSleep(msParam_t* secPtr, msParam_t* microsecPtr, ruleExecInfo_t *rei)
01086 {
01087
01088 int sec, microsec;
01089
01090 sec = atoi((char *) secPtr->inOutStruct);
01091 microsec = atoi((char *) microsecPtr->inOutStruct);
01092
01093 rodsSleep (sec, microsec);
01094 return(0);
01095 }
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 int
01143 msiApplyAllRules(msParam_t *actionParam, msParam_t* reiSaveFlagParam,
01144 msParam_t* allRuleExecFlagParam, ruleExecInfo_t *rei)
01145 {
01146 int i;
01147 char *action;
01148 int reiSaveFlag;
01149 int allRuleExecFlag;
01150
01151 action = (char *) actionParam->inOutStruct;
01152 reiSaveFlag = atoi((char *) reiSaveFlagParam->inOutStruct);
01153 allRuleExecFlag = atoi((char *) allRuleExecFlagParam->inOutStruct);
01154 i = applyAllRules(action, rei->msParamArray, rei, reiSaveFlag,allRuleExecFlag);
01155 return(i);
01156
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 int
01198 msiGetDiffTime(msParam_t* inpParam1, msParam_t* inpParam2, msParam_t* inpParam3, msParam_t* outParam, ruleExecInfo_t *rei)
01199 {
01200 long hours, minutes, seconds;
01201 char timeStr[TIME_LEN];
01202 char *format;
01203 int status;
01204
01205
01206
01207 RE_TEST_MACRO (" Calling msiGetDiffTime")
01208
01209
01210 if (rei == NULL || rei->rsComm == NULL) {
01211 rodsLog (LOG_ERROR, "msiGetDiffTime: input rei or rsComm is NULL");
01212 return (SYS_INTERNAL_NULL_INPUT_ERR);
01213 }
01214
01215
01216
01217 if ((parseMspForStr(inpParam1) == NULL)) {
01218 rodsLog (LOG_ERROR, "msiGetDiffTime: input inpParam1 is NULL");
01219 return (USER__NULL_INPUT_ERR);
01220 }
01221
01222 if ((parseMspForStr (inpParam2) == NULL)) {
01223 rodsLog (LOG_ERROR, "msiGetDiffTime: input inpParam2 is NULL");
01224 return (USER__NULL_INPUT_ERR);
01225 }
01226
01227
01228
01229 seconds = atol((char *) inpParam2->inOutStruct) - atol((char *)inpParam1->inOutStruct);
01230
01231
01232 format = (char *) inpParam3->inOutStruct;
01233
01234
01235
01236 if (format && !strcmp(format, "human")) {
01237
01238 hours = seconds / 3600;
01239 seconds = seconds % 3600;
01240 minutes = seconds / 60;
01241 seconds = seconds % 60;
01242
01243 snprintf(timeStr, TIME_LEN, "%ldh %ldm %lds", hours, minutes, seconds);
01244 }
01245 else {
01246 snprintf(timeStr, TIME_LEN, "%011ld", seconds);
01247 }
01248
01249
01250
01251 status = fillStrInMsParam (outParam, timeStr);
01252
01253 return(status);
01254 }
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 int
01292 msiGetSystemTime(msParam_t* outParam, msParam_t* inpParam, ruleExecInfo_t *rei)
01293 {
01294 char *format;
01295 char tStr0[TIME_LEN],tStr[TIME_LEN];
01296 int status;
01297
01298
01299 RE_TEST_MACRO (" Calling msiGetSystemTime")
01300
01301
01302 if (rei == NULL || rei->rsComm == NULL) {
01303 rodsLog (LOG_ERROR, "msiGetSystemTime: input rei or rsComm is NULL");
01304 return (SYS_INTERNAL_NULL_INPUT_ERR);
01305 }
01306
01307
01308 format = (char *) inpParam->inOutStruct;
01309
01310 if (!format || strcmp(format, "human")) {
01311 getNowStr(tStr);
01312 }
01313 else {
01314 getNowStr(tStr0);
01315 getLocalTimeFromRodsTime(tStr0,tStr);
01316 }
01317
01318 status = fillStrInMsParam (outParam,tStr);
01319
01320 return(status);
01321 }
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 int
01359 msiHumanToSystemTime(msParam_t* inpParam, msParam_t* outParam, ruleExecInfo_t *rei)
01360 {
01361 char sys_time[TIME_LEN], *hr_time;
01362 int status;
01363
01364
01365 RE_TEST_MACRO (" Calling msiHumanToSystemTime")
01366
01367
01368
01369 if (rei == NULL || rei->rsComm == NULL) {
01370 rodsLog (LOG_ERROR, "msiHumanToSystemTime: input rei or rsComm is NULL");
01371 return (SYS_INTERNAL_NULL_INPUT_ERR);
01372 }
01373
01374
01375
01376 if ((hr_time = parseMspForStr (inpParam)) == NULL) {
01377 rodsLog (LOG_ERROR, "msiHumanToSystemTime: parseMspForStr error for input param.");
01378 return (rei->status);
01379 }
01380
01381
01382
01383 memset(sys_time, '\0', TIME_LEN);
01384 sys_time[0] = '0';
01385
01386
01387
01388 if ((status = localToUnixTime (hr_time, &sys_time[1])) == 0) {
01389 status = fillStrInMsParam (outParam, sys_time);
01390 }
01391
01392
01393 return(status);
01394 }
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 int
01433 msiStrToBytesBuf(msParam_t* str_msp, msParam_t* buf_msp, ruleExecInfo_t *rei)
01434 {
01435 char *inStr;
01436 bytesBuf_t *outBuf;
01437
01438
01439 if ((inStr = parseMspForStr(str_msp)) == NULL)
01440 {
01441 rodsLog (LOG_ERROR, "msiStrToBytesBuf: input str_msp is NULL.");
01442 return (USER__NULL_INPUT_ERR);
01443 }
01444
01445
01446 outBuf = (bytesBuf_t *)malloc(sizeof(bytesBuf_t));
01447 memset (outBuf, 0, sizeof (bytesBuf_t));
01448
01449
01450 outBuf->len = strlen(inStr);
01451 outBuf->buf = inStr;
01452
01453
01454 fillBufLenInMsParam (buf_msp, outBuf->len, outBuf);
01455
01456 return 0;
01457 }
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 int
01499 msiListEnabledMS(msParam_t *outKVPairs, ruleExecInfo_t *rei)
01500 {
01501 FILE *radh;
01502
01503 keyValPair_t *results;
01504
01505 char lineStr[LONG_NAME_LEN];
01506 char modName[NAME_LEN];
01507 char *begPtr, *endPtr;
01508
01509
01510
01511 RE_TEST_MACRO (" Calling msiEnabledMS")
01512
01513
01514
01515 if (rei == NULL || rei->rsComm == NULL) {
01516 rodsLog (LOG_ERROR, "msiListEnabledMS: input rei or rsComm is NULL.");
01517 return (SYS_INTERNAL_NULL_INPUT_ERR);
01518 }
01519
01520
01521
01522 radh = fopen ("../re/include/reAction.h", "r");
01523 if(!radh) {
01524 rodsLog (LOG_ERROR, "msiListEnabledMS: unable to open reAction.h for reading.");
01525 return (UNIX_FILE_READ_ERR);
01526 }
01527
01528
01529
01530 while (fgets(lineStr, LONG_NAME_LEN, radh) != NULL)
01531 {
01532 if (strstr(lineStr, "microsdef_t MicrosTable[]") == lineStr)
01533 {
01534 break;
01535 }
01536 }
01537
01538
01539
01540 strncpy(modName, "core", NAME_LEN);
01541
01542
01543
01544 results = (keyValPair_t*)malloc(sizeof(keyValPair_t));
01545 memset (results, 0, sizeof (keyValPair_t));
01546
01547
01548
01549 while (fgets(lineStr, LONG_NAME_LEN, radh) != NULL)
01550 {
01551
01552 if (strstr(lineStr, "};") == lineStr)
01553 {
01554 break;
01555 }
01556
01557
01558 if ( (begPtr = strchr(lineStr, '\"')) && (endPtr = strrchr(lineStr, '\"')) )
01559 {
01560 endPtr[0] = '\0';
01561 addKeyVal(results, &begPtr[1], modName);
01562 }
01563 else
01564 {
01565
01566 if (strstr(lineStr, "module microservices") )
01567 {
01568
01569 begPtr = strchr(lineStr, ' ');
01570 endPtr = strchr(++begPtr, ' ');
01571 endPtr[0] = '\0';
01572
01573 strncpy(modName, begPtr, NAME_LEN-1);
01574 }
01575 }
01576 }
01577
01578
01579
01580 fclose(radh);
01581
01582
01583
01584 fillMsParam (outKVPairs, NULL, KeyValPair_MS_T, results, NULL);
01585
01586
01587 return 0;
01588 }
01589
01590
01591
01592
01593
01594
01595
01596
01597
01598
01599
01600
01601
01602
01603
01604
01605
01606
01607
01608
01609
01610
01611
01612
01613
01614
01615
01616
01617
01618
01619
01620
01621
01622
01623
01624
01625
01626
01627
01628
01629
01630 int
01631 msiGetFormattedSystemTime( msParam_t* outParam, msParam_t* inpParam, msParam_t* inpFormatParam, ruleExecInfo_t *rei )
01632 {
01633 char *format;
01634 char *dateFormat;
01635 char tStr[TIME_LEN];
01636 time_t myTime;
01637 struct tm *mytm;
01638 int status;
01639
01640
01641 RE_TEST_MACRO (" Calling msiGetFormattedSystemTime");
01642
01643
01644 if (rei == NULL || rei->rsComm == NULL) {
01645 rodsLog (LOG_ERROR,
01646 "msiGetFormattedSystemTime: input rei or rsComm is NULL");
01647 return (SYS_INTERNAL_NULL_INPUT_ERR);
01648 }
01649 format = (char*)inpParam->inOutStruct;
01650 dateFormat = (char*)inpFormatParam->inOutStruct;
01651
01652 if (!format || strcmp(format, "human")) {
01653 getNowStr(tStr);
01654 }
01655 else {
01656 myTime = time(NULL);
01657 mytm = localtime(&myTime);
01658
01659 snprintf (tStr, TIME_LEN, dateFormat,
01660 mytm->tm_year + 1900, mytm->tm_mon + 1, mytm->tm_mday,
01661 mytm->tm_hour, mytm->tm_min, mytm->tm_sec);
01662 }
01663 status = fillStrInMsParam (outParam,tStr);
01664 return(status);
01665 }
01666
01667
01668
01669
01670