mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [TTY] exclusive mode question
@ 2005-06-09  8:49 moreau francis
  2005-06-09  9:36 ` Frederik Deweerdt
  0 siblings, 1 reply; 13+ messages in thread
From: moreau francis @ 2005-06-09  8:49 UTC (permalink / raw)
  To: linux-kernel

Hi

When a process open a tty in exclusive mode (using ioctl(X, TIOCEXCL)), can the
process be sure to be the only one using this tty ?
If so I can't find in kernel code any checks in "tty_open" method for verifying
that the tty has not been opened previously by another process when
"TTY_EXCLUSIVE" flag is set.

Thanks

           Francis


	

	
		
_____________________________________________________________________________ 
Découvrez le nouveau Yahoo! Mail : 1 Go d'espace de stockage pour vos mails, photos et vidéos ! 
Créez votre Yahoo! Mail sur http://fr.mail.yahoo.com

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [TTY] exclusive mode question
  2005-06-09  8:49 [TTY] exclusive mode question moreau francis
@ 2005-06-09  9:36 ` Frederik Deweerdt
  2005-06-09  9:59   ` moreau francis
  0 siblings, 1 reply; 13+ messages in thread
From: Frederik Deweerdt @ 2005-06-09  9:36 UTC (permalink / raw)
  To: moreau francis; +Cc: linux-kernel

Le 09/06/05 10:49 +0200, moreau francis écrivit:
> Hi
> 
> When a process open a tty in exclusive mode (using ioctl(X, TIOCEXCL)), can the
> process be sure to be the only one using this tty ?
> If so I can't find in kernel code any checks in "tty_open" method for verifying
> that the tty has not been opened previously by another process when
> "TTY_EXCLUSIVE" flag is set.
> 
I've just greped and I found :

if (!retval && test_bit(TTY_EXCLUSIVE, &tty->flags) && !capable(CAP_SYS_ADMIN))
	retval = -EBUSY;
in drivers/char/tty_io.c:tty_open

Which sources are you looking at?

Regards,
Frederik Deweerdt


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [TTY] exclusive mode question
  2005-06-09  9:36 ` Frederik Deweerdt
@ 2005-06-09  9:59   ` moreau francis
  2005-06-09 10:41     ` Frederik Deweerdt
  0 siblings, 1 reply; 13+ messages in thread
From: moreau francis @ 2005-06-09  9:59 UTC (permalink / raw)
  To: Frederik Deweerdt; +Cc: linux-kernel


--- Frederik Deweerdt <dev.deweerdt@laposte.net> a écrit :

> I've just greped and I found :
> 
> if (!retval && test_bit(TTY_EXCLUSIVE, &tty->flags) &&
> !capable(CAP_SYS_ADMIN))
> 	retval = -EBUSY;
> in drivers/char/tty_io.c:tty_open
> 
> Which sources are you looking at?
> 

same source code but if another process has previously open the tty, how does
this source code detect it ?

             Francis


	
	
		
_____________________________________________________________________________ 
Découvrez le nouveau Yahoo! Mail : 1 Go d'espace de stockage pour vos mails, photos et vidéos ! 
Créez votre Yahoo! Mail sur http://fr.mail.yahoo.com/

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [TTY] exclusive mode question
  2005-06-09  9:59   ` moreau francis
@ 2005-06-09 10:41     ` Frederik Deweerdt
  2005-06-09 11:41       ` moreau francis
  2005-06-09 12:16       ` moreau francis
  0 siblings, 2 replies; 13+ messages in thread
From: Frederik Deweerdt @ 2005-06-09 10:41 UTC (permalink / raw)
  To: moreau francis; +Cc: Frederik Deweerdt, linux-kernel

