Customizing FreeBSD from source

Created: Sat Mar 9 15:07:59 CET 2019

Last mod­i­fied: Thu Mar 14 12:00:35 CET 2019

The goal of this ar­ti­cle is to show you how to edit and build base tools from the source tree.

On FreeBSD, when­ever you lo­gin from the con­sole, the MOTD is printed on screen be­fore you start typ­ing com­mands (ie. startx).

There is a C func­tion motd(const char *motdfile) which is called by the lo­gin(1) util­ity. motdfiles value is set in /etc/login.conf.

I want my MOTD to be piped through lol­cat. How do I go about this ?

(The easy way would be to echo 'cat /etc/motd | lolcat' >> ~/.login instead of re­ly­ing on lo­gin(1)’s con­fig­u­ra­tion file.)

First, down­load my fork of lol­cat. I sim­ply mod­i­fied lolcat.c in or­der to build a li­brary in­stead of an ex­e­cutable.

Now, as root, cd /usr/src/usr.bin/login. Also copy my ver­sion of lolcat.c in the same di­rec­tory.

We will need to im­port the lolcat() func­tion into login.c. We’ll try to keep it clean and just add the fol­low­ing sig­na­ture at the end of login.h,

int lolcat(double, double, const char *);

Next step is to edit the Makefile ac­cord­ingly,

#SRCS=   login.c login_fbtab.c
SRCS=    login.c login_fbtab.c lolcat.c

Now open login.c with your fa­vorite text ed­i­tor and re­move the sigint() func­tion en­tirely (or com­ment it out). It pre­vents the com­piler from er­ror­ing out since sig­int() won’t be needed any­more af­ter the next change; which is to re­place the de­f­i­n­i­tion of motd with the one be­low.

static int
motd(const char *motdfile)
    if (lolcat(0.23,0.1,motdfile) != 0)
        return (-1);
    return (0);

Finally, add printf '\033[0m' at the be­gin­ning of ~/.login. It’s to ensure that you wont get any funny col­ors in tty af­ter lo­gin(1) is done.

Run make && make install, exit your ses­sion, lo­gin again…

source code