aboutsummaryrefslogtreecommitdiffstats
path: root/src/estream.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* estream: Add missing malloc check.Werner Koch2019-06-271-1/+6
| | | | | | * src/estream.c (_gpgrt_poll): Check for malloc error. Signed-off-by: Werner Koch <[email protected]>
* estream: Don't use variable length array.NIIBE Yutaka2019-06-261-1/+7
| | | | | | | | | * src/estream.c [HAVE_POLL_H] (_gpgrt_poll): No VLA. -- Fixes-commit: a21a7de8c2cf986235382e7e04805744f6df116e Signed-off-by: NIIBE Yutaka <[email protected]>
* estream: Use poll(2) when available.NIIBE Yutaka2019-06-261-0/+82
| | | | | | | | | | | * configure.ac: Detect poll.h. * src/estream.c [HAVE_POLL_H] (_gpgrt_poll): Use poll. -- Here, we use C99 feature of array declaration with variable. Signed-off-by: NIIBE Yutaka <[email protected]>
* core: New functions gpgrt_abort and gpgrt_add_emergency_cleanup.Werner Koch2019-01-041-9/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | * 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]>
* core: New functions gpgrt_fprintf_sf anf gpgrt_fprintf_sf_unlocked.Werner Koch2018-11-261-5/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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: Add a limited version of gpgrt_ftruncate.Werner Koch2018-11-261-0/+31
| | | | | | | | | | | | | | | * src/gpg-error.h.in (gpgrt_ftruncate, es_ftruncate): New. * src/gpg-error.def.in, src/gpg-error.vers: Add gpgrt_ftruncate. * src/visibility.c (gpgrt_ftruncate): new. * src/gpgrt-int.h (COOKIE_IOCTL_TRUNCATE): New. * src/estream.c (func_mem_ioctl): Support new internal IOCTL. (_gpgrt_ftruncate): New. -- Right now the ftruncate works only on memory streams. Can easily be added to other stream times. Signed-off-by: Werner Koch <[email protected]>
* estream: Always propagate flush event to cookie functions.Werner Koch2018-07-121-3/+4
| | | | | | * src/estream.c (flush_stream): Always call cookie's flush func. Signed-off-by: Werner Koch <[email protected]>
* core: Fix gpgrt_poll for Windows under nPth.Werner Koch2018-04-301-0/+2
| | | | | | * src/estream.c (_gpgrt_poll) [W32]: Use syscall clamp. Signed-off-by: Werner Koch <[email protected]>
* doc: Typo fixes.Werner Koch2018-02-211-1/+1
| | | | --
* core: Unify syscall_clamp functions.Werner Koch2017-11-291-92/+32
| | | | | | | | | | | | | | | * src/estream.c (_gpgrt_set_syscall_clamp) (_gpgrt_get_syscall_clamp): Move to ... * src/syscall-clamp.c: new file. (_gpgrt_pre_syscall, _gpgrt_post_syscall): New. * src/Makefile.am (libgpg_error_la_SOURCES): Add that file. * src/estream.c: Replace the syscall wrapper with the new functions. * src/posix-lock.c: Ditto. * src/w32-lock.c: Ditto. * src/posix-thread.c: Ditto. * src/w32-thread.c: Ditto. Signed-off-by: Werner Koch <[email protected]>
* Align 'es_poll' semantics closer with POSIX.Justus Winter2017-05-311-3/+0
| | | | | | | | | | | | | * src/estream.c (_gpgrt_poll): Do not return early if some streams are found to be ready before even polling the others. -- POSIX mandates that all streams are examined and returning early violates that. It also imposes an order on how the callee serves the streams, which might be incompatible with the order the callee wants to serve them, leading to deadlocks. Signed-off-by: Justus Winter <[email protected]>
* Fix memory leak for estream.NIIBE Yutaka2017-05-301-5/+20
| | | | | | | * src/estream.c (do_list_remove): Free the item. (do_close): Free the buffer. Signed-off-by: NIIBE Yutaka <[email protected]>
* Minor clean up.NIIBE Yutaka2017-04-191-2/+2
| | | | | | | | * src/b64dec.c (_gpgrt_b64dec_proc): Add a comment. * src/estream.c (_gpgrt_fread, _gpgrt_fwrite): Use &&. * src/mkheader.c (xstrdup): Use memcpy as we know length. Signed-off-by: NIIBE Yutaka <[email protected]>
* Improve tracing of estream.Werner Koch2017-02-281-15/+39
| | | | | | | | | | | | * src/gpgrt-int.h (trace_errno): Add new parameter. Adjust all users. * src/init.c (trace_fp, trace_with_errno, trace_missing_lf) (trace_prefix_done): New vars. (_gpgrt_internal_trace_begin): Add arg WITH_ERRNO. Open a trace file on first use. Init new vars. (print_internal_trace_prefix): New. * src/estream.c, src/w32-estream.c: Improve tracing. Signed-off-by: Werner Koch <[email protected]>
* w32: Fix gpgrt_poll for Windows.Werner Koch2017-02-281-6/+0
| | | | | | | | | | | | * src/estream.c (_gpgrt_poll) [W32]: Do not call the syscall clamp. -- The system call clamp may only be used directloy around system calls. We don't need them here because we use independent threads to implement non-blocking behaviour. In fact the clamp may lead to a deadlock. Signed-off-by: Werner Koch <[email protected]>
* Use the new tracing ramework for estream.Werner Koch2017-02-261-9/+76
| | | | | | | | | * src/estream.c: Add trace calls to some functions. * src/w32-estream.c: Replace existing trace calls by the new framework. -- Signed-off-by: Werner Koch <[email protected]>
* Rename internal functions of estream.Werner Koch2017-02-261-90/+91
| | | | | | | | | | | | | | | | | | | | * src/estream.c (_gpgrt_es_init): Rename to _gpgrt_estream_init. (es_fill): Rename to fill_stream. (es_fflush): Rename to flush_stream. (es_deinitialize): Rename to deinit_stream_obj. (es_create): Rename to create_stream (es_read_nbf): Rename to do_read_nbf. (es_read_lbf): Rename to do_read_lbf. (es_read_fbf): Rename to do_read_fbf. (es_peek): Rename to peek_stream. (es_skip): Rename to skip_stream. (es_print): Rename to do_print_stream. -- The use of the "es_" was confusing. Avoid that. Signed-off-by: Werner Koch <[email protected]>
* w32: Do not use the syscall clamps in pollable mode.Werner Koch2017-02-241-10/+36
| | | | | | | | | | | | | * src/estream.c (estream_cookie_w32): Add flag no_syscall_clamp. (func_w32_create): Add arg no_syscall_clamp. (func_w32_read): Do not call pre/post_syscall_clamp when flag is set. (func_w32_write): Ditto. (func_w32_seek): Ditto. (do_w32open): Set NO_SYSCALL_CLAMP in pollable mode. (es_create) [W32]: Make sure that pollable-mode is unly used with the W32 backend. Signed-off-by: Werner Koch <[email protected]>
* estream: Correctly set ERRNO to EOPNOTSUPP.Werner Koch2017-01-191-2/+4
| | | | | | | * src/estream.c (es_flush, es_write_nbf): Fix setting of ERRNO to EOPNOTSUPP. Signed-off-by: Werner Koch <[email protected]>
* estream: Minor portability fix.Werner Koch2016-11-121-3/+3
| | | | | | | | | | -- A trailing comma in an enum is not groked by all compilers. Binary operation should have their own parentheses to make it clear that a binary operator was meant. Signed-off-by: Werner Koch <[email protected]>
* estream: Support 'es_poll' on Windows.Justus Winter2016-11-121-73/+52
| | | | | | | | | | | | | | | | | | | | | * src/Makefile.am (arch_sources): Add new file. * src/estream.c (O_NONBLOCK): Move to 'gpgrt-int.h'. (BUFFER_BLOCK_SIZE): Likewise. (BUFFER_UNREAD_SIZE): Likewise. (struct notify_list_s, notify_list_t): Likewise. (struct _gpgrt_stream_internal, estream_internal_t): Likewise. (X_POLLABLE): New macro. (parse_mode): Parse keyword 'pollable', emulate O_NONBLOCK using the same mechanism on Windows. (_gpgrt_poll): Use the new '_gpgrt_w32_poll' on Windows. * src/gpgrt-int.h (_gpgrt_functions_w32_pollable): New declaration. (_gpgrt_w32_pollable_create): New prototype. (_gpgrt_w32_poll): Likewise. * src/w32-estream.c: New file. This code is adapted from GPGME. * tests/t-poll.c (create_pipe): Create pollable streams. GnuPG-bug-id: 2731 Signed-off-by: Justus Winter <[email protected]>
* estream: Track the kind of backend used.Justus Winter2016-11-121-17/+22
| | | | | | | | | * src/estream.c (struct _gpgrt_stream_internal): Add 'kind'. (init_stream_obj): New parameter 'kind', initialize field. (es_create): New parameter 'kind'. Update all callers. * src/gpgrt-int.h (gpgrt_stream_backend_kind_t): New type. Signed-off-by: Justus Winter <[email protected]>
* estream: Rework how the cookie functions are handled.Justus Winter2016-11-121-49/+49
| | | | | | | | | | | | | | | | | | | | | | * src/estream.c (cookie_ioctl_function_t): Move to 'gpgrt-int.h', along with the macros for the IOCTL numbers. (estream_functions_mem): Use the new type and add the ioctl function. (estream_functions_fd): Likewise. (estream_functions_w32): Likewise. (estream_functions_fp): Likewise. (init_stream_object): Use the new type, and also initialize 'func_ioctl'. (es_create): Use the new type. (_gpgrt_fopen): Adapt. (_gpgrt_mopen): Likewise. (_gpgrt_fopenmem): Likewise. (_gpgrt_fopencookie): Likewise. (_gpgrt_fdopen): Likewise. (_gpgrt_fpopen): Likewise. (do_w32open): Likewise. * src/gpgrt-int.h (struct cookie_io_functions_s): New type. Signed-off-by: Justus Winter <[email protected]>
* estream: Rework modestring handling.Justus Winter2016-11-121-46/+44
| | | | | | | | | | | | | | | | | | * src/estream.c (X_SAMETHREAD, X_SYSOPEN): New macros. (parse_mode): Rework how information flows from here to 'es_create'. Instead of using an integer flag per mode, use flags. (init_stream_obj): Adapt accordingly. (es_create): Likewise. (_gpgrt_fopen): Likewise. (_gpgrt_mopen): Likewise. (_gpgrt_fopenmem): Likewise. (_gpgrt_fopencookie): Likewise. (_gpgrt_fdopen): Likewise. (_gpgrt_fpopen): Likewise. (do_w32open): Likewise. (_gpgrt_freopen): Likewise. Signed-off-by: Justus Winter <[email protected]>
* Add new interface gpgrt_get_syscall_clamp.Werner Koch2016-11-121-0/+11
| | | | | | | | | | | | | * src/visibility.c (gpgrt_get_syscall_clamp): New. * src/gpg-error.vers, src/gpg-error.def.in: Add function. * src/gpg-error.h.in: Ditto. * src/estream.c (_gpgrt_get_syscall_clamp): New. -- This function can be used by other libraries to set their own system clamp functions. Signed-off-by: Werner Koch <[email protected]>
* Use the syscall clamp functions also for lock functionsWerner Koch2016-11-111-1/+6
| | | | | | | | | | | | | | | | | | | | * src/posix-lock.c (pre_lock_func, post_lock_func): New. (_gpgrt_lock_set_lock_clamp): New. (_gpgrt_lock_lock): Use clamp functions. * src/w32-lock.c (pre_lock_func, post_lock_func): New. (_gpgrt_lock_set_lock_clamp): New. (_gpgrt_lock_lock): Use clamp functions. * src/posix-lock.c (pre_syscall_func, post_syscall_func): New. (_gpgrt_thread_set_syscall_clamp): New. (_gpgrt_yield): Use clamp functions. * src/w32-lock.c (pre_syscall_func, post_syscall_func): New. (_gpgrt_thread_set_syscall_clamp): New. (_gpgrt_yield): Use clamp functions. * src/estream.c: Include lock.h and thread.h. (do_deinit): Call _gpgrt_lock_set_lock_clamp. (_gpgrt_set_syscall_clamp): Ditto. Signed-off-by: Werner Koch <[email protected]>
* estream: Fix modestring parsing.Justus Winter2016-10-181-1/+1
| | | | | | * src/estream.c (parse_mode): Fix parsing the 'sysopen' flag. Signed-off-by: Justus Winter <[email protected]>
* Define EWOULDBLOCK in case it is not definedAndre Heinecke2016-07-051-0/+5
| | | | | | | * src/estream.c (EWOULDBLOCK): Define fallback. -- Older mingw versions (2.0) do not define EWOULDBLOCK in errno.h
* estream: Fix bug es_fclose_snatch if a seek has been used.Werner Koch2016-06-271-1/+1
| | | | | | * src/estream.c (func_mem_ioctl): Set LEN from DATA_LEN. Signed-off-by: Werner Koch <[email protected]>
* w32: Silence compiler warnings about redefined macros.Werner Koch2016-06-251-6/+19
| | | | | | * src/estream.c (S_IRGRP) [W32]: Protect against redefinition. Signed-off-by: Werner Koch <[email protected]>
* estream: Remove two compiler warning.Werner Koch2016-06-241-40/+41
| | | | | | | | | * src/estream.c (func_file_create): Remove dead assignment. (doreadline): Do not decrement SPACE_LEFT before breaking the loop. Add an extra block to limit the scope of that variable. -- Signed-off-by: Werner Koch <[email protected]>
* estream: Fix assertion failure due to es_flush.NIIBE Yutaka2016-06-151-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | * src/estream.c (es_writen): Set writing flag even if no data was written. -- GnuPG-bug-id: 2371 Signed-off-by: Werner Koch <[email protected]> gniibe tracked the problem down to a fully valid change in GnuPG (gnupg commit 12af2630cf4d1a39179179925fac8f2cce7504ff). He wrote: This is the first instance for estream to do READ and WRITE (in the history of the code > 10 years :-). In the [gnupg] function agent_write_private_key, the pattern is: es_fopen es_fread es_fseek es_fwrite which should work well, but if results core dump by assertion failure in the function es_flush of libgpg-error.
* Adjust memory limit of es_fopenmem to the block size.Werner Koch2016-06-151-0/+8
| | | | | | | | | | * src/estream.c (func_mem_create): Round up memory limit. -- This is required so that giving a memory limit to es_fopenmem won't fail if it is below the block size. Signed-off-by: Werner Koch <[email protected]>
* estream,w32: Temporary fix for gpgrt_poll.Werner Koch2016-04-051-0/+4
| | | | | | | | | | | * src/estream.c (_gpgrt_poll) [W32]: Do not use FD_ISSET. -- gpgrt_poll return an error on Windows anyway and thus it does not make sense to use a possible undefined macro here. Reported-by: Andre Heinecke Signed-off-by: Werner Koch <[email protected]>
* estream: Prepare for new mode flag "sysopen".Werner Koch2016-03-291-14/+47
| | | | | | * src/estream.c (parse_mode): Add arg "sysopen". Adjust all callers. Signed-off-by: Werner Koch <[email protected]>
* estream: Use simpler names for static functions.Werner Koch2016-03-291-44/+44
| | | | | | * src/estream.c: Replace all es_func_* to just func_*. Signed-off-by: Werner Koch <[email protected]>
* doc: Re-format comments in estream.cWerner Koch2016-03-291-150/+311
| | | | | -- Signed-off-by: Werner Koch <[email protected]>
* estream: Remove strange macro for better readability.Werner Koch2016-03-291-15/+11
| | | | | | | * src/estream.c (SET_UNLESS_NONZERO): Remove macro. (es_deinitialize): Replace that macro by direct code. Signed-off-by: Werner Koch <[email protected]>
* Convert http links to https where possible in the source.Daniel Kahn Gillmor2016-02-081-1/+1
| | | | | | | | | | | | | | | | -- * use https for bug reporting * in comments and docs, use https to refer to: - www.gnu.org - creativecommons.org - translationproject.org - mail.gnome.org - www.perl.org - www.ctan.org - www.cl.cam.ac.uk - www.ntg.nl - cygwin.com - www.ethnologue.com
* Fix typos found by codespell.Justus Winter2015-11-191-3/+3
| | | | | -- Signed-off-by: Justus Winter <[email protected]>
* estream: Avoid calling write(fd,NULL,n).Werner Koch2015-10-181-20/+32
| | | | | | | | | | | | | | | * src/estream.c (es_func_fd_write): Take care of a flush requests. (es_func_w32_write): Ditto. (es_func_fp_write): Ditto. -- The write handlers may be called with (BUFFER,SIZE) of (NULL,0) to propagate flush events to user supplied functions (es_fopencookie). However we need to take care to also do this with the internal handler. Might be a reason for system faults due to write or fwrite with a NULL buffer; on Linux this seems to be harmless. Signed-off-by: Werner Koch <[email protected]>
* estream: Keep track of EPIPE.Werner Koch2015-09-281-4/+25
| | | | | | | | | * src/estream.c (_gpgrt_stream_internal): Add indicators.hup. (init_stream_obj): Init it. (es_fill, es_flush, es_seek): Set that. (_gpgrt_poll): Set event. Signed-off-by: Werner Koch <[email protected]>
* estream: Add gpgrt_set_nonblock and gpgrt_poll.Werner Koch2015-09-251-4/+345
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * configure.ac (AC_CHECK_HEADERS): Add sys/select.h and sys/time.h. * src/estream.c: Include both header if available. (COOKIE_IOCTL_NONBLOCK): New. (struct estream_cookie_fd): Add field nonblock. (func_fd_create): Set nonblock from MODEFLAGS. (es_func_fd_ioctl): New. (parse_mode): Add modeflag "nonblock". (es_fill): Map EWOULDBLOCK to EAGAIN. Do not set error indicator for EAGAIN. (es_flush, es_seek, es_write_nbf): Map EWOULDBLOCK to EAGAIN. (do_fdopen): Call COOKIE_IOCTL_NONBLOCK. (_gpgrt_set_nonblock): New. (_gpgrt_get_nonblock): New. (_gpgrt_poll): New. * src/gpg-error.h.in (struct _gpgrt_poll_s): New. (gpgrt_poll_t, es_poll_t): New. (es_set_nonblock, es_get_nonblock, es_poll): New. * src/gpg-error.vers, src/gpg-error.def.in: Add gpgrt_set_nonblock, gpgrt_get_nonblock, and gpgrt_poll. * src/visibility.c (gpgrt_set_nonblock, gpgrt_get_nonblock): New. (gpgrt_poll): New. * tests/t-common.h (DIM): New. * tests/t-poll.c: New. * tests/Makefile.am (TESTS): Add t-poll. (t_poll_LDADD): New. -- The poll interface uses select(2) internally because that is more portable than poll(2). Signed-off-by: Werner Koch <[email protected]>
* estream: Replace indicator help functions to ease code reading.Werner Koch2015-09-241-33/+13
| | | | | | | * src/estream.c (es_set_indicators, es_get_indicator): Remove and change callers to set/get indicators directly. Signed-off-by: Werner Koch <[email protected]>
* w32: Make sure the setmode is called.Werner Koch2015-08-251-1/+7
| | | | | | * src/estream.c (HAVE_DOSISH_SYSTEM): Define if needed. Signed-off-by: Werner Koch <[email protected]>
* Remove useless conditions.Werner Koch2015-03-161-6/+3
| | | | | | | | * src/estream.c (fname_set_internal): Remove useless condition. * src/mkheader.c (main): Ditto. -- Detected by Stack 0.3.
* Change gpgrt_pending{,_unlocked} to macros.Werner Koch2014-10-031-3/+3
| | | | | | | | | | | | | | | | | | | | * src/gpg-error.h.in (gpgrt_pending): Change to a macro. (gpgrt_pending_unlocked): Change to a macro. (_gpgrt_pending, _gpgrt_pending_unlocked): New private functions. * src/visibility.c, src/visibility.h: Change accordingly. * src/gpg-error.vers, src/gpg-error.def.in: Ditto. * src/estream.c (_gpgrt_pending_unlocked): Rename to _gpgrt__pending_unlocked. (_gpgrt_pending): Rename to _gpgrt__pending. -- The function are supposed to be used with gprt_getc and thus we need to avoid the function call overhead. We may want to change them to inline functions, though. gpgrt_pending is changed to a macro with the idea that we eventually can export the samestream flags and thus avoid the function call overhead in the samethread case too.
* w32: Make it build again.Werner Koch2014-10-021-1/+1
| | | | * src/estream.c (es_func_w32_read): Fix var name.
* Add GPG_ERR_BOGUS_STRING and an experimental gpgrt_pending.Werner Koch2014-10-021-3/+108
| | | | | | | | | * src/visibility.c (gpgrt_pending, gpgrt_pending_unlocked): New. * src/estream.c (_gpgrt_pending, _gpgrt_pending_unlocked): New. (check_pending): new. (check_pending_fbf, check_pending_nbf): New. (es_func_mem_read, es_func_fd_read, es_func_w32_read) (es_func_fp_read, es_fill): Take care of the special 0 value for SIZE.
* doc updates and type fixes.Werner Koch2014-09-181-1/+1
| | | | --