Executing 'locate' in a jail returns "locate: database too small: /var/db/locate.database"
The database file is 0 length:
-r--r--r-- 1 nobody wheel 0 Aug 20 04:15 /var/db/locate.database
The script /usr/libexec/locate.updatedb is responsible for generating the locate(1) database (above file). Executing '/usr/libexec/locate.updatedb' in a jail returns "/usr/libexec/locate.updatedb: empty variable FILESYSTEMS".
One might be fooled into thinking this is a configuration issue with /etc/locate.rc but it is not. The root-cause is that /usr/libexec/locate.updatedb uses the lsvfs(1) command to get a list of local/non-synthetic filesystem types (and uses this as the default-value for $FILESYSTEMS). Within a jail, the lsvfs(1) output is redacted (see below):
Filesystem Refs Flags
-------------------------------- ----- ---------------
This redacted output results in a NULL default-value for $FILESYSTEMS, resulting in the odd, but true, fatal error message "/usr/libexec/locate.updatedb: empty variable FILESYSTEMS".
ASIDE: The value of $FILESYSTEMS is used by /usr/libexec/locate.updatedb, enumerated to find(1) as a list of "-fstype" arguments when generating the locate(1) database.
It then uses this list to build a series of "-fstype" excludes to pass to find(1) when generating the locate(1) database.
Fix: At the low-level, the problem is two-fold:
1. lsvfs(1) as-used by /usr/libexec/locate.updatedb returns a redacted list within a jail
2. find(1)'s "-fstype" flag does not work within a jail.
At the high-level, the problem is simpler to solve:
1. Make /usr/libexec/locate.updatedb not use lsvfs(1) or the "-fstype" flag of find(1) when running in a jail.
A patch has been attached that applys the above-described "high-level" change, allowing /usr/libexec/locate.db to function properly within a jail (thus allowing locate(1) to work as-expected within a jail).
Patch attached with submission follows:
How-To-Repeat: Execute 'locate' in a jail. Get the following error:
locate: database too small: /var/db/locate.database
Naturally, try and generate /var/db/locate.database by then executing:
Only to get the following fatal error:
/usr/libexec/locate.updatedb: empty variable FILESYSTEMS
NOTE: The error is misleading and caused by a bug. Please read "Full Description" for further explanation.
The previously attached patch didn't work for me on a virgin jail setup.
I've revised/updated it. Could still use a formal looking at by the respective
authors however (read: not intended for commit yet)
The information contained in this message is proprietary and/or confidential. If you are not the intended recipient, please: (i) delete the message and all copies; (ii) do not disclose, distribute or use the message in any manner; and (iii) notify the sender immediately. In addition, please be aware that any message addressed to our domain is subject to archiving and review by persons other than the intended recipient. Thank you.
For bugs matching the following conditions:
- Status == In Progress
- Assignee == "bugs@FreeBSD.org"
- Last Modified Year <= 2017
- Set Status to "Open"
Devin, is this patch still relevant?