<pre style='margin:0'>
Joshua Root (jmroot) pushed a commit to branch master
in repository macports-base.
</pre>
<p><a href="https://github.com/macports/macports-base/commit/4bda9ecf43066c119748da5dd92dfde42d34760e">https://github.com/macports/macports-base/commit/4bda9ecf43066c119748da5dd92dfde42d34760e</a></p>
<pre style="white-space: pre; background: #F8F8F8">The following commit(s) were added to refs/heads/master by this push:
<span style='display:block; white-space:pre;color:#404040;'> new 4bda9ecf4 portindex: mutex wrap reading old PortIndex
</span>4bda9ecf4 is described below
<span style='display:block; white-space:pre;color:#808000;'>commit 4bda9ecf43066c119748da5dd92dfde42d34760e
</span>Author: Joshua Root <jmr@macports.org>
AuthorDate: Mon Oct 31 02:47:46 2022 +1100
<span style='display:block; white-space:pre;color:#404040;'> portindex: mutex wrap reading old PortIndex
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> Reading the same file from multiple threads is safe in itself, but it
</span><span style='display:block; white-space:pre;color:#404040;'> appears that Tcl's seek command simply calls lseek() on the underlying
</span><span style='display:block; white-space:pre;color:#404040;'> fd and does not save the current offset in per-interpreter data. The
</span><span style='display:block; white-space:pre;color:#404040;'> offset could thus be changed by another thread between the seek and
</span><span style='display:block; white-space:pre;color:#404040;'> gets/read calls.
</span>---
src/port/portindex.tcl | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/src/port/portindex.tcl b/src/port/portindex.tcl
</span><span style='display:block; white-space:pre;color:#808080;'>index cd9c41349..3648a96ca 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/src/port/portindex.tcl
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/src/port/portindex.tcl
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -45,12 +45,14 @@ package require Thread
</span>
proc _read_index {idx} {
set offset $::qindex($idx)
<span style='display:block; white-space:pre;background:#e0ffe0;'>+ thread::mutex lock [tsv::get PortIndex mutex]
</span> seek $::oldfd $offset
gets $::oldfd line
<span style='display:block; white-space:pre;background:#ffe0e0;'>- set name [lindex $line 0]
</span> set len [lindex $line 1]
set line [read $::oldfd [expr {$len - 1}]]
<span style='display:block; white-space:pre;background:#e0ffe0;'>+ thread::mutex unlock [tsv::get PortIndex mutex]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set name [lindex $line 0]
</span>
return [list $name $len $line]
}
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -217,6 +219,7 @@ proc init_threads {} {
</span> set ::maxjobs [macports:get_parallel_jobs no]
set ::poolid [tpool::create -minworkers $::maxjobs -maxworkers $::maxjobs -initcmd $::worker_init_script]
array set ::pending_jobs {}
<span style='display:block; white-space:pre;background:#e0ffe0;'>+ tsv::set PortIndex mutex [thread::mutex create]
</span> }
proc handle_completed_jobs {} {
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -281,6 +284,7 @@ proc process_remaining {} {
</span> handle_completed_jobs
}
tpool::release $::poolid
<span style='display:block; white-space:pre;background:#e0ffe0;'>+ thread::mutex destroy [tsv::get PortIndex mutex]
</span> }
if {$argc > 8} {
</pre><pre style='margin:0'>
</pre>