Error[8]: Undefined offset: 2, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述我有一个GNU / Linux应用程序,它使用了许多共享内存对象.它可能会在同一系统上运行多次.为了保持整洁,我首先在/ dev / shm中为每个共享内存对象集创建一个目录. 问题是在较新的GNU / Linux发行版上,我似乎不再能够在/ dev / shm的子目录中创建它们. 以下是一个最小的C程序,说明了我在说什么: /*********************************** 我有一个GNU / Linux应用程序,它使用了许多共享内存对象.它可能会在同一系统上运行多次.为了保持整洁,我首先在/ dev / shm中为每个共享内存对象集创建一个目录.

问题是在较新的GNU / linux发行版上,我似乎不再能够在/ dev / shm的子目录中创建它们.

以下是一个最小的C程序,说明了我在说什么:

/****************************************************************************** shm_minimal.c** Test shm_open()** Expect to create shared memory file in:*  /dev/shm/*  └── my_dir*      └── shm_name** NOTE: Only visible on filesystem during execution.  I try to be nice,and*       clean up after myself.** Compile with:*   $gcc -lrt shm_minimal.c -o shm_minimal*******************************************************************************/#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <fcntl.h>#include <errno.h>#include <sys/mman.h>#include <sys/stat.h>#include <sys/types.h>int main(int argc,const char* argv[]) {  int shm_fd = -1;  char* shm_dir = "/dev/shm/my_dir";  char* shm_file = "/my_dir/shm_name";      /* does NOT work */  //char* shm_file = "/my_dir_shm_name";    /* works */  // Create directory in /dev/shm  mkdir(shm_dir,0777);  // make shared memory segment  shm_fd = shm_open(shm_file,O_RDWR | O_CREAT,0600);  if (-1 == shm_fd) {    switch (errno) {    case EINVAL:      /* Confirmed on:       *  kernel v3.14,GNU libc v2.19  (Archlinux)       *  kernel v3.13,GNU libc v2.19  (Ubuntu 14.04 Beta 2)       */      perror("FAIL - EINVAL");      return 1;    default:      printf("Some other problem not being tested\n");      return 2;    }  } else {    /* Confirmed on:     *  kernel v3.8,GNU libc v2.17    (Mint 15)     *  kernel v3.2,GNU libc v2.15    (Xubuntu 12.04 LTS)     *  kernel v3.1,GNU libc v2.13    (Debian 6.0)     *  kernel v2.6.32,GNU libc v2.12 (RHEL 6.4)     */    printf("Success !!!\n");  }  // clean up  close(shm_fd);  shm_unlink(shm_file);  rmdir(shm_dir);  return 0;}/* vi: set ts=2 sw=2 ai expandtab: */

当我在一个相当新的发行版上运行这个程序时,对shm_open()的调用返回-1,并且errno设置为EINVAL.但是,当我运行较旧的东西时,它会按预期在/ dev / shm / my_dir中创建共享内存对象.

对于更大的应用程序,解决方案很简单.我可以使用公共前缀而不是目录.

如果你可以帮助我了解这种明显的行为改变,那将会非常有帮助.我怀疑其他人可能会尝试做类似的事情.

解决方法 事实证明,问题源于GNU libc如何验证共享内存名称.具体来说,共享内存对象现在必须位于shmfs挂载点的根目录.

由于错误BZ #16274,这在glibc git commit b20de2c3d9中发生了变化.

具体来说,改变是这样的:

if (name[0] == '[+++]' || namelen > name_MAX || strchr (name,'/') != NulL)

现在不允许文件名中的任何位置使用’/'(不包括前导’/’)

总结

以上是内存溢出为你收集整理的在/ dev / shm的子目录中创建共享内存时,linux-shm_open()因EINVAL而失败全部内容,希望文章能够帮你解决在/ dev / shm的子目录中创建共享内存时,linux-shm_open()因EINVAL而失败所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
在 devshm的子目录中创建共享内存时,linux-shm_open()因EINVAL而失败_系统运维_内存溢出

