Motr  M0
traced.c File Reference
#include <stdio.h>
#include <err.h>
#include <errno.h>
#include <string.h>
#include <sysexits.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <signal.h>
#include <fcntl.h>
#include <unistd.h>
#include <syslog.h>
#include <stdarg.h>
#include <linux/limits.h>
#include <sys/sendfile.h>
#include <sys/utsname.h>
#include "motr/init.h"
#include "lib/uuid.h"
#include "lib/misc.h"
#include "lib/getopts.h"
#include "lib/thread.h"
#include "lib/user_space/types.h"
#include "lib/trace.h"
#include "lib/mutex.h"
#include "lib/cond.h"
#include "lib/trace_internal.h"
#include "module/instance.h"
Include dependency graph for traced.c:

Go to the source code of this file.

Data Structures

struct  rotator_ctx
 

Macros

#define DEFAULT_IN_FILE_NAME   "/sys/kernel/debug/motr/trace/buffer"
 
#define DEFAULT_OUT_FILE_NAME   "/var/log/motr/m0trace.bin"
 
#define MOTR_KO_CORE_IN_FILE_NAME   "/sys/kernel/debug/motr/core"
 
#define MOTR_KO_CORE_OUT_FILE_NAME   "/var/log/motr/m0tr_ko.img"
 
#define log_err(fmt, ...)   plog(LOG_ERR, fmt, ## __VA_ARGS__)
 
#define log_warn(fmt, ...)   plog(LOG_WARNING, fmt, ## __VA_ARGS__)
 
#define log_info(fmt, ...)   plog(LOG_INFO, fmt, ## __VA_ARGS__)
 
#define log_debug(fmt, ...)   plog(LOG_DEBUG, fmt, ## __VA_ARGS__)
 

Enumerations

enum  lr_action { LR_ROTATE, LR_STOP }
 
enum  { MAX_LOG_NAMES = 1024 }
 

Functions

static void plog (int level, const char *format,...) __attribute__((format(printf
 
void sig_term_quit_int_handler (int signum, siginfo_t *siginfo, void *uctx)
 
static const struct m0_trace_buf_headerread_trace_buf_header (int ifd)
 
static int write_trace_header (const struct m0_trace_buf_header *header, int *ofd, const char *ofname)
 
static int write_trace_data (int *fd_ptr, const void *buf, size_t size)
 
static const char * get_cur_pos (const struct m0_trace_buf_header *logheader, const char *logbuf)
 
static bool is_log_rotation_needed (int *fd_ptr)
 
static void wake_up_rotator_thread (enum lr_action a)
 
static int rotate_original_log (struct rotator_ctx *rctx)
 
static void log_rotator_thread (struct rotator_ctx *rctx)
 
static int process_trace_buffer (int *ofd_ptr, const struct m0_trace_buf_header *logheader, const char *logbuf)
 
static int init_log_names (void)
 
int save_kore_file (void)
 
int main (int argc, char *argv[])
 

Variables

static const char * progname
 
static const char * input_file_name = DEFAULT_IN_FILE_NAME
 
static const char * output_file_name = DEFAULT_OUT_FILE_NAME
 
static const char * output_kore_file_name = MOTR_KO_CORE_OUT_FILE_NAME
 
static bool daemon_mode = false
 
static bool pipe_mode = false
 
static bool fsync_enabled = false
 
static bool use_syslog = false
 
static bool save_kore = true
 
static int log_level = LOG_INFO
 
static bool rotation_enabled = true
 
static uint32_t log_rotation_dealy = 5
 
static uint32_t max_log_size = 1024
 
static uint32_t keep_logs = 6
 
static struct m0_mutex write_data_mutex
 
static struct m0_mutex rotator_mutex
 
static struct m0_cond rotator_cond
 
static enum lr_action rotator_action = LR_ROTATE
 
static volatile bool stop_processing = false
 
static char log_names [MAX_LOG_NAMES][PATH_MAX]