zoukankan      html  css  js  c++  java
  • lsof and dynamic array in bash/shell

    https://unix.stackexchange.com/questions/171519/lsof-warning-cant-stat-fuse-gvfsd-fuse-file-system


    FUSE and its access rights

    lsof by default checks all mounted file systems including FUSE - file systems implemented in user space which have special access rights in Linux.

    As you can see in this answer on Ask Ubuntu a mounted GVFS file system (special case of FUSE) is normally accessible only to the user which mounted it (the owner of gvfsd-fuse). Even root cannot access it. To override this restriction it is possible to use mount options allow_root and allow_other. The option must be also enabled in the FUSE daemon which is described for example in this answer ...but in your case you do not need to (and should not) change the access rights.

    Excluding file systems from lsof

    In your case lsof does not need to check the GVFS file systems so you can exclude the stat() calls on them using the -e option (or you can just ignore the waring):

    lsof -e /run/user/1000/gvfs
    

    Checking certain files by lsof

    You are using lsof to get information about all processes running on your system and only then you filter the complete output using grep. If you want to check just certain files and the related processes use the -f option without a value directly following it then specify a list of files after the "end of options" separator --. This will be considerably faster.

    lsof -e /run/user/1000/gvfs -f -- /tmp/report.csv
    

    General solution

    To exclude all mounted file systems on which stat() fails you can run something like this (in bash):

    x=(); for a in $(mount | cut -d' ' -f3); do test -e "$a" || x+=("-e$a"); done
    lsof "${x[@]}" -f -- /tmp/report.csv
    

    Or to be sure to use stat() (test -e could be implemented a different way):

    x=(); for a in $(mount | cut -d' ' -f3); do stat --printf= "$a" 2>/dev/null || x+=("-e$a"); done
    

    lsof always tries to obtain some basic information about all filesystems, even if the arguments happen to imply that no result will come from a particular filesystem. If it's unable to access a filesystem (specifically, to call stat at its mount point, as the message says), it complains.

    As root, you would normally have permission to access filesystems. However, due to the inner workings of FUSE, root does not automatically have all powers on a FUSE filesystem. This isn't a security feature (root can become the user who owns the filesystem and get access that way), it's a technical limitation.

    GVFS-FUSE is a FUSE interface to GVFS, which is a mechanism that allows Gnome applications to access virtual filesystems implemented by Gnome plugins: GVFS grants non-Gnome applications access to these virtual filesystems via the regular filesystem interface.


    -- 
    
    
    刘林强
    
    136-1133-1997
    liulinqiang@unipus.cn
    北京外研在线教育科技有限公司
    外语教学与研究出版社
  • 相关阅读:
    make、make clean、make install、make uninstall、make dist、make distcheck和make distclean
    Eclipse开发C/C++ 安装配置
    没有文件扩展“.js”的脚本引擎问题解决
    Linux目录架构详解
    Linux查看硬件信息以及驱动设备的命令
    23种设计模式彩图
    ACE在Linux下编译安装
    void及void指针含义的深刻解析
    centos7.x设置nginx开机自启动
    Centos7防火墙关闭和启用iptables操作
  • 原文地址:https://www.cnblogs.com/SZLLQ2000/p/8831749.html
Copyright © 2011-2022 走看看