Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 14 Sep 2024 01:23:51 -0700
From:      "Dan Mahoney (Ports)" <freebsd@gushi.org>
To:        questions <questions@freebsd.org>
Subject:   Just lost a few hours playing with daemon(8) and trying to set a path in an rc.d script
Message-ID:  <8E35B5EC-0C32-4783-B169-1600C5B003A7@gushi.org>

next in thread | raw e-mail | index | archive | help
Hey there all,

I=E2=80=99m answering my own question here, writing this in the hopes =
that someone finds it in the future, in the archives.  (xkcd.com/979 =
<http://xkcd.com/979>; is relevant)

Dyjob have a service (etherpad lite) that we start from rc.d, using =
daemon, but it runs as an unprivileged user and needs a special PATH =
(because npm wants to install and update its own modules.  I hate this, =
but this is the reality).

Setting export NODE_PATH=3D$HOME/.node/lib/node_modules:$NODE_PATH as =
part of the rc.d script was no problem.  It stuck, but for some reason, =
the PATH was not being set.

I tried setting PATH n the user=E2=80=99s home directories and login =
files, no dice.

I tried setting PATH as part of etherpadlite_env in the rc script, no =
dice.

I even tried explicitly setting the path as part of the =
etherpadlite_start() subroutine in the rc script.  A printenv showed it =
existing, but when the actual daemon command ran, it was erased.

=3D=3D=3D

I almost missed this bit in daemon.c, thinking it=E2=80=99s just an =
error check.  No, this is where daemon does it.

        if (setusercontext(NULL, pw, pw->pw_uid, LOGIN_SETALL) !=3D 0) {
                errx(1, "failed to set user environment");
        }

Turns out, it=E2=80=99s our old and almost never used friend, the login =
capabilities database well at work.  I had to define a custom =
.login_conf for this user and modify the path there, thusly:

me:\
:path=3D~/.node/bin /sbin /bin /usr/sbin /usr/bin /usr/local/sbin =
/usr/local/bin:

=3D=3D=3D

The manpage for daemon(8) is silent on this, saying only:

-u, --user user
Login name of the user to execute the program under.  Environment
             variables HOME, USER, and SHELL are set accordingly.  =
Requires
             adequate superuser privileges.

Adding a single line that *mentions* login.conf would have saved me a =
ton of time here, but because it mentions only HOME, USER, and SHELL, =
the assumption was that everything else would be preserved.

-Dan





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?8E35B5EC-0C32-4783-B169-1600C5B003A7>