FOSSology  4.7.0-rc1
Open Source License Compliance by Open Source Software
util.c
Go to the documentation of this file.
1 /*
2  SPDX-FileCopyrightText: © 2006-2009 Hewlett-Packard Development Company, L.P.
3 
4  SPDX-License-Identifier: GPL-2.0-only
5 */
6 /* Equivalent to core nomos v1.29 */
7 
14 #include <stdarg.h>
15 #include <stdio.h>
16 #include "nomos.h"
17 #include "util.h"
18 #include "list.h"
19 #include "nomos_regex.h"
20 #include "nomos_utils.h"
21 
22 #define MM_CACHESIZE 20
23 #define MAXLENGTH 100
24 
25 #ifdef REUSE_STATIC_MEMORY
26 static char grepzone[10485760]; /* 10M for now, adjust if needed */
27 #endif /* REUSE_STATIC_MEMORY */
28 
29 /*
30  File local variables
31  */
32 static va_list ap;
33 static char utilbuf[myBUFSIZ];
34 static struct mm_cache mmap_data[MM_CACHESIZE];
35 static char cmdBuf[PATH_MAX * 2 + 256];
36 
37 
38 #ifdef MEMORY_TRACING
39 #define MEMCACHESIZ 200000
40 static int memlast = -1;
41 static struct mm_cache memcache[MEMCACHESIZ];
42 void memCacheDump();
43 #endif /* MEMORY_TRACING */
44 
50 int isDIR(char *dpath)
51 {
52 #ifdef PROC_TRACE
53  traceFunc("== isDIR(%s)\n", dpath);
54 #endif /* PROC_TRACE */
55 
56  return(isINODE(dpath, S_IFDIR));
57 }
58 
65 int isEMPTYFILE(char *fpath)
66 {
67 #ifdef PROC_TRACE
68  traceFunc("== isEMPTYFILE(%s)\n", fpath);
69 #endif /* PROC_TRACE */
70 
71  if (!isFILE(fpath)) {
72  return(0);
73  }
74  return(cur.stbuf.st_size == 0);
75 }
76 
83 int isBLOCK(char *bpath)
84 {
85 #ifdef PROC_TRACE
86  traceFunc("== isBLOCK(%s)\n", bpath);
87 #endif /* PROC_TRACE */
88 
89  return(isINODE(bpath, S_IFBLK));
90 }
91 
98 int isCHAR(char *cpath)
99 {
100 #ifdef PROC_TRACE
101  traceFunc("== isCHAR(%s)\n", cpath);
102 #endif /* PROC_TRACE */
103 
104  return(isINODE(cpath, S_IFCHR));
105 }
106 
113 int isPIPE(char *ppath)
114 {
115 #ifdef PROC_TRACE
116  traceFunc("== isPIPE(%s)\n", ppath);
117 #endif /* PROC_TRACE */
118 
119  return(isINODE(ppath, S_IFIFO));
120 }
121 
128 int isSYMLINK(char *spath)
129 {
130 #ifdef PROC_TRACE
131  traceFunc("== isSYMLINK(%s)\n", spath);
132 #endif /* PROC_TRACE */
133 
134  return(isINODE(spath, S_IFLNK));
135 }
136 
143 int isINODE(char *ipath, int typ)
144 {
145  int ret;
146  char sErrorBuf[1024];
147 
148 #ifdef PROC_TRACE
149  traceFunc("== isINODE(%s, 0x%x)\n", ipath, typ);
150 #endif /* PROC_TRACE */
151 
152  if ((ret = stat(ipath, &cur.stbuf)) < 0) {
153  /*
154  IF we're trying to stat() a file that doesn't exist,
155  that's no biggie.
156  Any other error, however, is fatal.
157  */
158  if (errno == ENOENT) {
159  return 0;
160  }
161  strerror_r(errno, sErrorBuf, sizeof(sErrorBuf));
162  LOG_ERROR("Error: %s getting stat on file: %s", sErrorBuf, ipath)
163  }
164  if (typ == 0) {
165  return(1);
166  }
167  return((int)(cur.stbuf.st_mode & S_IFMT & typ));
168 }
169 
175 char *newReloTarget(char *basename)
176 {
177  static char newpath[myBUFSIZ];
178  int i;
179 
180 #ifdef PROC_TRACE
181  traceFunc("== newReloTarget(%s)\n", basename);
182 #endif /* PROC_TRACE */
183 
184  for (i = 0; i < MAX_RENAME; i++) {
185  (void) snprintf(newpath, sizeof(newpath), "%s_%s-renamed.%03d", basename, gl.progName, i);
186  if (access(newpath, F_OK) && errno == ENOENT) {
187  break;
188  }
189  }
190  if (i == MAX_RENAME) {
191  LOG_FATAL("%s: no suitable relocation target (%d tries)", basename, i)
192  Bail(-__LINE__);
193  }
194  return(newpath);
195 }
196 
197 
198 
199 #ifdef MEMORY_TRACING
205 char *memAllocTagged(int size, char *name)
206 {
207  void *ptr;
208  sErrorBuf[1024];
209 
210  /*
211  * we don't track memory allocated; we front-end for errors and return
212  * the pointer we were given.
213  */
214 
215 #if defined(PROC_TRACE) || defined(MEM_ACCT)
216  traceFunc("== memAllocTagged(%d, \"%s\")\n", size, name);
217 #endif /* PROC_TRACE || MEM_ACCT */
218 
219  if (size < 1) {
220  LOG_FATAL("Cannot alloc %d bytes!", size)
221  Bail(-__LINE__);
222  }
223  if (++memlast == MEMCACHESIZ) {
224  LOG_FATAL("*** memAllocTagged: out of memcache entries")
225  Bail(-__LINE__);
226  }
227 #ifdef USE_CALLOC
228  if ((ptr = calloc((size_t) 1, (size_t) size)) == (void *) NULL) {
229  strerror_r(errno, sErrorBuf, sizeof(sErrorBuf));
230  LOG_FATAL("calloc for %s, error: %s", name, sErrorBuf)
231  Bail(-__LINE__);
232  }
233 #else /* not USE_CALLOC */
234  if ((ptr = malloc((size_t) size)) == (void *) NULL) {
235  strerror_r(errno, sErrorBuf, sizeof(sErrorBuf));
236  LOG_FATAL("malloc for %s, error: %s", name, sErrorBuf)
237  Bail(-__LINE__);
238  }
239  (void) memset(ptr, 0, (size_t) size);
240 #endif /* not USE_CALLOC */
241 #if DEBUG > 3 || defined(MEM_ACCT)
242  printf("+%p:%p=(%d)\n", ptr, ptr+size-1, size);
243 #endif /* DEBUG > 3 || MEM_ACCT */
244  memcache[memlast].mmPtr = ptr;
245  memcache[memlast].size = size;
246  strncpy(memcache[memlast].label, name, sizeof(memcache[memlast].label) - 1);
247  memcache[memlast].label[sizeof(memcache[memlast].label) - 1] = '\0';
248 #ifdef MEM_ACCT
249  printf("memAllocTagged(%d, \"%s\") == %p [entry %04d]\n", size, name, ptr,
250  memlast);
251  /* memCacheDump("post-memAllocTagged:"); */
252 #endif /* MEM_ACCT */
253  return(ptr);
254 }
255 
256 
257 void memFreeTagged(void *ptr, char *note)
258 {
259  struct mm_cache *mmp;
260  int i;
261 
262 #if defined(PROC_TRACE) || defined(MEM_ACCT)
263  traceFunc("== memFree(%p, \"%s\")\n", ptr, note);
264 #endif /* PROC_TRACE || MEM_ACCT */
265 
266 #ifdef MEMORY_TRACING
267  DEBUG("mprobe(%p)\n", ptr)
268  mprobe(ptr); /* see if glibc still likes this memory */
269 #endif /* MEMORY_TRACING */
270  for (mmp = memcache, i = 0; i <= memlast; mmp++, i++) {
271  if (mmp->mmPtr == ptr) {
272 #ifdef MEM_ACCT
273  printf("memFree(%p, \"%s\") is entry %04d (%d bytes)\n", ptr, note, i,
274  mmp->size);
275 #endif /* MEM_ACCT */
276  break;
277  }
278  }
279  if (i > memlast) {
280  LOG_FATAL("Could not locate %p to free!", ptr)
281  Bail(-__LINE__);
282  }
283  free(ptr);
284 #if DEBUG > 3 || defined(MEM_ACCT)
285  printf("-%p=(%d)\n", ptr, mmp->size);
286 #endif /* DEBUG > 3 || MEM_ACCT */
287  if (i != memlast) {
288  (void) memmove(&memcache[i], &memcache[i+1],
289  (memlast-i)*sizeof(struct mm_cache));
290  }
291  memset(&memcache[memlast], 0, sizeof(struct mm_cache));
292  memlast--;
293 #ifdef MEM_ACCT
294  memCacheDump("post-memFree:");
295 #endif /* MEM_ACCT */
296  return;
297 }
298 
299 
300 void memCacheDump(char *s)
301 {
302  struct mm_cache *m;
303  static int first = 1;
304  int i, start;
305  /* */
306  if (s != NULL_STR) {
307  printf("%s\n", s);
308  }
309  if (memlast < 0) {
310  printf("%%%%%% mem-cache is EMPTY\n");
311  return;
312  }
313  start = (memlast > 50 ? memlast-50 : 0);
314  printf("%%%%%% mem-cache @ %p [last=%d]\n", memcache, memlast);
315  for (m = memcache+start, i = start; i <= memlast; m++, i++) {
316  printf("mem-entry %04d: %p (%d) - %s\n", i, m->mmPtr,
317  m->size, m->label);
318  if (!first) {
319  printf("... \"%s\"\n", m->mmPtr);
320  }
321  }
322  printf("%%%%%% mem-cache END\n");
323  if (first) {
324  first --;
325  }
326  return;
327 }
328 #endif /* MEMORY_TRACING */
329 
341 char *findBol(char *s, char *upperLimit)
342 {
343  char *cp;
344 
345 #ifdef PROC_TRACE
346  traceFunc("== findBol(%p, %p)\n", s, upperLimit);
347 #endif /* PROC_TRACE */
348 
349  if (s == NULL_STR || upperLimit == NULL_STR) {
350  return(NULL_STR);
351  }
352  for (cp = s; cp > upperLimit; cp--) {
353 #ifdef DEBUG
354  DEBUG("cp %p upperLimit %p\n", cp, upperLimit)
355 #endif /* DEBUG */
356  if (isEOL(*cp)) {
357 #ifdef DEBUG
358  DEBUG("Got it! BOL == %p\n", cp)
359 #endif /* DEBUG */
360  return((char*)(cp+1));
361  }
362  }
363  if (cp == upperLimit) {
364 #ifdef DEBUG
365  DEBUG("AT upperLimit %p\n", upperLimit);
366 #endif /* DEBUG */
367  return(upperLimit);
368  }
369  return(NULL_STR);
370 }
371 
379 char *findEol(char *s)
380 {
381  char *cp;
382 
383 #ifdef PROC_TRACE
384  traceFunc("== findEol(%p)\n", s);
385 #endif /* PROC_TRACE */
386 
387  if (s == NULL_STR) {
388  return(NULL_STR);
389  }
390  for (cp = s; *cp != NULL_CHAR; cp++) {
391  if (isEOL(*cp)) {
392  return(cp); /* return ptr to EOL or NULL */
393  }
394  }
395  if (*cp == NULL_CHAR) {
396  return(cp);
397  }
398  return(NULL_STR);
399 }
400 
410 void renameInode(char *oldpath, char *newpath)
411 {
412  int err = 0;
413  char sErrorBuf[1024];
414  /*
415  * we die here if the unlink() fails.
416  */
417 
418 #if defined(PROC_TRACE) || defined(UNPACK_DEBUG)
419  traceFunc("== renameInode(%s, %s)\n", oldpath, newpath);
420 #endif /* PROC_TRACE || UNPACK_DEBUG */
421 
422 #ifdef DEBUG
423  (void) mySystem("ls -ldi '%s'", oldpath);
424 #endif /* DEBUG */
425  if (rename(oldpath, newpath) < 0) {
426  if (errno == EXDEV) {
427  err = mySystem("mv '%s' %s", oldpath, newpath);
428  }
429  else {
430  err = 1;
431  }
432  if (err) {
433  strerror_r(errno, sErrorBuf, sizeof(sErrorBuf));
434  LOG_FATAL("rename(%s, %s) error: %s", oldpath, newpath, sErrorBuf)
435  Bail(-__LINE__);
436  }
437  }
438 #ifdef DEBUG
439  (void) mySystem("ls -ldi %s", newpath);
440 #endif /* DEBUG */
441  return;
442 }
443 
451 void chmodInode(char *pathname, int mode)
452 {
453  char sErrorBuf[1024];
454  /*
455  * we die here if the chmod() fails.
456  */
457 
458 #if defined(PROC_TRACE) || defined(UNPACK_DEBUG)
459  traceFunc("== chmodInode(%s, 0%o)\n", pathname, mode);
460 #endif /* PROC_TRACE || UNPACK_DEBUG */
461 
462  if (chmod(pathname, mode) < 0) {
463  strerror_r(errno, sErrorBuf, sizeof(sErrorBuf));
464  LOG_FATAL("chmod(\"%s\", 0%o) error: %s", pathname, mode, sErrorBuf)
465  Bail(-__LINE__);
466  }
467  return;
468 }
469 
477 FILE *fopenFile(char *pathname, char *mode)
478 {
479  FILE *fp;
480  char sErrorBuf[1024];
481  /*
482  * we don't track directories opened; we front-end and return what's
483  * given to us. we die here if the fopen() fails.
484  */
485 
486 #ifdef PROC_TRACE
487  traceFunc("== fopenFile(%s, \"%s\")\n", pathname, mode);
488 #endif /* PROC_TRACE */
489 
490  if ((fp = fopen(pathname, mode)) == (FILE *) NULL) {
491  strerror_r(errno, sErrorBuf, sizeof(sErrorBuf));
492  LOG_FATAL("fopen(%s) error: %s", pathname, sErrorBuf);
493  Bail(-__LINE__);
494  }
495  return(fp);
496 }
497 
498 /*
499  *
500  Save for now, could be useful for debugging
501 
502 static void printListToFile(list_t *l, char *filename, char *mode) {
503  FILE *fp;
504  item_t *ip;
505 
506  fp = fopenFile(filename, mode);
507  while ((ip = listIterate(l)) != NULL_ITEM) {
508  fprintf(fp, "%s\n", ip->str);
509  }
510  (void) fclose(fp);
511  return;
512 }
513  */
514 
522 FILE *popenProc(char *command, char *mode)
523 {
524  FILE *pp;
525  char sErrorBuf[1024];
526  /*
527  * we don't track directories opened; we front-end and return what's
528  * given to us. we die here if the popen() fails.
529  */
530 
531 #ifdef PROC_TRACE
532  traceFunc("== popenProc(\"%s\", %s)\n", command, mode);
533 #endif /* PROC_TRACE */
534 
535  if ((pp = popen(command, mode)) == (FILE *) NULL) {
536 #ifdef MEMORY_TRACING
537  memCacheDump("Post-popen-failure:");
538 #endif /* MEMORY_TRACING */
539  strerror_r(errno, sErrorBuf, sizeof(sErrorBuf));
540  LOG_FATAL("popen(\"%s\") error: %s", command, sErrorBuf)
541  Bail(-__LINE__);
542  }
543  return(pp);
544 }
545 
546 
552 char *wordCount(char *textp)
553 {
554  static char wcbuf[64];
555  int lines;
556  char *cp;
557 
558 #ifdef PROC_TRACE
559  traceFunc("== wordCount(%p)\n", textp);
560 #endif /* PROC_TRACE */
561 
562  lines = 0;
563  for (cp = textp; *cp; cp++) {
564  switch (*cp) {
565  case '\f':
566  break;
567  case '\n':
568  case '\r':
569  case '\v':
570  lines++;
571  break;
572  case ' ':
573  case '\t':
574  break;
575  default:
576  break;
577  }
578  }
579  (void) snprintf(wcbuf, sizeof(wcbuf), "%d lines", lines);
580  /*
581  * Save these values for use elsewhere, too.
582  */
583  cur.nLines = lines;
584  return(wcbuf);
585 }
586 
594 char *copyString(char *s, char *label)
595 {
596  char *cp;
597  int len;
598 
599 #ifdef PROC_TRACE
600  traceFunc("== copyString(%p, \"%s\")\n", s, label);
601 #endif /* PROC_TRACE */
602 
603  cp = memAlloc(len=(strlen(s)+1), label);
604 #ifdef DEBUG
605  printf("+CS: %d @ %p\n", len, cp);
606 #endif /* DEBUG */
607  (void) strcpy(cp, s);
608  return(cp);
609 }
610 
616 char *pathBasename(char *path)
617 {
618  char *cp;
619 
620 #ifdef PROC_TRACE
621  traceFunc("== pathBasename(\"%s\")\n", path);
622 #endif /* PROC_TRACE */
623 
624  cp = strrchr(path, '/');
625  return(cp == NULL_STR ? path : (char *)(cp+1));
626 }
627 
631 char *getInstances(char *textp, int size, int nBefore, int nAfter, char *regex,
632  int recordOffsets)
633 {
634  int i;
635  int notDone;
636  int buflen = 1;
637  static char *ibuf = NULL;
638  static int bufmax = 0;
639  char *sep = _REGEX(_UTIL_XYZZY);
640  item_t *p;
641  item_t *bp = 0;
642  char *fileeof;
643  char *start;
644  char *end;
645  char *curptr;
646  char *bufmark;
647  char save;
648  char *cp;
649  int newDataLen;
650  int regexFlags = REG_ICASE|REG_EXTENDED;
651 
652 #if defined(PROC_TRACE) || defined(PHRASE_DEBUG) || defined(DOCTOR_DEBUG)
653  traceFunc("== getInstances(%p, %d, %d, %d, \"%s\", %d)\n", textp, size,
654  nBefore, nAfter, regex, recordOffsets);
655 #endif /* PROC_TRACE || PHRASE_DEBUG || DOCTOR_DEBUG */
656 
657  if ((notDone = strGrep(regex, textp, regexFlags)) == 0) {
658 #ifdef PHRASE_DEBUG
659  printf("... no match: 1st strGrep()\n");
660 #endif /* PHRASE_DEBUG */
661  return(NULL_STR);
662  }
663  /*
664  * The global 'offsets list' is indexed by the seed/key (a regex) that we
665  * use for doctoring buffers... each entry will contain a list (containing
666  * the "paragraphs" that match the key) AND its size (e.g., # of 'chunks'),
667  * which also means, if there are N chunks, there are N-1 'xyzzy' separators.
668  */
669  p = listGetItem(&cur.offList, regex);
670  p->seqNo = cur.offList.used;
671  p->nMatch = 0;
672  if (recordOffsets) {
673  if (p->bList) free(p->bList);
674  p->bList = (list_t *)memAlloc(sizeof(list_t), MTAG_LIST);
675  (void) snprintf(utilbuf, sizeof(utilbuf), "\"%c%c%c%c%c%c%c%c%c%c\" match-list",
676  *regex, *(regex+1), *(regex+2), *(regex+3), *(regex+4),
677  *(regex+5), *(regex+6), *(regex+7), *(regex+8), *(regex+9));
678 #ifdef PHRASE_DEBUG
679  printf("Creating %s\n", utilbuf);
680 #endif /* PHRASE_DEBUG */
681  listInit(p->bList, 0, utilbuf); /* <- MEMORY LEAK from p->bList->items not freed */
682 #ifdef QA_CHECKS
683  p->val3++; /* sanity-check -- should never be >1 ! */
684  if (p->val3 > 1) {
685  LOG_FATAL("Called getInstances(%s) more than once", regex)
686  Bail(-__LINE__);
687  }
688 #endif /* QA_CHECKS */
689  }
690 #ifdef REUSE_STATIC_MEMORY
691  if (ibuf == NULL_STR) { /* first time, uninitialized */
692  ibuf = grepzone;
693  bufmax = sizeof(grepzone);
694  }
695  else if (ibuf != grepzone) {
696  memFree(ibuf, MTAG_DOUBLED); /* free the memory... */
697  ibuf = grepzone; /* ... and reset */
698  bufmax = sizeof(grepzone);
699  }
700 #else /* not REUSE_STATIC_MEMORY */
701  if (ibuf == NULL_STR) {
702  ibuf = memAlloc((bufmax = 1024*1024), MTAG_SEARCHBUF);
703  }
704 #endif /* not REUSE_STATIC_MEMORY */
705  *ibuf = NULL_CHAR;
706  bufmark = ibuf;
707  end = NULL_STR;
708  /*
709  * At this point, we know the string we're looking for is IN the file.
710  */
711 #ifdef PHRASE_DEBUG
712  printf("getInstances: \"%s\" [#1] in buf [%d-%d]\n", regex,
713  cur.regm.rm_so, cur.regm.rm_eo-1);
714  printf("Really in the buffer: [");
715  for (cp = textp + cur.regm.rm_so; cp < (textp + cur.regm.rm_eo); cp++) {
716  printf("%c", *cp);
717  }
718  printf("]\n");
719 #endif /* PHRASE_DEBUG */
720  /*
721  * Find the start of the text line containing the "first" match.
722  * locate start of "$nBefore lines above pattern match"; go up to the
723  * text on the _previous_ line before we 'really start counting'
724  */
725  curptr = textp;
726  fileeof = (char *) (textp+size);
727  while (notDone) { /* curptr is the 'current block' ptr */
728  p->nMatch++;
729 #ifdef PHRASE_DEBUG
730  printf("... found Match #%d\n", p->nMatch);
731 #endif /* PHRASE_DEBUG */
732  if (recordOffsets) {
733  (void) snprintf(utilbuf, sizeof(utilbuf), "buf%05d", p->nMatch);
734  bp = listGetItem(p->bList, utilbuf);
735  }
736  start = findBol(curptr + cur.regm.rm_so, textp);
737  /*
738  * Go to the beggining of the current line and, if nBefore > 0, go 'up'
739  * in the text "$nBefore" lines. Count 2-consecutive EOL-chars as one
740  * line since some text files use <CR><LF> as line-terminators.
741  */
742  if ((nBefore > 0) && (start > textp)) {
743  for (i = 0; (i < nBefore) && (start > textp); i++) {
744  start -= 2;
745  if ((start > textp) && isEOL(*start)) {
746  start--;
747  }
748  if (start > textp) {
749  start = findBol(start, textp);
750  }
751 #ifdef PHRASE_DEBUG
752  DEBUG("start = %p\n", start)
753 #endif /* PHRASE_DEBUG */
754  }
755  }
756  if (recordOffsets) {
757  bp->bStart = start-textp;
758  }
759  /*
760  * Now do what "grep -A $nAfter _filename+" does.
761  *****
762  * If nAfter == 0, we want the end of the current line.
763  *****
764  * If nAfter > 0, locate the end of the line of LAST occurrence of the
765  * string within the next $nAfter lines. Not well-worded, you say?
766  *****
767  * E.g., if we're saving SIX lines below and we see our pattern 4 lines
768  * below the first match then we'll save 10 lines from the first match.
769  * And to continue this example, if we then see our pattern 9 lines from
770  * the start of the buffer (since we're looking up to 10 lines now), we
771  * will save *15* lines. Repeat until the last 6 lines we save DO NOT
772  * have our pattern.
773  */
774  do {
775  curptr += cur.regm.rm_eo;
776  end = findEol(curptr);
777  if (end < fileeof) {
778  end++; /* first char past end-of-line */
779  }
780  if (nAfter > 0) {
781  for (i = 0; end < fileeof; end++) {
782  if (isEOL(*end)) { /* double-EOL */
783  end++; /* <CR><LF>? */
784  }
785  end = findEol(end);
786  if (end == NULL_STR) {
787  LOG_FATAL("lost the end-of-line")
788  Bail(-__LINE__);
789  }
790  if (*end == NULL_CHAR) {
791  break; /* EOF == done */
792  }
793  if (++i == nAfter) {
794  break;
795  }
796  }
797  if ((end < fileeof) && *end) {
798  end++; /* past newline-char */
799  }
800  }
801 #ifdef PHRASE_DEBUG
802  printf("Snippet, with %d lines below:\n----\n", nAfter);
803  for (cp = start; cp < end; cp++) {
804  printf("%c", *cp);
805  }
806  printf("====\n");
807 #endif /* PHRASE_DEBUG */
808  notDone = strGrep(regex, curptr, regexFlags);
809  if (notDone) { /* another match? */
810 #ifdef PHRASE_DEBUG
811  printf("... next match @ %d:%d (end=%d)\n",
812  curptr - textp + cur.regm.rm_so,
813  curptr - textp + cur.regm.rm_eo - 1, end - textp);
814 #endif /* PHRASE_DEBUG */
815 #ifdef QA_CHECKS
816  if ((curptr + cur.regm.rm_eo) > fileeof) {
817  Assert(YES, "Too far into file!");
818  }
819 #endif /* QA_CHECKS */
820  /* next match OUTSIDE the text we've already saved? */
821  if ((curptr + cur.regm.rm_eo) > end) {
822  break;
823  }
824  /* else, next match IS within the text we're looking at! */
825  }
826  } while (notDone);
827  /*
828  * Add this block of text to our buffer. If 'notdone' is true, there's
829  * at least one more block of text that goes in the buffer, so add the
830  * block-o-text-separator, too. And, make sure we don't overflow our
831  * buffer (BEFORE we modify it); we don't KNOW how much text to expect!
832  */
833  save = *end;
834  *end = NULL_CHAR; /* char PAST the newline! */
835  if (recordOffsets) {
836  bp->bLen = end-start;
837  bp->buf = copyString(start, MTAG_TEXTPARA);
838  bp->bDocLen = 0;
839 #ifdef PHRASE_DEBUG
840  printf("%s starts @%d, len %d ends [%c%c%c%c%c%c%c]\n",
841  utilbuf, bp->bStart, bp->bLen, *(end-8), *(end-7),
842  *(end-6), *(end-5), *(end-4), *(end-3), *(end-2));
843 #endif /* PHRASE_DEBUG */
844  }
845  newDataLen = end-start+(notDone ? strlen(sep)+1 : 0);
846  while (buflen+newDataLen > bufmax) {
847  char *new;
848 #ifdef QA_CHECKS
849  Assert(NO, "data(%d) > bufmax(%d)", buflen+newDataLen,
850  bufmax);
851 #endif /* QA_CHECKS */
852  bufmax *= 2;
853 #ifdef MEMSTATS
854  printf("... DOUBLE search-pattern buffer (%d -> %d)\n",
855  bufmax/2, bufmax);
856 #endif /* MEMSTATS */
857  new = memAlloc(bufmax, MTAG_DOUBLED);
858  (void) memcpy(new, ibuf, buflen);
859 #if 0
860  printf("REPLACING buf %p(%d) with %p(%d)\n", ibuf,
861  bufmax/2, new, bufmax);
862 #endif
863 #ifdef REUSE_STATIC_MEMORY
864  if (ibuf != grepzone) {
865  memFree(ibuf, MTAG_TOOSMALL);
866  }
867 #else /* not REUSE_STATIC_MEMORY */
868  memFree(ibuf, MTAG_TOOSMALL);
869 #endif /* not REUSE_STATIC_MEMORY */
870  ibuf = new;
871  }
872  cp = bufmark = ibuf+buflen-1; /* where the NULL is _now_ */
873  buflen += newDataLen; /* new end-of-data ptr */
874  int remaining = bufmax - (bufmark - ibuf);
875  int written = snprintf(bufmark, remaining, "%s", start);
876  bufmark += (written >= remaining) ? remaining - 1 : written;
877  if (notDone) {
878  remaining = bufmax - (bufmark - ibuf);
879  written = snprintf(bufmark, remaining, "%s\n", sep);
880  bufmark += (written >= remaining) ? remaining - 1 : written;
881  }
882  /*
883  * Some files use ^M as a line-terminator, so we need to convert those
884  * control-M's to 'regular newlines' in case we need to use the regex
885  * stuff on this buffer; the regex library apparently doesn't have a
886  * flag for interpretting ^M as end-of-line character.
887  */
888  while (*cp) {
889  if (*cp == '\r') { /* '\015'? */
890  *cp = '\n'; /* '\012'! */
891  }
892  cp++;
893  }
894  *end = save;
895 #ifdef PHRASE_DEBUG
896  printf("Loop end, BUF IS NOW: [\"%s\":%d]\n----\n%s====\n",
897  regex, strlen(ibuf), ibuf);
898 #endif /* PHRASE_DEBUG */
899  }
900 
901 #if defined(PHRASE_DEBUG) || defined(DOCTOR_DEBUG)
902  printf("getInstances(\"%s\"): Found %d bytes of data...\n", regex,
903  buflen-1);
904 #endif /* PHRASE_DEBUG || DOCTOR_DEBUG */
905 #ifdef PHRASE_DEBUG
906  printf("getInstances(\"%s\"): buffer %p --------\n%s\n========\n",
907  regex, ibuf, ibuf);
908 #endif /* PHRASE_DEBUG */
909 
910  return(ibuf);
911 }
912 
918 char *curDate()
919 {
920  static char datebuf[32];
921  char *cp;
922  time_t thyme;
923 
924  (void) time(&thyme);
925  (void) ctime_r(&thyme, datebuf);
926  if ((cp = strrchr(datebuf, '\n')) == NULL_STR) {
927  LOG_FATAL("Unexpected time format from ctime_r()!")
928  Bail(-__LINE__);
929  }
930  *cp = NULL_CHAR;
931  return(datebuf);
932 }
933 
934 
935 #ifdef MEMSTATS
936 void memStats(char *s)
937 {
938  static int first = 1;
939  static char mbuf[128];
940 
941  if (first) {
942  first = 0;
943  snprintf(mbuf, sizeof(mbuf), "grep VmRSS /proc/%d/status", getpid());
944  }
945  if (s && *s) {
946  int i;
947  printf("%s: ", s);
948  for (i = (int) (strlen(s)+2); i < 50; i++) {
949  printf(" ");
950  }
951  }
952  (void) mySystem(mbuf);
953 #if 0
954  system("grep Vm /proc/self/status");
955  system("grep Brk /proc/self/status");
956 #endif
957 }
958 #endif /* MEMSTATS */
959 
960 
965 void makeSymlink(char *path)
966 {
967 #if defined(PROC_TRACE) || defined(UNPACK_DEBUG)
968  traceFunc("== makeSymlink(%s)\n", path);
969 #endif /* PROC_TRACE || UNPACK_DEBUG */
970 
971  (void) snprintf(cmdBuf, sizeof(cmdBuf), ".%s", strrchr(path, '/'));
972  if (symlink(path, cmdBuf) < 0) {
973  perror(cmdBuf);
974  LOG_FATAL("Failed: symlink(%s, %s)", path, cmdBuf)
975  Bail(-__LINE__);
976  }
977  return;
978 }
979 
980 
991 void printRegexMatch(int n, int cached)
992 {
993  int save_so;
994  int save_eo;
995  int match;
996  static char debugStr[256];
997  static char misc[64];
998  char *cp;
999  char *x = NULL;
1000  char *textp;
1001 
1002 #ifdef PROC_TRACE
1003  traceFunc("== printRegexMatch(%d, %d)\n", n, cached);
1004 #endif /* PROC_TRACE */
1005 
1006  if (*debugStr == NULL_CHAR) {
1007  strncpy(debugStr, gl.initwd, sizeof(debugStr)-1);
1008  strncat(debugStr, "/Nomos.strings.txt", sizeof(debugStr)-1);
1009 #ifdef DEBUG
1010  printf("File: %s\n", debugStr);
1011 #endif /* DEBUG */
1012  }
1013  save_so = cur.regm.rm_so;
1014  save_eo = cur.regm.rm_eo;
1015  if (isFILE(debugStr)) {
1016  if ((match = (gl.flags & FL_SAVEBASE))) { /* assignment is deliberate */
1017  gl.flags &= ~FL_SAVEBASE;
1018  }
1019 #ifdef DEBUG
1020  printf("Match [%d:%d]\n", save_so, save_eo);
1021 #endif /* DEBUG */
1022  textp = mmapFile(debugStr);
1023  (void) snprintf(misc, sizeof(misc), "=#%03d", n);
1024  if (strGrep(misc, textp, REG_EXTENDED)) {
1025 #ifdef DEBUG
1026  printf("Patt: %s\nMatch: %d:%d\n", misc,
1027  cur.regm.rm_so, cur.regm.rm_eo);
1028 #endif /* DEBUG */
1029  x = textp + cur.regm.rm_so;
1030  cp = textp + cur.regm.rm_so;
1031  *x = NULL_CHAR;
1032  while (*--x != '[') {
1033  if (x == textp) {
1034  LOG_FATAL("Cannot locate debug symbol")
1035  Bail(-__LINE__);
1036  }
1037  }
1038  ++x; /* CDB - Moved from line below. Hope this is what was intended.*/
1039  (void) strncpy(misc, x, cp - x); /* CDB - Fix */
1040  misc[cp-x] = NULL_CHAR;
1041  } else {
1042  strncpy(misc, "?", sizeof(misc) - 1);
1043  misc[sizeof(misc) - 1] = '\0';
1044  }
1045  munmapFile(textp);
1046  if (match) {
1047  gl.flags |= FL_SAVEBASE;
1048  }
1049 #ifdef DEBUG
1050  printf("RESTR [%d:%d]\n", cur.regm.rm_so, cur.regm.rm_eo);
1051 #endif /* DEBUG */
1052  }
1053  cur.regm.rm_so = save_so;
1054  cur.regm.rm_eo = save_eo;
1055  printf("%s regex %d ", cached ? "Cached" : "Found", n);
1056  if (x) {
1057  printf("(%s) ", misc);
1058  }
1059  if (!cached) {
1060  printf("\"%s\"", _REGEX(n));
1061  }
1062  printf("\n");
1063 #ifdef DEBUG
1064  printf("Seed: \"%s\"\n", _SEED(n));
1065 #endif /* DEBUG */
1066  return;
1067 }
1068 
1074 void ReplaceNulls(char *Buffer, int BufferSize)
1075 {
1076  char *pBuf;
1077 
1078  for (pBuf = Buffer; BufferSize--; pBuf++)
1079  if (*pBuf == 0) *pBuf = ' ';
1080 }
1081 
1088 char *mmapFile(char *pathname) /* read-only for now */
1089 {
1090  struct mm_cache *mmp;
1091  int i;
1092  int n;
1093  int rem;
1094  char *cp;
1095 
1096 #ifdef PROC_TRACE
1097  traceFunc("== mmapFile(%s)\n", pathname);
1098 #endif /* PROC_TRACE */
1099 
1100  for (mmp = mmap_data, i = 0; i < MM_CACHESIZE; i++, mmp++) {
1101  if (mmp->inUse == 0) {
1102  break;
1103  }
1104  }
1105 
1106  if (i == MM_CACHESIZE) {
1107  printf("mmap-cache too small [%d]!\n", MM_CACHESIZE);
1108  mmapOpenListing();
1109  Bail(12);
1110  }
1111 
1112  if ((mmp->fd = open(pathname, O_RDONLY)) < 0) {
1113  if (errno == ENOENT) {
1114  mmp->inUse = 0; /* overkill? */
1115  mmp->size = -1; /* overkill? */
1116  mmp->mmPtr = (void *) NULL;
1117 #if (DEBUG > 3)
1118  printf("mmapFile: ENOENT %s\n", pathname);
1119 #endif /* DEBUG > 3 */
1120  return(NULL_STR);
1121  }
1122  perror(pathname);
1123  (void) mySystem("ls -l %s", pathname);
1124  LOG_FATAL("%s: open failure!", pathname)
1125  Bail(-__LINE__);
1126  }
1127 
1128  if (fstat(mmp->fd, &cur.stbuf) < 0) {
1129  printf("fstat failure!\n");
1130  perror(pathname);
1131  Bail(13);
1132  }
1133  if (S_ISDIR(cur.stbuf.st_mode)) {
1134  printf("mmapFile(%s): is a directory\n", pathname);
1135  Bail(14);
1136  }
1137 
1138  strncpy(mmp->label, pathname, sizeof(mmp->label) - 1);
1139  mmp->label[sizeof(mmp->label) - 1] = '\0';
1140  if (cur.stbuf.st_size)
1141  {
1142  mmp->size = cur.stbuf.st_size + 1;
1143  mmp->mmPtr = memAlloc(mmp->size, MTAG_MMAPFILE);
1144 #ifdef DEBUG
1145  printf("+MM: %lu @ %p\n", mmp->size, mmp->mmPtr);
1146 #endif /* DEBUG */
1147 
1148  /* Limit scan to first MAX_SCANBYTES
1149  * We have never found a license more than 64k into a file.
1150  */
1151 // if (cur.stbuf.st_size > MAX_SCANBYTES) mmp->size = MAX_SCANBYTES;
1152  if (mmp->size > MAX_SCANBYTES) mmp->size = MAX_SCANBYTES;
1153 
1154 
1155  rem = mmp->size-1;
1156  cp = mmp->mmPtr;
1157  while (rem > 0) {
1158  if ((n = (int) read(mmp->fd, cp, (size_t) rem)) < 0) {
1159  /* log error and move on. This way error will be logged
1160  * but job will continue
1161  */
1162  LOG_WARNING("nomos read error: %s, file: %s, read size: %d, pfile_pk: %ld\n", strerror(errno), pathname, rem, cur.pFileFk);
1163  break;
1164  }
1165  rem -= n;
1166  cp += n;
1167  }
1168  mmp->inUse = 1;
1169  /* Replace nulls with blanks so binary files can be scanned */
1170  ReplaceNulls(mmp->mmPtr, mmp->size-1);
1171  return((char *) mmp->mmPtr);
1172  }
1173  /*
1174  * If we're here, we hit some sort of error.
1175  */
1176  (void) close(mmp->fd);
1177 #ifdef QA_CHECKS
1178  Assert(NO, "mmapFile: returning NULL");
1179 #endif /* QA_CHECKS */
1180  return(NULL_STR);
1181 }
1182 
1183 
1184 void mmapOpenListing()
1185 {
1186  struct mm_cache *mmp;
1187  int i;
1188 
1189  printf("=== mm-cache BEGIN ===\n");
1190  for (mmp = mmap_data, i = 0; i < MM_CACHESIZE; i++, mmp++) {
1191  if (mmp->inUse) {
1192  printf("mm[%d]: (%d) %s:%d\n", i, mmp->fd,
1193  mmp->label, (int) mmp->size);
1194  }
1195  }
1196  printf("--- mm-cache END ---\n");
1197  return;
1198 }
1199 
1204 void munmapFile(void *ptr)
1205 {
1206  struct mm_cache *mmp;
1207  int i;
1208 
1209 #ifdef PROC_TRACE
1210  traceFunc("== munmapFile(%p)\n", ptr);
1211 #endif /* PROC_TRACE */
1212 
1213  if (ptr == (void *) NULL) {
1214 #ifdef QA_CHECKS
1215  Assert(NO, "NULL sent to munmapFile()!");
1216 #endif /* QA_CHECKS */
1217  return;
1218  }
1219  for (mmp = mmap_data, i = 0; i < MM_CACHESIZE; i++, mmp++) {
1220  if (mmp->inUse == 0) {
1221  continue;
1222  }
1223  if (mmp->mmPtr == ptr) {
1224 #if DEBUG > 4
1225  printf("munmapFile: clearing entry %d\n", i);
1226 #endif /* DEBUG > 4 */
1227 #if 0
1228  if (mmp->size) {
1229  (void) munmap((void *) ptr, (size_t) mmp->size);
1230  }
1231 #endif
1232  if (close(mmp->fd) < 0) {
1233  perror("close");
1234  Bail(16);
1235  }
1236 #ifdef PARANOID
1237  mmp->buf = (void *) NULL;
1238 #endif /* PARANOID */
1239  mmp->inUse = 0;
1240 #ifdef DEBUG
1241  printf("DEBUG: munmapFile: freeing %lu bytes\n",
1242  mmp->size);
1243 #endif /* DEBUG */
1244  memFree(mmp->mmPtr, MTAG_MMAPFILE);
1245  break;
1246  }
1247  }
1248  return;
1249 }
1250 
1260 int bufferLineCount(char *p, int len)
1261 {
1262  char *cp;
1263  char *eofaddr = NULL;
1264  int i;
1265 
1266 #ifdef PROC_TRACE
1267  traceFunc("== bufferLineCount(%p, %d)\n", p, len);
1268 #endif /* PROC_TRACE */
1269 
1270  if (eofaddr == p) {
1271  return(0);
1272  }
1273  eofaddr = (char *) (p+len);
1274  for (i = 0, cp = p; cp <= eofaddr; cp++, i++) {
1275  if ((cp = findEol(cp)) == NULL_STR || *cp == NULL_CHAR) {
1276  break;
1277  }
1278  }
1279 #if (DEBUG > 3)
1280  printf("bufferLineCount == %d\n", i);
1281 #endif /* DEBUG > 3 */
1282  return(i ? i : 1);
1283 }
1284 
1290 void appendFile(char *pathname, char *str)
1291 {
1292  FILE *fp;
1293 
1294 #ifdef PROC_TRACE
1295  traceFunc("== appendFile(%s, \"%s\")\n", pathname, str);
1296 #endif /* PROC_TRACE */
1297 
1298  fp = fopenFile(pathname, "a+");
1299  fprintf(fp, "%s\n", str);
1300  (void) fclose(fp);
1301  return;
1302 }
1303 
1310 int mySystem(const char *fmt, ...) {
1311  int ret;
1312  int len;
1313  va_start(ap, fmt);
1314  len = vsnprintf(cmdBuf, sizeof(cmdBuf), fmt, ap);
1315  va_end(ap);
1316 
1317  if(len < 0 || (size_t)len >= sizeof(cmdBuf)) {
1318  LOG_ERROR("mySystem: command truncated (%d bytes needed, buffer is %zu bytes)",
1319  len, sizeof(cmdBuf));
1320  return -1;
1321  }
1322 
1323 #if defined(PROC_TRACE) || defined(UNPACK_DEBUG)
1324  traceFunc("== mySystem('%s')\n", cmdBuf);
1325 #endif /* PROC_TRACE || UNPACK_DEBUG */
1326 
1327  ret = system(cmdBuf);
1328  if (WIFEXITED(ret)) {
1329  ret = WEXITSTATUS(ret);
1330 #ifdef DEBUG
1331  if (ret) {
1332  LOG_ERROR("system(%s) returns %d", cmdBuf, ret)
1333  }
1334 #endif /* DEBUG */
1335  }
1336  else if (WIFSIGNALED(ret)) {
1337  ret = WTERMSIG(ret);
1338  LOG_ERROR("system(%s) died from signal %d", cmdBuf, ret)
1339  }
1340  else if (WIFSTOPPED(ret)) {
1341  ret = WSTOPSIG(ret);
1342  LOG_ERROR("system(%s) stopped, signal %d", cmdBuf, ret)
1343  }
1344  return(ret);
1345 }
1346 
1347 
1353 int isFILE(char *pathname)
1354 {
1355 
1356 #ifdef PROC_TRACE
1357  traceFunc("== isFILE(%s)\n", pathname);
1358 #endif /* PROC_TRACE */
1359 
1360  return(isINODE(pathname, S_IFREG));
1361 }
1362 
1363 
1371 int addEntry(char *pathname, int forceFlag, const char *fmt, ...)
1372 {
1373  va_start(ap, fmt);
1374  vsnprintf(utilbuf, sizeof(utilbuf), fmt, ap);
1375  va_end(ap);
1376 
1377 #ifdef PROC_TRACE
1378  traceFunc("== addEntry(%s, %d, \"%s\")\n", pathname, forceFlag, utilbuf);
1379 #endif /* PROC_TRACE */
1380 
1381  if (pathname == NULL_STR) {
1382  Assert(YES, "addEntry - NULL pathname");
1383  }
1384  if (forceFlag || !lineInFile(pathname, utilbuf)) {
1385  appendFile(pathname, utilbuf);
1386  return(1);
1387  }
1388  return(0);
1389 }
1390 
1395 void Msg(const char *fmt, ...)
1396 {
1397  va_start(ap, fmt);
1398  (void) vprintf(fmt, ap);
1399  va_end(ap);
1400  return;
1401 }
1402 
1408 void Assert(int fatalFlag, const char *fmt, ...)
1409 {
1410  va_start(ap, fmt);
1411  (void) snprintf(utilbuf, sizeof(utilbuf), "ASSERT: ");
1412  int offset = strlen(utilbuf);
1413  int remaining_len = sizeof(utilbuf) - offset;
1414  (void) vsnprintf(utilbuf + offset, remaining_len, fmt, ap);
1415  va_end(ap);
1416 
1417 #ifdef PROC_TRACE
1418  traceFunc("!! Assert(\"%s\")\n", utilbuf+strlen(gl.progName)+3);
1419 #endif /* PROC_TRACE */
1420 
1421  (void) strcat(utilbuf, "\n");
1422  Msg("%s", utilbuf);
1423  if (fatalFlag) {
1424  Bail(17);
1425  }
1426  return;
1427 }
1428 
1429 
1430 void traceFunc(char *fmtStr, ...)
1431 {
1432  va_list args;
1433 
1434 #ifdef PROC_TRACE_SWITCH
1435  if (gl.ptswitch)
1436 #endif /* PROC_TRACE_SWITCH */
1437  va_start(args, fmtStr);
1438 
1439  vprintf(fmtStr, args);
1440  va_end(args);
1441 #ifdef PROC_TRACE_SWITCH
1442 }
1443 #endif /* PROC_TRACE_SWITCH */
1444 }
1445 
1446 
1447 #ifdef MEM_DEBUG
1448 char *memAllocLogged(int size)
1449 {
1450  register void *ptr;
1451  /* */
1452  ptr = calloc(size, 1);
1453  printf("%p = calloc( %d , 1 )\n", ptr, size);
1454  return(ptr);
1455 }
1456 
1457 void memFreeLogged(void *ptr)
1458 {
1459  printf("free( %p )\n", ptr);
1460  free(ptr);
1461  return;
1462 }
1463 #endif /* MEM_DEBUG */
int s
The socket that the CLI will use to communicate.
Definition: fo_cli.c:37
item_t * listGetItem(list_t *l, char *s)
get an item from the itemlist. If the item is not in the itemlist, then add it to the itemlist.
Definition: list.c:246
void listInit(list_t *l, int size, char *label)
intialize a list, if the list is not empty, empty it (initialize it to zero's).
Definition: list.c:54
char * findBol(char *s, char *upperLimit)
Find Begin of Line in a string.
Definition: util.c:341
int isSYMLINK(char *spath)
Check if given path is a symbolic link.
Definition: util.c:128
void munmapFile(void *ptr)
Definition: util.c:1204
void ReplaceNulls(char *Buffer, int BufferSize)
Replace all nulls in Buffer with blanks.
Definition: util.c:1074
FILE * fopenFile(char *pathname, char *mode)
Open a file and return the file pointer.
Definition: util.c:477
int isFILE(char *pathname)
Check if an inode is a file.
Definition: util.c:1353
int isINODE(char *ipath, int typ)
Check for a inode against a flag.
Definition: util.c:143
int isEMPTYFILE(char *fpath)
Check if given file is empty.
Definition: util.c:65
void printRegexMatch(int n, int cached)
CDB – Need to review this code, particularly for the use of an external file (Nomos....
Definition: util.c:991
char * pathBasename(char *path)
Get the basename from a file path.
Definition: util.c:616
char * getInstances(char *textp, int size, int nBefore, int nAfter, char *regex, int recordOffsets)
Get occurrence of a regex in a given string pointer.
Definition: util.c:631
FILE * popenProc(char *command, char *mode)
Open a process pipe using popen()
Definition: util.c:522
int isDIR(char *dpath)
Check if given path is a directory.
Definition: util.c:50
char * copyString(char *s, char *label)
Create a copy of a string.
Definition: util.c:594
int isPIPE(char *ppath)
Check if given path is a pipe.
Definition: util.c:113
char * curDate()
Get the current date.
Definition: util.c:918
void Assert(int fatalFlag, const char *fmt,...)
Raise an assert.
Definition: util.c:1408
char * wordCount(char *textp)
VERY simple line count, does NOT have to be perfect!
Definition: util.c:552
void renameInode(char *oldpath, char *newpath)
Rename an inode at oldpath to newpath.
Definition: util.c:410
int mySystem(const char *fmt,...)
Run a system command.
Definition: util.c:1310
int isBLOCK(char *bpath)
Check if given path is a Block device.
Definition: util.c:83
#define MM_CACHESIZE
MM Cache size.
Definition: util.c:22
int bufferLineCount(char *p, int len)
Finds the length of first line in a buffer.
Definition: util.c:1260
void appendFile(char *pathname, char *str)
Append a string at the end of the file.
Definition: util.c:1290
void chmodInode(char *pathname, int mode)
Change inode mode bits.
Definition: util.c:451
void makeSymlink(char *path)
Create symbolic links for a given path in current directory.
Definition: util.c:965
char * findEol(char *s)
Find first ROL in a string.
Definition: util.c:379
void Msg(const char *fmt,...)
DO NOT automatically add to a string passed to Msg(); in parseDistro, we sometimes want to dump a p...
Definition: util.c:1395
int addEntry(char *pathname, int forceFlag, const char *fmt,...)
adds a line to the specified pathname
Definition: util.c:1371
int isCHAR(char *cpath)
Check if given path is a character device.
Definition: util.c:98
char * mmapFile(char *pathname)
Blarg. Files that are EXACTLY a multiple of the system pagesize do not get a NULL on the end of the b...
Definition: util.c:1088
char * newReloTarget(char *basename)
Check if a relocation target is accessible.
Definition: util.c:175
char debugStr[myBUFSIZ]
Debug string.
Definition: nomos.c:28
Nomos header file.
#define memFree(x, y)
Definition: nomos.h:531
#define NULL_STR
NULL string.
Definition: nomos.h:235
#define _SEED(x)
Definition: nomos.h:451
#define MAX_RENAME
Max rename length.
Definition: nomos.h:124
#define MAX_SCANBYTES
Definition: nomos.h:131
#define _REGEX(x)
Definition: nomos.h:447
#define isEOL(x)
Check if x points to a EOL character.
Definition: nomos.h:240
#define YES
Definition: nomos.h:175
#define NO
Definition: nomos.h:171
void Bail(int exitval)
Close connections and exit.
Definition: nomos_utils.c:538
#define FL_SAVEBASE
Definition: nomos.h:155
#define NULL_CHAR
NULL character.
Definition: nomos.h:234
int lineInFile(char *pathname, char *regex)
Check if a line exists in a file.
Definition: nomos_regex.c:81
int strGrep(char *regex, char *data, int flags)
General-purpose grep function, used for one-time-only searches.
Definition: nomos_regex.c:139
start($application)
start the application Assumes application is restartable via /etc/init.d/<script>....
Definition: pkgConfig.php:1214
long pFileFk
Definition: nomos.h:396
char initwd[myBUFSIZ]
CDB, would like to workaround/eliminate.
Definition: nomos.h:345
int flags
Flags.
Definition: nomos.h:348
char progName[64]
Program name.
Definition: nomos.h:346
list_t type structure used to keep various lists. (e.g. there are multiple lists).
Definition: nomos.h:308
int used
Definition: nomos.h:310
tricky data structure used for a list of 'items'
Definition: nomos.h:274
void * buf
Definition: nomos.h:279
Store the results of a regex match.
Definition: scanners.hpp:28
int inUse
Cache in use.
Definition: nomos.h:253
int fd
File descriptor.
Definition: nomos.h:254
char label[myBUFSIZ]
Label.
Definition: nomos.h:257
void * mmPtr
Memory pointer.
Definition: nomos.h:256
unsigned long size
Size.
Definition: nomos.h:255