1 | /* $Id: wrapper.c 2413 2010-09-11 17:43:04Z bird $ */
|
---|
2 | /** @file
|
---|
3 | * Wrapper program for various debugging purposes.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (c) 2007-2010 knut st. osmundsen <[email protected]>
|
---|
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 3 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, see <http://www.gnu.org/licenses/>
|
---|
23 | *
|
---|
24 | */
|
---|
25 |
|
---|
26 | /*******************************************************************************
|
---|
27 | * Header Files *
|
---|
28 | *******************************************************************************/
|
---|
29 | #include <stdio.h>
|
---|
30 | #include <string.h>
|
---|
31 | #include <stdlib.h>
|
---|
32 | #ifdef _MSC_VER
|
---|
33 | # include <process.h>
|
---|
34 | #else
|
---|
35 | # include <unistd.h>
|
---|
36 | #endif
|
---|
37 |
|
---|
38 | int main(int argc, char **argv, char **envp)
|
---|
39 | {
|
---|
40 | const char *pszLogTo = getenv("WRAPPER_LOGTO");
|
---|
41 | const char *pszLogFileArgs = getenv("WRAPPER_LOGFILEARGS");
|
---|
42 | const char *pszLogEnv = getenv("WRAPPER_LOGENV");
|
---|
43 | const char *pszExec = getenv("WRAPPER_EXEC");
|
---|
44 | const char *pszSigSegv = getenv("WRAPPER_SIGSEGV");
|
---|
45 | const char *pszRetVal = getenv("WRAPPER_RETVAL");
|
---|
46 | int i;
|
---|
47 |
|
---|
48 | if (pszLogTo)
|
---|
49 | {
|
---|
50 | FILE *pLog = fopen(pszLogTo, "a");
|
---|
51 | if (pLog)
|
---|
52 | {
|
---|
53 | fprintf(pLog, "+++ %s pid=%ld +++\n", argv[0], (long)getpid());
|
---|
54 | for (i = 1; i < argc; i++)
|
---|
55 | {
|
---|
56 | fprintf(pLog, "argv[%d]: '%s'\n", i, argv[i]);
|
---|
57 | if (pszLogFileArgs)
|
---|
58 | {
|
---|
59 | FILE *pArg = fopen(argv[i], "r");
|
---|
60 | if (pArg)
|
---|
61 | {
|
---|
62 | int iLine = 0;
|
---|
63 | static char szLine[64*1024];
|
---|
64 | while (fgets(szLine, sizeof(szLine), pArg) && iLine++ < 42)
|
---|
65 | fprintf(pLog, "%2d: %s", iLine, szLine);
|
---|
66 | fclose(pArg);
|
---|
67 | }
|
---|
68 | }
|
---|
69 | }
|
---|
70 | if (pszLogEnv)
|
---|
71 | for (i = 0; envp[i]; i++)
|
---|
72 | fprintf(pLog, "envp[%d]: '%s'\n", i, envp[i]);
|
---|
73 | fprintf(pLog, "--- %s pid=%ld ---\n", argv[0], (long)getpid());
|
---|
74 | fclose(pLog);
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | if (pszSigSegv)
|
---|
79 | {
|
---|
80 | char *pchIllegal = (char *)1;
|
---|
81 | pchIllegal[0] = '\0';
|
---|
82 | }
|
---|
83 |
|
---|
84 | if (pszExec)
|
---|
85 | {
|
---|
86 | /** @todo */
|
---|
87 | }
|
---|
88 |
|
---|
89 | return pszRetVal ? atol(pszRetVal) : 1;
|
---|
90 | }
|
---|