/* harvestChildrenProcesses ** ** Purpose: ** The purpose of this function is to make sure that the exiting ** child processes do not become zombies. Secondly, we also remove ** the entry of the exiting process from the list we maintain. ** ** Parameter Dictionary: ** list Handle to the list of processes ** ** Return Values: ** APP_NORMAL ** ** Notes: ** ** Algorithm: ** Description of the algorithm (optional) and any other notes. */ static CONDITION harvestChildrenProcesses(LST_HEAD ** list) { #ifndef _MSC_VER int pid; int statusp; PROCESS_ELEMENT * e; /* Continue as long as status is available from any of the child proceses */ while ((pid = waitpid(-1, &statusp, WNOHANG)) > 0) { e = LST_Head(list); if (e != NULL) (void) LST_Position(list, e); while (e != NULL) { if (e->pid == pid) { printf("\n\n"); printf("***Child Exit Status*****************************\n"); printf("\tProcess ID #%d\n", pid); printf("\tCalling APP Title : %s\n", e->callingAPTitle); printf("\tCalled APP Title : %s\n", e->calledAPTitle); printf("\tExit status : %s\n", (statusp ? "ERROR" : "SUCCESS")); printf("*************************************************\n"); printf("\n\n"); (void) LST_Remove(list, LST_K_BEFORE); free(e); e = NULL; } else { e = LST_Next(list); } } } #endif return APP_NORMAL; }
/************************************************************************** * * GetMakeMacros * * SYNOPSIS * LST_LIST *GetMakeMacros (char *filename) * * PURPOSE * Parse a make file and gather it's macros and their tokens into * lists. * * INPUT * * * EFFECTS * * * RETURN VALUE * * * BUGS * * * HISTORY * * * SEE ALSO * */ LST_LIST *GetMakeMacros (char *filename) { FILE *fp; LST_LIST *mlist; MakeMacro *macro; MakeMacro *sub; MakeMacro *oldmac; NameType *name; NameType *last; int status; int cont; int len; int error = FALSE; char linebuff[MAXLINE]; char macroId[MAXLINE]; char *line; char *s; char *w; char c; fp = fopen (filename, "r"); if (!fp) { SetGlobalErr (ERR_FILE_NOT_FOUND); GEprintf1 ("Couldn't open file '%s' as makefile", filename); return NULL; } mlist = LST_CreateList (NULL); if (!mlist) { SetGlobalErr (ERR_OUT_OF_MEMORY); GEprintf ("OOM: allocating macro list"); return NULL; } CurrentType = 1; IgnoreSlash = TRUE; LineFunc = GetNextEnv; LineNumber = 0; while ((status = LineFunc (fp, linebuff)) > 0) { line = TrimWhiteSpace (linebuff); len = strlen (line); s = macroId; cont = FALSE; if (len && *line != '#') { while (*line && (isalnum(*line) || *line == '_')) { *s++ = *line++; } *s = '\0'; while (*line && isspace(*line)) { line++; } if (*line == '=') { line++; strupr (macroId); oldmac = (MakeMacro*)LST_FindName (mlist, macroId); if (oldmac) { if (oldmac->EnvFlag) { LST_Remove (oldmac); FreeMacro (oldmac); } else { printf ("ERROR:Duplicate Macro '%s' at line %d\n", macroId, LineNumber); error = TRUE; } } macro = (MakeMacro*)LST_CreateNode (sizeof (MakeMacro), macroId); if (!macro) { SetGlobalErr (ERR_OUT_OF_MEMORY); GEprintf ("OOM: macro\n"); return NULL; } macro->EnvFlag = CurrentType; LST_InitList (¯o->Names); LST_AddTail (mlist, macro); last = NULL; s = strtok (line, " \t"); if (s) { do { s = TrimWhiteSpace (s); len = strlen (s); if (len && s[len - 1] == '\\' && !IgnoreSlash) { len--; s[len] = '\0'; cont = TRUE; } if (len) { while (*s) { w = s; while (*s && !(*s == '$' && s[1] == '(')) { s++; } c = *s; *s = 0; if (strlen (w)) { name = (NameType*)LST_CreateNode (sizeof (NameType), w); if (!name) { SetGlobalErr (ERR_OUT_OF_MEMORY); GEprintf ("OOM: (2) finishing macro substitution"); return NULL; } LST_AddTail (¯o->Names, name); } *s = c; if (*s == '$' && s[1] == '(') { s += 2; w = s; s = strchr (s, ')'); if (!s) { printf ("ERROR:Macro missing ')' at line %d\n", LineNumber); error = TRUE; } else { *s = 0; s++; strupr (w); sub = (MakeMacro*)LST_FindName (mlist, w); if (!sub) { printf ("Undefined macro '%s' in line %d\n", w, LineNumber); error = TRUE; } else { name = (NameType*)LST_CreateNode (sizeof (NameType), NULL); if (!name) { SetGlobalErr (ERR_OUT_OF_MEMORY); GEprintf ("OOM: (4) finishing macro substitution"); return NULL; } name->Macro = sub; LST_AddTail (¯o->Names, name); } } } } name = (NameType*)LST_CreateNode (sizeof (NameType), NULL); if (!name) { SetGlobalErr (ERR_OUT_OF_MEMORY); GEprintf ("OOM: (6) adding delimiter"); return NULL; } name->Delim = TRUE; last = name; LST_AddTail (¯o->Names, name); } s = strtok (NULL, " \t"); if (!s && cont) { do { status = LineFunc (fp, linebuff); } while (status > 0 && *linebuff == '#'); if (status == 0) { SetGlobalErr (ERR_GENERIC); GEprintf ("EOF: unterminated macro"); return NULL; } else if (status < 0) { SetGlobalErr (ERR_GENERIC); GEprintf1 ("I/O ERROR: reading file '%s'", filename); return NULL; } line = TrimWhiteSpace (linebuff); s = strtok (line, " \t"); } cont = FALSE; } while (s); if (last && last->Delim) { LST_Remove (last); LST_DeleteNode (last); } } } } } /** Exit if error **/ if (status || error) { return NULL; } return mlist; } /* GetMakeMacros */