| 1 | /* $Id: wrapper.c 1322 2007-12-02 19:51:08Z bird $ */
|
|---|
| 2 | /** @file
|
|---|
| 3 | * Wrapper program for various debugging purposes.
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | /*
|
|---|
| 7 | * Copyright (c) 2007 knut st. osmundsen <bird-src-spam@anduin.net>
|
|---|
| 8 | *
|
|---|
| 9 | * This file is part of kBuild.
|
|---|
| 10 | *
|
|---|
| 11 | * kBuild is free software; you can redistribute it and/or modify
|
|---|
| 12 | * it under the terms of the GNU General Public License as published by
|
|---|
| 13 | * the Free Software Foundation; either version 2 of the License, or
|
|---|
| 14 | * (at your option) any later version.
|
|---|
| 15 | *
|
|---|
| 16 | * kBuild is distributed in the hope that it will be useful,
|
|---|
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 19 | * GNU General Public License for more details.
|
|---|
| 20 | *
|
|---|
| 21 | * You should have received a copy of the GNU General Public License
|
|---|
| 22 | * along with kBuild; if not, write to the Free Software
|
|---|
| 23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|---|
| 24 | *
|
|---|
| 25 | */
|
|---|
| 26 |
|
|---|
| 27 | #include <stdio.h>
|
|---|
| 28 | #include <string.h>
|
|---|
| 29 | #include <stdlib.h>
|
|---|
| 30 | #ifdef _MSC_VER
|
|---|
| 31 | # include <process.h>
|
|---|
| 32 | #else
|
|---|
| 33 | # include <unistd.h>
|
|---|
| 34 | #endif
|
|---|
| 35 |
|
|---|
| 36 | int main(int argc, char **argv, char **envp)
|
|---|
| 37 | {
|
|---|
| 38 | const char *pszLogTo = getenv("WRAPPER_LOGTO");
|
|---|
| 39 | const char *pszLogFileArgs = getenv("WRAPPER_LOGFILEARGS");
|
|---|
| 40 | const char *pszLogEnv = getenv("WRAPPER_LOGENV");
|
|---|
| 41 | const char *pszExec = getenv("WRAPPER_EXEC");
|
|---|
| 42 | const char *pszSigSegv = getenv("WRAPPER_SIGSEGV");
|
|---|
| 43 | const char *pszRetVal = getenv("WRAPPER_RETVAL");
|
|---|
| 44 | int i;
|
|---|
| 45 |
|
|---|
| 46 | if (pszLogTo)
|
|---|
| 47 | {
|
|---|
| 48 | FILE *pLog = fopen(pszLogTo, "a");
|
|---|
| 49 | if (pLog)
|
|---|
| 50 | {
|
|---|
| 51 | fprintf(pLog, "+++ %s pid=%ld +++\n", argv[0], (long)getpid());
|
|---|
| 52 | for (i = 1; i < argc; i++)
|
|---|
| 53 | {
|
|---|
| 54 | fprintf(pLog, "argv[%d]: '%s'\n", i, argv[i]);
|
|---|
| 55 | if (pszLogFileArgs)
|
|---|
| 56 | {
|
|---|
| 57 | FILE *pArg = fopen(argv[i], "r");
|
|---|
| 58 | if (pArg)
|
|---|
| 59 | {
|
|---|
| 60 | int iLine = 0;
|
|---|
| 61 | static char szLine[64*1024];
|
|---|
| 62 | while (fgets(szLine, sizeof(szLine), pArg) && iLine++ < 42)
|
|---|
| 63 | fprintf(pLog, "%2d: %s", iLine, szLine);
|
|---|
| 64 | fclose(pArg);
|
|---|
| 65 | }
|
|---|
| 66 | }
|
|---|
| 67 | }
|
|---|
| 68 | if (pszLogEnv)
|
|---|
| 69 | for (i = 0; envp[i]; i++)
|
|---|
| 70 | fprintf(pLog, "envp[%d]: '%s'\n", i, envp[i]);
|
|---|
| 71 | fprintf(pLog, "--- %s pid=%ld ---\n", argv[0], (long)getpid());
|
|---|
| 72 | fclose(pLog);
|
|---|
| 73 | }
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | if (pszSigSegv)
|
|---|
| 77 | {
|
|---|
| 78 | char *pchIllegal = (char *)1;
|
|---|
| 79 | pchIllegal[0] = '\0';
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | if (pszExec)
|
|---|
| 83 | {
|
|---|
| 84 | /** @todo */
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | return pszRetVal ? atol(pszRetVal) : 1;
|
|---|
| 88 | }
|
|---|