【问题标题】:fuse: error creating thread: Resource temporarily unavailable保险丝:错误创建线程:资源暂时不可用
【发布时间】:2019-08-14 22:17:57
【问题描述】:

在为最简单的 fuse 文件系统编写了 getattr 和 readdir 函数后,我得到 fuse: error creating thread: Resource暂时不可用。 。我想知道我的代码哪里出错了

我已经搜索过这个,但找不到任何让我满意的东西。在我看来,它超出了线程限制,但我不知道如何修复它。我用

编译它
$ gcc passthrough.c -o passthrough `pkg-config fuse --cflags --libs`
passthrough.c:65:2: warning: initialization from incompatible pointer type [enabled by default]
  .getattr = e_getattr,
  ^
passthrough.c:65:2: warning: (near initialization for 'oper.getattr') [enabled by default]

这是程序的源代码

#define FUSE_USE_VERSION 26

#include <fuse.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <dirent.h>
#include <errno.h>
#include <sys/time.h>
#include <limits.h>

char rootdir[100];

void get_fullpath(char fpath[PATH_MAX], const char *path){
    strcpy(fpath,rootdir);
    strncat(fpath,path,PATH_MAX);
    printf("[fullpath] file: %s\n",fpath);
}

int e_getattr(const char *path, struct stat *stbuf, struct fuse_file_info *fi){
    (void)fi;
    int res;

    char fpath[PATH_MAX];
    get_fullpath(fpath,path);

    printf("[getattr] file: %s\n",fpath);

    res = lstat(fpath,stbuf);
    if (res == -1)
        return -errno;
    return 0;
}

int e_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi){
    DIR *dp;
    struct dirent *de;

    (void)offset;
    (void)fi;

    char fpath[PATH_MAX];
    get_fullpath(fpath,path);
    printf("[readdir] file: %s\n",fpath);

    dp = opendir(fpath);
    if (dp == NULL)
        return -errno;

    while ((de = readdir(dp)) != NULL){
        struct stat st;
        memset(&st,0,sizeof(st));
        st.st_ino = de->d_ino;
        st.st_mode = de->d_type << 12;
        if (filler(buf,de->d_name,&st,0))
            break;
    }
    closedir(dp);
    return 0;
}

struct fuse_operations oper = {
    .getattr = e_getattr,
    .readdir = e_readdir,
};

int main(int argc, char * argv[]){
    umask(0);
    realpath(argv[2],rootdir);
    printf("Real path is %s\n",rootdir);
    return fuse_main(argc,argv,&oper,NULL);
}

这是我得到的输出

[fullpath] file: /home/echo/passthrough/test/
[getattr] file: /home/echo/passthrough/test/
[fullpath] file: /home/echo/passthrough/test/
[getattr] file: /home/echo/passthrough/test/
[fullpath] file: /home/echo/passthrough/test/
[getattr] file: /home/echo/passthrough/test/
[fullpath] file: /home/echo/passthrough/test/
[getattr] file: /home/echo/passthrough/test/
[fullpath] file: /home/echo/passthrough/test/
[getattr] file: /home/echo/passthrough/test/
[fullpath] file: /home/echo/passthrough/test/
[getattr] file: /home/echo/passthrough/test/
...
...
...
[fullpath] file: /home/echo/passthrough/test/
[getattr] file: /home/echo/passthrough/test/
fuse: error creating thread: Resource temporarily unavailable
[fullpath] file: /home/echo/passthrough/test/
[getattr] file: /home/echo/passthrough/test/

【问题讨论】:

  • 我想知道为什么passthrough.c:65:2: warning: initialization from incompatible pointer type [enabled by default] .getattr = e_getattr, 会发生...似乎与int(* getattr )(const char *, struct stat *, struct fuse_file_info *fi) 匹配...
  • 这也是让我困惑的事情之一,我从 libfuse github 关注 passthrough.c
  • 推荐阅读:how to use fuse
  • OT: about: realpath(argv[2],rootdir); 在没有首先检查argc 以确保实际输入了预期的命令行参数之前,永远不要访问argv[0] 以外的地方。当它们不是由用户输入时,输出到stderr,类似的USAGE消息:fprintf( stderr, "USAGE: %s &lt;descriptiion of each parameter&gt;\n", argv[0] ); followed by: exit(EXIT_FAILURE);`另外,argv[1]的期望是什么?它从未在发布的代码中使用
  • 关于:strncat(fpath,path,PATH_MAX); 不得使用:PATH_MAX,因为数组fpath 的一部分已经包含来自path 的数据。所以第三个参数应该类似于:PATH_MAX - (strlen( path ) +1)

标签: c fuse


【解决方案1】:

问题出在函数:e_getattr()应该写成:

static int e_getattr(const char *path, struct stat *stbuf )
{
    int res;

    char fpath[PATH_MAX];
    get_fullpath(fpath,path);

    printf("[getattr] file: %s\n",fpath);

    res = lstat(fpath,stbuf);
    if (res == -1)
        return -ENONET;
    return 0;
}

注意添加的修饰符static

注意去掉第三个函数参数

注意修改返回(错误时)为-ENONET

另外包含的头文件列表也缺少该语句;

#include <stdlib.h> // exposes function: `realpath()`

函数:e_getattr()也需要`static修饰符

【讨论】:

  • 它解决了编译期间的警告,但是运行的输出仍然与答案中的相同
  • 你的意思是:“喜欢问题”?
  • 问题是关于编译器警告以及无法启动另一个线程。这个答案是关于编译器警告的,因为它们需要首先更正
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-11
  • 1970-01-01
  • 1970-01-01
  • 2015-06-28
  • 2010-11-21
  • 2012-03-07
相关资源
最近更新 更多