package/ntp: run ntpd as ntp user

- in case libcap is enabled use the now enabled '-u' option to run nptd as
  user/group ntp

Signed-off-by: Peter Seiderer <ps.report@gmx.net>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
This commit is contained in:
Peter Seiderer 2021-11-10 20:37:28 +01:00 committed by Thomas Petazzoni
parent f84350e725
commit 0f0b1f59c3
3 changed files with 15 additions and 4 deletions

View file

@ -6,7 +6,7 @@
DAEMON="ntpd"
PIDFILE="/var/run/$DAEMON.pid"
NTPD_ARGS="-g"
NTPD_ARGS="@NTPD_EXTRA_ARGS@ -g"
# shellcheck source=/dev/null
[ -r "/etc/default/$DAEMON" ] && . "/etc/default/$DAEMON"

View file

@ -44,6 +44,10 @@ endif
ifeq ($(BR2_PACKAGE_LIBCAP),y)
NTP_CONF_OPTS += --enable-linuxcaps
NTP_DEPENDENCIES += libcap
define NTP_USERS
ntp -1 ntp -1 * - - - ntpd user
endef
NTP_DAEMON_EXTRA_ARGS = -u ntp:ntp
else
NTP_CONF_OPTS += --disable-linuxcaps
endif
@ -109,11 +113,18 @@ endif
ifeq ($(BR2_PACKAGE_NTP_NTPD),y)
define NTP_INSTALL_INIT_SYSV_NTPD
$(INSTALL) -D -m 755 package/ntp/S49ntp $(TARGET_DIR)/etc/init.d/S49ntp
mkdir -p $(TARGET_DIR)/etc/init.d
sed -e 's%@NTPD_EXTRA_ARGS@%$(NTP_DAEMON_EXTRA_ARGS)%g' \
package/ntp/S49ntp.in \
> $(TARGET_DIR)/etc/init.d/S49ntp
chmod 0755 $(TARGET_DIR)/etc/init.d/S49ntp
endef
define NTP_INSTALL_INIT_SYSTEMD
$(INSTALL) -D -m 644 package/ntp/ntpd.service $(TARGET_DIR)/usr/lib/systemd/system/ntpd.service
mkdir -p $(TARGET_DIR)/usr/lib/systemd/system
sed -e 's%@NTPD_EXTRA_ARGS@%$(NTP_DAEMON_EXTRA_ARGS)%g' \
package/ntp/ntpd.service.in \
> $(TARGET_DIR)/usr/lib/systemd/system/ntpd.service
endef
endif

View file

@ -9,7 +9,7 @@ PIDFile=/run/ntpd.pid
# correct time to work, but we likely won't acquire that without NTP. Let's
# break this chicken-and-egg cycle here.
Environment=SYSTEMD_NSS_RESOLVE_VALIDATE=0
ExecStart=/usr/sbin/ntpd -g -p /run/ntpd.pid
ExecStart=/usr/sbin/ntpd @NTPD_EXTRA_ARGS@ -g -p /run/ntpd.pid
[Install]
WantedBy=multi-user.target