linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: James Simmons <jsimmons@suse.com>
To: Kurt Garloff <garloff@suse.de>
Cc: Linus Torvalds <torvalds@transmeta.com>,
	Alan Cox <alan@lxorguk.ukuu.org.uk>,
	miquels@cistron.nl,
	Linux kernel list <linux-kernel@vger.kernel.org>
Subject: Re: TIOCGDEV ioctl
Date: Fri, 15 Dec 2000 17:18:56 -0800 (PST)	[thread overview]
Message-ID: <Pine.LNX.4.21.0012151709591.1176-100000@euclid.oak.suse.com> (raw)
In-Reply-To: <20001216015537.G21372@garloff.suse.de>


> Hi Linus, Alan,
> 
> some applications do need to know where the console (/dev/console)
> actually maps to. For processes with a controlling terminal, you may see 
> it in /proc/$$/stat. However, daemons are supposed to run detached (they
> don't want to get killed by ^C) and some processes like init or bootlogd 
> do still need to be able to find out.
> 
> The kernel provides this information -- sort of:
> It contains the TIOCTTYGSTRUCT syscall which returns a struct. Of course,
> it changes between different kernel archs and revisions, so using it is
> an ugly hack. Grab for TIOCTTYGSTRUCT_HACK in the bootlogd.c file of the
> sysvinit sources. Shudder!
> 
> Having a new ioctl, just returning the device no is a much cleaner solution,
> IMHO. So, I created the TIOCGDEV, which Miquel suggests in his sysvinit
> sources. It makes querying the actual console device as easy as 
> int tty; ioctl (0, TIOCGDEV, &tty);
> 
> Patches against 2.2.18 and 2.4.0-testX are attached.
> Please apply.

Based on fgconsole.c. I just threw it together in a few minutes.

/*
 * consolewhat.c - Prints which VC /dev/console is.
 */
#include <sys/ioctl.h>
#include <linux/vt.h>

int
main(){
    struct vt_stat vtstat;
    int fd;	

    fd = open("/dev/console", O_RDONLY);	

    if (fd < 0 && errno == EACCES)
	fd = open("/dev/console", O_WRONLY);
    if (fd < 0)
	return -1;

    if (ioctl(fd, VT_GETSTATE, &vtstat)) {
        perror("consolewhat: VT_GETSTATE");
	exit(1);
    }
    printf("%d\n", vtstat.v_active);
    return 0;
}

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

  parent reply	other threads:[~2000-12-16  1:49 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-12-16  0:55 TIOCGDEV ioctl Kurt Garloff
2000-12-16  1:11 ` Linus Torvalds
2000-12-16  1:54   ` Alexander Viro
2000-12-16 10:46     ` Miquel van Smoorenburg
2000-12-16 11:15       ` Alexander Viro
2000-12-16 11:40         ` Miquel van Smoorenburg
2000-12-16 11:57           ` Alexander Viro
2000-12-19 11:34             ` Kurt Garloff
2000-12-21 14:22   ` Dr. Werner Fink
2000-12-16  1:18 ` James Simmons [this message]
2000-12-16 10:54   ` Miquel van Smoorenburg
2000-12-18 17:07     ` James Simmons

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=Pine.LNX.4.21.0012151709591.1176-100000@euclid.oak.suse.com \
    --to=jsimmons@suse.com \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=garloff@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miquels@cistron.nl \
    --cc=torvalds@transmeta.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).