【问题标题】:Reading from a Closed File Descriptor从已关闭的文件描述符中读取
【发布时间】:2019-10-22 11:51:36
【问题描述】:

我使用strace跟踪gimp-2.8.22中的openreadclosedup系统调用,使用以下命令:

strace -eread,openat,open,close,dup,dup2 gimp

gimp 中,我打开了一个名为babr.jpg 的图像。跟踪显示此图像已打开(文件描述符为 14)、读取和关闭。但是,紧接着,相同的文件描述符(14 在最后一次关闭后未打开)用于读取。这怎么可能? 这是跟踪的相关部分:

read(14, "\371\331\25\233M\311j\261b\271\332\240\33\315d\234\340y\236\217\323\206(\214\270x2\303S\212\252\254"..., 4096) = 4096
read(14, "t\260\265fv<\243.5A\324\17\221+\36\207\265&+rL\247\343\366\372\236\353\353'\226\27\27"..., 4096) = 318
close(14)                               = 0
openat(AT_FDCWD, "/home/ahmad/Pictures/babr.jpg", O_RDONLY) = 14
read(14, "\377\330\377\340\0\20JFIF\0\1\1\1\1,\1,\0\0\377\355(\212Photosho"..., 4096) = 4096
close(14)                               = 0
openat(AT_FDCWD, "/opt/gimp-2.8.22/lib/gimp/2.0/plug-ins/file-jpeg", O_RDONLY) = 19
read(19, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P[\0\0\0\0\0\0"..., 4096) = 4096
close(19)                               = 0
close(20)                               = 0
read(19, "", 8)                         = 0
close(19)                               = 0
close(17)                               = 0
close(16)                               = 0
read(4, "\2\0\0\0\0\0\0\0", 16)         = 8
Gtk-^[[1;32mMessage^[[0m: ^[[34m15:09:02.956^[[0m: Failed to load module "canberra-gtk-module"
read(14, "\0\0\0\5", 4)                 = 4
read(14, "\0\0\0\23", 4)                = 4
read(14, "gimp-progress-init\0", 19)    = 19
read(14, "\0\0\0\2", 4)                 = 4

我还使用Pin 进行了检查,发现了相同的结果。

【问题讨论】:

  • 文件描述符可能被重用,因此与之前使用的文件无关。

标签: linux trace file-descriptor gimp strace


【解决方案1】:

第二个文件描述符#14 很可能是插件和 Gimp 之间的管道(空闲的句柄已被重用)。而且您不会跟踪管道的创建。

来自gimpplugin.c

  /* Open two pipes. (Bidirectional communication).
   */
  if ((pipe (my_read) == -1) || (pipe (my_write) == -1))
    {
      gimp_message (plug_in->manager->gimp, NULL, GIMP_MESSAGE_ERROR,
                    "Unable to run plug-in \"%s\"\n(%s)\n\npipe() failed: %s",
                    gimp_object_get_name (plug_in),
                    gimp_file_get_utf8_name (plug_in->file),
                    g_strerror (errno));
      return FALSE;
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-05
    • 2013-11-08
    • 1970-01-01
    • 1970-01-01
    • 2011-08-16
    • 1970-01-01
    相关资源
    最近更新 更多