Commit 844eaa6e authored by Ronny Wichers Schreur's avatar Ronny Wichers Schreur 🏢
Browse files

Optional logging

parent a859d213
......@@ -22,6 +22,18 @@
#include <sys/stat.h>
static void log (char *format, ...)
{
#ifdef DEBUG
va_list ap;
va_start(ap, format);
(void) vfprintf(stderr, format, ap);
va_end(ap);
fflush (stderr);
#endif
}
static int wait_for_child (pid_t pid, char *child_name, int *status_p)
{
int result, stat;
......@@ -29,13 +41,13 @@ static int wait_for_child (pid_t pid, char *child_name, int *status_p)
(void) waitpid (pid, &stat, 0);
result = WEXITSTATUS (stat);
if (WIFSIGNALED(stat))
fprintf (stderr,"%s signaled (%d, %d)\n",child_name,
log ("%s signaled (%d, %d)\n",child_name,
WTERMSIG(stat), stat&255);
else if (WIFEXITED (stat))
fprintf (stderr,"%s exited normally (%d, %d)\n", child_name,
log ("%s exited normally (%d, %d)\n", child_name,
WEXITSTATUS(stat),stat&255);
else
fprintf (stderr,"%s exited abnormally (%d, %d)\n",child_name,
log ("%s exited abnormally (%d, %d)\n",child_name,
result, stat&255);
*status_p=stat;
......@@ -47,16 +59,6 @@ static void error (char *error_string)
fprintf (stderr,"%s\n",error_string);
}
static void log (char *format, ...)
{
va_list ap;
va_start(ap, format);
(void) vfprintf(stderr, format, ap);
va_end(ap);
fflush (stderr);
}
static int compiler_initialised=0;
static pid_t compiler_pid=0;
static char *compiler_commands_name=NULL, *compiler_results_name=NULL;
......@@ -81,7 +83,7 @@ int stop_caching_compiler (void)
r=wait_for_child (pid, "Clean compiler",&status);
if (status!=0) {
fprintf (stderr, "r=%d status=%xd\n", r, status);
log ("r=%d status=%xd\n", r, status);
error ("clm: error after stopping compiler");
exit (1);
}
......@@ -128,7 +130,7 @@ static void child_died (int signal_no)
log ("child_died\n");
if (compiler_pid != 0)
{
fprintf (stderr,"cocl exited abnormally\n");
log ("cocl exited abnormally\n");
compiler_pid=0;
}
}
......@@ -197,7 +199,7 @@ int start_caching_compiler (CleanCharArray cocl_path)
execlp ((char *)cocl_path, "cocl", "--pipe", compiler_commands_name,
compiler_results_name, (char *) 0);
fprintf (stderr, "cocl path = %s\n", cocl_path);
log ("cocl path = %s\n", cocl_path);
perror ("clm: can't start the clean compiler");
exit(1);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment