/* * 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-2019 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 #ifdef ENABLE_I18N_SUPPORT #include #endif /* ENABLE_I18N_SUPPORT */ #include "program.h" #include "pgmpath.h" #include "pid.h" #include "log.h" #include "file.h" #include "parse.h" #include "system.h" const char *programPath; const char *programName; const char standardStreamArgument[] = "-"; const char standardInputName[] = ""; const char standardOutputName[] = ""; const char standardErrorName[] = ""; static void prepareLocale (void) { setlocale(LC_ALL, ""); #ifdef ENABLE_I18N_SUPPORT bindtextdomain(PACKAGE_TARNAME, LOCALE_DIRECTORY); textdomain(PACKAGE_TARNAME); #endif /* ENABLE_I18N_SUPPORT */ } 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))) { int index; for (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; 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(); }