00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 #include <stdio.h>
00068 #include <string.h>
00069 #include <unistd.h>
00070 #include <ctype.h>
00071 #include <stdlib.h>
00072 #include <time.h>
00073 #include <errno.h>
00074 #include <fnmatch.h>
00075
00076 #ifndef Lynx
00077 #include <sys/types.h>
00078 #include <sys/statfs.h>
00079 #include <sys/stat.h>
00080 #include <sys/dir.h>
00081 #endif
00082
00083 #include "rawcommn.h"
00084 #include "rawdefn.h"
00085 #include "rawentn.h"
00086
00087 extern FILE *fLogFile;
00088
00089 static int iFileList = sizeof(srawFileList);
00090
00091 #define BUFSIZE_SMALL 80
00092
00093 #ifndef Lynx
00094
00095
00096
00097
00098
00099
00100
00101 int rawGetDirEntries(char *pcStageFS)
00102 {
00103 char cModule[32]="rawGetDirEntries";
00104 int iDebug = 0;
00105
00106 int iRC;
00107 int iEntries = 0;
00108
00109 DIR *pDir;
00110 struct dirent *pEntry;
00111
00112 if (iDebug) fprintf(fLogFile,
00113 "\n-D- begin %s: FS %s\n", cModule, pcStageFS);
00114
00115 pDir = opendir(pcStageFS);
00116 if (pDir == NULL)
00117 {
00118 fprintf(fLogFile,
00119 "-E- %s: cannot open directory %s\n", cModule, pcStageFS);
00120 if (errno)
00121 {
00122 fprintf(fLogFile, " %s\n", strerror(errno));
00123 errno = 0;
00124 }
00125
00126 return -1;
00127 }
00128
00129 while ( (pEntry = readdir(pDir)) != NULL)
00130 {
00131 if ( (strcmp(pEntry->d_name, ".") == 0) ||
00132 (strcmp(pEntry->d_name, "..") == 0) )
00133 continue;
00134
00135 iEntries++;
00136
00137 if (iDebug)
00138 fprintf(fLogFile, " %d: %s\n", iEntries, pEntry->d_name);
00139 }
00140
00141 iRC = closedir(pDir);
00142
00143 if (iDebug)
00144 fprintf(fLogFile, " rc(closedir) = %d\n-D- end %s\n\n", iRC, cModule);
00145
00146 return(iEntries);
00147
00148 }
00149 #endif
00150
00151 #ifndef Lynx
00152
00153
00154
00155
00156
00157
00158
00159 int rawGetDirEntryList(
00160 char *pcDirName,
00161 char *pcEntryMask,
00162 int iEntryType,
00163
00164
00165
00166
00167
00168
00169 int iEntryLoop,
00170
00171 int iPrefixDir,
00172 char **ppFileList,
00173 char **ppDirList)
00174 {
00175 char cModule[32] = "rawGetDirEntryList";
00176 int iDebug = 0;
00177 int iRC = 0;
00178 int iRCE = 0;
00179 int ilen, iloc, ii, jj;
00180 char cTemp[MAX_FULL_FILE] = "";
00181
00182 int iTypeFound = 0;
00183
00184 char cEntryType[32] = "";
00185 int iEntries = 0;
00186 int iEntriesMatch = 0;
00187
00188 int iFileEntryMax = 0;
00189 int iFileEntryRem = 0;
00190 int iFileEntries = 0;
00191 int iFileEntriesOld = 0;
00192 int iFileEntriesNew = 0;
00193 int *piFileNo;
00194 int *piFileList;
00195 srawFileList *psFileList;
00196 srawFileList *psFileList0;
00197
00198 char *pcFileList2;
00199 int *piFileList2;
00200
00201 int iDirEntryMax = 0;
00202 int iDirEntryRem = 0;
00203 int iDirEntries = 0;
00204 int iDirEntriesOld = 0;
00205 int iDirEntriesNew = 0;
00206 int *piDirNo;
00207 int *piDirList;
00208 srawFileList *psDirList;
00209 srawFileList *psDirList0;
00210
00211 int iMatch = 0;
00212 int iStore = 0;
00213 int iCheck = 0;
00214
00215 DIR *pDir;
00216 struct dirent *pEntry;
00217
00218 struct stat sEntryStatus, *pEntryStatus;
00219
00220 if (iDebug)
00221 fprintf(fLogFile, "\n-D- begin %s\n", cModule);
00222
00223 pEntryStatus = &sEntryStatus;
00224
00225 if (strlen(pcDirName) <= 0)
00226 {
00227 fprintf(fLogFile, "-E- %s: empty directory name\n", cModule);
00228
00229 iRCE = -1;
00230 goto gEndDirEntryList;
00231 }
00232
00233 if (iEntryType >= 10)
00234 {
00235 if (strlen(pcEntryMask) <= 0)
00236 {
00237 fprintf(fLogFile,
00238 "-E- %s: empty mask for entry name\n", cModule);
00239
00240 iRCE = -1;
00241 goto gEndDirEntryList;
00242 }
00243
00244 iEntryType -= 10;
00245
00246 if (strcmp(pcEntryMask, "*") != 0)
00247 iMatch = 1;
00248 }
00249
00250 if (iEntryType == 0)
00251 strcpy(cEntryType, "entries");
00252 else if (iEntryType == 1)
00253 strcpy(cEntryType, "files");
00254 else if (iEntryType == 2)
00255 strcpy(cEntryType, "subdirs");
00256 else
00257 {
00258 fprintf(fLogFile,
00259 "-E- %s: invalid EntryType %d (allowed 0-2, 10-12)\n",
00260 cModule, iEntryType);
00261
00262 iRCE = -1;
00263 goto gEndDirEntryList;
00264 }
00265
00266
00267 if ( (iEntryType == 0) || (iEntryType == 1) )
00268 {
00269 if (ppFileList == NULL)
00270 {
00271 fprintf(fLogFile,
00272 "-E- %s: invalid pointer for entry list\n", cModule);
00273
00274 iRCE = -1;
00275 goto gEndDirEntryList;
00276 }
00277
00278 piFileNo = (int *) *ppFileList;
00279 piFileList = piFileNo;
00280 iFileEntriesOld = *piFileNo;
00281
00282 if (iEntryLoop)
00283 {
00284 if (iDebug)
00285 {
00286 if (iFileEntriesOld) fprintf(fLogFile,
00287 " %d files already available in list:\n",
00288 iFileEntriesOld);
00289 else fprintf(fLogFile,
00290 " still no files in list\n");
00291 if (iEntryLoop == 2)
00292 fprintf(fLogFile, " recursive file handling\n");
00293 }
00294 }
00295 else
00296 {
00297 if (iFileEntriesOld) fprintf(fLogFile,
00298 "-W- %s: no entry loop, but %d files already available in list\n",
00299 cModule, iFileEntriesOld);
00300 }
00301
00302 piFileList++;
00303 psFileList = (srawFileList *) piFileList;
00304 psFileList0 = psFileList;
00305
00306 if (iDebug)
00307 {
00308 if (iFileEntriesOld)
00309 {
00310 fprintf(fLogFile, "old files:\n");
00311 for (ii=1; ii<=iFileEntriesOld; ii++)
00312 {
00313 fprintf(fLogFile, " %d: %s\n", ii, psFileList->cFile);
00314 psFileList++;
00315 }
00316 }
00317 }
00318 else
00319 psFileList += iFileEntriesOld;
00320
00321 iFileEntries = iFileEntriesOld;
00322 iFileEntryMax = MAX_FILE_NO;
00323
00324
00325
00326 if (iFileEntriesOld > iFileEntryMax)
00327 {
00328 ii = iFileEntriesOld / iFileEntryMax;
00329 ii++;
00330 iFileEntryMax *= ii;
00331 }
00332 iFileEntryRem = iFileEntryMax - iFileEntriesOld;
00333
00334 if (iDebug) fprintf(fLogFile,
00335 " space available for %d file entries (max %d)\n",
00336 iFileEntryRem, iFileEntryMax);
00337
00338 }
00339
00340
00341 if ( (iEntryType == 0) || (iEntryType == 2) )
00342 {
00343 if (ppDirList == NULL)
00344 {
00345 fprintf(fLogFile,
00346 "-E- %s: invalid pointer for subdir list\n", cModule);
00347
00348 iRCE = -1;
00349 goto gEndDirEntryList;
00350 }
00351
00352 piDirNo = (int *) *ppDirList;
00353 piDirList = piDirNo;
00354 iDirEntriesOld = *piDirNo;
00355
00356 if (iEntryLoop)
00357 {
00358 if (iDebug)
00359 {
00360 if (iDirEntriesOld) fprintf(fLogFile,
00361 " %d subdirectories already available in list:\n",
00362 iDirEntriesOld);
00363 else fprintf(fLogFile,
00364 " still no subdirectories in list\n");
00365 }
00366 }
00367 else if (iDirEntriesOld) fprintf(fLogFile,
00368 "-W- %s: no entry loop, but %d subdirectories available in list\n",
00369 cModule, iDirEntriesOld);
00370
00371 piDirList++;
00372 psDirList = (srawFileList *) piDirList;
00373 psDirList0 = psDirList;
00374
00375 for (ii=1; ii<=iDirEntriesOld; ii++)
00376 {
00377 if (iDebug)
00378 {
00379 if (ii == 1)
00380 fprintf(fLogFile, "previous subdirs:\n");
00381 fprintf(fLogFile, " %d: %s\n", ii, psDirList->cFile);
00382 }
00383
00384 psDirList++;
00385 }
00386
00387 iDirEntries = iDirEntriesOld;
00388 iDirEntryMax = MAX_FILE_NO;
00389
00390
00391 if (iDirEntriesOld > iDirEntryMax)
00392 {
00393 ii = iDirEntriesOld / iDirEntryMax;
00394 ii++;
00395 iDirEntryMax *= ii;
00396 }
00397 iDirEntryRem = iDirEntryMax - iDirEntriesOld;
00398
00399 if (iDebug) fprintf(fLogFile,
00400 " space available for %d subdir entries (max %d)\n",
00401 iDirEntryRem, iDirEntryMax);
00402
00403 }
00404
00405 if (iDebug)
00406 {
00407 if ( (iEntryType == 0) && (iMatch) )
00408 {
00409 fprintf(fLogFile,
00410 " provide all files matching with %s and all subdirs in directory %s\n",
00411 pcEntryMask, pcDirName);
00412 }
00413 else
00414 {
00415 fprintf(fLogFile, " provide all %s", cEntryType);
00416 if (iMatch) fprintf(fLogFile,
00417 " matching with %s", pcEntryMask);
00418 fprintf(fLogFile, " in directory %s\n", pcDirName);
00419 }
00420 }
00421
00422 pDir = opendir(pcDirName);
00423 if (pDir == NULL)
00424 {
00425 fprintf(fLogFile,
00426 "-E- %s: cannot open directory %s\n", cModule, pcDirName);
00427 if (errno)
00428 {
00429 fprintf(fLogFile, "%s\n", strerror(errno));
00430 errno = 0;
00431 }
00432
00433 iRCE = -1;
00434 goto gEndDirEntryList;
00435 }
00436
00437 while ( (pEntry = readdir(pDir)) != NULL)
00438 {
00439 if ( (strcmp(pEntry->d_name, ".") == 0) ||
00440 (strcmp(pEntry->d_name, "..") == 0) )
00441 continue;
00442
00443 iEntries++;
00444 iCheck = 0;
00445 iStore = 0;
00446
00447
00448 if (pEntry->d_type == DT_UNKNOWN)
00449 {
00450 if ( (iEntries == 1) && (iDebug) ) fprintf(fLogFile,
00451 " %s: of type DT_UNKNOWN (1st entry)\n",
00452 pEntry->d_name);
00453
00454 strcpy(cTemp, pcDirName);
00455 strcat(cTemp, "/");
00456 strcat(cTemp, pEntry->d_name);
00457
00458 iRC = stat(cTemp, pEntryStatus);
00459 if (iRC)
00460 {
00461 if (errno)
00462 {
00463 fprintf(fLogFile, "-E- stat %s: %s\n",
00464 cTemp, strerror(errno));
00465
00466
00467 if (strcmp(strerror(errno),
00468 "Value too large for defined data type") == 0)
00469 {
00470 fprintf(fLogFile,
00471 "-E- %s: filesize of %s > 2 GByte: use 64 bit gStore client\n",
00472 cModule, cTemp);
00473
00474 errno = 0;
00475 return -99;
00476 }
00477 errno = 0;
00478 }
00479 else fprintf(fLogFile,
00480 "-W- %s: entry %s unavailable\n", cModule, pEntry->d_name);
00481
00482 continue;
00483 }
00484
00485 if (S_ISREG(pEntryStatus->st_mode))
00486 iTypeFound = 1;
00487 else if (S_ISDIR(pEntryStatus->st_mode))
00488 iTypeFound = 2;
00489 else
00490 {
00491 fprintf(fLogFile,
00492 "-W- %s: entry %s neither file nor directory, ignored\n",
00493 cModule, pEntry->d_name);
00494
00495 continue;
00496 }
00497 }
00498 else
00499 iTypeFound = 0;
00500
00501
00502 if ( (pEntry->d_type == DT_REG) || (iTypeFound == 1) )
00503 {
00504 if ( (iEntryType == 0) || (iEntryType == 1) )
00505 {
00506 if (iMatch)
00507 iCheck = 1;
00508 else
00509 iStore = 1;
00510 }
00511 }
00512 else if ( (pEntry->d_type == DT_DIR) || (iTypeFound == 2) )
00513 {
00514 if ( (iEntryType == 0) || (iEntryType == 2) )
00515 {
00516 if ( (iMatch) && (iEntryType == 2) )
00517 iCheck = 1;
00518 else
00519 iStore = 1;
00520 }
00521 }
00522
00523 if (iDebug == 2) fprintf(fLogFile,
00524 " %d: entry %s (check %d, store %d, type %d) \n",
00525 iEntries, pEntry->d_name, iCheck, iStore, pEntry->d_type);
00526
00527
00528 if (iCheck)
00529 {
00530
00531 if (fnmatch(pcEntryMask, pEntry->d_name, 0) == 0)
00532 {
00533 iStore = 1;
00534 iEntriesMatch++;
00535 }
00536 else
00537 iStore = 0;
00538 }
00539
00540 if (iStore)
00541 {
00542
00543 if ( (pEntry->d_type == DT_REG) ||
00544 (pEntry->d_type == DT_UNKNOWN) )
00545 {
00546 if (iPrefixDir)
00547 {
00548 strcpy(psFileList->cFile, pcDirName);
00549 strcat(psFileList->cFile, "/");
00550 strcat(psFileList->cFile, pEntry->d_name);
00551 }
00552 else
00553 strcpy(psFileList->cFile, pEntry->d_name);
00554
00555 iFileEntries++;
00556 iFileEntriesNew++;
00557
00558 if (iDebug)
00559 {
00560 if (iFileEntriesNew == 1)
00561 fprintf(fLogFile, "new files:\n");
00562 fprintf(fLogFile, " %d(%d): %s\n",
00563 iFileEntriesNew, iFileEntries, psFileList->cFile);
00564 }
00565
00566 if (iFileEntryRem <= 0)
00567 {
00568
00569
00570
00571
00572
00573
00574
00575
00576 iFileEntryMax += MAX_FILE_NO;
00577
00578
00579 ii = sizeof(int) + iFileEntryMax*iFileList;
00580 if ((pcFileList2 = (char *) calloc((unsigned) ii, 1)) == NULL)
00581 {
00582 fprintf(fLogFile,
00583 "-E- %s: allocating new filelist buffer (%d byte, %d entries)\n",
00584 cModule, ii, iFileEntryMax);
00585 if (errno)
00586 {
00587 fprintf(fLogFile, " %s\n", strerror(errno));
00588 errno = 0;
00589 }
00590
00591 iRCE = -1;
00592 goto gEndDirEntryList;
00593 }
00594
00595 if (iDebug) fprintf(fLogFile,
00596 " new filelist buffer allocated (%d byte, %d entries)\n",
00597 ii, iFileEntryMax);
00598
00599 iFileEntryRem = iFileEntryMax - iFileEntries;
00600 piFileList2 = (int *) pcFileList2;
00601 *piFileList2 = iFileEntries;
00602 *ppFileList = (char *) piFileList2;
00603 piFileList2++;
00604
00605 ii = iFileEntries*iFileList;
00606 memcpy(piFileList2, piFileList, ii);
00607
00608 psFileList = (srawFileList *) piFileList2;
00609 psFileList0 = psFileList;
00610
00611 if (iDebug) fprintf(fLogFile,
00612 " %d filelist entries copied, first %s\n",
00613 iFileEntries, psFileList->cFile);
00614 fflush(fLogFile);
00615
00616 psFileList += iFileEntries;
00617 piFileList = piFileList2;
00618 piFileList2--;
00619 piFileNo = piFileList2;
00620
00621 }
00622 else
00623 psFileList++;
00624
00625 iFileEntryRem--;
00626
00627 }
00628
00629
00630 if (pEntry->d_type == DT_DIR)
00631 {
00632 strcpy(psDirList->cFile, pEntry->d_name);
00633 iDirEntries++;
00634 iDirEntriesNew++;
00635 iDirEntryRem--;
00636
00637 if (iDebug)
00638 {
00639 if (iDirEntriesNew == 1)
00640 fprintf(fLogFile, "new subdirs:\n");
00641 fprintf(fLogFile, " %d(%d): %s\n",
00642 iDirEntriesNew, iDirEntries, psDirList->cFile);
00643 }
00644
00645 if (iDirEntryRem <= 0)
00646 {
00647 fprintf(fLogFile, "DDD2 new space must be allocated\n");
00648 }
00649
00650 psDirList++;
00651
00652 }
00653 }
00654 }
00655
00656 gEndDirEntryClose:
00657 iRC = closedir(pDir);
00658
00659 if (iDebug)
00660 fprintf(fLogFile, " rc(closedir) = %d\n", iRC);
00661
00662 if ( (iDebug) || (iEntryLoop != 2) )
00663 {
00664 fprintf(fLogFile,
00665 " %d entries in directory %s found\n",
00666 iEntries, pcDirName);
00667 if (iMatch) fprintf(fLogFile,
00668 " %d matching with %s\n", iEntriesMatch, pcEntryMask);
00669 }
00670
00671 if (iDebug)
00672 {
00673 if (iFileEntries) fprintf(fLogFile,
00674 " thereof %d files (%d new)\n",
00675 iFileEntries, iFileEntriesNew);
00676 if (iDirEntries) fprintf(fLogFile,
00677 " thereof %d subdirectories (%d new)\n",
00678 iDirEntries, iDirEntriesNew);
00679 }
00680
00681 if ( (iEntryType == 0) || (iEntryType == 1) )
00682 *piFileNo = iFileEntries;
00683 if ( (iEntryType == 0) || (iEntryType == 2) )
00684 *piDirNo = iDirEntries;
00685
00686 if (iDebug)
00687 {
00688 if (iFileEntries) fprintf(fLogFile,
00689 " %d files provided in list, first %s\n",
00690 iFileEntries, psFileList0->cFile);
00691 else if ( (iEntryType == 0) || (iEntryType == 1) )
00692 {
00693 fprintf(fLogFile, " no files in %s found",
00694 pcDirName);
00695 if (iMatch) fprintf(fLogFile,
00696 " matching with %s\n", pcEntryMask);
00697 else
00698 fprintf(fLogFile, "\n");
00699 }
00700
00701 if (iDirEntries) fprintf(fLogFile,
00702 " %d subdirs provided in list, first %s\n",
00703 iDirEntries, psDirList0->cFile);
00704 else if ( (iEntryType == 0) || (iEntryType == 2) )
00705 {
00706 fprintf(fLogFile, " no subdirs in %s found",
00707 pcDirName);
00708 if ( (iMatch) && (iEntryType == 2) ) fprintf(fLogFile,
00709 " matching with %s\n", pcEntryMask);
00710 else
00711 fprintf(fLogFile, "\n");
00712 }
00713 }
00714
00715 gEndDirEntryList:
00716
00717 if (iDebug)
00718 fprintf(fLogFile, "\n-D- end %s\n\n", cModule);
00719
00720 if (iRCE)
00721 return iRCE;
00722
00723 if (iMatch)
00724 return iEntriesMatch;
00725 return iEntries;
00726
00727 }
00728 #endif
00729
00730 #ifndef Lynx
00731
00732
00733
00734
00735
00736
00737
00738 int rawGetFSEntries(char *pcStageFS)
00739
00740 {
00741 char cModule[32]="rawGetFSEntries";
00742 int iDebug = 0;
00743
00744 int iRC;
00745 int ii = 0;
00746
00747 int iEntries = 0;
00748 struct dirent **fEntryList;
00749
00750 if (iDebug) fprintf(fLogFile,
00751 "\n-D- begin %s: FS %s\n", cModule, pcStageFS);
00752
00753 iRC = scandir(pcStageFS, &fEntryList, NULL, NULL);
00754 if (iRC < 0 )
00755 {
00756 fprintf(fLogFile,
00757 "-E- %s: calling system function scandir, rc=%d\n",
00758 cModule, iRC);
00759 if (errno)
00760 {
00761 fprintf(fLogFile, " %s\n", strerror(errno));
00762 errno = 0;
00763 }
00764
00765 return -1;
00766 }
00767
00768 iEntries = 0;
00769 for (ii=0; ii<iRC; ii++)
00770 {
00771 if (iDebug) fprintf(fLogFile,
00772 " %d: %s\n", ii, fEntryList[ii]->d_name);
00773
00774 if ( (strcmp(fEntryList[ii]->d_name, ".") == 0) ||
00775 (strcmp(fEntryList[ii]->d_name, "..") == 0) )
00776 continue;
00777
00778 iEntries++;
00779 }
00780
00781 if (iDebug)
00782 fprintf(fLogFile, "-D- end %s\n\n", cModule);
00783
00784 return(iEntries);
00785
00786 }
00787 #endif
00788
00789
00790
00791
00792
00793
00794
00795 int rawGetFSfree(char *pcStageFS)
00796 {
00797 char cModule[32]="rawGetFSfree";
00798 int iDebug = 0;
00799
00800 int iRC;
00801 unsigned int itemsize, itemno;
00802 int iFree = 0;
00803
00804 FILE *fPipe;
00805 int iBuf;
00806 char cName[BUFSIZE_SMALL] = "", *pName;
00807 char cBuf[BUFSIZE_SMALL] = "", *pBuf;
00808 char cTempFile[MAX_FULL_FILE] = "";
00809 char cCmd[256] = "/home/rawserv/rawdf.sh ";
00810
00811 time_t tTime;
00812 pid_t pstr;
00813
00814 pBuf = &cBuf[0];
00815 pName = &cName[0];
00816 strcpy(cTempFile, pcStageFS);
00817
00818 tTime = time(NULL);
00819 pstr = getpid();
00820 sprintf(cName, "/size.t%d.p%d", (int) tTime, pstr);
00821 strcat(cTempFile, pName);
00822
00823 strcat(cCmd, pcStageFS);
00824 strcat(cCmd, " ");
00825 strcat(cCmd, cTempFile);
00826
00827 if (iDebug)
00828 fprintf(fLogFile, "\n-D- begin %s: execute\n '%s'\n",
00829 cModule, cCmd);
00830
00831 if (system(NULL))
00832 {
00833 iRC = system(cCmd);
00834 if (iRC)
00835 {
00836 fprintf(fLogFile, "-W- %s: system() failed, rc = %d\n",
00837 cModule, iRC);
00838 return -1;
00839 }
00840 else
00841 {
00842 if (iDebug)
00843 fprintf(fLogFile,
00844 " shell command successfully executed\n");
00845 }
00846 }
00847 else
00848 {
00849 fprintf(fLogFile, "-W- %s: system() not available\n",
00850 cModule);
00851 return -1;
00852 }
00853
00854 fPipe = NULL;
00855 fPipe = fopen(cTempFile, "r");
00856 if (fPipe == NULL)
00857 {
00858 fprintf(fLogFile, "-E- %s: opening file %s\n",
00859 cModule, cTempFile);
00860 if (errno)
00861 {
00862 fprintf(fLogFile, " %s\n", strerror(errno));
00863 errno = 0;
00864 }
00865
00866 return -1;
00867 }
00868
00869 if (iDebug)
00870 fprintf(fLogFile, " file %s opened\n", cTempFile);
00871
00872 itemsize = sizeof(char);
00873 itemno = BUFSIZE_SMALL;
00874 iBuf = fread(pBuf, itemsize, itemno, fPipe);
00875 if (iBuf <= 0)
00876 {
00877 fprintf(fLogFile, "-E- %s: fread, rc = %d\n", cModule, iBuf);
00878 if (errno)
00879 {
00880 fprintf(fLogFile, " %s\n", strerror(errno));
00881 errno = 0;
00882 }
00883
00884 fprintf(fLogFile, " NO status buffer sent\n");
00885
00886 }
00887 else
00888 {
00889 iFree = atoi(pBuf);
00890 if (iDebug)
00891 {
00892 fprintf(fLogFile, " %d bytes in file: %s", iBuf, pBuf);
00893 fprintf(fLogFile, " free kB: %d\n", iFree);
00894 }
00895 }
00896
00897 iRC = fclose(fPipe);
00898 if (iRC)
00899 {
00900 fprintf(fLogFile, "-E- %s: rc = %d closing file\n",
00901 cModule, iRC);
00902 if (errno)
00903 {
00904 fprintf(fLogFile, " %s\n", strerror(errno));
00905 errno = 0;
00906 }
00907
00908 return(-1);
00909 }
00910
00911 if (iDebug)
00912 fprintf(fLogFile, " file %s closed\n", cTempFile);
00913
00914 iRC = remove(cTempFile);
00915 if (iRC)
00916 {
00917 fprintf(fLogFile, "-E- %s: rc = %d removing file %s\n",
00918 cModule, iRC, cTempFile);
00919 if (errno)
00920 {
00921 fprintf(fLogFile, " %s\n", strerror(errno));
00922 errno = 0;
00923 }
00924
00925 return -1;
00926 }
00927 if (iDebug)
00928 fprintf(fLogFile, " file %s removed\n", cTempFile);
00929
00930 if (iDebug)
00931 fprintf(fLogFile, "-D- end %s\n\n", cModule);
00932
00933 if (iBuf <= 0)
00934 return -1;
00935 else
00936 return(iFree);
00937
00938 }
00939
00940 #ifndef Lynx
00941
00942
00943
00944
00945
00946
00947
00948 int rawGetFSSpace(char *pcFileSystem,
00949 int *piSizeAll,
00950 int *piSizeAvail,
00951 int *piNodeAll,
00952 int *piNodeAvail)
00953 {
00954 char cModule[32] = "rawGetFSSpace";
00955 int iDebug = 0;
00956
00957 int iRC;
00958 int iBlockSize = 4;
00959 int iSizeAll = 0;
00960 int iSizeFree = 0;
00961 int iSizeAvail = 0;
00962 int iNodeAll = 0;
00963 int iNodeAvail = 0;
00964
00965 struct statfs sFSstatus, *pFSstatus;
00966
00967 if (iDebug) fprintf(fLogFile,
00968 "\n-D- begin %s: FS %s\n", cModule, pcFileSystem);
00969
00970 pFSstatus = &sFSstatus;
00971
00972 iRC = statfs(pcFileSystem, pFSstatus);
00973 if (iRC)
00974 {
00975 fprintf(fLogFile,
00976 "-E- %s: calling system function statfs, rc=%d\n",
00977 cModule, iRC);
00978 if (errno)
00979 {
00980 fprintf(fLogFile, " %s\n", strerror(errno));
00981 errno = 0;
00982 }
00983
00984 return -1;
00985 }
00986
00987 iBlockSize = (int) pFSstatus->f_bsize;
00988 if (iBlockSize == 0)
00989 {
00990 fprintf(fLogFile,
00991 "-W- unexpected blocksize found: 0 byte\n");
00992 return 1;
00993 }
00994 else
00995 {
00996 if (iDebug) fprintf(fLogFile,
00997 " blocksize found %d byte\n", iBlockSize);
00998 if (iBlockSize >= 1024)
00999 iBlockSize /= 1024;
01000 else
01001 {
01002 fprintf(fLogFile,
01003 "-W- unexpected blocksize found: %d byte\n", iBlockSize);
01004 return 1;
01005 }
01006 }
01007
01008
01009 iSizeAll = (int) (pFSstatus->f_blocks/1000)*iBlockSize;
01010 iSizeFree = (int) (pFSstatus->f_bfree/1000)*iBlockSize;
01011 iSizeAvail = (int) (pFSstatus->f_bavail/1000)*iBlockSize;
01012
01013 iNodeAll = (int) pFSstatus->f_files;
01014 iNodeAvail = (int) pFSstatus->f_ffree;
01015
01016 if (iDebug)
01017 {
01018 fprintf(fLogFile,
01019 " overall space %d MB, free %d MB, available %d MB\n",
01020 iSizeAll, iSizeFree, iSizeAvail);
01021 fprintf(fLogFile,
01022 " overall file nodes %d, available %d\n",
01023 iNodeAll, iNodeAvail);
01024 }
01025
01026 *piSizeAll = iSizeAll;
01027 *piSizeAvail = iSizeAvail;
01028 *piNodeAll = iNodeAll;
01029 *piNodeAvail = iNodeAvail;
01030
01031 if (iDebug)
01032 fprintf(fLogFile, "-D- end %s\n\n", cModule);
01033
01034 return 0;
01035
01036 }
01037 #endif
01038
01039
01040
01041
01042
01043
01044
01045 int rawGetFileAttr(char *pcFile, unsigned long *plFileSize)
01046 {
01047 char cModule[32] = "rawGetFileAttr";
01048 int iDebug = 0;
01049
01050 FILE *f_ifile;
01051 int iRC;
01052 unsigned long lFileSize;
01053 unsigned long lr;
01054 int iReclen;
01055
01056 int ilocSize = 5;
01057 int ilocFile = 9;
01058 int ii, ilen, iloc;
01059
01060 char cCmd[CMDLEN] = "ls -l ";
01061 char *pCmd;
01062 const char *pType = "r";
01063 char *pBuf, *pBuf0;
01064 const char *pcDollar = "$";
01065 char *pcc, *ploc;
01066
01067 char *pctoken;
01068 const char *pcblank = " ";
01069
01070 int icount = 0;
01071
01072
01073
01074 if (iDebug)
01075 {
01076 fprintf(fLogFile,
01077 "\n-D- begin %s: file %s\n", cModule, pcFile);
01078 fflush(fLogFile);
01079 }
01080
01081 iReclen = 0;
01082
01083
01084 ploc = strchr(pcFile, *pcDollar);
01085 if (ploc != NULL)
01086 {
01087 if (iDebug)
01088 {
01089 fprintf(fLogFile, "-D- $ in file name found: %s\n", pcFile);
01090 fflush(fLogFile);
01091 }
01092 ilen = strlen(pcFile);
01093 pcc = pcFile;
01094 for (ii = 1; ii <= ilen; ii++)
01095 {
01096 iloc = strncmp(pcc, pcDollar, 1);
01097 if (iloc == 0) strncat(cCmd, "\\", 1);
01098 strncat(cCmd, pcc++, 1);
01099 }
01100 }
01101 else strcat(cCmd, pcFile);
01102
01103 if (iDebug)
01104 {
01105 fprintf(fLogFile, "-D- %s: ex '%s'\n", cModule, cCmd);
01106 fflush(fLogFile);
01107 }
01108
01109 pCmd = &cCmd[0];
01110 f_ifile = popen(pCmd, pType);
01111 if (f_ifile == NULL)
01112 {
01113 fprintf(fLogFile, "-E- %s: opening pipe\n", cModule);
01114 return -1;
01115 }
01116 if (iDebug)
01117 {
01118 fprintf(fLogFile, " %s: pipe opened\n", cModule);
01119 fflush(fLogFile);
01120 }
01121
01122 if ( !(pBuf0 = (char *) malloc(BUFSIZE)) )
01123 {
01124 fprintf(fLogFile, "-E- %s: allocation buffer failed\n", cModule);
01125 pclose(f_ifile);
01126 return(-1);
01127 }
01128 if (iDebug)
01129 {
01130 fprintf(fLogFile, " %s: buffer allocated\n", cModule);
01131 fflush(fLogFile);
01132 }
01133
01134 pBuf = pBuf0;
01135 lr = fread(pBuf, sizeof(char), BUFSIZE, f_ifile);
01136 if (lr <= 0)
01137 {
01138 fprintf(fLogFile, "-E- %s: reading from pipe failed\n", cModule);
01139 pclose(f_ifile);
01140 return(-1);
01141 }
01142
01143 pBuf += (lr-1);
01144 strncpy(pBuf, "\0", 1);
01145
01146 if (iDebug)
01147 {
01148 fprintf(fLogFile, " %s: complete string: (%lu bytes): \n%s\n",
01149 cModule, lr, pBuf0);
01150 fflush(fLogFile);
01151 }
01152
01153 pBuf = pBuf0;
01154 while ( (pctoken = strtok(pBuf, pcblank)) != NULL)
01155 {
01156 icount++;
01157 if (iDebug)
01158 {
01159 fprintf(fLogFile, " token %d: %s\n", icount, pctoken);
01160 fflush(fLogFile);
01161 }
01162
01163 if (icount == 2)
01164 {
01165
01166
01167 iRC = strcmp(pctoken, ".kshrc");
01168 if (iRC == 0)
01169 {
01170 fprintf(fLogFile, " %s: token %d: %s found\n",
01171 cModule, icount, pctoken);
01172 ilocSize += 4;
01173 ilocFile += 4;
01174 }
01175 }
01176
01177 if (icount == ilocSize)
01178 {
01179
01180
01181
01182
01183 if ( ( iRC = sscanf( pctoken, "%lu", &lFileSize) ) <= 0 )
01184 {
01185 fprintf(fLogFile, "-E- %s: filesize %lu (%s) invalid\n",
01186 cModule, lFileSize, pctoken);
01187 if (errno)
01188 {
01189 fprintf(fLogFile, " %s\n", strerror(errno));
01190 errno = 0;
01191 }
01192 pclose(f_ifile);
01193
01194 return(-1);
01195 }
01196 if (iDebug)
01197 {
01198 fprintf(fLogFile, " file size %lu\n", lFileSize);
01199 fflush(fLogFile);
01200 }
01201
01202 if ( (lFileSize == 0) && (iDebug) )
01203 fprintf(fLogFile, " file %s empty\n", pcFile);
01204
01205 if (lFileSize > MAX_FILE_SIZE)
01206 {
01207 fprintf(fLogFile,
01208 "-E- %s: file %s too large (%lu byte), max allowed 2GB -1\n",
01209 cModule, pcFile, lFileSize);
01210 pclose(f_ifile);
01211 return(-1);
01212 }
01213 }
01214
01215 if (icount == ilocFile)
01216 {
01217 if ( (iRC = strcmp(pctoken, pcFile) ) != 0)
01218 {
01219 fprintf(fLogFile,
01220 "-E- %s: file name check: %s\n", cModule, pctoken);
01221 pclose(f_ifile);
01222 return(-1);
01223 }
01224 }
01225
01226 pBuf = NULL;
01227
01228 }
01229
01230 pclose(f_ifile);
01231
01232
01233 if (errno)
01234 errno = 0;
01235
01236 *plFileSize = lFileSize;
01237 if (iDebug)
01238 {
01239 fprintf(fLogFile, "-D- end %s\n\n", cModule);
01240 fflush(fLogFile);
01241 }
01242
01243 return 0;
01244
01245 }
01246
01247
01248
01249
01250
01251
01252 int rawGetFileList( char *pcFile,
01253 int iAccept,
01254
01255
01256 int iEntryLoop,
01257 char **ppFileList)
01258 {
01259 char cModule[32] = "rawGetFileList";
01260 int iDebug = 0;
01261
01262 int iRC = 0;
01263 int iRCE = 0;
01264 int iIgnore = 0;
01265 int ilen, iloc, ii, jj;
01266 int ird, ipc, ipc1, irem, grem = 0;
01267 int iFileno, iFilenoo;
01268 int *piFileno;
01269 int *piFileList;
01270
01271 char *pcc, *pcc0, *ploc;
01272 unsigned long lr;
01273
01274 FILE *f_ifile;
01275
01276 char cCmd[CMDLEN] = "ls -L ";
01277
01278
01279 char *pCmd;
01280 char *pBuf;
01281 char cBuf[MAX_FULL_FILE];
01282 const char *pcDollar = "$";
01283
01284 srawFileList *psFileList,
01285 *psFileList0,
01286 *psFileList0c;
01287
01288
01289
01290 if (iDebug)
01291 fprintf(fLogFile, "\n-D- begin %s\n", cModule);
01292
01293 ploc = strchr(pcFile, *pcDollar);
01294 if (ploc != NULL)
01295 {
01296 if (iDebug)
01297 fprintf(fLogFile, " '$' in file name found: %s\n", pcFile);
01298 ilen = strlen(pcFile);
01299 pcc = pcFile;
01300 for (ii=1; ii<=ilen; ii++)
01301 {
01302 iloc = strncmp(pcc, pcDollar, 1);
01303 if (iloc == 0) strncat(cCmd, "\\", 1);
01304 strncat(cCmd, pcc++, 1);
01305 }
01306 }
01307 else strcat(cCmd, pcFile);
01308 strcat(cCmd, " 2>/dev/null");
01309
01310 if (iDebug)
01311 fprintf(fLogFile, " command: %s\n", cCmd);
01312
01313 piFileList = (int *) *ppFileList;
01314 piFileno = piFileList++;
01315 iFilenoo = *piFileno;
01316 psFileList = (srawFileList *) piFileList;
01317 psFileList0 = psFileList;
01318
01319 if (iFilenoo)
01320 {
01321 if (iDebug) fprintf(fLogFile,
01322 " %d old files in list\n", iFilenoo);
01323
01324 for (ii=1; ii<=iFilenoo; ii++)
01325 {
01326 if (iDebug == 1) fprintf(fLogFile,
01327 " %d (old): %s\n", ii, psFileList->cFile);
01328 psFileList++;
01329 }
01330 }
01331
01332 pCmd = &cCmd[0];
01333 f_ifile = popen(pCmd, "r");
01334 if (f_ifile == NULL)
01335 {
01336 fprintf(fLogFile, "-E- %s: opening pipe\n", cModule);
01337 return(-1);
01338 }
01339 if (iDebug) fprintf(fLogFile, " pipe opened\n");
01340
01341 if ( !(pBuf = (char *) malloc(BUFSIZE)) )
01342 {
01343 fprintf(fLogFile,
01344 "-E- %s: allocation buffer failed\n", cModule);
01345 pclose(f_ifile);
01346 return(-1);
01347 }
01348 if (iDebug)
01349 fprintf(fLogFile, " buffer allocated\n");
01350
01351 memset(&cBuf[0], '\0', MAX_FULL_FILE);
01352 lr = 1;
01353 iFileno = 0;
01354 while (lr > 0)
01355 {
01356 gRead:
01357 memset(pBuf, '\0', BUFSIZE);
01358 lr = fread(pBuf, sizeof(char), BUFSIZE, f_ifile);
01359 if (lr > 0)
01360 {
01361 pcc0 = pBuf;
01362 pcc = pBuf;
01363 ird = lr;
01364
01365 if (iDebug == 2)
01366 fprintf(fLogFile, "-D- received %d bytes:\n", ird);
01367
01368 while(ird > 0)
01369 {
01370 if (iDebug == 2)
01371 fprintf(fLogFile, " '%s'", pcc0);
01372 ipc = strcspn(pcc0, "\n");
01373 irem = strlen(pcc0);
01374 pcc = strchr(pcc0, '\n');
01375 if (iDebug == 2) fprintf(fLogFile,
01376 "\n first length %d, total %d, remainder %d\n",
01377 ipc, irem, grem);
01378
01379 if (grem)
01380 {
01381 if (ipc > 0)
01382 {
01383 strncat(cBuf, pcc0, (unsigned) ipc);
01384 if (iDebug == 2) fprintf(fLogFile,
01385 " last concatenated: %s\n", cBuf);
01386 }
01387
01388 ii = strlen(cBuf);
01389
01390
01391 if (strncmp(&(cBuf[ii-1]), ":", 1) == 0)
01392 {
01393 if (iDebug) fprintf(fLogFile,
01394 "\n stop checking, ignore subdirectory %s\n",
01395 cBuf);
01396 lr = 0;
01397 break;
01398 }
01399
01400 if ( (strcmp(cBuf, "./")) &&
01401 (ii) &&
01402 (strncmp(&(cBuf[ii-1]), ":", 1)) )
01403
01404 {
01405 iRC = rawTestFileName(cBuf);
01406 if ( (iRC == 0) ||
01407 ( (iRC == 1) && (iAccept >= 1) ) )
01408 {
01409 if (iFilenoo)
01410 {
01411 psFileList0c = psFileList0;
01412
01413
01414 for (jj=1; jj<=iFilenoo; jj++)
01415 {
01416 iRC = strcmp(cBuf, psFileList0c->cFile);
01417 if (iRC == 0)
01418 {
01419 iIgnore = 1;
01420 if (iDebug) fprintf(fLogFile,
01421 " entry %s already available(1)\n",
01422 cBuf);
01423 break;
01424 }
01425 psFileList0c++;
01426 }
01427 }
01428
01429 if (iIgnore == 0)
01430 {
01431 strcpy(psFileList->cFile, cBuf);
01432 iFileno++;
01433 if (iDebug) fprintf(fLogFile,
01434 " %s stored(1), addr %p\n",
01435 psFileList->cFile, psFileList);
01436
01437 psFileList++;
01438 }
01439 else
01440 iIgnore = 0;
01441
01442 if (iFileno >= MAX_FILE_NO)
01443 {
01444 fprintf(fLogFile,
01445 "-E- %s: List of files for archive/retrieve currently limited to %d entries\n",
01446 cModule, --iFileno);
01447 fprintf(fLogFile,
01448 " %s: NOT ALL files handled\n",
01449 cModule);
01450 goto gFinishList;
01451 }
01452 }
01453 else
01454 {
01455 if (iRC == 1)
01456 {
01457 fprintf(fLogFile,
01458 "-W- file name %s has uppercase letters - ignored\n",
01459 cBuf);
01460 iRCE = 1;
01461 }
01462 if (iRC == 2)
01463 {
01464 fprintf(fLogFile,
01465 "-W- directory %s ignored\n", cBuf);
01466 }
01467 }
01468 }
01469
01470 memset(&cBuf, '\0', strlen(cBuf));
01471 grem = 0;
01472 }
01473 else
01474 {
01475 strncpy(cBuf, pcc0, (unsigned) ipc);
01476 strcat(cBuf, "\0");
01477 if (irem - ipc == 0)
01478 {
01479 ipc1 = strlen(cBuf);
01480 if (iDebug == 2) fprintf(fLogFile,
01481 " grem set, cBuf: %s (%d byte) \n", cBuf, ipc1);
01482 grem = 1;
01483 }
01484 else
01485 {
01486 ii = strlen(cBuf);
01487
01488
01489 if (strncmp(&(cBuf[ii-1]), ":", 1) == 0)
01490 {
01491 if (iDebug) fprintf(fLogFile,
01492 "\n stop checking, ignore subdirectory %s\n",
01493 cBuf);
01494 lr = 0;
01495 break;
01496 }
01497
01498 if ( (strcmp(cBuf, "./")) &&
01499 (ii) &&
01500 (strncmp(&(cBuf[ii-1]), ":", 1)) )
01501
01502 {
01503 iRC = rawTestFileName(cBuf);
01504 if ( (iRC == 0) ||
01505 ( (iRC == 1) && (iAccept >= 1) ) )
01506 {
01507 if (iFilenoo)
01508 {
01509 psFileList0c = psFileList0;
01510
01511
01512 for (jj=1; jj<=iFilenoo; jj++)
01513 {
01514 if (ipc == (int) strlen(psFileList0c->cFile))
01515 {
01516 iRC = strncmp(cBuf,
01517 psFileList0c->cFile,
01518 (unsigned) ipc);
01519 if (iRC == 0)
01520 {
01521 iIgnore = 1;
01522 if (iDebug) fprintf(fLogFile,
01523 " entry %s already available(2)\n",
01524 cBuf);
01525 break;
01526 }
01527 }
01528 psFileList0c++;
01529 }
01530 }
01531
01532 if (iIgnore == 0)
01533 {
01534 strncpy(psFileList->cFile, cBuf, (unsigned) ipc);
01535 iFileno++;
01536
01537 if (iDebug) fprintf(fLogFile,
01538 " %s stored(2), addr %p\n",
01539 psFileList->cFile, psFileList);
01540 psFileList++;
01541 }
01542 else
01543 iIgnore = 0;
01544
01545 if (iFileno >= MAX_FILE_NO)
01546 {
01547 fprintf(fLogFile,
01548 "-E- %s: List of files for archive/retrieve currently limited to %d entries\n",
01549 cModule, --iFileno);
01550 fprintf(fLogFile,
01551 " %s: NOT ALL files handled\n",
01552 cModule);
01553 goto gFinishList;
01554 }
01555 }
01556 else
01557 {
01558 if (iRC == 1)
01559 {
01560 fprintf(fLogFile,
01561 "-W- file name %s has uppercase letters - ignored\n",
01562 cBuf);
01563 iRCE = 1;
01564 }
01565 if (iRC == 2)
01566 fprintf(fLogFile,
01567 "-W- directory %s ignored\n", cBuf);
01568 }
01569 }
01570
01571 memset(&cBuf, '\0', strlen(cBuf));
01572 }
01573
01574 }
01575
01576 pcc0 = ++pcc;
01577 ird -= (ipc+1);
01578 }
01579
01580 }
01581
01582 }
01583
01584 gFinishList:
01585 if (iEntryLoop)
01586 {
01587 if (iFileno == 0)
01588 fprintf(fLogFile, "-I- no (new) files found\n");
01589 else if (iFileno > 1)
01590 fprintf(fLogFile, "-I- %d (new) files found\n", iFileno);
01591 }
01592
01593 if ( (iDebug) && (iFileno) )
01594 {
01595 psFileList = (srawFileList *) piFileList;
01596
01597 for (ii=1; ii<=iFilenoo; ii++)
01598 {
01599 if (iDebug == 1) fprintf(fLogFile,
01600 " %d (old): %s\n", ii, psFileList->cFile); psFileList++;
01601 }
01602 for (ii=iFilenoo+1; ii<=iFilenoo+iFileno; ii++)
01603 {
01604 if (iDebug == 1) fprintf(fLogFile,
01605 " %d: %s\n", ii, psFileList->cFile); psFileList++;
01606 }
01607 }
01608
01609 iFileno += iFilenoo;
01610 piFileno[0] = iFileno;
01611
01612 iRC = pclose(f_ifile);
01613 if (iDebug)
01614 {
01615 if (iRC)
01616 {
01617 fprintf(fLogFile, "-E- %s: iRC = %d closing pipe\n",
01618 cModule, iRC);
01619 if (errno)
01620 {
01621 fprintf(fLogFile, " %s\n", strerror(errno));
01622 errno = 0;
01623 }
01624 }
01625 else
01626 fprintf(fLogFile, " pipe closed\n");
01627
01628 fprintf(fLogFile, "-D- end %s\n\n", cModule);
01629 }
01630
01631
01632 if (errno)
01633 errno = 0;
01634
01635 if (iRCE)
01636 return iRCE;
01637 else
01638 return 0;
01639
01640 }
01641
01642
01643
01644
01645
01646
01647 int rawGetHostConn()
01648 {
01649 char cModule[32] = "rawGetHostConn";
01650 int iDebug = 0;
01651
01652 int iRC;
01653 int ii;
01654 int iBuf = 0;
01655 int iCol = 0;
01656 int iType = 0;
01657
01658
01659
01660
01661 char *pcc;
01662 char cToken[16] = "", *pToken;
01663 char cheadName[16], *pheadName;
01664 char cheadMtu[16] = "mtu", *pheadMtu;
01665 char cName[16] = "", *pName;
01666 char cMtu[16] = "", *pMtu;
01667 char cNameRef1[16] = "";
01668 char cNameRef2[16] = "";
01669
01670 char cCmd[CMDLEN] = "netstat -i", *pCmd;
01671 char cBuf[1024] = "", *pBuf;
01672 char cNode[MAX_NODE] = "";
01673
01674 FILE *f_ifile;
01675
01676 if (iDebug)
01677 fprintf(fLogFile, "\n-D- in %s\n", cModule);
01678
01679 #ifdef _AIX
01680 strcpy(cheadName, "name");
01681 #else
01682 strcpy(cheadName, "iface");
01683 #endif
01684
01685 iRC = gethostname(cNode, MAX_NODE);
01686 if (iRC)
01687 {
01688 fprintf(fLogFile,
01689 "-E- %s: getting client host name: %s\n",
01690 cModule, strerror(iRC));
01691 return(1);
01692 }
01693 if (iDebug) fprintf(fLogFile,
01694 " %s: client host %s\n", cModule, cNode);
01695
01696 if (strncmp(cNode, "lx", 2) == 0)
01697 return(2);
01698 if (strncmp(cNode, "linux", 5) == 0)
01699 return(2);
01700 if (strncmp(cNode, "sp2", 3) == 0)
01701 return(4);
01702
01703 pToken = &cToken[0];
01704 pheadName = &cheadName[0];
01705 pheadMtu = &cheadMtu[0];
01706 pName = &cName[0];
01707 pMtu = &cMtu[0];
01708 pCmd = &cCmd[0];
01709 pBuf = &cBuf[0];
01710
01711 f_ifile = popen(pCmd, "r");
01712 if (f_ifile == NULL)
01713 {
01714 fprintf(fLogFile, "-E- %s: opening pipe\n", cModule);
01715 return(-1);
01716 }
01717 if (iDebug)
01718 fprintf(fLogFile, " %s: pipe opened\n", cModule);
01719
01720 iBuf = fread(pBuf, sizeof(char), 1024, f_ifile);
01721 if (iBuf <= 0)
01722 {
01723 fprintf(fLogFile, "-E- %s: reading from pipe failed\n", cModule);
01724 goto gError;
01725 }
01726
01727 if (iDebug == 2)
01728 fprintf(fLogFile, " %s command output: \n%s", cModule, cBuf);
01729
01730 pToken = strtok(pBuf, " \n");
01731 pcc = pToken;
01732 while (*pcc != '\0')
01733 {
01734 *pcc = tolower(*pcc);
01735 pcc++;
01736 }
01737
01738 if (strcmp(pToken, pheadName))
01739 {
01740 fprintf(fLogFile, "-E- %s: invalid name heading (%s, expected %s)\n",
01741 cModule, pToken, pheadName);
01742 goto gError;
01743 }
01744
01745 pToken = strtok(NULL, " \n");
01746 pcc = pToken;
01747 while (*pcc != '\0')
01748 {
01749 *pcc = tolower(*pcc);
01750 pcc++;
01751 }
01752
01753 if (strcmp(pToken, pheadMtu))
01754 {
01755 fprintf(fLogFile, "-E- %s: invalid mtu heading (%s, expected %s)\n",
01756 cModule, pToken, pheadMtu);
01757 goto gError;
01758 }
01759
01760 #ifdef _AIX
01761 iCol = 9;
01762 strcpy(cNameRef1, "en0");
01763 strcpy(cNameRef2, "fi0");
01764 #endif
01765 #ifdef Linux
01766 iCol = 12;
01767 strcpy(cNameRef1, "eth0");
01768 strcpy(cNameRef2, "fdd0");
01769 #endif
01770
01771 for (ii=1; ii<=iCol-2; ii++)
01772 { pToken = strtok(NULL, " \n"); }
01773
01774 for (;;)
01775 {
01776 pToken = strtok(NULL, " \n");
01777 if (pToken == NULL) break;
01778 pcc = pToken;
01779 while (*pcc != '\0')
01780 {
01781 *pcc = tolower(*pcc);
01782 pcc++;
01783 }
01784
01785 if (iDebug == 2)
01786 fprintf(fLogFile, "DDD %s: %s\n", cModule, pToken);
01787
01788 if (strcmp(pToken, cNameRef1) == 0)
01789 {
01790 iType = 1;
01791 if (iDebug)
01792 fprintf(fLogFile, " %s: ethernet available\n", cModule);
01793 }
01794 else if (strcmp(pToken, cNameRef2) == 0)
01795 {
01796 iType = 3;
01797 break;
01798 }
01799 }
01800
01801 pclose(f_ifile);
01802 if ( (iType != 3) && (iType != 1) )
01803 {
01804 fprintf(fLogFile,
01805 "-E- %s: invalid network connection type (%d)\n",
01806 cModule, iType);
01807 goto gError;
01808 }
01809 else if (iDebug)
01810 fprintf(fLogFile, "-D- end %s: network connection type %d\n\n",
01811 cModule, iType);
01812 goto gEnd;
01813
01814 gError:
01815 iType = -1;
01816
01817 gEnd:
01818 return(iType);
01819
01820 }
01821
01822
01823
01824
01825
01826
01827 char *rawGetUserid()
01828 {
01829 char cModule[32] = "rawGetUserid";
01830 int iDebug = 0;
01831
01832 unsigned int lr;
01833 FILE *f_ifile;
01834
01835 char cCmd[CMDLEN] = "whoami";
01836 char *pCmd;
01837 char *pBuf, *pBuf0;
01838
01839 pCmd = &cCmd[0];
01840 f_ifile = popen(pCmd, "r");
01841 if (f_ifile == NULL)
01842 {
01843 fprintf(fLogFile, "-E- %s: opening pipe\n", cModule);
01844 return(NULL);
01845 }
01846 if (iDebug)
01847 fprintf(fLogFile, " %s: pipe opened\n", cModule);
01848
01849 if ( !(pBuf0 = (char *) malloc(BUFSIZE)) )
01850 {
01851 fprintf(fLogFile, "-E- %s: allocation buffer failed\n", cModule);
01852 pclose(f_ifile);
01853 return(NULL);
01854 }
01855 if (iDebug)
01856 fprintf(fLogFile, " %s: buffer allocated\n", cModule);
01857
01858 pBuf = pBuf0;
01859 lr = fread(pBuf, sizeof(char), BUFSIZE, f_ifile);
01860 if (lr <= 0)
01861 {
01862 fprintf(fLogFile, "-E- %s: reading from pipe failed\n", cModule);
01863 pclose(f_ifile);
01864 return(NULL);
01865 }
01866
01867 pBuf += (lr-1);
01868 strncpy(pBuf, "\0", 1);
01869
01870 pclose(f_ifile);
01871
01872 if (iDebug) fprintf(fLogFile,
01873 "-D- %s: user name (%lu bytes): %s\n", cModule, lr, pBuf0);
01874
01875 return(pBuf0);
01876
01877 }