当我以常规用户的身份手动运行脚本时,一切正常。但是,如果收到一封电子邮件并通过管道发送到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
脚本运行在已添加到拨号组的“监视用户”下,“后缀用户”(Postfix User)也在“拨号”中运行。
在我的脚本中,我运行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的设置有问题。