Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 2 | /* |
Eric Andersen | 7f6295f | 2003-10-22 10:34:15 +0000 | [diff] [blame] | 3 | * Disallocate virtual terminal(s) |
4 | * | ||||
5 | * Copyright (C) 2003 by Tito Ragusa <farmatito@tiscali.it> | ||||
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 6 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> |
Eric Andersen | 7f6295f | 2003-10-22 10:34:15 +0000 | [diff] [blame] | 7 | * |
"Robert P. J. Day" | 801ab14 | 2006-07-12 07:56:04 +0000 | [diff] [blame^] | 8 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 9 | */ |
Eric Andersen | 7f6295f | 2003-10-22 10:34:15 +0000 | [diff] [blame] | 10 | |
11 | /* no options, no getopt */ | ||||
12 | |||||
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 13 | #include <stdlib.h> |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 14 | #include <stdio.h> |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 15 | #include <fcntl.h> |
16 | #include <sys/types.h> | ||||
17 | #include <sys/ioctl.h> | ||||
Eric Andersen | cbe31da | 2001-02-20 06:14:08 +0000 | [diff] [blame] | 18 | #include "busybox.h" |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 19 | |
20 | /* From <linux/vt.h> */ | ||||
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 21 | enum { VT_DISALLOCATE = 0x5608 }; /* free memory associated to vt */ |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 22 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 23 | int deallocvt_main(int argc, char *argv[]) |
24 | { | ||||
Glenn L McGrath | 17b4a20 | 2004-01-15 11:50:19 +0000 | [diff] [blame] | 25 | /* num = 0 deallocate all unused consoles */ |
26 | int num = 0; | ||||
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 27 | |
Rob Landley | ead1930 | 2006-03-10 23:16:25 +0000 | [diff] [blame] | 28 | switch (argc) { |
Glenn L McGrath | 17b4a20 | 2004-01-15 11:50:19 +0000 | [diff] [blame] | 29 | case 2: |
Rob Landley | ead1930 | 2006-03-10 23:16:25 +0000 | [diff] [blame] | 30 | if ((num = bb_xgetlarg(argv[1], 10, 0, INT_MAX)) == 0) { |
Glenn L McGrath | 17b4a20 | 2004-01-15 11:50:19 +0000 | [diff] [blame] | 31 | bb_error_msg_and_die("0: illegal VT number"); |
Rob Landley | ead1930 | 2006-03-10 23:16:25 +0000 | [diff] [blame] | 32 | } |
Rob Landley | 9f0e00f | 2005-09-08 03:27:06 +0000 | [diff] [blame] | 33 | /* Fallthrough */ |
Eric Andersen | a860bec | 2003-04-27 10:42:31 +0000 | [diff] [blame] | 34 | case 1: |
Eric Andersen | a860bec | 2003-04-27 10:42:31 +0000 | [diff] [blame] | 35 | break; |
36 | default: | ||||
Glenn L McGrath | 17b4a20 | 2004-01-15 11:50:19 +0000 | [diff] [blame] | 37 | bb_show_usage(); |
Mark Whitley | 6f6aa9b | 2000-12-13 23:23:30 +0000 | [diff] [blame] | 38 | } |
Glenn L McGrath | 17b4a20 | 2004-01-15 11:50:19 +0000 | [diff] [blame] | 39 | |
Rob Landley | ead1930 | 2006-03-10 23:16:25 +0000 | [diff] [blame] | 40 | if (-1 == ioctl(get_console_fd(), VT_DISALLOCATE, num)) { |
Glenn L McGrath | 17b4a20 | 2004-01-15 11:50:19 +0000 | [diff] [blame] | 41 | bb_perror_msg_and_die("VT_DISALLOCATE"); |
42 | } | ||||
43 | return EXIT_SUCCESS; | ||||
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 44 | } |