Skip to content
This repository was archived by the owner on Jun 8, 2022. It is now read-only.
This repository was archived by the owner on Jun 8, 2022. It is now read-only.

ln -sf only appears as DELETE on linux #102

@bobrik

Description

@bobrik
ln -sf /var/log/scribe/wtf_125 /var/log/scribe/wtf_current

appears as:

2014/07/08 13:28:03 "/var/log/scribe/wtf_current": DELETE

in strace it looks like this:

stat("/var/log/scribe/wtf_current", {st_mode=S_IFREG|0600, st_size=29, ...}) = 0
lstat("/var/log/scribe/wtf_current", {st_mode=S_IFLNK|0777, st_size=23, ...}) = 0
stat("/var/log/scribe/wtf_125", {st_mode=S_IFREG|0600, st_size=29, ...}) = 0
symlink("/var/log/scribe/wtf_125", "/var/log/scribe/wtf_current") = -1 EEXIST (File exists)
unlink("/var/log/scribe/wtf_current")   = 0
symlink("/var/log/scribe/wtf_125", "/var/log/scribe/wtf_current") = 0

At the same time, this works as expected:

rm /var/log/scribe/wtf_current; ln -s /var/log/scribe/wtf_125 /var/log/scribe/wtf_current
2014/07/08 13:29:23 "/var/log/scribe/wtf_current": DELETE
2014/07/08 13:29:23 "/var/log/scribe/wtf_current": CREATE
unlinkat(AT_FDCWD, "/var/log/scribe/wtf_current", 0) = 0
... different process ...
stat("/var/log/scribe/wtf_current", 0x7fffcbc6baa0) = -1 ENOENT (No such file or directory)
symlink("/var/log/scribe/wtf_125", "/var/log/scribe/wtf_current") = 0

The next C program gives correct events with probability ~80%:

#include <unistd.h>

int main() {
    unlink("/var/log/scribe/wtf_current");
    usleep(1);
    symlink("/var/log/scribe/wtf_125", "/var/log/scribe/wtf_current");
    return 0;
}

Removing usleep leads to absence of CREATE events.

I suspect race condition somewhere.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions