#include <libgen.h>
#include <sys/types.h>
#include <unistd.h>
+#include <pthread.h>
#include <dlog.h>
#include <Eina.h>
int file_id;
int nr_of_lines;
char *filename;
+ pthread_mutex_t cri_lock;
} s_info = {
.fp = NULL,
.file_id = 0,
.nr_of_lines = 0,
.filename = NULL,
+ .cri_lock = PTHREAD_MUTEX_INITIALIZER,
};
if (filename) {
snprintf(filename, namelen, "%s/%d_%s.%d", SLAVE_LOG_PATH, s_info.file_id, s_info.filename, getpid());
- if (s_info.fp)
- fclose(s_info.fp);
+ if (s_info.fp) {
+ if (fclose(s_info.fp) != 0)
+ ErrPrint("fclose: %s\n", strerror(errno));
+ }
s_info.fp = fopen(filename, "w+");
if (!s_info.fp)
{
va_list ap;
int ret;
+ int status;
if (!s_info.fp)
return LB_STATUS_ERROR_IO;
+ status = pthread_mutex_lock(&s_info.cri_lock);
+ if (status != 0)
+ ErrPrint("lock: %s\n", strerror(status));
+
fprintf(s_info.fp, "%lf [%s:%d] ", util_timestamp(), util_basename((char *)func), line);
va_start(ap, fmt);
s_info.nr_of_lines++;
rotate_log();
+
+ status = pthread_mutex_unlock(&s_info.cri_lock);
+ if (status != 0)
+ ErrPrint("unlock: %s\n", strerror(status));
+
return ret;
}
}
if (s_info.fp) {
- fclose(s_info.fp);
+ if (fclose(s_info.fp) != 0)
+ ErrPrint("fclose: %s\n", strerror(errno));
s_info.fp = NULL;
}
}