Odi's astoundingly incomplete notes

New Entries

Kill idle TTYs

Here is a simple shell script to kill terminals that have been idle for a long time. You can identify such sessions in the IDLE column of the Linux w command. This corresponds to the last modified date of the respective TTY device file.
$ w
 10:56:54 up 10 days, 23:54,  7 users,  load average: 1.17, 1.10, 1.16
aron     pts/0     10:56    1.00s  0.01s  0.01s w
betty    pts/4      Mi10   22:25m  0.02s  0.00s tail -F error.log
cher     pts/5     06:32    4:16m  0.04s  0.04s -bash
dave     pts/8     09:56   41:02   0.06s  0.05s vim config
erin     pts/9     08:26    2:26m  0.03s  0.03s -bash
fritz    pts/12    09:30    1:25m  0.03s  0.02s git server
greg     pts/13    10:47    9:26   0.32s  0.32s less +F -S --follow-name /var/log/messages

# Sends SIGHUP to TTYs which are idle for a defined time.
# Default is 8 hours. 
# Syntax: kill-idle [idle-hours]
NOW=$(stat -t "${T}" | awk '{ print $12}')
[ -z ${NOW} ] && exit 1
cd /dev
for TTY in pts/*; do
  if [ "${TTY}" = "pts/ptmx" ]; then
  # field 12 is "last access" which is the time of last write to the tty (last keypress)
  MOD=$(stat -t "${TTY}" | awk '{ print $12}')
  let AGO=$((NOW - MOD))
  if [ ${AGO} -gt $((LIMIT*3600)) ]; then
    pkill -HUP -t "${TTY}"
rm "${T}"

posted on 2020-06-18 11:01 CEST in Code | 0 comments | permalink

Fix Eclipse wide fonts

If fonts in Eclipse and other GTK UI on Linux look too wide or too high or have too much padding around them, then check your GTK font settings! Using a different font may give you a much better layout.

Especially DejaVu Sans and Liberation Sans have a much lower height than Noto Sans for example.

gtk-font-name=Liberation Sans, 10

posted on 2020-05-29 16:59 CEST in Code | 0 comments | permalink

Make very sure Oracle uses async IO on Linux

A default installation of Oracle on Linux will use synchronous IO. You have to explicitly enable asynchronous IO by setting a parameter (sic!):
and restart Oracle. If you don't do that then synchronous IO during logfile switches / checkpoints will cause unnecessary waits: log file switch (checkpoint incomplete). At the same time Oracle DBW process will not saturate IO. Your DB will become barely usable during those times.

As this also enables direct writes (which circumvent the OS page cache) you must also ensure that the SGA size is close to the RAM size (70-80%). Do not enable the parameter above for small SGAs (< 4GB).
posted on 2020-03-04 13:52 CET in Code | 0 comments | permalink

package.keywords becomes package.accept_keywords

As of sys-apps/portage-2.3.89 Gentoo installations must rename /etc/portage/package.keywords to /etc/portage/package.accept_keywords.

posted on 2020-03-03 15:56 CET in Code | 0 comments | permalink

Relaying SIGINT signal to child processes

Here is a bash function (plus test program) that correctly relays important signals to child processes. So that pressing Ctrl-C reliably terminates both all child processes and the parent process.

posted on 2020-01-09 10:32 CET in Code | 0 comments | permalink

Fix Firefox Password suggestions

If you have many saved passwords in Firefox's Password Manager then the password suggestions on login forms can become unusably long.

To restore the previous behaviour, in about:config set signon.includeOtherSubdomainsInLookup to false.

posted on 2020-01-06 16:24 CET in Code | 0 comments | permalink

linux-5.5 mm looks very good

My tests with the upcoming Linux kernel are looking very promising. For me memory management issue has been improved a lot. In recent 5.x kernels the mm would trigger a lot of reclaim scans even with low memory pressure. For example  on a 2GB laptop the Normal zone is quite small. Most memory is in the DMA32 zone. And those kernels would trigger reclaim and even swap when opening a browser or using gitk on the kernel repo. Even though there is still plenty of usable RAM.
With 5.5 this is resolved. Reclaim scans are rare again and swap is not used in these situations.

posted on 2020-01-01 14:29 CET in Code | 0 comments | permalink

Gentoo updating gcc, mpfr, mpc

When Gentoo updates gcc together with mpfr and mpc the normal emerge procedure will cause building of gcc twice. Because mpfr and mpc cause automatic rebuild of the (existing) gcc. But if you are going to update gcc anyway then this is utterly pointless waste of energy.

Instead you can emerge --ignore-built-slot-operator-deps=y -1uav mpfr mpc first without doing the rebuild. This leaves you with a broken gcc maybe (but actually probably not because portage preserves the old library versions), but next you simply emerge -1uav gcc anyway.

After gcc update don't forget to switch to the new compiler with gcc-config and rebuild libtool.

posted on 2019-11-28 09:09 CET in Code | 0 comments | permalink

Gentoo replacing ntp, vixie-cron, man

Gentoo is cleaning out its closet. It has removed unmaintained upstream packages which were still popular: ntp, vixie-cron and man. Of course it's a logical step and using the modern replacements is rational.

For net-misc/ntp, use net-misc/ntpsec: This has way more robust configuration while eliminating ancient obscure features like traps.

For vixie-cron, use sys-process/cronie. It also itegrates anacron, so you get two in one.

For man, use man-db which is faster as it uses a BDB backend instead of text files.

posted on 2019-10-14 07:06 CEST in Code | 0 comments | permalink

Java and its use of filesystem syscalls

File f = new File("build.xml");
// openat(AT_FDCWD, "build.xml", O_RDONLY) = 96
// fstat(96
InputStream io = new FileInputStream(f);
// read(96
// read(96
// close(96)

Path p = f.toPath();
// openat(AT_FDCWD, "build.xml", O_RDONLY) = 96
io = Files.newInputStream(p);
// read(96
// read(96
// close(96)
The NIO way of creating an input stream from a file actually saves an fstat syscall.
posted on 2019-10-01 13:36 CEST in Code | 0 comments | permalink