int rg_vsyslog(int entity_id, rg_error_level_t severity, reboot_func_t reboot,
               const char *format, va_list ap)
{
    rg_error_level_t _severity = severity & LLEVEL_MASK;
    int need_rg_closelog = 0;

    if (_severity)
    {
        int priority;
        static int priorities[] = {
            LOG_EMERG,
            LOG_ALERT,
            LOG_CRIT,
            LOG_ERR,
            LOG_WARNING,
            LOG_NOTICE,
            LOG_INFO,
            LOG_DEBUG,
        };

        priority = LOG_DAEMON | priorities[_severity - 1];

        if (!rg_openlog_initialized)
        {
            /* There are some external processes that might call rg_error()
             * indirectly (for example, by calling ipc_connect()), before
             * rg_openlog() has been called. Since we need the entity ID in
             * rg_error() calls, we call rg_openlog ourselves, and then close
             * it, so the process will be able to call rg_openlog later */
            rg_openlog_full(entity_id, NULL, LOG_CONS | LOG_NDELAY | LOG_PID,
                            LOG_USER);
            need_rg_closelog = 1;
        }
        vsyslog(priority, format, ap);
    }

    if (severity & LDOEXIT && reboot)
        reboot();

    if (need_rg_closelog)
        rg_closelog();

    return -1;
}
int rg_error_full(log_entity_id_t entity_id, rg_error_level_t severity,
    const char *format, ...)
{
    va_list ap;
    int priority, need_rg_closelog = 0;
    u32 severity_level = severity & LLEVEL_MASK;    
    static int priorities[] = {
	LOG_EMERG,
	LOG_ALERT,
	LOG_CRIT,
	LOG_ERR,
	LOG_WARNING,
	LOG_NOTICE,
	LOG_INFO,
	LOG_DEBUG,
    };
    
    priority = LOG_DAEMON | priorities[severity_level];
   
    if (!rg_openlog_initialized)
    {
	/* There are some external processes that might call rg_error()
	 * indirectly (for example, by calling ipc_connect()), before
	 * rg_openlog() has been called. Since we need the entity ID in
	 * rg_error() calls, we call rg_openlog ourselves, and then close it,
	 * so the process will be able to call rg_openlog later */
	rg_openlog_full(entity_id, NULL, LOG_CONS | LOG_NDELAY | LOG_PID,
	    LOG_USER);
	need_rg_closelog = 1;
    }
    va_start(ap, format);
    vsyslog(priority, format, ap);
    va_end(ap);

    if (severity_level == LEXIT || severity_level == LPANIC)
	rg_reboot();
    
    if (need_rg_closelog)
	rg_closelog();

    return -1;
}