diff --git a/fix-locking-in-_IO_cleanup.patch b/fix-locking-in-_IO_cleanup.patch index b3f591b..72eabae 100644 --- a/fix-locking-in-_IO_cleanup.patch +++ b/fix-locking-in-_IO_cleanup.patch @@ -1,18 +1,39 @@ Always do locking when accessing streams [BZ #15142] - * libio/genops.c (_IO_list_all_stamp): Delete. All uses removed. - (_IO_flush_all_all_lockp): Delete. - (_IO_flush_all): Replace with body of _IO_flush_all_all_lockp. - Always do locking. - (_IO_unbuffer_all): Always do locking. - (_IO_cleanup): Call _IO_flush_all instead of _IO_flush_all_lockp. - * libio/libioP.h (_IO_flush_all_all_lockp): Remove declaration. + * include/libio.h (_IO_ftrylockfile) [_IO_MTSAVE_IO]: Define. + * libio/genops.c (_IO_list_all_stamp): Delete. All uses removed. + * libio/genops.c (_IO_flush_all_lockp): Make static. Rename + argument to skip_locked, callers changed. Skip files that are + locked if skip_locked. + (_IO_unbuffer_all): Lock files before access, but skip locked + files. + * libio/libioP.h (_IO_flush_all_all_lockp): Don't declare. -diff --git a/libio/genops.c b/libio/genops.c -index e0ce8cc..9def1d4 100644 ---- a/libio/genops.c -+++ b/libio/genops.c +Index: glibc-2.26/include/libio.h +=================================================================== +--- glibc-2.26.orig/include/libio.h ++++ 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 @@ static _IO_lock_t list_all_lock = _IO_lock_initializer; #endif @@ -24,7 +45,7 @@ index e0ce8cc..9def1d4 100644 static _IO_FILE *run_fp; #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) ; else if (fp == _IO_list_all) @@ -42,7 +63,7 @@ index e0ce8cc..9def1d4 100644 break; } 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 fp->file._chain = (_IO_FILE *) _IO_list_all; _IO_list_all = fp; @@ -50,12 +71,14 @@ index e0ce8cc..9def1d4 100644 #ifdef _IO_MTSAFE_IO _IO_funlockfile ((_IO_FILE *) fp); 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 (void) ++static int ++_IO_flush_all_lockp (bool skip_locked) { int result = 0; struct _IO_FILE *fp; @@ -76,12 +99,20 @@ index e0ce8cc..9def1d4 100644 { run_fp = fp; - if (do_lock) -- _IO_flockfile (fp); -+ _IO_flockfile (fp); ++ if (skip_locked) ++ { ++ /* 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 defined _LIBC || defined _GLIBCPP_USE_WCHAR_T -@@ -848,52 +834,30 @@ _IO_flush_all_lockp (int do_lock) +@@ -820,24 +816,13 @@ _IO_flush_all_lockp (int do_lock) && _IO_OVERFLOW (fp, EOF) == EOF) result = EOF; @@ -109,18 +140,16 @@ index e0ce8cc..9def1d4 100644 #endif return result; - } -- -- --int --_IO_flush_all (void) --{ -- /* We want locking. */ +@@ -848,7 +833,7 @@ int + _IO_flush_all (void) + { + /* We want locking. */ - return _IO_flush_all_lockp (1); --} ++ return _IO_flush_all_lockp (false); + } libc_hidden_def (_IO_flush_all) - void +@@ -856,16 +841,13 @@ void _IO_flush_all_linebuffered (void) { struct _IO_FILE *fp; @@ -138,7 +167,7 @@ index e0ce8cc..9def1d4 100644 { run_fp = 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); run_fp = NULL; @@ -154,7 +183,7 @@ index e0ce8cc..9def1d4 100644 } #ifdef _IO_MTSAFE_IO -@@ -947,6 +902,12 @@ static void +@@ -919,24 +892,26 @@ static void _IO_unbuffer_all (void) { struct _IO_FILE *fp; @@ -166,11 +195,19 @@ index e0ce8cc..9def1d4 100644 + 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) -@@ -956,15 +917,8 @@ _IO_unbuffer_write (void) + /* Iff stream is un-orientated, it wasn't used. */ && fp->_mode != 0) { - #ifdef _IO_MTSAFE_IO +-#ifdef _IO_MTSAFE_IO - int cnt; -#define MAXTRIES 2 - 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 - stream. */ - __sched_yield (); -+ run_fp = fp; -+ _IO_flockfile (fp); - #endif - +-#endif +- 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) - _IO_lock_unlock (*fp->_lock); -+ _IO_funlockfile (fp); -+ run_fp = NULL; - #endif +-#endif } -@@ -989,6 +943,11 @@ _IO_unbuffer_write (void) + /* Make sure that never again the wide char functions can be used. */ fp->_mode = -1; ++ ++ _IO_funlockfile (fp); ++ run_fp = NULL; } + +#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 _IO_cleanup (void) { - /* We do *not* want locking. Some threads might use streams but - that is their problem, we flush them underneath them. */ - 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 C++ static destructors are executed in the correct order. -diff --git a/libio/libioP.h b/libio/libioP.h -index 8a7b85b..3e3a724 100644 ---- a/libio/libioP.h -+++ b/libio/libioP.h -@@ -488,7 +488,6 @@ extern int _IO_new_do_write (_IO_FILE *, const char *, _IO_size_t); +Index: glibc-2.26/libio/libioP.h +=================================================================== +--- glibc-2.26.orig/libio/libioP.h ++++ glibc-2.26/libio/libioP.h +@@ -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_wdo_write (_IO_FILE *, const wchar_t *, _IO_size_t); libc_hidden_proto (_IO_wdo_write) @@ -231,6 +273,3 @@ index 8a7b85b..3e3a724 100644 extern int _IO_flush_all (void); libc_hidden_proto (_IO_flush_all) extern int _IO_cleanup (void); --- -1.9.1 - diff --git a/glibc.changes b/glibc.changes index 0c4317a..f050d53 100644 --- a/glibc.changes +++ b/glibc.changes @@ -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