#include <getopt.h>
#include <errno.h>
+#include "glite/lbu/log.h"
#include "glite/lb/context-int.h"
#include "glite/lb/timeouts.h"
#include "logd_proto.h"
*
* handle_signal -
* HUP - reread log4crc
- * USR1 - set all priorities to DEBUG
- * USR2 - set all priorities back to initial values
+ * USR1 - print priorities of all standard categories
+ * USR2 - print priorities of all LB categories
*
*----------------------------------------------------------------------
*/
switch (num) {
case SIGHUP:
log4c_reread();
- glite_common_log_priority_security = log4c_category_get_priority(log4c_category_get(LOG_CATEGORY_SECURITY));
- glite_common_log_priority_access = log4c_category_get_priority(log4c_category_get(LOG_CATEGORY_ACCESS));
- glite_common_log_priority_control = log4c_category_get_priority(log4c_category_get(LOG_CATEGORY_CONTROL));
/* TODO: probably also restart parent logd process? */
break;
case SIGUSR1:
- log4c_category_set_priority(log4c_category_get(LOG_CATEGORY_SECURITY),LOG_PRIORITY_DEBUG);
- log4c_category_set_priority(log4c_category_get(LOG_CATEGORY_ACCESS),LOG_PRIORITY_DEBUG);
- log4c_category_set_priority(log4c_category_get(LOG_CATEGORY_CONTROL),LOG_PRIORITY_DEBUG);
glite_common_log(LOG_CATEGORY_CONTROL,LOG_PRIORITY_INFO,
- "Logging priority is now %s\n", log4c_priority_to_string(LOG_PRIORITY_DEBUG));
+ "Logging priority is now %s for %s, %s for %s and %s for %s\n",
+ log4c_priority_to_string(log4c_category_get_priority(log4c_category_get(LOG_CATEGORY_SECURITY))),
+ LOG_CATEGORY_SECURITY,
+ log4c_priority_to_string(log4c_category_get_priority(log4c_category_get(LOG_CATEGORY_ACCESS))),
+ LOG_CATEGORY_ACCESS,
+ log4c_priority_to_string(log4c_category_get_priority(log4c_category_get(LOG_CATEGORY_CONTROL))),
+ LOG_CATEGORY_CONTROL);
break;
case SIGUSR2:
- log4c_category_set_priority(log4c_category_get(LOG_CATEGORY_SECURITY),glite_common_log_priority_security);
- log4c_category_set_priority(log4c_category_get(LOG_CATEGORY_ACCESS),glite_common_log_priority_access);
- log4c_category_set_priority(log4c_category_get(LOG_CATEGORY_CONTROL),glite_common_log_priority_control);
glite_common_log(LOG_CATEGORY_CONTROL,LOG_PRIORITY_INFO,
- "Logging priority is now %s for %s, %s for %s and %s for %s\n",
- log4c_priority_to_string(glite_common_log_priority_security),LOG_CATEGORY_SECURITY,
- log4c_priority_to_string(glite_common_log_priority_access),LOG_CATEGORY_ACCESS,
- log4c_priority_to_string(glite_common_log_priority_control),LOG_CATEGORY_CONTROL);
+ "Logging priority is now %s for %s, %s for %s, %s for %s and %s for %s\n",
+ log4c_priority_to_string(log4c_category_get_priority(log4c_category_get(LOG_CATEGORY_LB))),
+ LOG_CATEGORY_LB,
+ log4c_priority_to_string(log4c_category_get_priority(log4c_category_get(LOG_CATEGORY_LB_LOGD))),
+ LOG_CATEGORY_LB_LOGD,
+ log4c_priority_to_string(log4c_category_get_priority(log4c_category_get(LOG_CATEGORY_LB_IL))),
+ LOG_CATEGORY_LB_IL,
+ log4c_priority_to_string(log4c_category_get_priority(log4c_category_get(LOG_CATEGORY_LB_SERVER))),
+ LOG_CATEGORY_LB_SERVER);
break;
case SIGPIPE:
glite_common_log(LOG_CATEGORY_CONTROL,LOG_PRIORITY_INFO,"Broken pipe, lost communication channel.\n");
timeout.tv_sec = ACCEPT_TIMEOUT;
timeout.tv_usec = 0;
getpeername(socket,(struct sockaddr *) &peer,&alen);
- glite_common_log(LOG_CATEGORY_NAME,LOG_PRIORITY_DEBUG,"Accepting connection (remaining timeout %d.%06d sec)\n",
+ glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"Accepting connection (remaining timeout %d.%06d sec)\n",
(int)timeout.tv_sec, (int) timeout.tv_usec);
if ((ret = edg_wll_gss_accept(cred_handle,socket,&timeout,&con, &gss_stat)) < 0) {
- glite_common_log(LOG_CATEGORY_NAME,LOG_PRIORITY_DEBUG,"timeout after gss_accept is %d.%06d sec\n",
+ glite_common_log(LOG_CATEGORY_SECURITY,LOG_PRIORITY_DEBUG,"timeout after gss_accept is %d.%06d sec\n",
(int)timeout.tv_sec, (int) timeout.tv_usec);
- glite_common_log(LOG_CATEGORY_NAME,LOG_PRIORITY_ERROR,"%s: edg_wll_gss_accept() failed\n",inet_ntoa(peer.sin_addr));
+// TODO: glite_common_log(LOG_CATEGORY_SECURITY,LOG_PRIORITY_WARN,"%s: edg_wll_gss_accept() failed\n",inet_ntoa(peer.sin_addr));
return edg_wll_log_proto_server_failure(ret,&gss_stat,"edg_wll_gss_accept() failed\n");
}
/* authenticate */
- glite_common_log(LOG_CATEGORY_NAME,LOG_PRIORITY_INFO,"Processing authentication:\n");
+ glite_common_log(LOG_CATEGORY_SECURITY,LOG_PRIORITY_DEBUG,"Processing authentication:\n");
ret = edg_wll_gss_get_client_conn(&con, &client, &gss_stat);
if (ret) {
char *gss_err;
edg_wll_gss_get_error(&gss_stat, "Cannot read client identification", &gss_err);
- glite_common_log(LOG_CATEGORY_NAME,LOG_PRIORITY_WARN, "%s: %s\n", inet_ntoa(peer.sin_addr),gss_err);
+ glite_common_log(LOG_CATEGORY_SECURITY,LOG_PRIORITY_WARN, "%s: %s\n", inet_ntoa(peer.sin_addr),gss_err);
free(gss_err);
}
if (ret || client->flags & EDG_WLL_GSS_FLAG_ANON) {
- glite_common_log(LOG_CATEGORY_NAME,LOG_PRIORITY_INFO," User not authenticated, setting as \"%s\". \n",EDG_WLL_LOG_USER_DEFAULT);
+ glite_common_log(LOG_CATEGORY_SECURITY,LOG_PRIORITY_WARN," User not authenticated, setting as \"%s\". \n",EDG_WLL_LOG_USER_DEFAULT);
subject=strdup(EDG_WLL_LOG_USER_DEFAULT);
} else {
- glite_common_log(LOG_CATEGORY_NAME,LOG_PRIORITY_INFO," User successfully authenticated as:\n");
- glite_common_log(LOG_CATEGORY_NAME,LOG_PRIORITY_INFO, " %s\n", client->name);
+ glite_common_log(LOG_CATEGORY_SECURITY,LOG_PRIORITY_INFO," User successfully authenticated as: %s\n",client->name);
subject=strdup(client->name);
}
if (client)
while (timeout.tv_sec > 0) {
count++;
- glite_common_log(LOG_CATEGORY_NAME,LOG_PRIORITY_DEBUG,"Waiting for data delivery no. %d (remaining timeout %d.%06d sec)\n",
+ glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"Waiting for data delivery no. %d (remaining timeout %d.%06d sec)\n",
count, (int)timeout.tv_sec, (int) timeout.tv_usec);
FD_SET(con.sock,&fdset);
fd = select(con.sock+1,&fdset,NULL,NULL,&timeout);
switch (fd) {
case 0: /* timeout */
- glite_common_log(LOG_CATEGORY_NAME,LOG_PRIORITY_DEBUG,"Connection timeout expired\n");
+ glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"Connection timeout expired\n");
timeout.tv_sec = 0;
break;
case -1: /* error */
switch(errno) {
case EINTR:
- glite_common_log(LOG_CATEGORY_NAME,LOG_PRIORITY_DEBUG,"XXX: Waking up (remaining timeout %d.%06d sec)\n",
+ glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"XXX: Waking up (remaining timeout %d.%06d sec)\n",
(int)timeout.tv_sec, (int) timeout.tv_usec);
continue;
default:
}
break;
default:
- glite_common_log(LOG_CATEGORY_NAME,LOG_PRIORITY_DEBUG,"Waking up (remaining timeout %d.%06d sec)\n",
+ glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"Waking up (remaining timeout %d.%06d sec)\n",
(int)timeout.tv_sec, (int) timeout.tv_usec);
break;
}
if (FD_ISSET(con.sock,&fdset)) {
ret = edg_wll_log_proto_server(&con,&timeout,subject,file_name_prefix,noipc,noparse);
+ // TODO: put into edg_wll_log_proto_server?
if (ret != 0) {
- glite_common_log(LOG_CATEGORY_NAME,LOG_PRIORITY_DEBUG,"timeout after edg_wll_log_proto_server is %d.%06d sec\n",
+ glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"timeout after edg_wll_log_proto_server is %d.%06d sec\n",
(int)timeout.tv_sec, (int) timeout.tv_usec);
if (ret != EDG_WLL_GSS_ERROR_EOF)
- glite_common_log(LOG_CATEGORY_NAME,LOG_PRIORITY_ERROR,"edg_wll_log_proto_server(): Error\n");
+ glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN,"edg_wll_log_proto_server(): Error\n");
else if (count == 1)
- glite_common_log(LOG_CATEGORY_NAME,LOG_PRIORITY_ERROR,"edg_wll_log_proto_server(): Error. EOF occured.\n");
+ glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN,"edg_wll_log_proto_server(): Error. EOF occured.\n");
timeout.tv_sec = 0;
timeout.tv_usec = 0;
break;
}
doit_end:
- glite_common_log(LOG_CATEGORY_NAME,LOG_PRIORITY_DEBUG, "Closing descriptor '%d'...",con.sock);
+ glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG, "Closing descriptor '%d'...",con.sock);
edg_wll_gss_close(&con, NULL);
if (con.sock == -1)
glite_common_log(LOG_CATEGORY_NAME,LOG_PRIORITY_DEBUG, "o.k.\n");
usage(argv[0]); exit(0);
}
}
- if (debug) {
- glite_common_log_init(LOG_PRIORITY_DEBUG);
- } else {
-#ifdef LB_PERF
- glite_common_log_init(verbose ? LOG_PRIORITY_INFO : LOG_PRIORITY_NOTSET);
-#else
- glite_common_log_init(verbose ? LOG_PRIORITY_DEBUG : LOG_PRIORITY_NOTSET);
-#endif
+ if (glite_common_log_init()) {
+ fprintf(stderr,"glite_common_log_init() failed, exiting.");
+ exit(1);
}
glite_common_log(LOG_CATEGORY_CONTROL,LOG_PRIORITY_INFO,"Initializing...\n");
#include <errno.h>
#include "glite/lbu/escape.h"
+#include "glite/lbu/log.h"
#include "glite/lb/context-int.h"
#include "glite/lb/events_parse.h"
}
switch(code) {
case EDG_WLL_GSS_ERROR_EOF:
- glite_common_log(LOG_CATEGORY_NAME,LOG_PRIORITY_ERROR,"%s: %s, EOF occured\n", func, text);
+ glite_common_log(LOG_CATEGORY_SECURITY,LOG_PRIORITY_WARN,"%s: %s, EOF occured\n", func, text);
ret = EAGAIN;
break;
case EDG_WLL_GSS_ERROR_TIMEOUT:
- glite_common_log(LOG_CATEGORY_NAME,LOG_PRIORITY_ERROR,"%s: %s, timeout expired\n", func, text);
+ glite_common_log(LOG_CATEGORY_SECURITY,LOG_PRIORITY_WARN,"%s: %s, timeout expired\n", func, text);
ret = EAGAIN;
break;
case EDG_WLL_GSS_ERROR_ERRNO:
SYSTEM_ERROR(func);
- glite_common_log(LOG_CATEGORY_NAME,LOG_PRIORITY_ERROR,"%s: %s, system error occured\n", func, text);
+ glite_common_log(LOG_CATEGORY_SECURITY,LOG_PRIORITY_WARN,"%s: %s, system error occured\n", func, text);
ret = EAGAIN;
break;
case EDG_WLL_GSS_ERROR_GSS:
char *gss_err;
edg_wll_gss_get_error(gss_code, "GSS error occured", &gss_err);
- glite_common_log(LOG_CATEGORY_NAME,LOG_PRIORITY_ERROR,"%s: %s, %s\n", func, text, gss_err);
+ glite_common_log(LOG_CATEGORY_SECURITY,LOG_PRIORITY_WARN,"%s: %s, %s\n", func, text, gss_err);
free(gss_err);
ret = EAGAIN;
break;
}
default:
- glite_common_log(LOG_CATEGORY_NAME,LOG_PRIORITY_ERROR,"%s: %s, unknown error occured\n");
+ glite_common_log(LOG_CATEGORY_SECURITY,LOG_PRIORITY_ERROR,"%s: %s, unknown error occured\n");
break;
}
return ret;
}
-/*
- *----------------------------------------------------------------------
- *
- * glite_common_log_init - initialize the logging level
- *
- *----------------------------------------------------------------------
- */
-int glite_common_log_init(int a_priority) {
- int ret = log4c_init();
-
- if (a_priority != LOG_PRIORITY_NOTSET) {
- /* override initial priority values */
- log4c_category_set_priority(log4c_category_get(LOG_CATEGORY_SECURITY),a_priority);
- log4c_category_set_priority(log4c_category_get(LOG_CATEGORY_ACCESS),a_priority);
- log4c_category_set_priority(log4c_category_get(LOG_CATEGORY_CONTROL),a_priority);
- glite_common_log_priority_security = a_priority;
- glite_common_log_priority_access = a_priority;
- glite_common_log_priority_control = a_priority;
- } else {
- glite_common_log_priority_security = log4c_category_get_priority(log4c_category_get(LOG_CATEGORY_SECURITY));
- glite_common_log_priority_access = log4c_category_get_priority(log4c_category_get(LOG_CATEGORY_ACCESS));
- glite_common_log_priority_control = log4c_category_get_priority(log4c_category_get(LOG_CATEGORY_CONTROL));
- }
-
- return ret;
-}
-
-/*
-int glite_common_log_setappender(char *catName, char *appName) {
- log4c_category_set_appender(log4c_category_get(catName)
- ,log4c_appender_get(appName));
- return(0);
-}
-*/
-
-/*
- *----------------------------------------------------------------------
- *
- * glite_common_log_fini - finish and explicitly call the log4c cleanup routine
- *
- *----------------------------------------------------------------------
- */
-int glite_common_log_fini() {
- return(log4c_fini());
-}
-
-
-/*
- *----------------------------------------------------------------------
- *
- * edg_wll_ll_log - print to stderr according to logging level
- * serious messages are also written to syslog
- *
- *----------------------------------------------------------------------
- */
-/*
-void glite_common_log(LOG_CATEGORY_NAME,int level, const char *fmt, ...) {
- char *err_text;
- va_list fmt_args;
-
- va_start(fmt_args, fmt);
- vasprintf(&err_text, fmt, fmt_args);
- va_end(fmt_args);
-
- if(level <= glite_common_log_level)
- fprintf(stderr, "[%d] %s", (int) getpid(), err_text);
- if(level <= LOG_PRIORITY_ERROR) {
- openlog(NULL, LOG_PID | LOG_CONS, LOG_DAEMON);
- syslog(level, "%s", err_text);
- closelog();
- }
-
- if (err_text) free(err_text);
-}
-*/
-
-void glite_common_log_msg(char *catName,int a_priority, char *msg) {
- const log4c_category_t* a_category = log4c_category_get(catName);
-
- if (log4c_category_is_priority_enabled(a_category, a_priority)) {
- log4c_category_log(log4c_category_get(catName), a_priority, msg);
- }
-}
-
-void glite_common_log(char *catName,int a_priority, const char* a_format,...) {
- const log4c_category_t* a_category = log4c_category_get(catName);
-
- if (log4c_category_is_priority_enabled(a_category, a_priority)) {
- va_list va;
-
- va_start(va, a_format);
- log4c_category_vlog(a_category, a_priority, a_format, va);
- va_end(va);
- }
-}
-
extern "C" {
#endif
-
#include <syslog.h>
-#include <log4c.h>
#include "glite/lb/log_proto.h"
#include "glite/security/glite_gss.h"
int edg_wll_log_proto_server(edg_wll_GssConnection *con, struct timeval *timeout, char *name, char *prefix, int noipc, int noparse);
int edg_wll_log_proto_server_failure(int code, edg_wll_GssStatus *gss_code, const char *text);
-/* locallogger daemon error handling */
-/* gLite common logging recommendations v1.1 https://twiki.cern.ch/twiki/pub/EGEE/EGEEgLite/logging.html */
-
-#define LOG_CATEGORY_NAME "root"
-#define LOG_CATEGORY_SECURITY "glite-common-logging-security"
-#define LOG_CATEGORY_ACCESS "glite-common-logging-access"
-#define LOG_CATEGORY_CONTROL "glite-common-logging-control"
-
-/* other priorities may be added, see include/log4c/priority.h */
-#define LOG_PRIORITY_FATAL LOG4C_PRIORITY_FATAL
-#define LOG_PRIORITY_ERROR LOG4C_PRIORITY_ERROR
-#define LOG_PRIORITY_WARN LOG4C_PRIORITY_WARN
-#define LOG_PRIORITY_INFO LOG4C_PRIORITY_INFO
-#define LOG_PRIORITY_DEBUG LOG4C_PRIORITY_DEBUG
-#define LOG_PRIORITY_NOTSET LOG4C_PRIORITY_NOTSET
-
-#define glite_common_log_security(priority,msg) glite_common_log_msg(LOG_CATEGORY_SECURITY,priority,msg)
-#define glite_common_log_access(priority,msg) glite_common_log_msg(LOG_CATEGORY_ACCESS,priority,msg)
-#define glite_common_log_control(priority,msg) glite_common_log_msg(LOG_CATEGORY_CONTROL,priority,msg)
-
-#define SYSTEM_ERROR(my_err) { \
- if (errno !=0 ) \
- glite_common_log(LOG_CATEGORY_NAME,LOG_PRIORITY_ERROR,"%s: %s\n",my_err,strerror(errno)); \
- else \
- glite_common_log(LOG_CATEGORY_NAME,LOG_PRIORITY_ERROR,"%s\n",my_err); }
-
-extern int glite_common_log_priority_security;
-extern int glite_common_log_priority_access;
-extern int glite_common_log_priority_control;
-
-int glite_common_log_init(int a_priority);
-int glite_common_log_fini(void);
-// int glite_common_log_setappender(char *catName, char *appName);
-// void edg_wll_ll_log(int level, const char *fmt, ...);
-void glite_common_log_msg(char *catName,int a_priority, char *msg);
-void glite_common_log(char *catName,int a_priority, const char* a_format,...);
-
-
/* fcntl defaults */
#define FCNTL_ATTEMPTS 5
#define FCNTL_TIMEOUT 1