balance command complains about missing rendezvous directory

Brian Inglis Brian.Inglis@SystematicSw.ab.ca
Fri Jun 14 20:18:00 GMT 2019


On 2019-06-14 09:25, Marco Coletti wrote:
> Windows 10 x64
> Just installed Cygwin and balance package.
> =======
> $ balance -d -f -b 127.0.0.1 1080 127.0.0.1:1090
> source port 1080
> ERROR: rendezvous directory not available and/or creatable
>        please create /var/run/balance/ with mode 01777 like this:
>        # mkdir -m 01777 /var/run/balance/
> argv[0]=/usr/bin/balance
> bindhost=127.0.0.1
> $ ls -ld /var/run/balance
> drwxrwxrwt+ 1 SO000419 Domain Users 0 Jun 14 16:48 /var/run/balance
> $ ls -l /var/run/balance/.keep-balance
> -rw-r--r-- 1 SO000419 Domain Users 0 Apr 28  2013 /var/run/balance/.keep-balance
> ========
> The same balance command works on Ubuntu 16.04.6.

The error is produced by the following code in balance.c:

  stat(SHMDIR, &buffer);
  if (!S_ISDIR(buffer.st_mode)) {
    mode_t old = umask(0);
    if (mkdir(SHMDIR, 01777) < 0) {
      if(errno != EEXIST) {
        fprintf(stderr, "ERROR: rendezvous directory not available and/or
creatable\n");
        fprintf(stderr, "       please create %s with mode 01777 like this: \n",
SHMDIR);
        fprintf(stderr, "       # mkdir -m 01777 %s\n", SHMDIR);
        umask(old);
        exit(EX_UNAVAILABLE);
      }
    }
    umask(old);
  }

where balance.h defines:
#define SHMDIR          "/var/run/balance/"

I ran mkdir under strace on a similar directory and got the expected errno:
$ ls -dglo /var/run/blkid
drwxrwxrwt+ 1 0 Mar 23 05:30 /var/run/blkid
$ strace -o mkdir.strace /bin/mkdir -m01777 /var/run/blkid/
/usr/bin/mkdir: cannot create directory ‘/var/run/blkid/’: File exists
$ grep -m1 ', errno' mkdir.strace
58   71709 [main] mkdir 5564 mkdir: -1 = mkdir(/var/run/blkid, 1005), errno 17
$ fgrep -w EEXIST /usr/include/sys/errno.h
#define EEXIST 17       /* File exists */

You could run balance under strace to see the errno reported:
$ strace -o balance.strace balance -d -f -b 127.0.0.1 1080 127.0.0.1:1090
and scan balance.strace log for the mkdir call and errno value as above, and
what happens after.

If the strace output does not show enough info, you may have to install the
balance-debuginfo package to be able to run balance under gdb, to see the mkdir
errno value returned, and what happens after.

The quoted code is not very robust, as buffer is on the stack so starts with
random bits, and the stat result is not checked to see if it succeeds, before
checking the mode, which may be unset; it assumes static zero initialization,
failing the mode check if stat fails; it would be safer rewritten as:

  if (stat(SHMDIR, &buffer) < 0 ||
      !S_ISDIR(buffer.st_mode)) {

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

This email may be disturbing to some readers as it contains
too much technical detail. Reader discretion is advised.

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple



More information about the Cygwin mailing list