0

I am using socat version 1.7.3.2 to create a character device from a VLAN Ethernet device for communication. I create the device using following command:

socat INTERFACE:wwan0.vlan_dev1,type=2 PTY,mode=0777,rawer,link="/dev/ser_vlan0" &

It creates files as:

/dev/ser_vlan0 -> /dev/pts/22

Even after the wwan0 device is removed, the files /dev/ser_vlan0 and /dev/pts/22 still exist.

Is there a way to remove these files automatically when wwan0 no longer exists?

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
Raj
  • 3,300
  • 8
  • 39
  • 67
  • 1
    While `socat` is still running? – Azeem Jun 28 '17 at 09:22
  • yes, the `socat` is still running but the network device is gone. So can it automatically clear the buffer and delete the device? – Raj Jun 29 '17 at 10:14
  • According to documentation, it does, in some cases. So, the `/dev/ser_vlan0` is the actual file and `/dev/pts/22` the symbolic link, right? Is this what that arrow `->` is for in your question? – Azeem Jun 29 '17 at 10:54
  • The closest thing that looks like the solution you want is [`unlink-close`](http://www.mit.edu/afs.new/athena/system/i386_deb50/os-ubuntu-9.04/usr/share/doc/socat/socat.html#OPTION_UNLINK_CLOSE). Can you test it and confirm? – Azeem Jun 29 '17 at 11:00
  • I tried with `unlink-close` and this doesn't work. The socat keeps the file open for sometime. It is not killed immediately. – Raj Jun 29 '17 at 11:21
  • But, it is killed, eventually? – Azeem Jun 29 '17 at 11:22
  • after sometime. I don't know what is the event that kills it. – Raj Jun 29 '17 at 11:22
  • Right. That delay could be due to the `timeout` i.e. `0.5` second. From [OPTIONS](http://www.mit.edu/afs.new/athena/system/i386_deb50/os-ubuntu-9.04/usr/share/doc/socat/socat.html#OPTIONS) documentation: **"`-t`: When one channel has reached EOF, the write part of the other channel is shut down. Then, socat waits [timeval] seconds before terminating. Default is 0.5 seconds. This timeout only applies to addresses where write and read part can be closed independently. When during the timeout interval the read part gives EOF, socat terminates without awaiting the timeout."** – Azeem Jun 29 '17 at 11:27
  • Can you test it with a smaller `timeout` value? – Azeem Jun 29 '17 at 11:30
  • Are you saying that `socat` itself was `kill`ed? – Azeem Jun 29 '17 at 11:52
  • If `socat` terminates on disconnecting device, you can run it in a loop as show in this post: https://stackoverflow.com/questions/28032549/socat-terminates-after-connection-close – Azeem Jun 29 '17 at 12:23
  • The option you specified `-t 0` works perfect for me. Please post that as an answer. :) – Raj Jun 29 '17 at 14:40
  • Finally! :) Sure. I'm posting that as an answer. I'd suggest that you update your question with your final command for it'll help others in future. – Azeem Jun 29 '17 at 15:11

1 Answers1

1

From socat's OPTIONS documentation:

-t < timeout >:

When one channel has reached EOF, the write part of the other channel is shut down. Then, socat waits seconds before terminating. Default is 0.5 seconds. This timeout only applies to addresses where write and read part can be closed independently. When during the timeout interval the read part gives EOF, socat terminates without awaiting the timeout.

You need to set the timeout as 0.

Azeem
  • 11,148
  • 4
  • 27
  • 40