So that we'll probably give a better error if you point it at something that's not an nstool hold control socket. Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au> --- test/nstool.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/nstool.c b/test/nstool.c index 428c9c4..e995f3e 100644 --- a/test/nstool.c +++ b/test/nstool.c @@ -12,6 +12,7 @@ #include <stdlib.h> #include <string.h> #include <stdbool.h> +#include <stdint.h> #include <errno.h> #include <unistd.h> #include <getopt.h> @@ -45,7 +46,10 @@ const struct ns_type nstypes[] = { { CLONE_NEWUTS, "uts" }, }; +#define NSTOOL_MAGIC 0x75601d75 + struct holder_info { + uint64_t magic; pid_t pid; uid_t uid; gid_t gid; @@ -101,6 +105,10 @@ static int connect_ctl(const char *sockpath, bool wait, if ((size_t)len < sizeof(*info)) die("short read() on control socket %s\n", sockpath); + if (info->magic != NSTOOL_MAGIC) + die("Control socket %s doesn't appear to belong to nstool\n", + sockpath); + if (peercred) { socklen_t optlen = sizeof(*peercred); @@ -140,6 +148,7 @@ static void cmd_hold(int argc, char *argv[]) if (rc < 0) die("listen() on %s: %s\n", sockpath, strerror(errno)); + info.magic = NSTOOL_MAGIC; info.pid = getpid(); info.uid = getuid(); info.gid = getgid(); -- 2.39.2