]> git.ipfire.org Git - thirdparty/nqptp.git/commitdiff
Improve some of the error messages. Remove the setcap command from Makefile.am, since...
authorMike Brady <4265913+mikebrady@users.noreply.github.com>
Tue, 19 Sep 2023 10:08:27 +0000 (11:08 +0100)
committerMike Brady <4265913+mikebrady@users.noreply.github.com>
Tue, 19 Sep 2023 10:08:27 +0000 (11:08 +0100)
Makefile.am
configure.ac
nqptp-utilities.c
nqptp.c

index 78f36d72971029b2e9eda63ea3d96eb5dd30794f..d2b399256bd84148f07d75d6abccc9077282260e 100644 (file)
@@ -19,8 +19,9 @@ endif
 
 install-exec-hook:
 if BUILD_FOR_LINUX
-# NQPTP runs as user/group nqptp/nqptp on Linux and uses setcap to access ports 319 and 320
-       setcap 'cap_net_bind_service=+ep' $(bindir)/nqptp
+# Note: NQPTP runs as user/group nqptp/nqptp on Linux.
+# Access is given via AmbientCapabilities in the service file.
+# If you want to run it from the command line, e.g. for debugging, run it as root user.
 # no installer for System V
 if INSTALL_SYSTEMD_STARTUP
        getent group nqptp &>/dev/null || groupadd -r nqptp &>/dev/null
index 12e54b21cbe54e8e9ee3051d5411d023b1f48b3e..a7cba2f7fdca1116fdbd8144ddec83e38df92baa 100644 (file)
@@ -2,7 +2,7 @@
 # Process this file with autoconf to produce a configure script.
 
 AC_PREREQ([2.68])
-AC_INIT([nqptp], [1.2.4d0], [4265913+mikebrady@users.noreply.github.com])
+AC_INIT([nqptp], [1.2.5-dev], [4265913+mikebrady@users.noreply.github.com])
 AM_INIT_AUTOMAKE
 AC_CANONICAL_HOST
 
index 9d6a95dfc2a8d3a40897fe549faf8d35d7347bb2..9964b22e3f330ee053fdf8edb00b58d6484a91f2 100644 (file)
@@ -105,15 +105,11 @@ void open_sockets_at_port(const char *node, uint16_t port,
   }
   freeaddrinfo(info);
   if (sockets_opened == 0) {
-    if (port < 1024)
-      die("unable to listen on port %d. The error is: \"%s\". NQPTP must run as root to access "
-          "this port. Or is another PTP daemon -- possibly another instance on NQPTP -- running "
-          "already?",
-          port, strerror(errno));
-    else
-      die("unable to listen on port %d. The error is: \"%s\". "
-          "Is another instance on NQPTP running already?",
-          port, strerror(errno));
+    if (errno == EACCES) {
+      die("nqptp does not have permission to access port %u. It must (a) [Linux only] have been given CAP_NET_BIND_SERVICE capabilities using e.g. setcap or systemd's AmbientCapabilities, or (b) run as root.", port);
+    } else {
+      die("nqptp is unable to listen on port %u. The error is: %d, \"%s\".", port, errno, strerror(errno));
+    }
   }
 }
 
diff --git a/nqptp.c b/nqptp.c
index e5f29885e5174f9d68f0ae60e308c4221f7537c4..a1a3c76a389166b1c2694be86e68538dc071fd82 100644 (file)
--- a/nqptp.c
+++ b/nqptp.c
@@ -198,7 +198,7 @@ int main(int argc, char **argv) {
   mode_t oldumask = umask(0);
   shm_fd = shm_open(NQPTP_INTERFACE_NAME, O_RDWR | O_CREAT, 0644);
   if (shm_fd == -1) {
-    die("cannot open shared memory \"%s\".", NQPTP_INTERFACE_NAME);
+    die("nqptp cannot open the shared memory \"%s\" for writing. Is another copy of nqptp (e.g. an nqptp daemon) running already?", NQPTP_INTERFACE_NAME);
   }
   (void)umask(oldumask);