Bug 13890 - nmbd fails to start with "Failed to create directory for pid files, check 'pid directory'"
Summary: nmbd fails to start with "Failed to create directory for pid files, check 'pi...
Status: NEW
Alias: None
Product: Samba 4.1 and newer
Classification: Unclassified
Component: Other (show other bugs)
Version: 4.10.0
Hardware: All Linux
: P5 normal (vote)
Target Milestone: ---
Assignee: Andrew Bartlett
QA Contact: Samba QA Contact
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-04-07 08:11 UTC by mail@andreasbaumann.cc
Modified: 2019-04-07 08:11 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description mail@andreasbaumann.cc 2019-04-07 08:11:09 UTC
Happening on Archlinux, systemd with /var/run symlinked to /run.

systemctl start nmb

[2019/04/07 08:36:32.254927, 0] ../../lib/util/become_daemon.c:122(exit_daemon)
exit_daemon: daemon failed to start: Failed to create directory for pid files, check 'pid directory', error code 17

pid directory is /var/run (default)

The root cause is a rewrite in Samba in lib/util/util.c in 4.10, 'directory_create_or_exist' which does:

ret = mkdir(dname, dir_perms);
...
if (ret != 0 && errno == EEXIST) {
  ...
  ret = lstat(dname, &sbuf);
  ...
  if (!S_ISDIR(sbuf.st_mode)) {
    return false;
  }
}

This means with /var/run being a symlink to /run, this fails.

lstat doesn't follow the symbolic link, but returns information about
the symbolic link.

I personally would use 'stat', follow the symlink and check if the
referenced file descriptor is a directory. 

Also I would first check if the directory already exists and not blindly
excute a 'mkdir' and check for EEXIST. I don't see the benefit of doing that.