我正在尝试写入 /sys/kernel/config/usb_gadget
下的系统文件与 fs.writeFileSync
但是在写 ""
时作为内容,文件保持不变(原始内容完好无损)并导致
Error: EBUSY: resource busy or locked, write
at Object.writeSync (fs.js:581:3)
at Object.writeFileSync (fs.js:1275:26)
at Socket.<anonymous> (/opt/sterling/ip-kvm-interface/app.js:249:6)
at Socket.emit (events.js:210:5)
at /opt/sterling/ip-kvm-interface/node_modules/socket.io/lib/socket.js:528:12
at processTicksAndRejections (internal/process/task_queues.js:75:11) {
errno: -16,
syscall: 'write',
code: 'EBUSY'
}
在写一些其他内容时。目标写入文件的权限为 777。
是
fs.writeFileSync
无法写入 sys
下的文件还是我错过了其他东西?使用
fsuser /sys/kernel/config/usb_gadget/kvm-gadget/UDC
不返回任何内容(即使 Node 进程正在运行)和 lsof | grep /sys/kernel/config/usb_gadget/kvm-gadget/UDC
也不返回任何内容。我必须要
spawn
echo
使其工作的过程(不是首选但我想到了 - 因为不确定如何将其转换为同步任务)?
最佳答案
https://github.com/nodejs/help/issues/2459
Are there undocumented limitations to fs.writeFileSync that I am unaware of?
Nothing specific to fs.writeFileSync(), you can get the same error with a plain C program.
/sys/kernel/config/usb_gadget is not a real file, it's a communication channel with the kernel's usb gadget driver. It's that driver that is returning the error.
(I could point you to the line of code if you're really interested. It's drivers/usb/gadget/configfs.c in the kernel source tree in any case.)
关于Node.js:使用 fs.writeFileSync 写入系统文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59996022/