diff options
author | Javier Martinez Canillas <martinez.javier@gmail.com> | 2010-11-27 07:49:17 +0100 |
---|---|---|
committer | Javier Martinez Canillas <martinez.javier@gmail.com> | 2010-11-27 07:49:17 +0100 |
commit | ab121f379a3cff458c90e6f480ba4bb68c8733dd (patch) | |
tree | a9851af109ee83646d108bc247d03b131461b764 /misc-progs/setconsole.c | |
download | ldd3-ab121f379a3cff458c90e6f480ba4bb68c8733dd.tar.gz |
Linux Device Drivers 3 examples
Diffstat (limited to 'misc-progs/setconsole.c')
-rw-r--r-- | misc-progs/setconsole.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/misc-progs/setconsole.c b/misc-progs/setconsole.c new file mode 100644 index 0000000..04bc11d --- /dev/null +++ b/misc-progs/setconsole.c @@ -0,0 +1,42 @@ +/* + * setconsole.c -- choose a console to receive kernel messages + * + * Copyright (C) 1998,2000,2001 Alessandro Rubini + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <unistd.h> +#include <sys/ioctl.h> + +int main(int argc, char **argv) +{ + char bytes[2] = {11,0}; /* 11 is the TIOCLINUX cmd number */ + + if (argc==2) bytes[1] = atoi(argv[1]); /* the chosen console */ + else { + fprintf(stderr, "%s: need a single arg\n",argv[0]); exit(1); + } + if (ioctl(STDIN_FILENO, TIOCLINUX, bytes)<0) { /* use stdin */ + fprintf(stderr,"%s: ioctl(stdin, TIOCLINUX): %s\n", + argv[0], strerror(errno)); + exit(1); + } + exit(0); +} |