- if (logging && !logfile) {
- logfile=fopen(logfilename, "a");
- if (!logfile) {
- fprintf(stderr, "Can't open logfile, logging disabled!\n");
- logging=0;
- }
- }
-
+ // lock this section to avoid interlacing prints from different threads
+ pthread_mutex_lock(&print_lock);
+
+ if (logging && !logfile) {
+ logfile=fopen(logfilename, "a");
+ if (!logfile) {
+ fprintf(stderr, "Can't open logfile, logging disabled!\n");
+ logging=0;
+ }
+ }
+
+#ifdef RL_STATE_READCMD
+ // We are using GNU readline.