▲ 10 r/Tcl

[Expect] Is the "catch" in the "catch wait result" idiom really necessary? It seems very broken.

I see this a lot in example code, where people wait on a process to exit and then collect it's return code using "catch wait result" and then usually do something like "exit [lindex $result 3]" to return the process' exit code. This doesn't seem right at all.

Firstoff, it seems like wait already does a pretty good job of handling weird process termination. From [1]:

> wait normally returns a list of four integers. The first integer is the pid of the process that was waited upon. The second integer is the corresponding spawn id. The third integer is -1 if an operating system error occurred, or 0 otherwise. If the third integer was 0, the fourth integer is the status returned by the spawned process. If the third integer was -1, the fourth integer is the value of errno set by the operating system. The global variable errorCode is also set.

so it seems like "set result [wait]" would be sufficient. Or even "exit [lindex [wait] 3]" (see postscript for caveats).

Second, nobody actually seems to be checking the returncode of catch, they're just silently catching any errors and continuing. Going by [2] this means that if wait did fail, then result will not contain the 4-element list people are anticipating:

> When the return code from the script is 1 (TCL_ERROR), the value stored in varName is an error message. When the return code from the script is 0 (TCL_OK), the value stored in resultVarName is the value returned from script.

Meaning in the case that catch does do something and somehow catches an error from wait, the variable $result will contain some random string of text which may or may not be an iterable list. (could be something like "killed" or "no space left on device"?) It's very possible that "exit [lindex $result 3]" would result in trying to return the 4th word of a textual error message as a returncode, which probably isn't likely to go very well.

If anyone knows of a case where wait could fail with TCL_ERROR etc, please do chime in.

[1] https://www.tcl-lang.org/man/expect5.31/expect.1.html

[2] https://www.tcl-lang.org/man/tcl8.4/TclCmd/catch.htm

P.S. technically "exit [lindex [wait] 3]" still only sort-of correct, since if "lindex [wait] 2" is -1 you're returning the OS errno not the process returncode. Most (but not all) of the time they agree that 0 is success (so if you're using this as a wrapper you'll probably still detect the presence of an error correctly) but actually trying to interpret the error condition outside of expect is likely to go haywire when the OS-generated errno is misinterpreted as a return code from the process itself.

An actual situation where a process exits with non-zero as success (eg. 1) is a very tricky one indeed, because then any failure in TCL could be misinterpreted. This gets tricky because your TCL script either has to be infallible(?) or surrounded in catch, with logic to return some made-up returncode. You'd think this to be a rare occurrence, but I've seen software in the wild that does things like return 0/1/2/3 to indicate one of four successful outcomes, or returns the number of items processed.

reddit.com
u/ThatDeveloper12 — 1 month ago

[BUG] SAPS announcements meant to trigger in specific areas/events can occasionally trigger anywhere in the game

I've noticed watching some twitch streams that SAPS announcements that are meant to trigger at specific points in the campaign or in response to specific events can sometimes trigger randomly in place of generic "ambiance" announcements. For example, the announcement warning about auditory hallucinations rising from below in delta labs can sometimes trigger in the middle of abyss.

reddit.com
u/ThatDeveloper12 — 2 months ago

Alpine releases and upgrading - old packages?

Hi, I'm relatively new to alpine and have a couple of questions:

(1) With new releases every 6 months and each release's community repo supported for that amount of time, does that mean packages in the community repo will stop seeing updates then? (making it a good idea to continually move to the latest release if you're using community packages)

(2) After upgrading to a new release, eg. via [1], what's the best way to find old packages that are a holdover from the previous release? Is there a way to list packages based on what release's main/community repos they came from?

[1] https://wiki.alpinelinux.org/wiki/Upgrading_Alpine_Linux_to_a_new_release_branch

reddit.com
u/ThatDeveloper12 — 2 months ago
▲ 20 r/ipv6+1 crossposts

NAT46/DNS46 implementation?

Have many legacy IPv4-only devices, and an IPv6-only upstream. Looking for an implementation of, or way to implement, NAT46+DNS46. Right now it seems Fortinet are shipping something packaged (the only ones in fact), but I'm looking for something I can set up on generic linux/FreeBSD.

CLAT/464xlat is explicitly out of scope because it requires cooperation on the PLAT side. Actual NAT46 translation is vastly preferable and would enable connections over IPv6 directly to IPv6-only hosts. To the rest of the world the network appears IPv6-capable, or at worst like a NAT66, and everyone can get on with their lives.

For those unfamiliar, NAT46/DNS46 is where DNS queries are received from IPv4 clients, the public IPv6 address is determined, and a temporary mapping between public IPv6 address and internal-use-only IPv4 address is created, allowing IPv4 clients inside to communicate with IPv6 hosts outside. (For those fretting about conflicts with existing public IPv4 addresses, the ones used in the mappings don't have to be globally routable. For those fretting about IPv6 addresses being larger than IPv4 address, this is translation not embedding, and few networks need enough simultaneous connections for this to be an issue.)

A userspace daemon or plugin for Tayga etc. etc. would be fine, it doesn't need to be implemented in-kernel.

reddit.com
u/ThatDeveloper12 — 3 months ago