#include "qemu/cutils.h"
#include "trace/control.h"
#include "qemu/thread.h"
+#include "qemu/lockable.h"
static char *logfilename;
static QemuMutex qemu_logfile_mutex;
QemuLogFile *logfile;
rcu_read_lock();
- logfile = atomic_rcu_read(&qemu_logfile);
+ logfile = qatomic_rcu_read(&qemu_logfile);
if (logfile) {
va_list ap;
va_start(ap, fmt);
if (qemu_loglevel && (!is_daemonized() || logfilename)) {
need_to_open_file = true;
}
- qemu_mutex_lock(&qemu_logfile_mutex);
+ QEMU_LOCK_GUARD(&qemu_logfile_mutex);
if (qemu_logfile && !need_to_open_file) {
logfile = qemu_logfile;
- atomic_rcu_set(&qemu_logfile, NULL);
+ qatomic_rcu_set(&qemu_logfile, NULL);
call_rcu(logfile, qemu_logfile_free, rcu);
} else if (!qemu_logfile && need_to_open_file) {
logfile = g_new0(QemuLogFile, 1);
#endif
log_append = 1;
}
- atomic_rcu_set(&qemu_logfile, logfile);
+ qatomic_rcu_set(&qemu_logfile, logfile);
}
- qemu_mutex_unlock(&qemu_logfile_mutex);
}
void qemu_log_needs_buffers(void)
* Allow the user to include %d in their logfile which will be
* substituted with the current PID. This is useful for debugging many
* nested linux-user tasks but will result in lots of logs.
+ *
+ * filename may be NULL. In that case, log output is sent to stderr
*/
void qemu_set_log_filename(const char *filename, Error **errp)
{
- char *pidstr;
g_free(logfilename);
logfilename = NULL;
- pidstr = strstr(filename, "%");
- if (pidstr) {
- /* We only accept one %d, no other format strings */
- if (pidstr[1] != 'd' || strchr(pidstr + 2, '%')) {
- error_setg(errp, "Bad logfile format: %s", filename);
- return;
- } else {
- logfilename = g_strdup_printf(filename, getpid());
- }
- } else {
- logfilename = g_strdup(filename);
+ if (filename) {
+ char *pidstr = strstr(filename, "%");
+ if (pidstr) {
+ /* We only accept one %d, no other format strings */
+ if (pidstr[1] != 'd' || strchr(pidstr + 2, '%')) {
+ error_setg(errp, "Bad logfile format: %s", filename);
+ return;
+ } else {
+ logfilename = g_strdup_printf(filename, getpid());
+ }
+ } else {
+ logfilename = g_strdup(filename);
+ }
}
+
qemu_log_close();
qemu_set_log(qemu_loglevel);
}
QemuLogFile *logfile;
rcu_read_lock();
- logfile = atomic_rcu_read(&qemu_logfile);
+ logfile = qatomic_rcu_read(&qemu_logfile);
if (logfile) {
fflush(logfile->fd);
}
logfile = qemu_logfile;
if (logfile) {
- atomic_rcu_set(&qemu_logfile, NULL);
+ qatomic_rcu_set(&qemu_logfile, NULL);
call_rcu(logfile, qemu_logfile_free, rcu);
}
qemu_mutex_unlock(&qemu_logfile_mutex);
#ifdef CONFIG_PLUGIN
{ CPU_LOG_PLUGIN, "plugin", "output from TCG plugins\n"},
#endif
+ { LOG_STRACE, "strace",
+ "log every user-mode syscall, its input, and its result" },
{ 0, NULL, NULL },
};