/dev/ttyACM0 文件不存在,而 Postfix 管道存在问题。

huangapple go评论78阅读模式
英文:

/dev/ttyACM0 File does not exist while Postfix pipe

问题

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

脚本正在以watch用户身份运行,该用户已添加到dialout组中,为了确保,postfix用户也在dialout组中。

在我的脚本中,我运行了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

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

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: 没有该文件或目录

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

我甚至禁用了SELinux,这不是我想要的,但在寻找解决方案时,我尝试了任何可能的方法。

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

英文:

When I run script as regular user manually, everything is OK. But if an email is received and piped into Go script, I can not open serial port because file does not exist.

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

Script is running under watch user who has been added to dialout group, postfix user, just to be sure, is in dialout also.

In my script I ran ls -la command to find out which files do truly exist:

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 

I am certain following file exists but is not shown when postfix pipe is executed.

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

I tried chmod 777 on the file but no luck in that department. Opening file via https://github.com/tarm/serial library which uses Go function:

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

results with

> ttyACM0: no such file or directory

The problem is not the path because I tried relative (using chdir) and absolute with same exact outcome.

I even disabled SELinux which is not what I want to do but in search of solution I try anything.

Code is OK because manual execution of the script passes through properly. I think there is something wrong with Linux settings.

答案1

得分: 0

ttyACM0的正确路径是/dev/ttyACM0。当它连接时,您可以定义udev规则来设置文件模式。

如果您的程序无法访问该路径,可能是因为您的程序在chroot环境中运行。

英文:

The correct path the ttyACM0 is /dev/ttyACM0. You define a udev rules to set the file mode when it attaches.

If that is not reachable from your program, it might be the case that your program runs chrooted().

答案2

得分: 0

似乎是真正的Linux问题,涉及到我不理解的一些底层结构。我之前在运行Fedora 25时遇到了这个问题,但在Debian 8上没有发生。

英文:

It seems like it was truly Linux problem and some underlying fabrics of it which I do not understand. I was running Fedora25 but the problem does not occur on Debian8.

huangapple
  • 本文由 发表于 2017年2月25日 20:55:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/42456328.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定