diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-06 01:23:53 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-06 01:23:53 +0000 |
commit | c000cad09d0b54c455c99271bfb996c2dfe13073 (patch) | |
tree | e47ca809ed512d7fb43ec3d555753b1b658e9819 /servers/slapd/slapi/printmsg.c | |
parent | Initial commit. (diff) | |
download | openldap-c000cad09d0b54c455c99271bfb996c2dfe13073.tar.xz openldap-c000cad09d0b54c455c99271bfb996c2dfe13073.zip |
Adding upstream version 2.4.47+dfsg.upstream/2.4.47+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'servers/slapd/slapi/printmsg.c')
-rw-r--r-- | servers/slapd/slapi/printmsg.c | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/servers/slapd/slapi/printmsg.c b/servers/slapd/slapi/printmsg.c new file mode 100644 index 0000000..92be577 --- /dev/null +++ b/servers/slapd/slapi/printmsg.c @@ -0,0 +1,100 @@ +/* $OpenLDAP$ */ +/* This work is part of OpenLDAP Software <http://www.openldap.org/>. + * + * Copyright 2002-2018 The OpenLDAP Foundation. + * Portions Copyright 1997,2002-2003 IBM Corporation. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted only as authorized by the OpenLDAP + * Public License. + * + * A copy of this license is available in the file LICENSE in the + * top-level directory of the distribution or, alternatively, at + * <http://www.OpenLDAP.org/license.html>. + */ +/* ACKNOWLEDGEMENTS: + * This work was initially developed by IBM Corporation for use in + * IBM products and subsequently ported to OpenLDAP Software by + * Steve Omrani. + */ + +#include <portable.h> +#include <stdio.h> +#include <ac/string.h> +#include <ac/stdarg.h> +#include <ac/unistd.h> +#include <fcntl.h> +#include <ac/errno.h> + +#include <ldap.h> +#include <ldap_config.h> +#include <slap.h> +#include <slapi.h> + +#include <ldap_pvt_thread.h> + +/* Single threads access to routine */ +ldap_pvt_thread_mutex_t slapi_printmessage_mutex; +char *slapi_log_file = NULL; +int slapi_log_level = SLAPI_LOG_PLUGIN; + +int +slapi_int_log_error( + int level, + char *subsystem, + char *fmt, + va_list arglist ) +{ + int rc = 0; + FILE *fp = NULL; + + char timeStr[100]; + struct tm *ltm; + time_t currentTime; + + assert( subsystem != NULL ); + assert( fmt != NULL ); + + ldap_pvt_thread_mutex_lock( &slapi_printmessage_mutex ) ; + + /* for now, we log all severities */ + if ( level <= slapi_log_level ) { + fp = fopen( slapi_log_file, "a" ); + if ( fp == NULL) { + rc = -1; + goto done; + } + + /* + * FIXME: could block + */ + while ( lockf( fileno( fp ), F_LOCK, 0 ) != 0 ) { + /* DO NOTHING */ ; + } + + time( ¤tTime ); + ltm = localtime( ¤tTime ); + strftime( timeStr, sizeof(timeStr), "%x %X", ltm ); + fputs( timeStr, fp ); + + fprintf( fp, " %s: ", subsystem ); + vfprintf( fp, fmt, arglist ); + if ( fmt[ strlen( fmt ) - 1 ] != '\n' ) { + fputs( "\n", fp ); + } + fflush( fp ); + + lockf( fileno( fp ), F_ULOCK, 0 ); + + fclose( fp ); + + } else { + rc = -1; + } + +done: + ldap_pvt_thread_mutex_unlock( &slapi_printmessage_mutex ); + + return rc; +} |