Le 09/06/05 11:59 +0200, moreau francis écrivit:
> 
> --- Frederik Deweerdt <dev.deweerdt@laposte.net> a écrit :
> 
> > I've just greped and I found :
> > 
> > if (!retval && test_bit(TTY_EXCLUSIVE, &tty->flags) &&
> > !capable(CAP_SYS_ADMIN))
> > 	retval = -EBUSY;
> > in drivers/char/tty_io.c:tty_open
> > 
> > Which sources are you looking at?
> > 
> 
> same source code but if another process has previously open the tty, how does
> this source code detect it ?
> 
Sorry I misunderstood your question, there's no check on previous opens:
from man tty_ioctl:

       TIOCEXCL  void
              Put the tty into exclusive mode.  No _further_ open(2) operations  on  the  terminal  are  permitted.
              (They will fail with EBUSY, except for root.)

Emphasis mine.
Regards,
Frederik Deweerdt

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [TTY] exclusive mode question
  2005-06-09 10:41     ` Frederik Deweerdt
@ 2005-06-09 11:41       ` moreau francis
  2005-06-09 12:16         ` Frederik Deweerdt
  2005-06-09 12:16       ` moreau francis
  1 sibling, 1 reply; 13+ messages in thread
From: moreau francis @ 2005-06-09 11:41 UTC (permalink / raw)
  To: Frederik Deweerdt; +Cc: Frederik Deweerdt, linux-kernel


--- Frederik Deweerdt <dev.deweerdt@laposte.net> a écrit :

> > > I've just greped and I found :
> > > 
> > > if (!retval && test_bit(TTY_EXCLUSIVE, &tty->flags) &&
> > > !capable(CAP_SYS_ADMIN))
> > > 	retval = -EBUSY;
> > > in drivers/char/tty_io.c:tty_open
> > > 
> > > Which sources are you looking at?
> > > 
> > 
> > same source code but if another process has previously open the tty, how
> does
> > this source code detect it ?
> > 
> Sorry I misunderstood your question, there's no check on previous opens:
> from man tty_ioctl:
> 
>        TIOCEXCL  void
>               Put the tty into exclusive mode.  No _further_ open(2)
> operations  on  the  terminal  are  permitted.
>               (They will fail with EBUSY, except for root.)
> 

oh ok...sorry I misunderstood TIOEXCL meaning ;)
Do you know how I could implement such exclusive mode (the one I described) ?

thanks

            Francis


	
	
		
_____________________________________________________________________________ 
Découvrez le nouveau Yahoo! Mail : 1 Go d'espace de stockage pour vos mails, photos et vidéos ! 
Créez votre Yahoo! Mail sur http://fr.mail.yahoo.com/

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [TTY] exclusive mode question
  2005-06-09 10:41     ` Frederik Deweerdt
  2005-06-09 11:41       ` moreau francis
@ 2005-06-09 12:16       ` moreau francis
  1 sibling, 0 replies; 13+ messages in thread
From: moreau francis @ 2005-06-09 12:16 UTC (permalink / raw)
  To: Frederik Deweerdt; +Cc: Frederik Deweerdt, linux-kernel


--- Frederik Deweerdt <dev.deweerdt@laposte.net> a écrit :

> Le 09/06/05 11:59 +0200, moreau francis écrivit:
> > 
> > --- Frederik Deweerdt <dev.deweerdt@laposte.net> a écrit :
> > 
> > > I've just greped and I found :
> > > 
> > > if (!retval && test_bit(TTY_EXCLUSIVE, &tty->flags) &&
> > > !capable(CAP_SYS_ADMIN))
> > > 	retval = -EBUSY;
> > > in drivers/char/tty_io.c:tty_open
> > > 
> > > Which sources are you looking at?
> > > 
> > 
> > same source code but if another process has previously open the tty, how
> does
> > this source code detect it ?
> > 
> Sorry I misunderstood your question, there's no check on previous opens:
> from man tty_ioctl:
> 
>        TIOCEXCL  void
>               Put the tty into exclusive mode.  No _further_ open(2)
> operations  on  the  terminal  are  permitted.
>               (They will fail with EBUSY, except for root.)
> 

BTW, I don't see any use of this mode since it can't ensure that nothing is
using the tty...Do you know what kind of purpose it is for ?

               Francis


	
	
		
_____________________________________________________________________________ 
Découvrez le nouveau Yahoo! Mail : 1 Go d'espace de stockage pour vos mails, photos et vidéos ! 
Créez votre Yahoo! Mail sur http://fr.mail.yahoo.com/

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [TTY] exclusive mode question
  2005-06-09 11:41       ` moreau francis
@ 2005-06-09 12:16         ` Frederik Deweerdt
  2005-06-09 14:22           ` moreau francis
  0 siblings, 1 reply; 13+ messages in thread
From: Frederik Deweerdt @ 2005-06-09 12:16 UTC (permalink / raw)
  To: moreau francis; +Cc: Frederik Deweerdt, linux-kernel

Le 09/06/05 13:41 +0200, moreau francis écrivit:
> 
> oh ok...sorry I misunderstood TIOEXCL meaning ;)
> Do you know how I could implement such exclusive mode (the one I described) ?
> 
This is handled through lock files, google for LCK..ttyS0
Regards,
Frederik Deweerdt

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [TTY] exclusive mode question
  2005-06-09 12:16         ` Frederik Deweerdt
@ 2005-06-09 14:22           ` moreau francis
  2005-06-09 15:12             ` Russell King
  0 siblings, 1 reply; 13+ messages in thread
From: moreau francis @ 2005-06-09 14:22 UTC (permalink / raw)
  To: Frederik Deweerdt; +Cc: Frederik Deweerdt, linux-kernel


--- Frederik Deweerdt <dev.deweerdt@laposte.net> a écrit :

> Le 09/06/05 13:41 +0200, moreau francis écrivit:
> > 
> > oh ok...sorry I misunderstood TIOEXCL meaning ;)
> > Do you know how I could implement such exclusive mode (the one I described)
> ?
> > 
> This is handled through lock files, google for LCK..ttyS0
>

This lock mechanism is a convention but nothing prevent a user application to
issue a "echo foo > /dev/ttyS0" command while "LCK..ttyS0" file exists...

            Francis


	
	
		
___________________________________________________________________________ 
Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger 
Téléchargez cette version sur http://fr.messenger.yahoo.com

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [TTY] exclusive mode question
  2005-06-09 14:22           ` moreau francis
@ 2005-06-09 15:12             ` Russell King
  2005-06-10  7:03               ` Denis Vlasenko
  0 siblings, 1 reply; 13+ messages in thread
From: Russell King @ 2005-06-09 15:12 UTC (permalink / raw)
  To: moreau francis; +Cc: Frederik Deweerdt, linux-kernel

On Thu, Jun 09, 2005 at 04:22:49PM +0200, moreau francis wrote:
> --- Frederik Deweerdt <dev.deweerdt@laposte.net> a écrit :
> > Le 09/06/05 13:41 +0200, moreau francis écrivit:
> > > 
> > > oh ok...sorry I misunderstood TIOEXCL meaning ;)
> > > Do you know how I could implement such exclusive mode (the one I described)
> > ?
> > > 
> > This is handled through lock files, google for LCK..ttyS0
> >
> 
> This lock mechanism is a convention but nothing prevent a user application to
> issue a "echo foo > /dev/ttyS0" command while "LCK..ttyS0" file exists...

Which is absolutely necessary to work if you think about an application
like minicom and its file transfer helpers, which may need to re-open
the serial port.

TTY locking is done via lock files only, and all non-helper applications
must coordinate their access via the lock files.  There is no other
mechanism.

-- 
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [TTY] exclusive mode question
  2005-06-09 15:12             ` Russell King
@ 2005-06-10  7:03               ` Denis Vlasenko
  2005-06-10  7:11                 ` moreau francis
  2005-06-10  9:36                 ` moreau francis
  0 siblings, 2 replies; 13+ messages in thread
From: Denis Vlasenko @ 2005-06-10  7:03 UTC (permalink / raw)
  To: Russell King, moreau francis; +Cc: Frederik Deweerdt, linux-kernel

On Thursday 09 June 2005 18:12, Russell King wrote:
> On Thu, Jun 09, 2005 at 04:22:49PM +0200, moreau francis wrote:
> > --- Frederik Deweerdt <dev.deweerdt@laposte.net> a écrit :
> > > Le 09/06/05 13:41 +0200, moreau francis écrivit:
> > > > 
> > > > oh ok...sorry I misunderstood TIOEXCL meaning ;)
> > > > Do you know how I could implement such exclusive mode (the one I described)
> > > ?
> > > > 
> > > This is handled through lock files, google for LCK..ttyS0
> > >
> > 
> > This lock mechanism is a convention but nothing prevent a user application to
> > issue a "echo foo > /dev/ttyS0" command while "LCK..ttyS0" file exists...
> 
> Which is absolutely necessary to work if you think about an application
> like minicom and its file transfer helpers, which may need to re-open
> the serial port.
> 
> TTY locking is done via lock files only, and all non-helper applications
> must coordinate their access via the lock files.  There is no other
> mechanism.

I think original reporter is saying that TIOEXCL is nearly useless then.
--
vda


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [TTY] exclusive mode question
  2005-06-10  7:03               ` Denis Vlasenko
@ 2005-06-10  7:11                 ` moreau francis
  2005-06-10  9:36                 ` moreau francis
  1 sibling, 0 replies; 13+ messages in thread
From: moreau francis @ 2005-06-10  7:11 UTC (permalink / raw)
  To: Denis Vlasenko, Russell King; +Cc: Frederik Deweerdt, linux-kernel


--- Denis Vlasenko <vda@ilport.com.ua> a écrit :

> On Thursday 09 June 2005 18:12, Russell King wrote:
> > On Thu, Jun 09, 2005 at 04:22:49PM +0200, moreau francis wrote:
> > > --- Frederik Deweerdt <dev.deweerdt@laposte.net> a écrit :
> > > > Le 09/06/05 13:41 +0200, moreau francis écrivit:
> > > > > 
> > > > > oh ok...sorry I misunderstood TIOEXCL meaning ;)
> > > > > Do you know how I could implement such exclusive mode (the one I
> described)
> > > > ?
> > > > > 
> > > > This is handled through lock files, google for LCK..ttyS0
> > > >
> > > 
> > > This lock mechanism is a convention but nothing prevent a user
> application to
> > > issue a "echo foo > /dev/ttyS0" command while "LCK..ttyS0" file exists...
> > 
> > Which is absolutely necessary to work if you think about an application
> > like minicom and its file transfer helpers, which may need to re-open
> > the serial port.
> > 
> > TTY locking is done via lock files only, and all non-helper applications
> > must coordinate their access via the lock files.  There is no other
> > mechanism.
> 
> I think original reporter is saying that TIOEXCL is nearly useless then.
> --

yes it is what I was trying to say....



	
	
		
___________________________________________________________________________ 
Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger 
Téléchargez cette version sur http://fr.messenger.yahoo.com

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [TTY] exclusive mode question
  2005-06-10  7:03               ` Denis Vlasenko
  2005-06-10  7:11                 ` moreau francis
@ 2005-06-10  9:36                 ` moreau francis
  2005-06-10 16:24                   ` Russell King
  1 sibling, 1 reply; 13+ messages in thread
From: moreau francis @ 2005-06-10  9:36 UTC (permalink / raw)
  To: Denis Vlasenko, Russell King; +Cc: Frederik Deweerdt, linux-kernel


--- Denis Vlasenko <vda@ilport.com.ua> a écrit :

> On Thursday 09 June 2005 18:12, Russell King wrote:
> > On Thu, Jun 09, 2005 at 04:22:49PM +0200, moreau francis wrote:
> > > --- Frederik Deweerdt <dev.deweerdt@laposte.net> a écrit :
> > > > Le 09/06/05 13:41 +0200, moreau francis écrivit:
> > > > > 
> > > > > oh ok...sorry I misunderstood TIOEXCL meaning ;)
> > > > > Do you know how I could implement such exclusive mode (the one I
> described)
> > > > ?
> > > > > 
> > > > This is handled through lock files, google for LCK..ttyS0
> > > >
> > > 
> > > This lock mechanism is a convention but nothing prevent a user
> application to
> > > issue a "echo foo > /dev/ttyS0" command while "LCK..ttyS0" file exists...
> > 
> > Which is absolutely necessary to work if you think about an application
> > like minicom and its file transfer helpers, which may need to re-open
> > the serial port.
> > 
> > TTY locking is done via lock files only, and all non-helper applications
> > must coordinate their access via the lock files.  There is no other
> > mechanism.
> 
> I think original reporter is saying that TIOEXCL is nearly useless then.
>

Why not using mandatory locks instead of this "weak" user lock mechanism ?

              Francis


	
	
		
___________________________________________________________________________ 
Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger 
Téléchargez cette version sur http://fr.messenger.yahoo.com

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [TTY] exclusive mode question
  2005-06-10  9:36                 ` moreau francis
