/* * BRLTTY - A background process providing access to the console screen (when in * text mode) for a blind person using a refreshable braille display. * * Copyright (C) 1995-2021 by The BRLTTY Developers. * * BRLTTY comes with ABSOLUTELY NO WARRANTY. * * This is free software, placed under the terms of the * GNU Lesser General Public License, as published by the Free Software * Foundation; either version 2.1 of the License, or (at your option) any * later version. Please see the file LICENSE-LGPL for details. * * Web Page: http://brltty.app/ * * This software is maintained by Dave Mielke . */ #include "prologue.h" #include #include #include #include #include #include #include #include "program.h" #include "messages.h" #include "pgmpath.h" #include "pid.h" #include "log.h" #include "file.h" #include "parse.h" #include "system.h" const char standardStreamArgument[] = "-"; const char standardInputName[] = ""; const char standardOutputName[] = ""; const char standardErrorName[] = ""; const char *programPath; const char *programName; static char * testProgram (const char *directory, const char *name) { char *path; if ((path = makePath(directory, name))) { if (testProgramPath(path)) return path; free(path); } return NULL; } static char * findProgram (const char *name) { char *path = NULL; const char *string; if ((string = getenv("PATH"))) { int count; char **array; if ((array = splitString(string, ':', &count))) { for (unsigned int index=0; indexname = strdup(name); pxe->handler = handler; pxe->data = data; pxe->next = programExitEntries; programExitEntries = pxe; logMessage(LOG_DEBUG, "program exit event added: %s", name); } else { logMallocError(); } } static void exitProgramMemory (void *data) { char **pointer = data; if (*pointer) { free(*pointer); *pointer = NULL; } } void registerProgramMemory (const char *name, void *pointer) { onProgramExit(name, exitProgramMemory, pointer); } void endProgram (void) { logMessage(LOG_DEBUG, "stopping program components"); while (programExitEntries) { ProgramExitEntry *pxe = programExitEntries; const char *name = pxe->name; programExitEntries = pxe->next; if (!name) name = "unknown"; logMessage(LOG_DEBUG, "stopping program component: %s", name); pxe->handler(pxe->data); if (pxe->name) free(pxe->name); free(pxe); } logMessage(LOG_DEBUG, "stopped program components"); popLogPrefix(); }