On Thu, 6 Apr 2023 12:31:55 +1000 David Gibson <david(a)gibson.dropbear.id.au> wrote:On Wed, Apr 05, 2023 at 01:58:00PM +0200, Stefano Brivio wrote: [...]Ah, sure, it makes sense now.I didn't spot this earlier, but... does it really make sense to wait in cmd_pid(), also on ENOENT, rather than making 'hold' return only once the socket is ready?So, this is a consequence of the fact that the holder doesn't move into the background itself - it just sits in the foreground until terminated. That means that the typical usecase puts it into the background from the shell with &, which in turn means that when we reach the next shell command the socket may not be ready - or not even created. One of the things I had in mind for a hypothetical "nstool unshare" would be to avoid this and have it background itself once the socket is ready.Yes, same here, but it's something I file under the same category (I don't remember why nsholder would hang, you probably explained at some point...).I don't think it would be outrageous to have 'nstool pid' failing if the holding process doesn't exist. Admittely, I'm biased by the few hundreds of times I needed to 'killall -9 nsholder' in the past months. :)So... I agree that's irritating, I've done it a similar number of times. However, I don't think that's really related to the question above - in my experience it's always been the holder process that's hung around, not something waiting on a holder.I meant: rc = write(fd, &(char){ 'Q' }, 1); ...so that one doesn't need to look at 'buf'. nstool is C99 anyway. -- StefanoUh.. I don't see where a compound literal would even go here.rc = getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &peercred, &optlen); if (rc < 0) - die("getsockopet(SO_PEERCRED): %s\n", strerror(errno)); + die("getsockopet(SO_PEERCRED) %s: %s\n", + sockpath, strerror(errno)); close(fd); printf("%d\n", peercred.pid); } -static void stop(int fd, const struct sockaddr_un *addr) +static void cmd_stop(int argc, char *argv[]) { - int rc; + const char *sockpath = argv[1]; + int fd, rc; char buf = 'Q'; - rc = connect(fd, (struct sockaddr *)addr, sizeof(*addr)); - if (rc < 0) - die("connect(): %s\n", strerror(errno)); + if (argc != 2) + usage(); + + fd = connect_ctl(sockpath, false); rc = write(fd, &buf, sizeof(buf));Unrelated: a compound literal would make this more readable.