#include "ovs-thread.h"
#include "timeval.h"
#include "util.h"
-#include "vlog.h"
+#include "openvswitch/vlog.h"
VLOG_DEFINE_THIS_MODULE(lockfile);
* symlink, not one for each. */
filename = follow_symlinks(filename_);
slash = strrchr(filename, '/');
+
+#ifdef _WIN32
+ char *backslash = strrchr(filename, '\\');
+ if (backslash && (!slash || backslash > slash)) {
+ slash = backslash;
+ }
+#endif
+
lockname = (slash
? xasprintf("%.*s/.%s.~lock~",
(int) (slash - filename), filename, slash + 1)
if (error == EACCES) {
error = EAGAIN;
}
- if (pid) {
+ if (pid == getpid()) {
+ VLOG_WARN("%s: cannot lock file because this process has already "
+ "locked it", lock_name);
+ } else if (pid) {
VLOG_WARN("%s: cannot lock file because it is already locked by "
"pid %ld", lock_name, (long int) pid);
} else {
retval = LockFileEx(lock_handle, LOCKFILE_EXCLUSIVE_LOCK
| LOCKFILE_FAIL_IMMEDIATELY, 0, 1, 0, &overl);
if (!retval) {
- VLOG_WARN("Failed to lock file : %s", ovs_lasterror_to_string());
- return EEXIST;
+ VLOG_DBG("Failed to lock file : %s", ovs_lasterror_to_string());
+ *pidp = getpid();
+ return EDEADLK;
}
lockfile = xmalloc(sizeof *lockfile);
/* Check whether we've already got a lock on that file. */
if (!stat(name, &s)) {
if (lockfile_find(s.st_dev, s.st_ino)) {
+ *pidp = getpid();
return EDEADLK;
}
} else if (errno != ENOENT) {