在 devshm的子目录中创建共享内存时,linux-shm_open()因EINVAL而失败

在 devshm的子目录中创建共享内存时,linux-shm_open()因EINVAL而失败,第1张

概述我有一个GNU / Linux应用程序,它使用了许多共享内存对象.它可能会在同一系统上运行多次.为了保持整洁,我首先在/ dev / shm中为每个共享内存对象集创建一个目录. 问题是在较新的GNU / Linux发行版上,我似乎不再能够在/ dev / shm的子目录中创建它们. 以下是一个最小的C程序,说明了我在说什么: /*********************************** 我有一个GNU / Linux应用程序,它使用了许多共享内存对象.它可能会在同一系统上运行多次.为了保持整洁,我首先在/ dev / shm中为每个共享内存对象集创建一个目录.

问题是在较新的GNU / linux发行版上,我似乎不再能够在/ dev / shm的子目录中创建它们.

以下是一个最小的C程序,说明了我在说什么:

/****************************************************************************** shm_minimal.c** Test shm_open()** Expect to create shared memory file in:*  /dev/shm/*  └── my_dir*      └── shm_name** NOTE: Only visible on filesystem during execution.  I try to be nice,and*       clean up after myself.** Compile with:*   $gcc -lrt shm_minimal.c -o shm_minimal*******************************************************************************/#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <fcntl.h>#include <errno.h>#include <sys/mman.h>#include <sys/stat.h>#include <sys/types.h>int main(int argc,const char* argv[]) {  int shm_fd = -1;  char* shm_dir = "/dev/shm/my_dir";  char* shm_file = "/my_dir/shm_name";      /* does NOT work */  //char* shm_file = "/my_dir_shm_name";    /* works */  // Create directory in /dev/shm  mkdir(shm_dir,0777);  // make shared memory segment  shm_fd = shm_open(shm_file,O_RDWR | O_CREAT,0600);  if (-1 == shm_fd) {    switch (errno) {    case EINVAL:      /* Confirmed on:       *  kernel v3.14,GNU libc v2.19  (Archlinux)       *  kernel v3.13,GNU libc v2.19  (Ubuntu 14.04 Beta 2)       */      perror("FAIL - EINVAL");      return 1;    default:      printf("Some other problem not being tested\n");      return 2;    }  } else {    /* Confirmed on:     *  kernel v3.8,GNU libc v2.17    (Mint 15)     *  kernel v3.2,GNU libc v2.15    (Xubuntu 12.04 LTS)     *  kernel v3.1,GNU libc v2.13    (Debian 6.0)     *  kernel v2.6.32,GNU libc v2.12 (RHEL 6.4)     */    printf("Success !!!\n");  }  // clean up  close(shm_fd);  shm_unlink(shm_file);  rmdir(shm_dir);  return 0;}/* vi: set ts=2 sw=2 ai expandtab: */

当我在一个相当新的发行版上运行这个程序时,对shm_open()的调用返回-1,并且errno设置为EINVAL.但是,当我运行较旧的东西时,它会按预期在/ dev / shm / my_dir中创建共享内存对象.

对于更大的应用程序,解决方案很简单.我可以使用公共前缀而不是目录.

如果你可以帮助我了解这种明显的行为改变,那将会非常有帮助.我怀疑其他人可能会尝试做类似的事情.

解决方法 事实证明,问题源于GNU libc如何验证共享内存名称.具体来说,共享内存对象现在必须位于shmfs挂载点的根目录.

由于错误BZ #16274,这在glibc git commit b20de2c3d9中发生了变化.

具体来说,改变是这样的:

if (name[0] == '' || namelen > name_MAX || strchr (name,'/') != NulL)

现在不允许文件名中的任何位置使用’/'(不包括前导’/’)

总结

以上是内存溢出为你收集整理的在/ dev / shm的子目录中创建共享内存时,linux-shm_open()因EINVAL而失败全部内容,希望文章能够帮你解决在/ dev / shm的子目录中创建共享内存时,linux-shm_open()因EINVAL而失败所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/1028178.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存