aboutsummaryrefslogtreecommitdiffstats
path: root/src/logging.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* core: New function gpgrt_add_post_log_func.Werner Koch2024-04-221-0/+67
| | | | | | | | | | | | | | | | * src/gpg-error.h.in (gpgrt_add_post_log_func): New. * src/gpg-error.vers: Add new function * src/gpg-error.def.in: Ditto. * src/visibility.c (gpgrt_add_post_log_func): New. * src/logging.c (struct post_log_func_item_s): New. (post_log_func_list): New. (_gpgrt_add_post_log_func): new. (run_post_log_funcs): New. (_gpgrt_logv_internal): Call for fatal and bug log levels. -- This is required in case an application or library needs to do do some quick cleanups after a log_fatal.
* logging: Indent continuation lines of log_printhex.Werner Koch2024-04-191-6/+14
| | | | | | * src/logging.c (_gpgrt_logv_internal): Change to return the length w/o prefix. (_gpgrt_logv_printhex): Indent wrapped lines properly.
* logging: Add a truncate keyword to log_printhex.Werner Koch2024-04-121-0/+19
| | | | | | | | | | | | | | | * src/logging.c (_gpgrt_logv_printhex): Add keyword support. -- A keyword in the format string is indicated by a leading pipe symbo, and exlamation mark, an arbitrary string of keywords, and a fina pipe sumbol. The only supprted keyword righty now is "trunc". Thus gpgrt_log_printhex (buf, buflen, "|!trunc|The buffer:") Will output not more that 32 hex bytes after "The buffer:" and instead of wrapping indicate the truncation by an Unicode horizontal ellipsis (#x2026).
* Avoid segv in logging with improper use of the "socket://" .Werner Koch2023-03-211-2/+2
| | | | | | | | | * src/logging.c (fun_writer): Protect calling socket_dir_cb if not set. -- If no callback has been registered the use of the "socket://" shortcut caused a segv.
* Silence compiler warnings.NIIBE Yutaka2022-09-081-2/+2
| | | | | | | | | * src/argparse.c (show_version): It's no args. (_gpgrt_log_get_fd, _gpgrt_log_get_stream): Likewise. -- Signed-off-by: NIIBE Yutaka <[email protected]>
* logging: Fix the previous commit.NIIBE Yutaka2022-04-071-1/+1
| | | | | | * src/logging.c (set_file_fd): Open with append mode. Signed-off-by: NIIBE Yutaka <[email protected]>
* logging: Fix gpgrt_log_get_fd for file.NIIBE Yutaka2022-04-071-68/+21
| | | | | | | | | | | | | | * src/logging.c (fun_writer): Only use this for socket writing. (set_file_fd): Use es_stderr when "-". Use the stream by _gpgrt_fdopen when FD is specified. Use the stream by _gpgrt_fopen when name is not socket. Only use the stream by _gpgrt_fopencookie for socket. [HAVE_W32CE_SYSTEM]: Remove W32CE support. -- GnuPG-bug-id: 5922 Signed-off-by: NIIBE Yutaka <[email protected]>
* logging: Also protect gpgrt_inc_errorcount against counter overflow.Werner Koch2020-02-101-7/+5
| | | | | | | | | | | | | * src/logging.c (_gpgrt_inc_errorcount): Protect against counter overflow. (_gpgrt_logv_internal): Use that function here so that we have only one check for counter overflow. -- We already had an overflow checking for log_error but not for the silent increment function. Signed-off-by: Werner Koch <[email protected]>
* logging: Fix the case of using socket_dir_cb which may return NULL.NIIBE Yutaka2019-09-181-3/+4
| | | | | | | * src/logging.c (fun_writer): Fix for socket_dir_cb. GnuPG-bug-id: 4698 Signed-off-by: NIIBE Yutaka <[email protected]>
* estream: Increase buffer size for Windows.Werner Koch2019-03-191-1/+1
| | | | | | | | * src/gpgrt-int.h (BUFFER_BLOCK_SIZE) [W32]: Increase from 512 to 8k. * src/w32-estream.c (READBUF_SIZE, WRITEBUF_SIZE): Increase from 4k to 8k. Signed-off-by: Werner Koch <[email protected]>
* core: New functions gpgrt_abort and gpgrt_add_emergency_cleanup.Werner Koch2019-01-041-7/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | * src/init.c (emergency_cleanup_list): New gloabl var. (_gpgrt_add_emergency_cleanup): New. (_gpgrt_abort): New. Repalce all calls to abort by this. Also replace all assert by either log_assert or a stderr output followed by a _gpgrt_abort. (run_emergency_cleanup): New. * src/visibility.c (gpgrt_add_emergency_cleanup): New public API. (gpgrt_abort): New public API. -- Libgcrypt uses its own assert function which makes sure to terminate the secure memory. This is safe as log as an assert is triggered internally in Libgcrypt. GnuPG runs emergency cleanup handlers right before log_fatal etc to tell Libgcrypt to terminate the secure memory. With the move of the logging function to gpgrt in gnupg 2.3 this did not anymore. Thus we now provide a mechanism in gpgrt to do right that. Eventually Libgcrypt can also make use of this. What this does not handle are calls to abort or failed asserts in external libraries or in libc. We can't do anything about it in a library because a library may not setup signal handlers. Signed-off-by: Werner Koch <[email protected]>
* logging: Escape controls in string arguments of log_ functions.Werner Koch2018-12-061-1/+103
| | | | | | | | | | | | | | | | * src/logging.c (struct fmt_string_filter_s): New. (fmt_string_filter): New. (_gpgrt_logv_internal): Use the filter. -- This change has two advantages: a) There is no more need to first escape string arguments before passing them to a log function and b) you can't forget to do the escaping and thus attacks using diagnostic output to trick out users won't work. The drawback is that you see \n instead of a real LF and under Windows the backslash in file names are doubled. Signed-off-by: Werner Koch <[email protected]>
* core: Allow logging to an estream.Werner Koch2018-12-051-7/+14
| | | | | | | | | * src/logging.c (set_file_fd): Add and use new arg 'stream'. (_gpgrt_log_set_sink): Implement setting an estream sink. * tests/t-logging.c: New test. * tests/Makefile.am (TESTS): Add test. Signed-off-by: Werner Koch <[email protected]>
* core: New functions gpgrt_fprintf_sf anf gpgrt_fprintf_sf_unlocked.Werner Koch2018-11-261-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | * src/gpg-error.h.in (gpgrt_string_filter_t): New type. (gpgrt_fprintf_sf, gpgrt_fprintf_sf_unlocked): New. * src/gpg-error.vers, src/gpg-error.def.in: Add them. * src/visibility.c (gpgrt_fprintf_sf): New. (gpgrt_fprintf_sf_unlocked): New. * src/estream-printf.c (pr_string): Add and use args sf, sfvalue and string_no. (do_format): Add args sf and sfvalue. Keep a string format counter. (_gpgrt_estream_format): Add args sf and sfvalue. Change all callers to provide NULL for them. * src/estream.c (_gpgrt_vfprintf_unlocked, _gpgrt_vfprintf): Add sf and sfvalue and adjust all callers. (do_print_stream): Ditto. * tests/t-printf.c (stream_to_string): New. (struct sfstate_s): New. (string_filter): New. (check_fprintf_sf): New. (main): Call new test. -- The actual reason to implement these functions is to enhance the internal logging function with a filter to sanitized strings so that control values or other things can be quoted. Signed-off-by: Werner Koch <[email protected]>
* core: Fix regression on arm64 due to invalid use of va_list.Werner Koch2018-03-181-4/+14
| | | | | | | | | | | * src/logging.c (_gpgrt_log_printhex): Provide a dummy arg instead of NULL. -- Fix Suggested-by: Jakub Wilk <[email protected]> Signed-off-by: Werner Koch <[email protected]>
* core: Rename the gpgrt_log_levels enum values.Werner Koch2017-12-081-26/+28
| | | | | | | | | | | * src/gpg-error.h.in (gprt_log_levels): Rename to GPGRT_LOGLVL. -- Explicitly naming them and not distinguishing them from the other log constants is a Good Thing anyway. It also helps against the symbol name clash with the GPGRT enum values from gnupg's logging module. Signed-off-by: Werner Koch <[email protected]>
* core: Prepare to build with gpgscm.Werner Koch2017-11-281-1/+1
| | | | | | | | | | | | * configure.ac: New option --enable-gpgscm. Create gpgscm/Makefile. (GPGRT_ENABLE_LOG_MACROS): Define. * Makefile.am (SUBDIRS): Add gpgscm * src/logging.c (_gpgrt_logv_clock): Do not use the log_debug macro. -- Note that gpscm does not yet build. Signed-off-by: Werner Koch <[email protected]>
* core: Avoid endless recursion if log_set_sink has not been used.Werner Koch2017-11-271-2/+3
| | | | | | | * src/logging.c (_gpgrt_log_set_sink): Do not call gf_is_valid if the default sink has been requested. Signed-off-by: Werner Koch <[email protected]>
* w32: Add new API fucntion gpgrt_w32_reg_query_string.Werner Koch2017-11-171-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | * src/w32-reg.c: New. * src/w32-add.h: Add gpgrt_w32_reg_query_string. * src/visibility.c (gpgrt_w32_reg_query_string): New wrapper. * src/gpg-error.def.in: Add gpgrt_w32_reg_query_string. * configure.ac (ac_check_funcs): Add stpcpy. * src/Makefile.am (arch_sources): Add w32-reg.c (socklibs): New. (libgpg_error_la_LIBADD): Add socklibs. * src/gpgrt-int.h (xfree, xtrymalloc, xtrycalloc) (xtryrealloc): New internal macros. (_gpgrt_stpcpy, stpcpy): New replacement fucntion and macro. * src/logging.c (_gpgrt_logv_internal): Use new registry query function and add standard registry key. -- This also fixes the build failure on Widnwos for logging.c. The code for gpgrt_w32_reg_query_string has been taken from the function read_w32_registry_string in w32-utils.c in the GPGME package. Signed-off-by: Werner Koch <[email protected]>
* core: Add logging API.Werner Koch2017-11-171-187/+305
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * src/visibility.c (gpgrt_get_errorcount): New API. (gpgrt_inc_errorcount): New API. (gpgrt_log_set_sink): New API. (gpgrt_log_set_socket_dir_cb): New API. (gpgrt_log_set_pid_suffix_cb): New API. (gpgrt_log_set_prefix): New API. (gpgrt_log_get_prefix): New API. (gpgrt_log_test_fd): New API. (gpgrt_log_get_fd): New API. (gpgrt_log_get_stream): New API. (gpgrt_log): New API. (gpgrt_logv): New API. (gpgrt_logv_prefix): New API. (gpgrt_log_string): New API. (gpgrt_log_info): New API. (gpgrt_log_error): New API. (gpgrt_log_fatal): New API. (gpgrt_log_bug): New API. (gpgrt_log_debug): New API. (gpgrt_log_debug_string): New API. (gpgrt_log_printf): New API. (gpgrt_log_flush): New API. (gpgrt_log_printhex): New API. (gpgrt_log_clock): New API. (_gpgrt_log_assert): New function for the ABI. * src/visibility.h: Add corresponding macros. * src/gpg-error.def.in: Add new functions. * src/gpg-error.vers: Add new functions. * src/gpg-error.h.in (GPGRT_LOG_WITH_PREFIX): New constant. (GPGRT_LOG_WITH_TIME): New constant. (GPGRT_LOG_WITH_PID): New constant. (GPGRT_LOG_RUN_DETACHED): New constant. (GPGRT_LOG_NO_REGISTRY): New constant. (GPGRT_LOG_BEGIN): New enum value. (GPGRT_LOG_CONT): New enum value. (GPGRT_LOG_INFO): New enum value. (GPGRT_LOG_WARN): New enum value. (GPGRT_LOG_ERROR): New enum value. (GPGRT_LOG_FATAL): New enum value. (GPGRT_LOG_BUG): New enum value. (GPGRT_LOG_DEBUG): New enum value. (log_get_errorcount, log_inc_errorcount, log_set_file, log_set_fd) (log_set_stream, log_set_socket_dir_cb, log_set_pid_suffix_cb) (log_set_prefix, log_get_prefix, log_test_fd, log_get_fd) (log_get_stream, log_log, log_logv, log_logv_prefix, log_string) (log_bug, log_fatal, log_error, log_info, log_debug, log_debug_string) (log_printf, log_printhex, log_clock) (log_flush) [GPGRT_ENABLE_LOG_MACROS]: New wrapper macros. (gpgrt_assert): New macro. * src/gpgrt-int.h: Add prototypes for logging.c. (gpgrt_assert): Redefine for internal use. * src/logging.h: Remove. * src/logging.c: Include gpgrt-int.h instead of the stuff from GnuPG. Use _gpgrt malloc funcsions and the internal versions of the estream functions. Rename all public fucntions with a _gpgrt_ prefix. (print_prefix): Return the printed length. (_gpgrt_logv_internal): Ditto. (_gpgrt_log_printhex): Change order of args and turn into a printf like function. (_gpgrt_logv_printhex): New. Take the core of the former log_printhex. (_gpgrt_log_clock): Turn into a printf like functions. (_gpgrt_logv_clock): New. Take the core of the former log_clock. -- This logging API is a slightly modified version of what we are using in GnuPG. Signed-off-by: Werner Koch <[email protected]>
* core: Change license of logging.[ch] to LGPLv2.1Werner Koch2017-10-051-22/+14
| | | | | | | | | | | -- This file has a long history. I was first written by me in 1998 for GnuPG under the name logger.c. In 2010 it was renamed to logging.c. Almost everything was written by me. A few minor fixes are from g10 Code employees and some other people. Signed-off-by: Werner Koch <[email protected]>
* core: Import of logging.[ch] from GnuPGWerner Koch2017-10-051-0/+1103
-- Taken from GnuPG master commit 98c260e057e7829580da99f0c8e0037a3896bfae Signed-off-by: Werner Koch <[email protected]>