<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.8" -->
<?xml-stylesheet href="https://baszerr.eu/lib/exe/css.php?s=feed" type="text/css"?>
<rss version="2.0">
    <channel xmlns:g="http://base.google.com/ns/1.0">
        <title>BaSzErr - blog:2022:05:29</title>
        <description></description>
        <link>https://baszerr.eu/</link>
        <lastBuildDate>Sun, 03 May 2026 06:46:14 +0000</lastBuildDate>
        <generator>FeedCreator 1.8</generator>
        <image>
            <url>https://baszerr.eu/lib/exe/fetch.php?media=wiki:dokuwiki.svg</url>
            <title>BaSzErr</title>
            <link>https://baszerr.eu/</link>
        </image>
        <item>
            <title>2022-05-29_-_bash_and_raii</title>
            <link>https://baszerr.eu/doku.php?id=blog:2022:05:29:2022-05-29_-_bash_and_raii</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;bash_and_raii&quot;&gt;2022-05-29 - bash and RAII&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
during both &lt;code&gt;$DAY_JOB&lt;/code&gt; and &lt;code&gt;$PET_PROJECT&lt;/code&gt; i often use &lt;a href=&quot;https://en.wikipedia.org/wiki/Bash (Unix shell)&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/Bash (Unix shell)&quot;&gt;bash&lt;/a&gt;. like A LOT. ;) sometimes to automate some repetitive actions, sometimes to do a quick 1-off task on loads of data… anyway – there&amp;#039;s a lot of &lt;code&gt;bash&lt;/code&gt; involved, typically. to make scripts react properly on errors, i typically start off with:
&lt;/p&gt;
&lt;pre class=&quot;code bash&quot;&gt;&lt;span class=&quot;co0&quot;&gt;#!/bin/bash&lt;/span&gt;
&lt;span class=&quot;kw1&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;re5&quot;&gt;-eu&lt;/span&gt; &lt;span class=&quot;re5&quot;&gt;-o&lt;/span&gt; pipefail
&lt;span class=&quot;co0&quot;&gt;# actual code goes here&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
it&amp;#039;s almost like a c&amp;amp;p sequence in my head. it&amp;#039;s great as it allows you to catch bugs and errors early and stop the action, before any more damage gets done. the common problem there however is to cleanup stuff afterwards.
&lt;/p&gt;

&lt;p&gt;
let&amp;#039;s imagine we have some complex logic, that needs 3 temp files to operate, created at different stages of the script. sth along these lines:
&lt;/p&gt;
&lt;pre class=&quot;code bash&quot;&gt;&lt;span class=&quot;co0&quot;&gt;#!/bin/bash&lt;/span&gt;
&lt;span class=&quot;kw1&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;re5&quot;&gt;-eu&lt;/span&gt; &lt;span class=&quot;re5&quot;&gt;-o&lt;/span&gt; pipefail
&lt;span class=&quot;re2&quot;&gt;tmp1&lt;/span&gt;=$&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;mktemp&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;co0&quot;&gt;# do sth with tmp1&lt;/span&gt;
&lt;span class=&quot;re2&quot;&gt;tmp2&lt;/span&gt;=$&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;mktemp&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;co0&quot;&gt;# do sth with tmp1 and tmp2&lt;/span&gt;
&lt;span class=&quot;re2&quot;&gt;tmp3&lt;/span&gt;=$&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;mktemp&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;co0&quot;&gt;# do sth with tmp1, tmp2 and tmp3&lt;/span&gt;
&lt;span class=&quot;kw2&quot;&gt;rm&lt;/span&gt; &lt;span class=&quot;re5&quot;&gt;-f&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;&lt;span class=&quot;es2&quot;&gt;$tmp1&lt;/span&gt;&amp;quot;&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;&lt;span class=&quot;es2&quot;&gt;$tmp2&lt;/span&gt;&amp;quot;&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;&lt;span class=&quot;es2&quot;&gt;$tmp3&lt;/span&gt;&amp;quot;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
all good, when script goes well. the problem begins, when sth fails in the middle (eg. after creating 2nd temp file). then we end up with &lt;em&gt;not&lt;/em&gt; calling &lt;code&gt;rm -f …&lt;/code&gt; part, and thus leave out garbage.
&lt;/p&gt;

&lt;p&gt;
in &lt;code&gt;bash&lt;/code&gt; there is a &lt;a href=&quot;https://ss64.com/bash/trap.html&quot; class=&quot;urlextern&quot; title=&quot;https://ss64.com/bash/trap.html&quot; rel=&quot;ugc nofollow&quot;&gt;trap&lt;/a&gt; statement, that allows to &lt;a href=&quot;https://www.linuxjournal.com/content/bash-trap-command&quot; class=&quot;urlextern&quot; title=&quot;https://www.linuxjournal.com/content/bash-trap-command&quot; rel=&quot;ugc nofollow&quot;&gt;call some actions on given signals&lt;/a&gt;… or &lt;code&gt;EXIT&lt;/code&gt; event. so you can do this:
&lt;/p&gt;
&lt;pre class=&quot;code bash&quot;&gt;&lt;span class=&quot;co0&quot;&gt;#!/bin/bash&lt;/span&gt;
&lt;span class=&quot;kw1&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;re5&quot;&gt;-eu&lt;/span&gt; &lt;span class=&quot;re5&quot;&gt;-o&lt;/span&gt; pipefail
&lt;span class=&quot;re2&quot;&gt;tmp1&lt;/span&gt;=$&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;mktemp&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;re2&quot;&gt;tmp2&lt;/span&gt;=$&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;mktemp&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;re2&quot;&gt;tmp3&lt;/span&gt;=$&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;mktemp&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;kw3&quot;&gt;trap&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;rm -f &#039;&lt;span class=&quot;es2&quot;&gt;$tmp1&lt;/span&gt;&#039; &#039;&lt;span class=&quot;es2&quot;&gt;$tmp2&lt;/span&gt;&#039; &#039;&lt;span class=&quot;es2&quot;&gt;$tmp3&lt;/span&gt;&#039;&amp;quot;&lt;/span&gt; EXIT
&lt;span class=&quot;co0&quot;&gt;# do sth with tmp1&lt;/span&gt;
&lt;span class=&quot;co0&quot;&gt;# do sth with tmp1 and tmp2&lt;/span&gt;
&lt;span class=&quot;co0&quot;&gt;# do sth with tmp1, tmp2 and tmp3&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
now all the temp files will auto-cleanup nicely&lt;sup&gt;&lt;a href=&quot;#fn__1&quot; id=&quot;fnt__1&quot; class=&quot;fn_top&quot;&gt;1)&lt;/a&gt;&lt;/sup&gt;. there is just one problem with that – you can have only 1 &lt;code&gt;trap&lt;/code&gt; per signal/event in the script. declaring new one will overwrite the previous. it is therefor all good when you can say upfront what elements do you need to “release”.
&lt;/p&gt;

&lt;p&gt;
but what if you don&amp;#039;t? what if these are runtime-defined? or names are known only any at a certain point in time? there is an excellent paradigm / pattern in &lt;a href=&quot;https://en.wikipedia.org/wiki/C++&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/C++&quot;&gt;C++&lt;/a&gt; called &lt;a href=&quot;https://en.wikipedia.org/wiki/RAII&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/RAII&quot;&gt;RAII&lt;/a&gt;. while there are no “object destructors” in &lt;code&gt;bash&lt;/code&gt;, there are “scopes”. in particular you can spawn new shell, in a given “scope”, nesting things, effectively giving you as many &lt;code&gt;trap&lt;/code&gt;s as you want. example:
&lt;/p&gt;
&lt;pre class=&quot;code bash&quot;&gt;&lt;span class=&quot;co0&quot;&gt;#!/bin/bash&lt;/span&gt;
&lt;span class=&quot;kw1&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;re5&quot;&gt;-eu&lt;/span&gt; &lt;span class=&quot;re5&quot;&gt;-o&lt;/span&gt; pipefail
&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;
  &lt;span class=&quot;re2&quot;&gt;tmp1&lt;/span&gt;=$&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;mktemp&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span class=&quot;kw3&quot;&gt;trap&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;rm &#039;&lt;span class=&quot;es2&quot;&gt;$tmp1&lt;/span&gt;&#039;&amp;quot;&lt;/span&gt; EXIT
  &lt;span class=&quot;co0&quot;&gt;# do sth with tmp1&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;
    &lt;span class=&quot;re2&quot;&gt;tmp2&lt;/span&gt;=$&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;mktemp&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span class=&quot;kw3&quot;&gt;trap&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;rm &#039;&lt;span class=&quot;es2&quot;&gt;$tmp2&lt;/span&gt;&#039;&amp;quot;&lt;/span&gt; EXIT
    &lt;span class=&quot;co0&quot;&gt;# do sth with tmp1 and tmp2&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;
      &lt;span class=&quot;re2&quot;&gt;tmp3&lt;/span&gt;=$&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;mktemp&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
      &lt;span class=&quot;kw3&quot;&gt;trap&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;rm &#039;&lt;span class=&quot;es2&quot;&gt;$tmp3&lt;/span&gt;&#039;&amp;quot;&lt;/span&gt; EXIT
      &lt;span class=&quot;co0&quot;&gt;# do sth with tmp1, tmp2 and tmp3&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
…and voila! now you can have as many “cleanup” procedures as you want, each being called once resource is “descoped”. as a free bonus, it also solves the issue of failure of initialization Nth element, before trap gets registered, like in our 2nd example.
&lt;/p&gt;

&lt;p&gt;
i ten to call this pattern &lt;code&gt;bash&lt;/code&gt;-RAII – it tend to work exceptionally well in practice.
&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;footnotes&quot;&gt;
&lt;div class=&quot;fn&quot;&gt;&lt;sup&gt;&lt;a href=&quot;#fnt__1&quot; id=&quot;fn__1&quot; class=&quot;fn_bot&quot;&gt;1)&lt;/a&gt;&lt;/sup&gt; 
&lt;div class=&quot;content&quot;&gt;ok – it won&amp;#039;t , if creating one of the temp files would fail itself. but let&amp;#039;s leave that 1 out for a sec.&lt;/div&gt;&lt;/div&gt;
&lt;/div&gt;
</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Sun, 29 May 2022 18:36:03 +0000</pubDate>
        </item>
        <item>
            <title>2022-05-29_-_more_on_wifi_roaming</title>
            <link>https://baszerr.eu/doku.php?id=blog:2022:05:29:2022-05-29_-_more_on_wifi_roaming</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;more_on_wifi_roaming&quot;&gt;2022-05-29 - more on WiFi roaming&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
almost exactly one year ago i wrote about &lt;a href=&quot;https://baszerr.eu/doku.php?id=blog:2021:06:04:2021-06-04_-_wifi_roaming&quot; class=&quot;wikilink1&quot; title=&quot;blog:2021:06:04:2021-06-04_-_wifi_roaming&quot; data-wiki-id=&quot;blog:2021:06:04:2021-06-04_-_wifi_roaming&quot;&gt;WiFi romaing&lt;/a&gt;. it workes nice ever since, but i&amp;#039;ve notice it&amp;#039;s a bit difficult to get just the right TX power setting, to make all clients eager to switch over. the problem is that in real life there is a huge difference in how well given device receives WiFi. eg. my laptop was still able to I/O most of the packages throughout the entire house, while cell phone was loosing signal 2/3 down the way.
&lt;/p&gt;

&lt;p&gt;
i was wondering how could i make the WiFi roaming a bit more “aggressive” in roaming clients? it turned out to be tricky, as it&amp;#039;s essentially a client feature. however in &lt;a href=&quot;https://openwrt.org&quot; class=&quot;urlextern&quot; title=&quot;https://openwrt.org&quot; rel=&quot;ugc nofollow&quot;&gt;OpenWRT&lt;/a&gt; there is a nice way of “helping” clients to make the right call – “coverage cell density”. what it (effectively) does is it does not offer lower speed rates. this in turn forces clients that are further away, to switch over, as they can no longer I/O at high speeds! so client has to switch, even though connection would still be usable at degraded speeds, normally. after enabling that option, all my clients start switching over exactly as expected, where expected.
&lt;/p&gt;

&lt;p&gt;
&lt;a href=&quot;https://baszerr.eu/lib/exe/detail.php?id=blog%3A2022%3A05%3A29%3A2022-05-29_-_more_on_wifi_roaming&amp;amp;media=blog:2022:05:29:openwrt_and_wifiroaming.png&quot; class=&quot;media&quot; title=&quot;blog:2022:05:29:openwrt_and_wifiroaming.png&quot;&gt;&lt;img src=&quot;https://baszerr.eu/lib/exe/fetch.php?media=blog:2022:05:29:openwrt_and_wifiroaming.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; title=&quot;WiFi roaming settings, for better client switching over&quot; alt=&quot;WiFi roaming settings, for better client switching over&quot; /&gt;&lt;/a&gt;
&lt;/p&gt;

&lt;/div&gt;
</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Sun, 29 May 2022 17:59:11 +0000</pubDate>
        </item>
        <item>
            <title>2022-05-29_-_test_your_page_with_no_javascript</title>
            <link>https://baszerr.eu/doku.php?id=blog:2022:05:29:2022-05-29_-_test_your_page_with_no_javascript</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;test_your_page_with_no_javascript&quot;&gt;2022-05-29 - test your page with no javascript&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
some time ago i was contacted by a software house – the usual “come work for us” stuff you get loads of at linked-in. i do note remember details at this points, however there was sth interesting enough in there, for me to check out their homepage. when it opened, i saw a huge marketing screen, that looked like this:
&lt;/p&gt;

&lt;p&gt;
&lt;a href=&quot;https://baszerr.eu/lib/exe/detail.php?id=blog%3A2022%3A05%3A29%3A2022-05-29_-_test_your_page_with_no_javascript&amp;amp;media=blog:2022:05:29:no_js_counters_page.png&quot; class=&quot;media&quot; title=&quot;blog:2022:05:29:no_js_counters_page.png&quot;&gt;&lt;img src=&quot;https://baszerr.eu/lib/exe/fetch.php?w=600&amp;amp;tok=89889d&amp;amp;media=blog:2022:05:29:no_js_counters_page.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; title=&quot;no JS -- counters on the page&quot; alt=&quot;no JS -- counters on the page&quot; width=&quot;600&quot; /&gt;&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;
so… they company has zero years of experience, no experts on board and no development whatsoever. cool.
&lt;/p&gt;

&lt;p&gt;
&lt;a href=&quot;https://en.wikipedia.org/wiki/Root cause analysis&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/Root cause analysis&quot;&gt;RCA&lt;/a&gt;? i have javascript disabled for all pages by default (#cybersec #privacy). the above counters were animated in javascript, so in order to show anything, JS had to be enabled. when it was not… well – it looked funny, to say it lightly. ;) it&amp;#039;s astounding how many pages silently relay on JS just being there. funny enough, it doe not seem even to be a test case for pages all too often.
&lt;/p&gt;

&lt;p&gt;
&lt;em&gt;not&lt;/em&gt; testing stuff at your own risk – you know the drill… ;)
&lt;/p&gt;

&lt;/div&gt;
</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Sun, 29 May 2022 18:33:07 +0000</pubDate>
        </item>
    </channel>
</rss>
