All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alan Cox <alan@lxorguk.ukuu.org.uk>
To: Kay Sievers <kay.sievers@vrfy.org>
Cc: linux-kernel <linux-kernel@vger.kernel.org>,
	Greg KH <greg@kroah.com>,
	Lennart Poettering <lennart@poettering.net>,
	Werner Fink <werner@suse.de>, Jiri Slaby <jslaby@suse.cz>
Subject: Re: tty: add 'active' sysfs attribute to tty0 and console device
Date: Tue, 16 Nov 2010 15:57:17 +0000	[thread overview]
Message-ID: <20101116155717.6671e484@lxorguk.ukuu.org.uk> (raw)
In-Reply-To: <1289922400.1253.3.camel@yio.site>

On Tue, 16 Nov 2010 16:46:40 +0100
Kay Sievers <kay.sievers@vrfy.org> wrote:

> commit be0d5f02c9194fe41c1aad11d7282db117bda938
> Author: Kay Sievers <kay.sievers@vrfy.org>
> Date:   Tue Nov 9 18:53:59 2010 +0100
> 
>     tty: add 'active' sysfs attribute to tty0 and console device

This is all somewhat weird.

>     Userspace can query the actual virtual console, and the configured
>     console devices behind /dev/tt0 and /dev/console.

All the other vt interface code is in the vt driver, the ioctls for it
are in the vt driver and a query about what is the active vt only has
meaning within that context as you need to post a waitevent first to
track changes during the query. So if you need a VT_GETACTIVE interface
put it in the tty ioctls where it can be properly locked and used.

> +What:		/sys/class/tty/tty0/active
> +Date:		Nov 2010
> +Contact:	Kay Sievers <kay.sievers@vrfy.org>
> +Description:
> +		 Shows the currently active virtual console
> +		 device, like 'tty1'.
> +		 The file supports poll() to detect virtual
> +		 console switches.

NAK this, its a nonsense interface

Seriously what use is an interface that tells you "what the console might
have been", this is why we have a proper event tracking interface instead.

> +static ssize_t show_cons_active(struct device *dev,
> +				struct device_attribute *attr, char *buf)
> +{
> +	struct console *cs[16];
> +	int i = 0;
> +	struct console *c;
> +	ssize_t count = 0;
> +
> +	acquire_console_sem();
> +	for (c = console_drivers; c; c = c->next) {
> +		if (!c->device)
> +			continue;
> +		if (!c->write)
> +			continue;
> +		if ((c->flags & CON_ENABLED) == 0)
> +			continue;
> +		cs[i++] = c;
> +		if (i >= ARRAY_SIZE(cs))
> +			break;
> +	}
> +	while (i--)
> +		count += sprintf(buf + count, "%s%d%c",
> +				 cs[i]->name, cs[i]->index, i ? ' ':'\n');
> +	release_console_sem();
> +
> +	return count;
> +}
> +static DEVICE_ATTR(active, S_IRUGO, show_cons_active, NULL);

This makes more sense.

> -	device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 0), NULL,
> -			      "tty");
> +	device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 0), NULL, "tty");

Please keep unneccessary reformatting patches out of code changes, submit
them separately.

>  static ATOMIC_NOTIFIER_HEAD(vt_notifier_list);
> @@ -688,6 +696,8 @@ void redraw_screen(struct vc_data *vc, int is_switch)
>  			save_screen(old_vc);
>  			set_origin(old_vc);
>  		}
> +		if (tty0dev)
> +			sysfs_notify(&tty0dev->kobj, NULL, "active");

What is the locking on tty0dev at this point ? Wrong place anyway - we
have vt change notifiers that do this properly and can track other
changes like console sizes, add and remove. See the VT_WAITACTIVE stuff
etc.

> +static ssize_t show_tty_active(struct device *dev,
> +				struct device_attribute *attr, char *buf)
> +{
> +	return sprintf(buf, "tty%d\n", fg_console + 1);
> +}
> +static DEVICE_ATTR(active, S_IRUGO, show_tty_active, NULL);

How do you ensure fg_console returned to user space is right when the
console can change during and after the call ?


  reply	other threads:[~2010-11-16 15:58 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-16 15:46 tty: add 'active' sysfs attribute to tty0 and console device Kay Sievers
2010-11-16 15:57 ` Alan Cox [this message]
2010-11-16 16:13   ` Kay Sievers
2010-11-16 17:14     ` Alan Cox
2010-11-16 18:51       ` Kay Sievers
2010-11-16 19:55         ` Alan Cox
2010-11-16 20:15           ` Kay Sievers
2010-11-16 20:49             ` Alan Cox
2010-11-16 21:29               ` Kay Sievers
2010-11-16 21:42               ` Lennart Poettering
2010-11-16 22:51                 ` Alan Cox
2010-11-16 22:58                   ` Lennart Poettering
2010-11-16 23:04                     ` Alan Cox
2010-11-16 23:18                       ` Lennart Poettering
2010-11-16 23:49                         ` Etched Pixels
2010-11-16 21:36           ` Lennart Poettering
2010-11-16 22:56             ` Alan Cox
2010-11-16 23:10               ` Lennart Poettering
2010-11-16 23:45                 ` Alan Cox
2010-11-17 16:31                 ` John Stoffel
2010-11-17 22:01                 ` Valdis.Kletnieks
2010-11-17 23:40                   ` Kay Sievers
2010-11-17 23:56                     ` Alan Cox
2010-11-18  1:27                       ` Greg KH
2010-11-18  1:48                         ` Lennart Poettering
2010-11-18  1:53                           ` Greg KH
2010-11-18  2:29                             ` Lennart Poettering
2010-11-18 11:00                             ` Dr. Werner Fink
2010-11-18 11:23                               ` Alan Cox
2010-11-18 12:12                                 ` Dr. Werner Fink
2010-11-18 12:58                                   ` Alan Cox
2010-11-18 13:14                                     ` Dr. Werner Fink
2010-11-18 14:41                                       ` Alan Cox
2010-11-19 13:21                                         ` Dr. Werner Fink
2010-11-19 15:47                                           ` Alan Cox
2010-11-19 17:07                                             ` Dr. Werner Fink
2010-11-19 18:02                                             ` Greg KH
2010-11-19 18:41                                               ` Dr. Werner Fink
2010-11-20 12:40                                                 ` Alan Cox
2010-12-01 11:15                                                   ` Dr. Werner Fink
2010-11-18 12:04                               ` Kay Sievers
2010-11-18 10:15                         ` Alan Cox
2010-11-18 11:55                           ` Kay Sievers
2010-11-18 13:01                             ` Alan Cox
     [not found] <20101201112004.12d78cd7@lxorguk.ukuu.org.uk>
2010-12-01 12:32 ` Dr. Werner Fink
     [not found]   ` <tiocgdev1@mdm.bga.com>
2010-12-03 11:48     ` Dr. Werner Fink

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20101116155717.6671e484@lxorguk.ukuu.org.uk \
    --to=alan@lxorguk.ukuu.org.uk \
    --cc=greg@kroah.com \
    --cc=jslaby@suse.cz \
    --cc=kay.sievers@vrfy.org \
    --cc=lennart@poettering.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=werner@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.