Skip to content
Snippets Groups Projects
Commit cdadf183 authored by rswindell's avatar rswindell
Browse files

Mutex-protect the log-output (to the console typically) so that foreground and

background threads don't step on eachother (as well as error reports and status
messages).
parent 8a0d082b
No related branches found
No related tags found
No related merge requests found
......@@ -72,6 +72,7 @@ BOOL terminated=FALSE;
BOOL recycled;
DWORD log_mask=DEFAULT_LOG_MASK;
int err_level=DEFAULT_ERR_LOG_LVL;
pthread_mutex_t output_mutex;
#if defined(__unix__)
BOOL daemonize=FALSE;
#endif
......@@ -157,6 +158,10 @@ int lprintf(int level, char *fmt, ...)
return(ret);
}
#endif
/* Mutex-protect stdout/stderr */
pthread_mutex_lock(&output_mutex);
if(level<=err_level) {
ret=fprintf(errfp,"%s\n",sbuf);
if(errfp!=stderr && confp!=stdout)
......@@ -164,6 +169,8 @@ int lprintf(int level, char *fmt, ...)
}
if(level>err_level || errfp!=stderr)
ret=fprintf(confp,"%s\n",sbuf);
pthread_mutex_unlock(&output_mutex);
return(ret);
}
......@@ -700,7 +707,7 @@ long js_exec(const char *fname, char** args)
return(-1);
}
if((diff=xp_timer()-start) > 0)
fprintf(statfp,"%s compiled in %.2Lf seconds\n"
lprintf(LOG_INFO,"%s compiled in %.2Lf seconds"
,path
,diff);
......@@ -709,14 +716,14 @@ long js_exec(const char *fname, char** args)
js_EvalOnExit(js_cx, js_glob, &branch);
if((diff=xp_timer()-start) > 0)
fprintf(statfp,"%s executed in %.2Lf seconds\n"
lprintf(LOG_INFO,"%s executed in %.2Lf seconds"
,path
,diff);
JS_GetProperty(js_cx, js_glob, "exit_code", &rval);
if(rval!=JSVAL_VOID && JSVAL_IS_NUMBER(rval)) {
fprintf(statfp,"Using JavaScript exit_code: %s\n",JS_GetStringBytes(JS_ValueToString(js_cx,rval)));
lprintf(LOG_DEBUG,"Using JavaScript exit_code: %s",JS_GetStringBytes(JS_ValueToString(js_cx,rval)));
JS_ValueToInt32(js_cx,rval,&result);
}
......@@ -732,13 +739,13 @@ long js_exec(const char *fname, char** args)
void break_handler(int type)
{
fprintf(statfp,"\n-> Terminated Locally (signal: %d)\n",type);
lprintf(LOG_NOTICE,"\n-> Terminated Locally (signal: %d)",type);
terminated=TRUE;
}
void recycle_handler(int type)
{
fprintf(statfp,"\n-> Recycled Locally (signal: %d)\n",type);
lprintf(LOG_NOTICE,"\n-> Recycled Locally (signal: %d)",type);
recycled=TRUE;
branch.terminated=&recycled;
}
......@@ -964,10 +971,12 @@ int main(int argc, char **argv, char** environ)
signal(SIGPIPE,SIG_IGN);
#endif
output_mutex = PTHREAD_MUTEX_INITIALIZER;
do {
if(exec_count++)
fprintf(statfp,"\nRe-running: %s\n", module);
lprintf(LOG_INFO,"\nRe-running: %s", module);
recycled=FALSE;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment