Constructing debugging syntax
I wanted to echo parameter values when I set them in my blog’s frog.rkt
config file.
Nothing simpler in Racket!
First I create this macro for echoing a single parameter value when it is set:
1
2
3
4
5
6
7
8
9
10
11
12 |
(define-syntax-rule (verbose-set-parameter parameter-id parameter-value)
(begin
;; Set the parameter.
(parameter-id parameter-value)
;; Then call the parameter and print is's value.
;; The "'parameter-id" is special syntax
;; for turning a "parameter-id" identifier to a symbol.
;; We can also write it like:
;; > (quote parameter-id)
;; to be less confusing.
(printf "[DEBUG] (~a ~v)\n" 'parameter-id (parameter-id))))
|
then, I create a wrapper for above macro that can take multiple parameter pairs:
|
(define-syntax-rule (verbose-set-parameters (parameter-id parameter-value) ...)
(begin
;; Unpack a chain of "(parameter-id parameter-value)" pairs
;; using the "..." syntax.
(verbose-set-parameter parameter-id parameter-value) ...))
|
Using the macro
Afterwards we can call it like so:
|
(verbose-set-parameters
(current-title "XGQT's blog")
(current-author "Maciej Barć"))
|
Notice that even the form of setting a parameter, that is (parameter-procedure "value")
, remains the same, but in reality it is just similar to how the syntax macro pattern-matches on it.
Inspecting macro expansion
In racket-mode
inside GNU Emacs we can inspect the macro expansion with racket-expand-region
. Stepping through the expansion provided this result:
|
(begin
(begin
(current-title "XGQT's blog")
(printf "[DEBUG] (~a ~v)\n" 'current-title (current-title)))
(begin
(current-author "Maciej Barć")
(printf "[DEBUG] (~a ~v)\n" 'current-author (current-author))))
|
Unwanted (VDI) present
Recently I was given a task to run a outdated piece of commercial software on a very outdated (in)famous operating system. Unlucky for me on the given VDI (VirtualBox disk image) the so-called “Guests Additions” that enabled “better” time synchronization were already installed.
Fighting VBox time
So, this is what I had to do to keep the old clock:
- turn off networking card in the virtual machine configuration, because we do not want the system to use NTP or other newt service to get the “new” time,
- disable getting the host’s clock time:
VBoxManage setextradata "WinXP"
"VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" 1
,
- and… this magic:
VBoxManage modifyvm "WinXP"
--biossystemtimeoffset "-341597644449"
, this thing does the very weird thing of telling the virtual machine BIOS how much to set it back in time, the offset
here is total milliseconds between some old date and current date.
Getting the old date
With the Python script snippet below you will get the milliseconds to set back the VirtualBox clock to 01.01.2012 01:00
.
|
from datetime import datetime
round((datetime.strptime("01.01.2012 01:00", "%d.%m.%Y %H:%M")
- datetime.now()).total_seconds() * 1000)
|
Equality methods
By implementing a method for equality equal-to?
and two extraction methods equal-hash-code-of
and equal-secondary-hash-code-of
we can define our own object comparison rules.
For more info see Object Equality and Hashing.
Consider the following example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14 |
|
If we create a new integer%
object we can notice that it is not transparent (we can not inspect values of any of it’s fields).
|
(new integer%)
;; => (object:integer% ...)
|
But if we compare two fresh integer%
objects they will be equal.
Transparent class
A transparent cvlass is a class with the inspect
expression valuye se to #false
.
From Racket documentation Creating Classes:
Just as for structure types, an inspector controls access to the class’s fields, including private fields, and also affects comparisons using equal?.
Consider the following example:
If we create a new integer%
object we can see it’s field values.
|
(new integer%)
;; => (object:integer% 0)
|
And if we compare two fresh integer%
objects they will be equal.
I have moved my main Fediverse account from @xgqt@fosstodon.org to @xgqt@emacs.ch.
The new account’s RSS feed can be found at emacs.ch/users/xgqt.rss.
Config
First let’s prepare a suitable nginx configuration file.
This one is pretty bare but it works well for our case:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 |
worker_processes 1;
daemon off;
pid ./nginx/temp/nginx.pid;
error_log /dev/stdout info;
events {
worker_connections 1024;
}
http {
client_body_temp_path ./nginx/temp/client 1 2;
proxy_temp_path ./nginx/temp/proxy;
fastcgi_temp_path ./nginx/temp/fastcgi;
uwsgi_temp_path ./nginx/temp/uwsgi;
scgi_temp_path ./nginx/temp/scgi;
server {
listen 127.0.0.1:8080;
server_name localhost;
access_log /dev/stdout;
error_log /dev/stdout info;
root ./;
location / {
autoindex on;
}
}
}
|
Server config is set up for serving all static files from the current directory.
Startup
Preparation
Based on how you want to store _temp_path
files it might be necessary to create (or clean up) additional directories, for example:
|
rm -r ./nginx/temp
mkdir -p ./nginx/temp
|
Run in current directory
|
nginx -c ./nginx.conf -p ./
|
BTW, you may want to replace ./
with "$(pwd)"
and occurrences in the config with static paths.
Bonus: other simple servers
Some of no-dependency-except-itself http servers it’s good to know about:
Python http.server
|
python3 -m http.server -b 127.0.0.1 8080
|
Busybox
|
busybox httpd -f -p 127.0.0.1:8080 -v
|
You can read more about configuring busybox’s httpd on OpenWRT docs.
System preparation
Qemu
Emerge qemu
with static-user
USE enabled and your wanted architectures.
|
app-emulation/qemu QEMU_SOFTMMU_TARGETS: aarch64 arm x86_64
app-emulation/qemu QEMU_USER_TARGETS: aarch64 arm x86_64
app-emulation/qemu static-user
dev-libs/glib static-libs
sys-apps/attr static-libs
sys-libs/zlib static-libs
dev-libs/libpcre2 static-libs
|
OpenRC
Enable qemu-binfmt
:
|
rc-update add qemu-binfmt default
|
Start qemu-binfmt
:
|
rc-service qemu-binfmt start
|
Chrooting
- select chroot location (eg
/chroots/gentoo-arm64-musl-stable
)
- unpack the desired rootfs
- create needed directories
mkdir -p /chroots/gentoo-arm64-musl-stable/var/cache/distfiles
- execute
bwrap
- with last
ro-bind
mount the qemu emulator binary (eg qemu-aarch64
)
- execute the mounted emulator binary giving it a shell program (eg
bash
)
Chroot with bwrap
:
|
bwrap \
--bind /chroots/gentoo-arm64-musl-stable / \
--dev /dev \
--proc /proc \
--perms 1777 --tmpfs /dev/shm \
--tmpfs /run \
--ro-bind /etc/resolv.conf /etc/resolv.conf \
--bind /var/cache/distfiles /var/cache/distfiles \
--ro-bind /usr/bin/qemu-aarch64 /usr/bin/qemu-aarch64 \
/usr/bin/qemu-aarch64 /bin/bash -l
|
User-mode
By default you would probably have something like this, the user-mode network:
|
<interface type="user">
<mac address="00:00:00:00:00:00"/>
<model type="virtio"/>
<address type="pci" domain="0x0000" bus="0x01" slot="0x00" function="0x0"/>
</interface>
|
Bridge
Bridges can be easily created using the NetworkManager’s TUI tool called nmtui
.
Bridge XML configuration for Libvirt
|
<interface type="bridge">
<mac address="00:00:00:00:00:00"/>
<source bridge="br1"/>
<target dev="vnet2"/>
<model type="virtio"/>
<alias name="net0"/>
<address type="pci" domain="0x0000" bus="0x06" slot="0x00" function="0x0"/>
</interface>
|
Sysctl options
Be sure the following options are enabled (1
):
net.ipv4.ip_forward
net.ipv4.conf.all.send_redirects
and the following options are disabled (0
):
net.bridge.bridge-nf-call-iptables