aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2020-06-26 13:24:43 +0000
committerWerner Koch <[email protected]>2020-06-26 13:25:27 +0000
commit3413489d25577e3fe7f529b8e610a45d2bd1857c (patch)
tree466a62f1a7cb34d8811a01f868157f30e370985e /src
parentbuild: Fix the gpg-error-config test for cross build. (diff)
downloadlibgpg-error-3413489d25577e3fe7f529b8e610a45d2bd1857c.tar.gz
libgpg-error-3413489d25577e3fe7f529b8e610a45d2bd1857c.zip
estream: Add gpgrt_fcancel
* src/estream.c (do_close): Add arg 'cancel_mode' and chnage all callers. (_gpgrt_fcancel): New. * src/gpg-error.def.in, src/gpg-error.vers: Add function. * src/visibility.c (gpgrt_fcancel): New. * src/gpg-error.h.in (gpgrt_fcancel): New. -- Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/estream.c41
-rw-r--r--src/gpg-error.def.in1
-rw-r--r--src/gpg-error.h.in1
-rw-r--r--src/gpg-error.vers1
-rw-r--r--src/gpgrt-int.h1
-rw-r--r--src/visibility.c6
-rw-r--r--src/visibility.h2
7 files changed, 44 insertions, 9 deletions
diff --git a/src/estream.c b/src/estream.c
index 6b531fb..06ebdaa 100644
--- a/src/estream.c
+++ b/src/estream.c
@@ -2167,10 +2167,11 @@ create_stream (estream_t *r_stream, void *cookie, es_syshd_t *syshd,
/*
- * Deinitialize a stream object and destroy it.
+ * Deinitialize a stream object and destroy it. With CANCEL_MODE set
+ * try to cancel as much as possible (see _gpgrt_fcancel).
*/
static int
-do_close (estream_t stream, int with_locked_list)
+do_close (estream_t stream, int cancel_mode, int with_locked_list)
{
int err;
@@ -2179,6 +2180,11 @@ do_close (estream_t stream, int with_locked_list)
if (stream)
{
do_list_remove (stream, with_locked_list);
+ if (cancel_mode)
+ {
+ stream->flags.writing = 0;
+ es_empty (stream);
+ }
while (stream->intern->onclose)
{
notify_list_t tmp = stream->intern->onclose->next;
@@ -2943,7 +2949,7 @@ doreadline (estream_t _GPGRT__RESTRICT stream, size_t max_length,
out:
if (line_stream)
- do_close (line_stream, 0);
+ do_close (line_stream, 0, 0);
else if (line_stream_cookie)
func_mem_destroy (line_stream_cookie);
@@ -3617,7 +3623,7 @@ _gpgrt_freopen (const char *_GPGRT__RESTRICT path,
if (create_called)
func_fd_destroy (cookie);
- do_close (stream, 0);
+ do_close (stream, 0, 0);
stream = NULL;
}
else
@@ -3632,7 +3638,7 @@ _gpgrt_freopen (const char *_GPGRT__RESTRICT path,
/* FIXME? We don't support re-opening at the moment. */
_set_errno (EINVAL);
deinit_stream_obj (stream);
- do_close (stream, 0);
+ do_close (stream, 0, 0);
stream = NULL;
}
@@ -3645,7 +3651,22 @@ _gpgrt_fclose (estream_t stream)
{
int err;
- err = do_close (stream, 0);
+ err = do_close (stream, 0, 0);
+
+ return err;
+}
+
+
+/* gpgrt_fcancel does the same as gpgrt_fclose but tries to avoid
+ * flushing out any data still held in internal buffers. It may or
+ * may not remove a new file created for that stream by the open
+ * function. */
+int
+_gpgrt_fcancel (estream_t stream)
+{
+ int err;
+
+ err = do_close (stream, 1, 0);
return err;
}
@@ -3698,7 +3719,7 @@ _gpgrt_fclose_snatch (estream_t stream, void **r_buffer, size_t *r_buflen)
*r_buflen = buflen;
}
- err = do_close (stream, 0);
+ err = do_close (stream, 0, 0);
leave:
if (err && r_buffer)
@@ -3726,8 +3747,10 @@ _gpgrt_fclose_snatch (estream_t stream, void **r_buffer, size_t *r_buflen)
FIXME: Unregister is not thread safe.
- The notification will be called right before the stream is closed.
- It may not call any estream function for STREAM, neither direct nor
+ The notification will be called right before the stream is
+ closed. If gpgrt_fcancel is used, the cancellation of internal
+ buffers is done before the notifications. The notification handler
+ may not call any estream function for STREAM, neither direct nor
indirectly. */
int
_gpgrt_onclose (estream_t stream, int mode,
diff --git a/src/gpg-error.def.in b/src/gpg-error.def.in
index bf8773b..de408db 100644
--- a/src/gpg-error.def.in
+++ b/src/gpg-error.def.in
@@ -236,5 +236,6 @@ EXPORTS
gpgrt_absfnameconcat @179
gpgrt_reallocarray @180
+ gpgrt_fclose @181
;; end of file with public symbols for Windows.
diff --git a/src/gpg-error.h.in b/src/gpg-error.h.in
index e915797..925ef51 100644
--- a/src/gpg-error.h.in
+++ b/src/gpg-error.h.in
@@ -689,6 +689,7 @@ gpgrt_stream_t gpgrt_fopencookie (void *_GPGRT__RESTRICT cookie,
const char *_GPGRT__RESTRICT mode,
gpgrt_cookie_io_functions_t functions);
int gpgrt_fclose (gpgrt_stream_t stream);
+int gpgrt_fcancel (gpgrt_stream_t stream);
int gpgrt_fclose_snatch (gpgrt_stream_t stream,
void **r_buffer, size_t *r_buflen);
int gpgrt_onclose (gpgrt_stream_t stream, int mode,
diff --git a/src/gpg-error.vers b/src/gpg-error.vers
index ab3bbb0..e67a16f 100644
--- a/src/gpg-error.vers
+++ b/src/gpg-error.vers
@@ -55,6 +55,7 @@ GPG_ERROR_1.0 {
gpgrt_freopen;
gpgrt_fopencookie;
gpgrt_fclose;
+ gpgrt_fcancel;
gpgrt_fclose_snatch;
gpgrt_onclose;
gpgrt_fileno;
diff --git a/src/gpgrt-int.h b/src/gpgrt-int.h
index 629f527..913b9ba 100644
--- a/src/gpgrt-int.h
+++ b/src/gpgrt-int.h
@@ -339,6 +339,7 @@ gpgrt_stream_t _gpgrt_fopencookie (void *_GPGRT__RESTRICT cookie,
const char *_GPGRT__RESTRICT mode,
gpgrt_cookie_io_functions_t functions);
int _gpgrt_fclose (gpgrt_stream_t stream);
+int _gpgrt_fcancel (gpgrt_stream_t stream);
int _gpgrt_fclose_snatch (gpgrt_stream_t stream,
void **r_buffer, size_t *r_buflen);
int _gpgrt_onclose (gpgrt_stream_t stream, int mode,
diff --git a/src/visibility.c b/src/visibility.c
index 2e6aed7..85caef3 100644
--- a/src/visibility.c
+++ b/src/visibility.c
@@ -251,6 +251,12 @@ gpgrt_fclose (estream_t stream)
}
int
+gpgrt_fcancel (estream_t stream)
+{
+ return _gpgrt_fcancel (stream);
+}
+
+int
gpgrt_fclose_snatch (estream_t stream, void **r_buffer, size_t *r_buflen)
{
return _gpgrt_fclose_snatch (stream, r_buffer, r_buflen);
diff --git a/src/visibility.h b/src/visibility.h
index f7d16be..3b12acf 100644
--- a/src/visibility.h
+++ b/src/visibility.h
@@ -79,6 +79,7 @@ MARK_VISIBLE (gpgrt_fpopen_nc)
MARK_VISIBLE (gpgrt_freopen)
MARK_VISIBLE (gpgrt_fopencookie)
MARK_VISIBLE (gpgrt_fclose)
+MARK_VISIBLE (gpgrt_fcancel)
MARK_VISIBLE (gpgrt_fclose_snatch)
MARK_VISIBLE (gpgrt_onclose)
MARK_VISIBLE (gpgrt_fileno)
@@ -265,6 +266,7 @@ MARK_VISIBLE (gpgrt_absfnameconcat);
#define gpgrt_freopen _gpgrt_USE_UNDERSCORED_FUNCTION
#define gpgrt_fopencookie _gpgrt_USE_UNDERSCORED_FUNCTION
#define gpgrt_fclose _gpgrt_USE_UNDERSCORED_FUNCTION
+#define gpgrt_fcancel _gpgrt_USE_UNDERSCORED_FUNCTION
#define gpgrt_fclose_snatch _gpgrt_USE_UNDERSCORED_FUNCTION
#define gpgrt_onclose _gpgrt_USE_UNDERSCORED_FUNCTION
#define gpgrt_fileno _gpgrt_USE_UNDERSCORED_FUNCTION