question on tty open and close
Hi,
in tty_io.c::tty_open():
if (!retval) {
if (tty->driver->open)
retval = tty->driver->open(tty, filp);
else
retval = -ENODEV;
}
filp->f_flags = saved_flags;
if (!retval && test_bit(TTY_EXCLUSIVE, &tty->flags) && !capable(CAP_SYS_ADMIN))
retval = -EBUSY;
if (retval) {
#ifdef TTY_DEBUG_HANGUP
printk(KERN_DEBUG "error %d in opening %s...", retval,
tty->name);
#endif
release_dev(filp);We find that a failure in open() leads to release_dev() being called. release_dev() calls close():
if (tty->driver->close) tty->driver->close(tty, filp);
So we have a file that's closed although open() never succeeded? What's the reason for that?
Regards
Oliver
From: [email protected]
Quoted 1 line
in
tty_io.c::tty_open():
[snip]
Quoted 7 lines
We find that a failure in
open()leads torelease_dev()being called.release_dev()callsclose():if (tty->driver->close) tty->driver->close(tty, filp);So we have a file that's closed although
open()never succeeded?
That's correct! It's been a pain in my butt for years.
Quoted 1 line
What's the reason for that?
No idea. Would *love* to hear an explanation.
..Stu
Am Mittwoch, 28. März 2007 15:10 schrieb Stuart MacDonald:
Quoted 9 lines
Quoted 7 lines
We find that a failure in
open()leads torelease_dev()being called.release_dev()callsclose():if (
tty->driver->close)
tty->driver->close(tty, filp);So we have a file that's closed although
open()never succeeded?That's correct! It's been a pain in my butt for years.
How did you deal with that proctological issue?
Regards
Oliver
From: Oliver Neukum [mailto:[email protected]]
Quoted 5 lines
Am Mittwoch, 28. März 2007 15:10 schrieb Stuart MacDonald:
Quoted 1 line
Quoted 1 line
We find that a failure in
open()leads torelease_dev()being called.
Quoted 2 lines
Quoted 2 lines
release_dev()callsclose():
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
if (
tty->driver->close)
tty->driver->close(tty, filp);So we have a file that's closed although
open()never succeeded?That's correct! It's been a pain in my butt for years.
How did you deal with that proctological issue?
Just make sure the close() handles the situation properly. It makes reference counting... fun.
The serial driver has always handled it like this.
..Stu
Quoted 10 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
So we have a file that's closed although
open()never succeeded?That's correct! It's been a pain in my butt for years.
How did you deal with that proctological issue?
Just make sure the
close()handles the situation properly. It makes reference counting... fun.The serial driver has always handled it like this.
I'm also not aware of any reason other than history, which means if someone cares to double check the other drivers there really shouldn't be an obstacle to "fixing" this behaviour.
Unless anyone knows different ?
Alan
Quoted 5 lines · Alan Cox
I'm also not aware of any reason other than history, which means if someone cares to double check the other drivers there really shouldn't be an obstacle to "fixing" this behaviour.
Unless anyone knows different ?
As long as the new behavior continues to call driver->close() if driver->open() succeeds then I see no problem.
If individual drivers are correctly doing internal reference counting to handle driver->close() calls without a preceding successful driver->open() call (usually just doing nothing), then they should continue to operate correctly without the extra and unnecessary driver->close().
Signature · 2 lines
Paul Fulghum Microgate Systems, Ltd.
Quoted 3 lines
As long as the new behavior continues to call
driver->close()ifdriver->open()succeeds
then I see no problem.
It breaks if any existing driver is doing no cleanup in ->open() when it fails but relying upon ->close() being called. That is what needs auditing first of all.
Quoted 3 lines · Alan Cox
It breaks if any existing driver is doing no cleanup in ->open() when it fails but relying upon ->close() being called. That is what needs auditing first of all.
Yes, I did not think of that.
Signature · 2 lines
Paul Fulghum Microgate Systems, Ltd.
Hi Alan,
Quoted 7 lines
Quoted 3 lines
As long as the new behavior continues to call
driver->close()ifdriver->open()succeeds
then I see no problem.It breaks if any existing driver is doing no cleanup in ->open() when it fails but relying upon ->close() being called. That is what needs auditing first of all.
I know at least that the Bluetooth TTY emulation (RFCOMM) will break since I have a big fat warning in my code:
/* We don't leak this refcount. For reasons which are not entirely
clear, the TTY layer will call our ->close() method even if the
open fails. We decrease the refcount there, and decreasing it
here too would cause breakage. */
dev = rfcomm_dev_get(id);
if (!dev)
return -ENODEV;Regards
Marcel