@ 2005-06-10 16:24                   ` Russell King
  0 siblings, 0 replies; 13+ messages in thread
From: Russell King @ 2005-06-10 16:24 UTC (permalink / raw)
  To: moreau francis; +Cc: Denis Vlasenko, Frederik Deweerdt, linux-kernel

On Fri, Jun 10, 2005 at 11:36:54AM +0200, moreau francis wrote:
> 
> --- Denis Vlasenko <vda@ilport.com.ua> a écrit :
> 
> > On Thursday 09 June 2005 18:12, Russell King wrote:
> > > On Thu, Jun 09, 2005 at 04:22:49PM +0200, moreau francis wrote:
> > > > --- Frederik Deweerdt <dev.deweerdt@laposte.net> a écrit :
> > > > > Le 09/06/05 13:41 +0200, moreau francis écrivit:
> > > > > > 
> > > > > > oh ok...sorry I misunderstood TIOEXCL meaning ;)
> > > > > > Do you know how I could implement such exclusive mode (the one I
> > described)
> > > > > ?
> > > > > > 
> > > > > This is handled through lock files, google for LCK..ttyS0
> > > > >
> > > > 
> > > > This lock mechanism is a convention but nothing prevent a user
> > application to
> > > > issue a "echo foo > /dev/ttyS0" command while "LCK..ttyS0" file exists...
> > > 
> > > Which is absolutely necessary to work if you think about an application
> > > like minicom and its file transfer helpers, which may need to re-open
> > > the serial port.
> > > 
> > > TTY locking is done via lock files only, and all non-helper applications
> > > must coordinate their access via the lock files.  There is no other
> > > mechanism.
> > 
> > I think original reporter is saying that TIOEXCL is nearly useless then.
> >
> 
> Why not using mandatory locks instead of this "weak" user lock mechanism ?

As I've already said - helper applications.

There's another case as well.  Consider the following:

- getty is listening on the serial port for an incoming modem call
  (eg, mgetty)
- you want to make an outgoing call (eg, minicom)

Both have to co-operate with each other via the lock files to ensure
that they don't stomp on each other - and the point at which they claim
the lock is most definitely not at serial port open time.

-- 
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2005-06-10 16:25 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-09  8:49 [TTY] exclusive mode question moreau francis
2005-06-09  9:36 ` Frederik Deweerdt
2005-06-09  9:59   ` moreau francis
2005-06-09 10:41     ` Frederik Deweerdt
2005-06-09 11:41       ` moreau francis
2005-06-09 12:16         ` Frederik Deweerdt
2005-06-09 14:22           ` moreau francis
2005-06-09 15:12             ` Russell King
2005-06-10  7:03               ` Denis Vlasenko
2005-06-10  7:11                 ` moreau francis
2005-06-10  9:36                 ` moreau francis
2005-06-10 16:24                   ` Russell King
2005-06-09 12:16       ` moreau francis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®