The Findutils package contains programs to find files. These programs are provided to recursively search through a directory tree and to create, maintain, and search a database (often faster than the recursive find, but unreliable if the database has not been recently updated).
The following command will build Findutils with additional compiler warnings:
find . -type f -name Makefile.in -exec \
sed 's/^CFLAGS =.*/& -Wformat -Wformat-security \\\
-Werror -Wfatal-errors/' -i.orig {} \;
The -D_FORTIFY_SOURCE=2 GCC option will produce a few warnings about unused return values. We can wrap the affected functions with if statements which will produce an error at runtime if the function does not succeed (hence using the return value):
sed 's/fwrite (segment->text, 1, segment->text_len, fp);/if (fwrite (segment->text, 1, segment->text_len, fp) != 0) {error;}/' \
-i.orig find/pred.c
sed -e 's/#include <sys\/types.h>/&\n#include <error.h>/' -e \
's/fwrite (LOCATEDB_MAGIC, sizeof (LOCATEDB_MAGIC), 1, stdout);/if (fwrite (LOCATEDB_MAGIC, sizeof (LOCATEDB_MAGIC), 1, stdout) != 0) {error;}/' \
-i.orig locate/frcode.c
sed -e 's/#include <sys\/types.h>/&\n#include <error.h>/' \
-e 's/fgets (bigrams, 257, fp);/if (fgets (bigrams, 257, fp) != 0) {error;}/' \
-e 's/fwrite (bigrams, 1, 256, stdout);/if (fwrite (bigrams, 1, 256, stdout) != 0) {error;}/' \
-i.orig locate/code.c
Prepare Findutils for compilation:
./configure --prefix=/usr --libexecdir=/usr/lib/findutils \
--localstatedir=/var/lib/locate
The meaning of the configure options:
This option changes the location of the locate database to be in /var/lib/locate, which is FHS-compliant.
Compile the package:
make
To test the results, issue: make check.
Install the package:
make install
Some of the scripts in the LFS-Bootscripts package depend on find. As /usr may not be available during the early stages of booting, this program needs to be on the root partition. The updatedb script also needs to be modified to correct an explicit path:
mv -v /usr/bin/find /bin
sed 's/find:=${BINDIR}/find:=\/bin/' -i.orig /usr/bin/updatedb