-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend the printf pattern for hostnames for left trimming
This provides more flexibility in specifying hostname patterns that include all or part of the board's serial number. Before this change, "%s" and "%.4s" (4 is the number of characters to use of the serial number) were supported. After this change, the printf pattern also supports "%-.4s" to use the rightmost characters in the board's serial number. This is an extension to printf. I found one reference to someone else doing this based on web searches and it was the only hit, so it doesn't look like there's any precedence to follow. While making this change, the custom sprintf was dumbed down to only support these escapes and nothing else. This might prevent a crash.
- Loading branch information
Showing
8 changed files
with
545 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#!/usr/bin/env bash | ||
|
||
# | ||
# Test that calling out to a unique id generator does the right thing | ||
# | ||
|
||
cat >"$CONFIG" <<EOF | ||
-v | ||
# Specify a hostname pattern that has a unique id part | ||
--hostname-pattern nerves-%s- | ||
# Call out to a dummy unique id generator | ||
--uniqueid-exec "/usr/bin/make-unique-id" | ||
EOF | ||
|
||
cat >"$WORK/usr/bin/make-unique-id" <<EOF | ||
#!/usr/bin/env bash | ||
echo "12345678" | ||
EOF | ||
chmod +x "$WORK/usr/bin/make-unique-id" | ||
|
||
cat >"$EXPECTED" <<EOF | ||
erlinit: cmdline argc=1, merged argc=6 | ||
erlinit: merged argv[0]=/sbin/init | ||
erlinit: merged argv[1]=-v | ||
erlinit: merged argv[2]=--hostname-pattern | ||
erlinit: merged argv[3]=nerves-%s- | ||
erlinit: merged argv[4]=--uniqueid-exec | ||
erlinit: merged argv[5]=/usr/bin/make-unique-id | ||
fixture: mount("proc", "/proc", "proc", 14, data) | ||
fixture: mount("sysfs", "/sys", "sysfs", 14, data) | ||
fixture: mount("devtmpfs", "/dev", "devtmpfs", 42, data) | ||
fixture: mkdir("/dev/pts", 755) | ||
fixture: mkdir("/dev/shm", 1777) | ||
fixture: mount("devpts", "/dev/pts", "devpts", 10, data) | ||
fixture: symlink("/dev/mmcblk0","/dev/rootdisk0") | ||
fixture: symlink("/dev/mmcblk0p4","/dev/rootdisk0p4") | ||
fixture: symlink("/dev/mmcblk0p3","/dev/rootdisk0p3") | ||
fixture: symlink("/dev/mmcblk0p2","/dev/rootdisk0p2") | ||
fixture: symlink("/dev/mmcblk0p1","/dev/rootdisk0p1") | ||
erlinit: set_ctty | ||
fixture: setsid() | ||
fixture: mount("tmpfs", "/tmp", "tmpfs", 14, data) | ||
fixture: mount("tmpfs", "/run", "tmpfs", 14, data) | ||
erlinit: find_release | ||
erlinit: No release found in /srv/erlang. | ||
erlinit: find_erts_directory | ||
erlinit: setup_environment | ||
erlinit: setup_networking | ||
fixture: ioctl(SIOCGIFFLAGS) | ||
fixture: ioctl(SIOCSIFFLAGS) | ||
fixture: ioctl(SIOCGIFINDEX) | ||
erlinit: configure_hostname | ||
erlinit: system_cmd '/usr/bin/make-unique-id' | ||
erlinit: Hostname: nerves-12345678- | ||
fixture: sethostname("nerves-12345678-", 16) | ||
fixture: mkdir("/root/seedrng", 700) | ||
erlinit: Saving 256 bits of creditable seed for next boot | ||
erlinit: Env: 'HOME=/home/user0' | ||
erlinit: Env: 'PATH=/usr/sbin:/usr/bin:/sbin:/bin' | ||
erlinit: Env: 'TERM=xterm-256color' | ||
erlinit: Env: 'ROOTDIR=/usr/lib/erlang' | ||
erlinit: Env: 'BINDIR=/usr/lib/erlang/erts-6.0/bin' | ||
erlinit: Env: 'EMU=beam' | ||
erlinit: Env: 'PROGNAME=erlexec' | ||
erlinit: Arg: 'erlexec' | ||
erlinit: Arg: '-boot_var' | ||
erlinit: Arg: 'RELEASE_LIB' | ||
erlinit: Arg: '/srv/erlang/lib' | ||
erlinit: Launching erl... | ||
Hello from erlexec | ||
erlinit: Erlang VM exited | ||
erlinit: kill_all | ||
erlinit: Sending SIGTERM to all processes | ||
fixture: kill(-1, 15) | ||
fixture: sleep(1) | ||
erlinit: Sending SIGKILL to all processes | ||
fixture: kill(-1, 9) | ||
fixture: mkdir("/root/seedrng", 700) | ||
erlinit: Seeding 256 bits and crediting | ||
fixture: ioctl(RNDADDENTROPY) | ||
erlinit: Saving 256 bits of creditable seed for next boot | ||
erlinit: unmount_all | ||
erlinit: unmounting tmpfs at /sys/fs/cgroup... | ||
fixture: umount("/sys/fs/cgroup") | ||
erlinit: unmounting tmpfs at /dev/shm... | ||
fixture: umount("/dev/shm") | ||
erlinit: unmounting devpts at /dev/pts... | ||
fixture: umount("/dev/pts") | ||
erlinit: unmounting proc at /proc... | ||
fixture: umount("/proc") | ||
erlinit: unmounting sysfs at /sys... | ||
fixture: umount("/sys") | ||
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#!/usr/bin/env bash | ||
|
||
# | ||
# Test that calling out to a unique id generator does the right thing | ||
# | ||
|
||
cat >"$CONFIG" <<EOF | ||
-v | ||
# Specify a hostname pattern that has a unique id part | ||
--hostname-pattern nerves-%-.4s- | ||
# Call out to a dummy unique id generator | ||
--uniqueid-exec "/usr/bin/make-unique-id" | ||
EOF | ||
|
||
cat >"$WORK/usr/bin/make-unique-id" <<EOF | ||
#!/usr/bin/env bash | ||
echo "12345678" | ||
EOF | ||
chmod +x "$WORK/usr/bin/make-unique-id" | ||
|
||
cat >"$EXPECTED" <<EOF | ||
erlinit: cmdline argc=1, merged argc=6 | ||
erlinit: merged argv[0]=/sbin/init | ||
erlinit: merged argv[1]=-v | ||
erlinit: merged argv[2]=--hostname-pattern | ||
erlinit: merged argv[3]=nerves-%-.4s- | ||
erlinit: merged argv[4]=--uniqueid-exec | ||
erlinit: merged argv[5]=/usr/bin/make-unique-id | ||
fixture: mount("proc", "/proc", "proc", 14, data) | ||
fixture: mount("sysfs", "/sys", "sysfs", 14, data) | ||
fixture: mount("devtmpfs", "/dev", "devtmpfs", 42, data) | ||
fixture: mkdir("/dev/pts", 755) | ||
fixture: mkdir("/dev/shm", 1777) | ||
fixture: mount("devpts", "/dev/pts", "devpts", 10, data) | ||
fixture: symlink("/dev/mmcblk0","/dev/rootdisk0") | ||
fixture: symlink("/dev/mmcblk0p4","/dev/rootdisk0p4") | ||
fixture: symlink("/dev/mmcblk0p3","/dev/rootdisk0p3") | ||
fixture: symlink("/dev/mmcblk0p2","/dev/rootdisk0p2") | ||
fixture: symlink("/dev/mmcblk0p1","/dev/rootdisk0p1") | ||
erlinit: set_ctty | ||
fixture: setsid() | ||
fixture: mount("tmpfs", "/tmp", "tmpfs", 14, data) | ||
fixture: mount("tmpfs", "/run", "tmpfs", 14, data) | ||
erlinit: find_release | ||
erlinit: No release found in /srv/erlang. | ||
erlinit: find_erts_directory | ||
erlinit: setup_environment | ||
erlinit: setup_networking | ||
fixture: ioctl(SIOCGIFFLAGS) | ||
fixture: ioctl(SIOCSIFFLAGS) | ||
fixture: ioctl(SIOCGIFINDEX) | ||
erlinit: configure_hostname | ||
erlinit: system_cmd '/usr/bin/make-unique-id' | ||
erlinit: Hostname: nerves-5678- | ||
fixture: sethostname("nerves-5678-", 12) | ||
fixture: mkdir("/root/seedrng", 700) | ||
erlinit: Saving 256 bits of creditable seed for next boot | ||
erlinit: Env: 'HOME=/home/user0' | ||
erlinit: Env: 'PATH=/usr/sbin:/usr/bin:/sbin:/bin' | ||
erlinit: Env: 'TERM=xterm-256color' | ||
erlinit: Env: 'ROOTDIR=/usr/lib/erlang' | ||
erlinit: Env: 'BINDIR=/usr/lib/erlang/erts-6.0/bin' | ||
erlinit: Env: 'EMU=beam' | ||
erlinit: Env: 'PROGNAME=erlexec' | ||
erlinit: Arg: 'erlexec' | ||
erlinit: Arg: '-boot_var' | ||
erlinit: Arg: 'RELEASE_LIB' | ||
erlinit: Arg: '/srv/erlang/lib' | ||
erlinit: Launching erl... | ||
Hello from erlexec | ||
erlinit: Erlang VM exited | ||
erlinit: kill_all | ||
erlinit: Sending SIGTERM to all processes | ||
fixture: kill(-1, 15) | ||
fixture: sleep(1) | ||
erlinit: Sending SIGKILL to all processes | ||
fixture: kill(-1, 9) | ||
fixture: mkdir("/root/seedrng", 700) | ||
erlinit: Seeding 256 bits and crediting | ||
fixture: ioctl(RNDADDENTROPY) | ||
erlinit: Saving 256 bits of creditable seed for next boot | ||
erlinit: unmount_all | ||
erlinit: unmounting tmpfs at /sys/fs/cgroup... | ||
fixture: umount("/sys/fs/cgroup") | ||
erlinit: unmounting tmpfs at /dev/shm... | ||
fixture: umount("/dev/shm") | ||
erlinit: unmounting devpts at /dev/pts... | ||
fixture: umount("/dev/pts") | ||
erlinit: unmounting proc at /proc... | ||
fixture: umount("/proc") | ||
erlinit: unmounting sysfs at /sys... | ||
fixture: umount("/sys") | ||
EOF |
Oops, something went wrong.