/dev/ttyACM0 Postfix 管道时文件不存在

/dev/ttyACM0 File does not exist while Postfix pipe

当我 运行 以普通用户手动编写脚本时,一切正常。但是如果收到一封电子邮件并通过管道传输到 Go 脚本中,我无法打开串行端口,因为文件不存在。

postfix   1239  1025  0 13:20 ? 00:00:00 pipe -n watchParadox -t unix flags=F user=watch argv=/usr/local/bin/watch -paradox
watch     1240  1239  0 13:20 ? 00:00:00 /usr/local/bin/watch -paradox

脚本 运行ning 在已添加到拨出组的 watch 用户下,postfix 用户也在拨出中。

在我的脚本中,我 运行 ls -la 命令找出哪些文件确实存在:

drwxr-xr-x   6 root root  380 Feb 25 13:19 .
dr-xr-xr-x. 18 root root 4096 Feb 22 17:53 ..
lrwxrwxrwx   1 root root   11 Feb 25 13:19 core -> /proc/kcore
lrwxrwxrwx   1 root root   13 Feb 25 13:19 fd -> /proc/self/fd
crw-rw-rw-   1 root root 1, 7 Feb 25 13:19 full
drwxr-xr-x   2 root root    0 Feb 25 13:19 hugepages
lrwxrwxrwx   1 root root   28 Feb 25 13:19 log -> /run/systemd/journal/dev-log
drwxrwxrwt   2 root root   40 Feb 25 13:19 mqueue
crw-rw-rw-   1 root root 1, 3 Feb 25 13:19 null
lrwxrwxrwx   1 root root    8 Feb 25 13:19 ptmx -> pts/ptmx
drwxr-xr-x   2 root root    0 Feb 25 13:19 pts
crw-rw-rw-   1 root root 1, 8 Feb 25 13:19 random
drwxrwxrwt   2 root root   40 Feb 25 13:19 shm
lrwxrwxrwx   1 root root   15 Feb 25 13:19 stderr -> /proc/self/fd/2
lrwxrwxrwx   1 root root   15 Feb 25 13:19 stdin -> /proc/self/fd/0
lrwxrwxrwx   1 root root   15 Feb 25 13:19 stdout -> /proc/self/fd/1
crw-rw-rw-   1 root root 5, 0 Feb 25 13:19 tty
crw-rw-rw-   1 root root 1, 9 Feb 25 13:19 urandom 

我确定以下文件存在,但在执行后缀管道时未显示。

crw-rw---- 1 root dialout 166, 0 25. úno 13.19 ttyACM0

我在文件上尝试了 chmod 777,但在那个部门没有成功。通过使用 Go 函数的 https://github.com/tarm/serial 库打开文件:

os.OpenFile("ttyACM0", syscall.O_RDWR|syscall.O_NOCTTY|syscall.O_NONBLOCK, 0666)

结果

ttyACM0: no such file or directory

问题不在于路径,因为我尝试了相对路径(使用 chdir)和绝对路径,结果完全相同。

我什至禁用了 SELinux,这不是我想做的,但为了寻找解决方案,我尝试了任何方法。

代码没有问题,因为脚本的手动执行正确通过。我认为 Linux 设置有问题。

ttyACM0 的正确路径是 /dev/ttyACM0。您定义一个 udev 规则以在附加时设置文件模式。

如果您的程序无法访问它,则可能是您的程序运行了 chrooted()。

这似乎确实是 Linux 问题,而且它的一些底层结构我不明白。我是运行 Fedora25 但是在Debian8 上没有出现这个问题。