• [^] # Re: Race conditions

    Posté par (site web personnel) . En réponse à la dépêche Exploiter inotify, c’est simple. Évalué à 2. Dernière modification le 25 novembre 2014 à 15:55.

    Ça semble plus être un problème du coté de pyinotify qu'une bizarrerie de l'API :

    $ inotifywait -rm /tmp/inotify/
    [...]
    $ mkdir /tmp/inotify/aze
    /tmp/inotify/ CREATE,ISDIR aze
    /tmp/inotify/ OPEN,ISDIR aze
    /tmp/inotify/ CLOSE_NOWRITE,CLOSE,ISDIR aze
    $ touch /tmp/inotify/aze/k
    /tmp/inotify/aze/ CREATE k
    /tmp/inotify/aze/ OPEN k
    /tmp/inotify/aze/ ATTRIB k
    /tmp/inotify/aze/ CLOSE_WRITE,CLOSE k
    $ mv /tmp/inotify/aze /tmp/
    /tmp/inotify/ MOVED_FROM,ISDIR aze
    /tmp/inotify/aze/ MOVE_SELF 
    $ mv /tmp/aze /tmp/inotify/
    /tmp/inotify/ MOVED_TO,ISDIR aze
    /tmp/inotify/ OPEN,ISDIR aze
    /tmp/inotify/ CLOSE_NOWRITE,CLOSE,ISDIR aze
    

    (inotifywait 3.14, Kernel 3.9.10)

    Pas de plainte lorsque le répertoire s'en va (le parent autant que le répertoire lui-même "voient" l'événement) et pas de problème particulier lorsque le répertoire revient.

    D'ailleurs inotifywait se débrouille pour ajouter à nouveau des watches dans ce répertoire (parce qu’il est en mode récursif, j'imagine) :

    $ ls -l /proc/$(pidof inotifywait)/fd | grep anon_inode:inotify
    lr-x------ 1 xfennec xfennec 64 25 nov. 15:37 3 -> anon_inode:inotify
    $ cat /proc/$(pidof inotifywait)/fdinfo/3 | grep inotify
    inotify wd:4 ino:162801 sdev:fd00001 mask:800afff ignored_mask:0 fhandle-bytes:8 fhandle-type:1 f_handle:01281600a35a90fa
    inotify wd:2 ino:162195 sdev:fd00001 mask:800afff ignored_mask:0 fhandle-bytes:8 fhandle-type:1 f_handle:952116009d5a90fa
    ls -lai /tmp/inotify/
    1450389 drwxrwxr-x 4 xfennec xfennec 4096 25 nov. 15:48 .
    1438977 drwxrwxrwt. 34 root root 20480 25 nov. 15:47 ..
    1452033 drwxrwxr-x 2 xfennec xfennec 4096 25 nov. 15:35 aze
    

    0x162801 = 1452033 (/tmp/inotify/aze)
    0x162195 = 1450389 (/tmp/inotify)