RPi-Distro / repo

Issue tracking for the archive.raspberrypi.org repo
37 stars 1 forks source link

SANE: The home directory `/var/lib/saned/` is missing #262

Closed keks24 closed 2 years ago

keks24 commented 2 years ago

TL;DR: Remove the parameter --no-create-home from the following line from the shell script postinst, so calibration (.cal) files can be saved in /var/lib/saned/.sane/:

$ vi "postinst"
[...]
adduser --home /var/lib/saned --quiet --system --group saned || true
[...]

Hello,

I would like to report a bug, where the home directory /var/lib/saned/ in the Raspbian package sane-utils_1.0.27-3.2_armhf.deb is missing.

While I was investigating the USB bug -1 EPIPE (Broken Pipe) on my Raspberry Pi 4 (8 GB), which uses Raspbian (Debian Buster) as operating system, I analysed the saned process via strace:

$ while [[ true ]]; do strace -p $(pgrep sane) 2>&1 | tee --append strace_saned; sleep 1; done

I figured out, that the process tries to create the directory /var/lib/saned/.sane/ while scanning:

> mkdir("/var/lib/saned/.sane", 0700) = -1 ENOENT (No such file or directory)

It then tries to create and open the binary file hewlett-packard-scanjet-2300c.cal in that directory after the client detached from the saned process/socket:

> openat(AT_FDCWD, "/var/lib/saned/.sane/hewlett-packard-scanjet-2300c.cal", O_RDONLY) = -1 ENOENT (No such file or directory)

With this knowledge, I created the home directory for saned like so:

$ getent passwd saned
saned:x:109:117::/var/lib/saned:/usr/sbin/nologin
$ cd "/var/lib/"
$ mkhomedir_helper saned
$ chmod 700 "saned/"
$ ls -ld saned/
drwx------ 2 saned saned 4096 Sep 21 18:12 saned/
$ tree -augpsh saned/
saned/
├── [-rw-r--r-- saned saned 220] .bash_logout
├── [-rw-r--r-- saned saned 3.4K] .bashrc
└── [-rw-r--r-- saned saned 807] .profile

0 directories, 3 files

Then, I scanned one more time and found the above mentioned directory .sane/ and the binary file hewlett-packard-scanjet-2300c.cal:

$ tree -augpsh saned/
saned/
├── [-rw-r--r-- saned saned 220] .bash_logout
├── [-rw-r--r-- saned saned 3.4K] .bashrc
├── [-rw-r--r-- saned saned 807] .profile
└── [drwx------ saned saned 4.0K] .sane
    └── [-rw-r--r-- saned saned 32K] hewlett-packard-scanjet-2300c.cal

After that, I did some more investigation, if creating the home directory has some impact and it does.

If the home directory is missing, it causes the saned process to initialise the scanner every time the client initiates a scan process. I always hear the servo motor adjusting for each initiated scan with a timeout of about three to five seconds. This timeout is hardware related. During tests with other hardware to investigate the USB bug, the following rule of thumb should apply: The less CPU power, the higher the timeout after initiating a scan.

If the home directory exists on the other hand, the process will look for a suiting .cal file in there first and then loads it. Initiating a scan with a pre-loaded .cal file will skip the servo motor adjustments and the scanner just scans.

Digging further and looking into the postinst file; I found the section, where the user saned is created via adduser:

$ cd "$(mktemp --directory)"
$ apt download sane-utils
$ ar x "sane-utils_1.0.27-3.2_armhf.deb"
$ tar --xz --extract --verbose --preserve-permissions --file="control.tar.xz"
$ < "postinst"
[...]
# Create saned user/group if they do not exist
if ! getent passwd | grep -q "^saned:"; then
    echo "Adding saned group and user..."
    adduser --home /var/lib/saned --quiet --system --no-create-home --group saned || true
fi
[...]

The user saned is created and will use the home directory /var/lib/saned/. The parameter --home will actually create the given path automatically, but the parameter --no-create-home prevents this.

It would be nice, if --no-create-home could be removed in further updates.

-Ramon

XECDesign commented 2 years ago

This package seems to be unmodified by us or by Raspbian and the issue isn't caused by an interaction with one of our other changes. Since it's a straight Debian package and I don't know enough about how it's meant to work, this one is probably for the maintainers of the package.

https://www.debian.org/Bugs/Reporting

If they agree that this makes sense, I can backport their change.

keks24 commented 2 years ago

Alright!

I reported the issue here.