Example #1
0
static void parse_options(int argc, char **argv, struct a6o_daemon_options *opts)
{
	opts->no_daemon = 0;
	opts->unix_path = DEFAULT_SOCKET_PATH;
	opts->s_log_level = DEFAULT_LOG_LEVEL;
	opts->pid_file = DEFAULT_PID_FILE;
	opts->ipc_type = DEFAULT_IPC_TYPE;

	while (1) {
		int c, option_index = 0;

		c = getopt_long(argc, argv, "hVnl:a:i:c:", daemon_option_defs, &option_index);

		if (c == -1)
			break;

		switch (c) {
		case 'h': /* help */
			usage();
			break;
		case 'V': /* version */
			version();
			break;
		case 'n': /* no-daemon */
			opts->no_daemon = 1;
			break;
		case 'l': /* log-level */
			if (check_log_level(optarg))
				usage();
			opts->s_log_level = strdup(optarg);
			break;
		case 'a': /* path */
			opts->unix_path = strdup(optarg);
			break;
		case 'i': /* pidfile */
			opts->pid_file = strdup(optarg);
			break;
		case 'c': /* ipc */
			if (strcmp(optarg, "old") && strcmp(optarg, "json"))
				usage();
			opts->ipc_type = (!strcmp(optarg, "old")) ? OLD_IPC : JSON_IPC;
			break;
		case '?':
			/* getopt_long already printed an error message. */
			break;
		default:
			abort ();
		}
	}

	/* Print any remaining command line arguments (not options). */
	if (optind < argc)
		usage();
}
Example #2
0
int log_t::log(const char* module, int level, const char* fmt, va_list ap)
{
    int rc;
    rc = check_module(module);
    if(rc) return rc;

    rc = check_log_level(level);
    if (0 != rc) return rc;

    time_t timep = time(NULL);
    struct tm *tmp = localtime(&timep);

    char logmsg[MAX_LOG_LINE];
    format_log_head(logmsg, module, level, tmp);

    int len = strlen(logmsg);
    vsnprintf(logmsg + len, MAX_LOG_LINE - len - 2 - strlen(COLOR_END), fmt, ap);

    strcat(logmsg, "\n");
    strcat(logmsg, COLOR_END);
    logmsg[MAX_LOG_LINE - 1] = 0;

    std::ostringstream os;
    os << logmsg;

    if (m_print_screen_flag)
    {
        if (NULL != m_print_screen_callback)
        {
            (*m_print_screen_callback)(os.str());
        }
        else
        {
            handle_print_screen(os.str());
        }
    }

    if (m_print_file_flag)
    {
        if (NULL != m_print_file_callback)
        {
            (*m_print_file_callback)(os.str());
        }
        else
        {
            handle_print_file(os.str());
        }
    }
    return 0;
}