3 * Wrapper program for various debugging purposes.
7 * Copyright (c) 2007-2009 knut st. osmundsen <bird-kBuild-spamix@anduin.net>
9 * This file is part of kBuild.
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.
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.
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/>
26 /*******************************************************************************
28 *******************************************************************************/
38 int main(int argc
, char **argv
, char **envp
)
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");
50 FILE *pLog
= fopen(pszLogTo
, "a");
53 fprintf(pLog
, "+++ %s pid=%ld +++\n", argv
[0], (long)getpid());
54 for (i
= 1; i
< argc
; i
++)
56 fprintf(pLog
, "argv[%d]: '%s'\n", i
, argv
[i
]);
59 FILE *pArg
= fopen(argv
[i
], "r");
63 static char szLine
[64*1024];
64 while (fgets(szLine
, sizeof(szLine
), pArg
) && iLine
++ < 42)
65 fprintf(pLog
, "%2d: %s", iLine
, szLine
);
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());
80 char *pchIllegal
= (char *)1;
89 return pszRetVal
? atol(pszRetVal
) : 1;