Esempio n. 1
0
File: log.c Progetto: yubo/quagga
static void syslog_sigsafe(int priority, const char *msg, size_t msglen)
{
	static int syslog_fd = -1;
	char buf[sizeof("<1234567890>ripngd[1234567890]: ") + msglen + 50];
	char *s;

	if ((syslog_fd < 0) && ((syslog_fd = syslog_connect()) < 0))
		return;

#define LOC s,buf+sizeof(buf)-s
	s = buf;
	s = str_append(LOC, "<");
	s = num_append(LOC, priority);
	s = str_append(LOC, ">");
	/* forget about the timestamp, too difficult in a signal handler */
	s = str_append(LOC, zlog_default->ident);
	if (zlog_default->syslog_options & LOG_PID) {
		s = str_append(LOC, "[");
		s = num_append(LOC, getpid());
		s = str_append(LOC, "]");
	}
	s = str_append(LOC, ": ");
	s = str_append(LOC, msg);
	write(syslog_fd, buf, s - buf);
#undef LOC
}
Esempio n. 2
0
static int __init ipt_log_init(void)
{
    int ret;
    struct proc_dir_entry *proc;

    ret = xt_register_target(&ipt_log_reg);
    if (ret < 0)
        return ret;

    proc = create_proc_entry(STAT_PROC_FS_NAME, 0, init_net.proc_net);
    if (proc) {
        proc->owner = THIS_MODULE;
        proc->proc_fops = &ip_syslogstat_proc_fops;
    } else {
        printk(KERN_ERR "ip_SYSLOG: failed to create proc entry\n");
        goto cleanup_target;
    }

    ret = syslog_connect(&sl_socket);
    if (ret < 0)
    {
        if (ret == -ECONNREFUSED)
        {
            timer.expires = jiffies + msecs_to_jiffies(reconnect_freq);
            add_timer(&timer);
        }
        else
            goto cleanup_proc;
    }

    nf_log_register(PF_INET, &ipt_log_logger);
    return 0;

cleanup_proc:
    proc_net_remove(&init_net, STAT_PROC_FS_NAME);
cleanup_target:
    xt_unregister_target(&ipt_log_reg);
    return ret;
}
Esempio n. 3
0
static void syslog_work_fn(struct work_struct *work)
{
    struct msghdr   msg;
    struct kvec     iov;
    int ret;
    size_t n = 0;
    struct logs * log_entry;

    if (sl_socket != NULL)
        goto cont;
    ret = syslog_connect(&sl_socket);
    if (ret >= 0)
        goto cont;
    if (!timer_pending(&timer))
    {
        timer.expires = jiffies + msecs_to_jiffies(reconnect_freq);
        add_timer(&timer);
    }
    return ;

cont:

    if (list_empty(&logs_list))
        return;

    spin_lock_irq(&log_lock);

    while (!list_empty(&logs_list))
    {
        log_entry =  list_first_entry(&logs_list, struct logs, logs_list);

        printk(KERN_DEBUG "ip_syslog: work data (%d): %d\n", counter, log_entry->counter);

        n = strlen(log_entry->data);
        iov.iov_base     = (void *)log_entry->data;
        iov.iov_len      = n;
        msg.msg_name = NULL;
        msg.msg_namelen = 0;
        msg.msg_iov = (struct iovec *)&iov;
        msg.msg_iovlen = 1;
        msg.msg_control = NULL;
        msg.msg_controllen = 0;
        msg.msg_namelen = 0;
        msg.msg_flags = MSG_DONTWAIT|MSG_NOSIGNAL;

        ret = kernel_sendmsg(sl_socket, &msg, &iov, 1, n);
        if (ret < 0)
        {
            printk("ip_syslog: kernel_sendmsg error:%d\n", ret);
            if (ret == -EPIPE)
            {
                syslog_close(&sl_socket);
                schedule_work(&syslog_work);
            }
            break;
        }

        loglist_total--;
        list_del(&log_entry->logs_list);
        kfree(log_entry->data);
        kfree(log_entry);
    }

    spin_unlock_irq(&log_lock);
    return ;
}