build: suppress ignoring return value warnings Suppress ignoring return value warnings to fix compile issues with gcc5 The is actually a bug in gcc5 as it does not recognize the no-format-truncation option although it's silently accepted unless the source file under compilation had already generated some warnings before. Therefore suppress ignoring return value warnings which trigger the problem. Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
mount: try lazy unmount if normal one fails If umount call fails (e.g. because of some application accessing old path) the only chance of getting mount entry cleaned is receiving autofs expire packet. This isn't fully reliable: 1) Sometimes expire can happen before closing all handles. In such case a second unmount try will fail as well and there won't be a next one. 2) Expire happens after specified timeout. If device reappears quickly (e.g. due to being replugged or USB controller restart) it may be worth having old mount cleaned up earlier for better user experience. This problem can be easily handled by using MNT_DETACH (lazy) umount as a fallback. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
mount: create not working symlink when unmounting fails If device disappears but there is still some application trying to access it, unmounting will fail with the EBUSY errno. Unlinking /tmp/mounts/<symlink> would succeed but things could go wrong depending on the application accessing that path. If some app doesn't check if /tmp/mounts/<symlink> exists it could just create it and start writing to it filling RAM instead of saving data to a mounted drive. Moreover the next time mountd tries to create that symlink it will fail because there will be already a directory under that path. Things could go even worse once mountd fires /sbin/hotplug-call and other apps start using /tmp/mounts/<symlink> believing there's a mounteg storage there. To fix this, detect failed umount call and replace /tmp/mounts/<symlink> with a new symlink pointing to the not existing file. That will prevent applications from re-creating that directory and writing to it filling the RAM. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
mount: drop duplicated unlink() call from the mount_dev_del() There is no need to call unlink() there as mount_enum_drives() does it too, soon after calling mount_dev_del(). Also mount_enum_drives() does that for STATUS_EXPIRED - which is expected - as there is no unlink() call when device expires. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
mount: fix/improve unmounting log messages The message in mount_dev_del() had a typo and was printing non-existing directory: 1) mount->dev is valid for /tmp/run/mountd/ 2) mount->name is valid for uci_path (e.g. /tmp/mounts/) The old message was mixing /tmp/run/mountd/ with mount->name. While at it change mount_remove() to match updated mount_dev_del(). Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
mount: fix removing mount point if it's expired Kernel can report mount point as expired and when that happens mountd unmounts it. When such a device disappears it's still important to: 1) Cleanup directories 2) Call hotplug scripts Fix this by adding a new EXPIRED status and checking it when block device disappears. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
mount: struct mount: replace "mounted" and "ignore" fileds with a "status" There is no need to store status using these 2 separated fields. Obviously ignored mount should never get mounted. This change will also allow adding more statuses easily in the future if needed. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
mount: improve handling mounts table size This is static array with a size set to MAX_MOUNTED. Old code: 1) Was never using the last table entry/row 2) Was logging the same message for every mount entry above limit This fixes off-by-one, moves limit check to the proper place and uses "break" when needed. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>