Accepting request 571299 from home:Andreas_Schwab:Factory
- fix-locking-in-_IO_cleanup.patch: Skip locked files during exit (bsc#1070491, BZ #15142) OBS-URL: https://build.opensuse.org/request/show/571299 OBS-URL: https://build.opensuse.org/package/show/Base:System/glibc?expand=0&rev=490
This commit is contained in:
parent
2a7ebdfb1e
commit
4c21a0b663
@ -1,18 +1,39 @@
|
|||||||
Always do locking when accessing streams
|
Always do locking when accessing streams
|
||||||
|
|
||||||
[BZ #15142]
|
[BZ #15142]
|
||||||
|
* include/libio.h (_IO_ftrylockfile) [_IO_MTSAVE_IO]: Define.
|
||||||
* libio/genops.c (_IO_list_all_stamp): Delete. All uses removed.
|
* libio/genops.c (_IO_list_all_stamp): Delete. All uses removed.
|
||||||
(_IO_flush_all_all_lockp): Delete.
|
* libio/genops.c (_IO_flush_all_lockp): Make static. Rename
|
||||||
(_IO_flush_all): Replace with body of _IO_flush_all_all_lockp.
|
argument to skip_locked, callers changed. Skip files that are
|
||||||
Always do locking.
|
locked if skip_locked.
|
||||||
(_IO_unbuffer_all): Always do locking.
|
(_IO_unbuffer_all): Lock files before access, but skip locked
|
||||||
(_IO_cleanup): Call _IO_flush_all instead of _IO_flush_all_lockp.
|
files.
|
||||||
* libio/libioP.h (_IO_flush_all_all_lockp): Remove declaration.
|
* libio/libioP.h (_IO_flush_all_all_lockp): Don't declare.
|
||||||
|
|
||||||
diff --git a/libio/genops.c b/libio/genops.c
|
Index: glibc-2.26/include/libio.h
|
||||||
index e0ce8cc..9def1d4 100644
|
===================================================================
|
||||||
--- a/libio/genops.c
|
--- glibc-2.26.orig/include/libio.h
|
||||||
+++ b/libio/genops.c
|
+++ glibc-2.26/include/libio.h
|
||||||
|
@@ -33,11 +33,15 @@ libc_hidden_proto (_IO_vfscanf)
|
||||||
|
if (((_fp)->_flags & _IO_USER_LOCK) == 0) _IO_lock_lock (*(_fp)->_lock)
|
||||||
|
# define _IO_funlockfile(_fp) \
|
||||||
|
if (((_fp)->_flags & _IO_USER_LOCK) == 0) _IO_lock_unlock (*(_fp)->_lock)
|
||||||
|
+# define _IO_ftrylockfile(_fp) \
|
||||||
|
+ (((_fp)->_flags & _IO_USER_LOCK) == 0 ? _IO_lock_trylock (*(_fp)->_lock) : 0)
|
||||||
|
# else
|
||||||
|
# define _IO_flockfile(_fp) \
|
||||||
|
if (((_fp)->_flags & _IO_USER_LOCK) == 0) _IO_flockfile (_fp)
|
||||||
|
# define _IO_funlockfile(_fp) \
|
||||||
|
if (((_fp)->_flags & _IO_USER_LOCK) == 0) _IO_funlockfile (_fp)
|
||||||
|
+# define _IO_ftrylockfile(_fp) \
|
||||||
|
+ (((_fp)->_flags & _IO_USER_LOCK) == 0 ? _IO_ftrylockfile (_fp) : 0)
|
||||||
|
# endif
|
||||||
|
#endif /* _IO_MTSAFE_IO */
|
||||||
|
|
||||||
|
Index: glibc-2.26/libio/genops.c
|
||||||
|
===================================================================
|
||||||
|
--- glibc-2.26.orig/libio/genops.c
|
||||||
|
+++ glibc-2.26/libio/genops.c
|
||||||
@@ -38,10 +38,6 @@
|
@@ -38,10 +38,6 @@
|
||||||
static _IO_lock_t list_all_lock = _IO_lock_initializer;
|
static _IO_lock_t list_all_lock = _IO_lock_initializer;
|
||||||
#endif
|
#endif
|
||||||
@ -24,7 +45,7 @@ index e0ce8cc..9def1d4 100644
|
|||||||
static _IO_FILE *run_fp;
|
static _IO_FILE *run_fp;
|
||||||
|
|
||||||
#ifdef _IO_MTSAFE_IO
|
#ifdef _IO_MTSAFE_IO
|
||||||
@@ -70,16 +66,12 @@ _IO_un_link (fp)
|
@@ -69,16 +65,12 @@ _IO_un_link (struct _IO_FILE_plus *fp)
|
||||||
if (_IO_list_all == NULL)
|
if (_IO_list_all == NULL)
|
||||||
;
|
;
|
||||||
else if (fp == _IO_list_all)
|
else if (fp == _IO_list_all)
|
||||||
@ -42,7 +63,7 @@ index e0ce8cc..9def1d4 100644
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fp->file._flags &= ~_IO_LINKED;
|
fp->file._flags &= ~_IO_LINKED;
|
||||||
@@ -108,7 +100,6 @@ _IO_link_in (fp)
|
@@ -106,7 +98,6 @@ _IO_link_in (struct _IO_FILE_plus *fp)
|
||||||
#endif
|
#endif
|
||||||
fp->file._chain = (_IO_FILE *) _IO_list_all;
|
fp->file._chain = (_IO_FILE *) _IO_list_all;
|
||||||
_IO_list_all = fp;
|
_IO_list_all = fp;
|
||||||
@ -50,12 +71,14 @@ index e0ce8cc..9def1d4 100644
|
|||||||
#ifdef _IO_MTSAFE_IO
|
#ifdef _IO_MTSAFE_IO
|
||||||
_IO_funlockfile ((_IO_FILE *) fp);
|
_IO_funlockfile ((_IO_FILE *) fp);
|
||||||
run_fp = NULL;
|
run_fp = NULL;
|
||||||
@@ -818,25 +809,20 @@ _IO_get_column (fp)
|
@@ -789,25 +780,30 @@ _IO_get_column (_IO_FILE *fp)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
int
|
-int
|
||||||
-_IO_flush_all_lockp (int do_lock)
|
-_IO_flush_all_lockp (int do_lock)
|
||||||
+_IO_flush_all (void)
|
+static int
|
||||||
|
+_IO_flush_all_lockp (bool skip_locked)
|
||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
struct _IO_FILE *fp;
|
struct _IO_FILE *fp;
|
||||||
@ -76,12 +99,20 @@ index e0ce8cc..9def1d4 100644
|
|||||||
{
|
{
|
||||||
run_fp = fp;
|
run_fp = fp;
|
||||||
- if (do_lock)
|
- if (do_lock)
|
||||||
- _IO_flockfile (fp);
|
+ if (skip_locked)
|
||||||
+ _IO_flockfile (fp);
|
+ {
|
||||||
|
+ /* Skip files that are currently locked. */
|
||||||
|
+ if (_IO_ftrylockfile (fp))
|
||||||
|
+ {
|
||||||
|
+ run_fp = NULL;
|
||||||
|
+ continue;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ else
|
||||||
|
_IO_flockfile (fp);
|
||||||
|
|
||||||
if (((fp->_mode <= 0 && fp->_IO_write_ptr > fp->_IO_write_base)
|
if (((fp->_mode <= 0 && fp->_IO_write_ptr > fp->_IO_write_base)
|
||||||
#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
|
@@ -820,24 +816,13 @@ _IO_flush_all_lockp (int do_lock)
|
||||||
@@ -848,52 +834,30 @@ _IO_flush_all_lockp (int do_lock)
|
|
||||||
&& _IO_OVERFLOW (fp, EOF) == EOF)
|
&& _IO_OVERFLOW (fp, EOF) == EOF)
|
||||||
result = EOF;
|
result = EOF;
|
||||||
|
|
||||||
@ -109,18 +140,16 @@ index e0ce8cc..9def1d4 100644
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
@@ -848,7 +833,7 @@ int
|
||||||
-
|
_IO_flush_all (void)
|
||||||
-
|
{
|
||||||
-int
|
/* We want locking. */
|
||||||
-_IO_flush_all (void)
|
|
||||||
-{
|
|
||||||
- /* We want locking. */
|
|
||||||
- return _IO_flush_all_lockp (1);
|
- return _IO_flush_all_lockp (1);
|
||||||
-}
|
+ return _IO_flush_all_lockp (false);
|
||||||
|
}
|
||||||
libc_hidden_def (_IO_flush_all)
|
libc_hidden_def (_IO_flush_all)
|
||||||
|
|
||||||
void
|
@@ -856,16 +841,13 @@ void
|
||||||
_IO_flush_all_linebuffered (void)
|
_IO_flush_all_linebuffered (void)
|
||||||
{
|
{
|
||||||
struct _IO_FILE *fp;
|
struct _IO_FILE *fp;
|
||||||
@ -138,7 +167,7 @@ index e0ce8cc..9def1d4 100644
|
|||||||
{
|
{
|
||||||
run_fp = fp;
|
run_fp = fp;
|
||||||
_IO_flockfile (fp);
|
_IO_flockfile (fp);
|
||||||
@@ -903,15 +867,6 @@ _IO_flush_all_linebuffered (void)
|
@@ -875,15 +857,6 @@ _IO_flush_all_linebuffered (void)
|
||||||
|
|
||||||
_IO_funlockfile (fp);
|
_IO_funlockfile (fp);
|
||||||
run_fp = NULL;
|
run_fp = NULL;
|
||||||
@ -154,7 +183,7 @@ index e0ce8cc..9def1d4 100644
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _IO_MTSAFE_IO
|
#ifdef _IO_MTSAFE_IO
|
||||||
@@ -947,6 +902,12 @@ static void
|
@@ -919,24 +892,26 @@ static void
|
||||||
_IO_unbuffer_all (void)
|
_IO_unbuffer_all (void)
|
||||||
{
|
{
|
||||||
struct _IO_FILE *fp;
|
struct _IO_FILE *fp;
|
||||||
@ -166,11 +195,19 @@ index e0ce8cc..9def1d4 100644
|
|||||||
+
|
+
|
||||||
for (fp = (_IO_FILE *) _IO_list_all; fp; fp = fp->_chain)
|
for (fp = (_IO_FILE *) _IO_list_all; fp; fp = fp->_chain)
|
||||||
{
|
{
|
||||||
|
+ run_fp = fp;
|
||||||
|
+ /* Skip files that are currently locked. */
|
||||||
|
+ if (_IO_ftrylockfile (fp))
|
||||||
|
+ {
|
||||||
|
+ run_fp = NULL;
|
||||||
|
+ continue;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
if (! (fp->_flags & _IO_UNBUFFERED)
|
if (! (fp->_flags & _IO_UNBUFFERED)
|
||||||
@@ -956,15 +917,8 @@ _IO_unbuffer_write (void)
|
/* Iff stream is un-orientated, it wasn't used. */
|
||||||
&& fp->_mode != 0)
|
&& fp->_mode != 0)
|
||||||
{
|
{
|
||||||
#ifdef _IO_MTSAFE_IO
|
-#ifdef _IO_MTSAFE_IO
|
||||||
- int cnt;
|
- int cnt;
|
||||||
-#define MAXTRIES 2
|
-#define MAXTRIES 2
|
||||||
- for (cnt = 0; cnt < MAXTRIES; ++cnt)
|
- for (cnt = 0; cnt < MAXTRIES; ++cnt)
|
||||||
@ -180,25 +217,28 @@ index e0ce8cc..9def1d4 100644
|
|||||||
- /* Give the other thread time to finish up its use of the
|
- /* Give the other thread time to finish up its use of the
|
||||||
- stream. */
|
- stream. */
|
||||||
- __sched_yield ();
|
- __sched_yield ();
|
||||||
+ run_fp = fp;
|
-#endif
|
||||||
+ _IO_flockfile (fp);
|
-
|
||||||
#endif
|
|
||||||
|
|
||||||
if (! dealloc_buffers && !(fp->_flags & _IO_USER_BUF))
|
if (! dealloc_buffers && !(fp->_flags & _IO_USER_BUF))
|
||||||
@@ -980,8 +934,8 @@ _IO_unbuffer_write (void)
|
{
|
||||||
_IO_wsetb (fp, NULL, NULL, 0);
|
fp->_flags |= _IO_USER_BUF;
|
||||||
|
@@ -950,17 +925,20 @@ _IO_unbuffer_all (void)
|
||||||
|
|
||||||
#ifdef _IO_MTSAFE_IO
|
if (fp->_mode > 0)
|
||||||
|
_IO_wsetb (fp, NULL, NULL, 0);
|
||||||
|
-
|
||||||
|
-#ifdef _IO_MTSAFE_IO
|
||||||
- if (cnt < MAXTRIES && fp->_lock != NULL)
|
- if (cnt < MAXTRIES && fp->_lock != NULL)
|
||||||
- _IO_lock_unlock (*fp->_lock);
|
- _IO_lock_unlock (*fp->_lock);
|
||||||
+ _IO_funlockfile (fp);
|
-#endif
|
||||||
+ run_fp = NULL;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -989,6 +943,11 @@ _IO_unbuffer_write (void)
|
/* Make sure that never again the wide char functions can be
|
||||||
used. */
|
used. */
|
||||||
fp->_mode = -1;
|
fp->_mode = -1;
|
||||||
|
+
|
||||||
|
+ _IO_funlockfile (fp);
|
||||||
|
+ run_fp = NULL;
|
||||||
}
|
}
|
||||||
+
|
+
|
||||||
+#ifdef _IO_MTSAFE_IO
|
+#ifdef _IO_MTSAFE_IO
|
||||||
@ -208,22 +248,24 @@ index e0ce8cc..9def1d4 100644
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1008,9 +967,7 @@ libc_freeres_fn (buffer_free)
|
@@ -980,9 +958,9 @@ libc_freeres_fn (buffer_free)
|
||||||
int
|
int
|
||||||
_IO_cleanup (void)
|
_IO_cleanup (void)
|
||||||
{
|
{
|
||||||
- /* We do *not* want locking. Some threads might use streams but
|
- /* We do *not* want locking. Some threads might use streams but
|
||||||
- that is their problem, we flush them underneath them. */
|
- that is their problem, we flush them underneath them. */
|
||||||
- int result = _IO_flush_all_lockp (0);
|
- int result = _IO_flush_all_lockp (0);
|
||||||
+ int result = _IO_flush_all ();
|
+ /* We want to skip locked streams. Some threads might use streams but
|
||||||
|
+ that is their problem, we don't flush those. */
|
||||||
|
+ int result = _IO_flush_all_lockp (true);
|
||||||
|
|
||||||
/* We currently don't have a reliable mechanism for making sure that
|
/* We currently don't have a reliable mechanism for making sure that
|
||||||
C++ static destructors are executed in the correct order.
|
C++ static destructors are executed in the correct order.
|
||||||
diff --git a/libio/libioP.h b/libio/libioP.h
|
Index: glibc-2.26/libio/libioP.h
|
||||||
index 8a7b85b..3e3a724 100644
|
===================================================================
|
||||||
--- a/libio/libioP.h
|
--- glibc-2.26.orig/libio/libioP.h
|
||||||
+++ b/libio/libioP.h
|
+++ glibc-2.26/libio/libioP.h
|
||||||
@@ -488,7 +488,6 @@ extern int _IO_new_do_write (_IO_FILE *, const char *, _IO_size_t);
|
@@ -507,7 +507,6 @@ extern int _IO_new_do_write (_IO_FILE *,
|
||||||
extern int _IO_old_do_write (_IO_FILE *, const char *, _IO_size_t);
|
extern int _IO_old_do_write (_IO_FILE *, const char *, _IO_size_t);
|
||||||
extern int _IO_wdo_write (_IO_FILE *, const wchar_t *, _IO_size_t);
|
extern int _IO_wdo_write (_IO_FILE *, const wchar_t *, _IO_size_t);
|
||||||
libc_hidden_proto (_IO_wdo_write)
|
libc_hidden_proto (_IO_wdo_write)
|
||||||
@ -231,6 +273,3 @@ index 8a7b85b..3e3a724 100644
|
|||||||
extern int _IO_flush_all (void);
|
extern int _IO_flush_all (void);
|
||||||
libc_hidden_proto (_IO_flush_all)
|
libc_hidden_proto (_IO_flush_all)
|
||||||
extern int _IO_cleanup (void);
|
extern int _IO_cleanup (void);
|
||||||
--
|
|
||||||
1.9.1
|
|
||||||
|
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
-------------------------------------------------------------------
|
||||||
|
Tue Jan 30 16:42:14 UTC 2018 - schwab@suse.de
|
||||||
|
|
||||||
|
- fix-locking-in-_IO_cleanup.patch: Skip locked files during exit
|
||||||
|
(bsc#1070491, BZ #15142)
|
||||||
|
|
||||||
-------------------------------------------------------------------
|
-------------------------------------------------------------------
|
||||||
Tue Jan 30 15:04:47 UTC 2018 - schwab@suse.de
|
Tue Jan 30 15:04:47 UTC 2018 - schwab@suse.de
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user