From 0428aab877c66809cc78736411351e21c1eaba2d Mon Sep 17 00:00:00 2001 From: Julian Noble Date: Wed, 19 Nov 2025 02:41:31 +1100 Subject: [PATCH] shellthread::manager::get_tag_config - check if tag/configuration valid for new shellfilter::log::open calls --- src/modules/shellfilter-999999.0a1.0.tm | 14 ++++++++----- src/modules/shellthread-999999.0a1.0.tm | 28 ++++++++++++++++++------- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/modules/shellfilter-999999.0a1.0.tm b/src/modules/shellfilter-999999.0a1.0.tm index c8fdfb23..54a6119f 100644 --- a/src/modules/shellfilter-999999.0a1.0.tm +++ b/src/modules/shellfilter-999999.0a1.0.tm @@ -18,16 +18,19 @@ tcl::namespace::eval shellfilter::log { proc disable {} { variable is_enabled set is_enabled 0 - proc ::shellfilter::log::open {tag settingsdict} {} - proc ::shellfilter::log::write {tag msg} {} - proc ::shellfilter::log::write_sync {tag msg} {} - proc ::shellfilter::log::close {tag} {} + proc ::shellfilter::log::open {tag settingsdict} {} + proc ::shellfilter::log::write {tag msg} {} + proc ::shellfilter::log::write_sync {tag msg} {} + proc ::shellfilter::log::close {tag} {} } proc enable {} { variable is_enabled set is_enabled 1 #'tag' is an identifier for the log source. + #(well.. really it's a common *target* of file and/or syslog host:port which can be written to from any thread that uses the tag) + #the terminology here is kinda ratshit. + # each tag will use it's own thread to write to the configured log target proc ::shellfilter::log::open {tag {settingsdict {}}} { upvar ::shellfilter::sources sourcelist @@ -2824,7 +2827,8 @@ namespace eval shellfilter { #chan configure $inchan -buffering none -blocking 1 ;#test - chan configure $inchan -buffering $inbuffering -blocking 0 ;#we are setting up a readable handler for this - so non-blocking ok + #chan configure $inchan -buffering $inbuffering -blocking 0 ;#we are setting up a readable handler for this - so non-blocking ok + chan configure $inchan -buffering $inbuffering chan configure $errchan -buffering $errbuffering diff --git a/src/modules/shellthread-999999.0a1.0.tm b/src/modules/shellthread-999999.0a1.0.tm index c32783ed..7e82e45f 100644 --- a/src/modules/shellthread-999999.0a1.0.tm +++ b/src/modules/shellthread-999999.0a1.0.tm @@ -483,13 +483,19 @@ namespace eval shellthread::manager { } if {[dict exists $workers $sourcetag]} { - set winfo [dict get $workers $sourcetag] - if {[dict get $winfo tid] ne "noop" && [thread::exists [dict get $winfo tid]]} { - #add our client-info to existing worker thread - dict lappend winfo list_client_tids $tidclient - dict set workers $sourcetag $winfo ;#writeback - return [dict get $winfo tid] - } + set winfo [dict get $workers $sourcetag] + if {[dict get $winfo tid] ne "noop" && [thread::exists [dict get $winfo tid]]} { + # add our client-info to existing worker thread + set existing_settings [get_tag_config $sourcetag] + if {$settingsdict eq $existing_settings} { + #same settings - share the worker + dict lappend winfo list_client_tids $tidclient + dict set workers $sourcetag $winfo ;#writeback + return [dict get $winfo tid] + } else { + error "shellthread::manager::new_worker error: tag $sourcetag already has a worker with a different configuration\nexisting: $existing_settings\nattempted: $settingsdict" + } + } } #noop fake worker for empty syslog and empty file @@ -703,6 +709,14 @@ namespace eval shellthread::manager { } return $taginfo_list } + proc get_tag_config {tag} { + variable workers + if {![dict exists $workers $tag]} { + error "shellthread::manager::get_tag_config error no existing tag $tag" + } + set workertid [dict get $workers $tag tid] + set conf [thread::send $workertid {set ::shellthread::worker::settings}] + } #finalisation proc shutdown_free_threads {{timeout 2500}} {