I added debuging as follows: /* no O_EXCL, existence check is via the fcntl lock */ lockfile_fd = open(lockfile_name.buf, O_NONBLOCK|O_CREAT|O_WRONLY, 0644); if (lockfile_fd == -1) { ret = errno; DEBUG(1, ("%s: open failed: %s\n", __func__, strerror(errno))); return ret; } DEBUG(1, ("lock file name is: %s\n",lockfile_name.buf)); lck = (struct flock) { .l_type = F_WRLCK, .l_whence = SEEK_SET }; ret = fcntl(lockfile_fd, F_SETLK, &lck); if (ret == -1) { ret = errno; DEBUG(1, ("%s: fcntl failed: %s\n", __func__, strerror(ret))); goto fail_close; } DEBUG(1, ("unique is %u\n", unique)); unique_len = snprintf(buf, sizeof(buf), "%ju\n", (uintmax_t)unique); DEBUG(1, ("unique_len is: %i\n", unique_len)); /* shorten a potentially preexisting file */ ret = ftruncate(lockfile_fd, unique_len); if (ret == -1) { ret = errno; DEBUG(1, ("%s: ftruncate failed: %s\n", __func__, strerror(ret))); goto fail_unlink; } And the output of ./smbd -i -d 2 is: lock file name is: /opt/local/samba4/var/cache/lck/7561 unique is 0 unique_len is: -1 messaging_dgm_lockfile_create: ftruncate failed: Invalid argument messaging_dgm_init: messaging_dgm_create_lockfile failed: Invalid argument messaging_dgm_init failed: Invalid argument Tom Schulz Applied Dynamics Intl. schulz at adi.com
On Tue, Feb 10, 2015 at 10:25:06PM -0500, Thomas Schulz wrote:> > DEBUG(1, ("unique is %u\n", unique)); > unique_len = snprintf(buf, sizeof(buf), "%ju\n", (uintmax_t)unique); > DEBUG(1, ("unique_len is: %i\n", unique_len)); > > /* shorten a potentially preexisting file */ > > ret = ftruncate(lockfile_fd, unique_len); > if (ret == -1) { > ret = errno; > DEBUG(1, ("%s: ftruncate failed: %s\n", __func__, > strerror(ret))); > goto fail_unlink; > } > > And the output of ./smbd -i -d 2 is: > > lock file name is: /opt/local/samba4/var/cache/lck/7561 > unique is 0 > unique_len is: -1 > messaging_dgm_lockfile_create: ftruncate failed: Invalid argument > messaging_dgm_init: messaging_dgm_create_lockfile failed: Invalid argument > messaging_dgm_init failed: Invalid argumentAh ok - I expected as much. snprintf seems to be broken in that it's returning -1. Is this our snprintf or one from Solaris ? Can you try and track down why it's returning -1 ?
On Tue, Feb 10, 2015 at 08:59:21PM -0800, Jeremy Allison wrote:> On Tue, Feb 10, 2015 at 10:25:06PM -0500, Thomas Schulz wrote: > > > > DEBUG(1, ("unique is %u\n", unique)); > > unique_len = snprintf(buf, sizeof(buf), "%ju\n", (uintmax_t)unique); > > DEBUG(1, ("unique_len is: %i\n", unique_len)); > > > > /* shorten a potentially preexisting file */ > > > > ret = ftruncate(lockfile_fd, unique_len); > > if (ret == -1) { > > ret = errno; > > DEBUG(1, ("%s: ftruncate failed: %s\n", __func__, > > strerror(ret))); > > goto fail_unlink; > > } > > > > And the output of ./smbd -i -d 2 is: > > > > lock file name is: /opt/local/samba4/var/cache/lck/7561 > > unique is 0 > > unique_len is: -1 > > messaging_dgm_lockfile_create: ftruncate failed: Invalid argument > > messaging_dgm_init: messaging_dgm_create_lockfile failed: Invalid argument > > messaging_dgm_init failed: Invalid argument > > Ah ok - I expected as much. snprintf seems to be > broken in that it's returning -1. > > Is this our snprintf or one from Solaris ? Can > you try and track down why it's returning -1 ?According to the Linux man pages, snprintf shouldn't return -1. However: The glibc implementation of the functions snprintf() and vsnprintf() conforms to the C99 standard, that is, behaves as described above, since glibc version 2.1. Until glibc 2.0.6 they would return -1 when the output was truncated.
On Tue, Feb 10, 2015 at 08:59:21PM -0800, Jeremy Allison wrote:> Ah ok - I expected as much. snprintf seems to be > broken in that it's returning -1. > > Is this our snprintf or one from Solaris ? Can > you try and track down why it's returning -1 ?Maybe Solaris' snprintf does not know about the %j modifier? Ralph, can you check? Volker -- SerNet GmbH, Bahnhofsallee 1b, 37081 G?ttingen phone: +49-551-370000-0, fax: +49-551-370000-9 AG G?ttingen, HRB 2816, GF: Dr. Johannes Loxen http://www.sernet.de, mailto:kontakt at sernet.de
On Wed, Feb 11, 2015 at 11:13:42AM +0100, Volker Lendecke wrote:> On Tue, Feb 10, 2015 at 08:59:21PM -0800, Jeremy Allison wrote: > > Ah ok - I expected as much. snprintf seems to be > > broken in that it's returning -1. > > > > Is this our snprintf or one from Solaris ? Can > > you try and track down why it's returning -1 ? > > Maybe Solaris' snprintf does not know about the %j modifier?Crap... Probably our own libreplace snprintf version does not do it.... Volker -- SerNet GmbH, Bahnhofsallee 1b, 37081 G?ttingen phone: +49-551-370000-0, fax: +49-551-370000-9 AG G?ttingen, HRB 2816, GF: Dr. Johannes Loxen http://www.sernet.de, mailto:kontakt at sernet.de