From d579bb58abb8a28bba8007bebee26661ef924300 Mon Sep 17 00:00:00 2001
From: Vivek Kumar Bhagat <vivek.bhagat89@gmail.com>
Date: Wed, 5 Feb 2014 18:13:31 +0530
Subject: [PATCH 3/3] Added deallocvt command

---
 toys/other/deallocvt.c |   38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)
 create mode 100644 toys/other/deallocvt.c

diff --git a/toys/other/deallocvt.c b/toys/other/deallocvt.c
new file mode 100644
index 0000000..77af53f
--- /dev/null
+++ b/toys/other/deallocvt.c
@@ -0,0 +1,38 @@
+/* deallocvt.c - Deallocate virtual terminal(s)
+ *
+ * Copyright 2014 Vivek Kumar Bhagat <vivek.bhagat89@gmail.com>
+ *
+ * No Standard.
+
+USE_DEALLOCVT(NEWTOY(deallocvt, ">1", TOYFLAG_USR|TOYFLAG_BIN))
+
+config DEALLOCVT
+  bool "deallocvt"
+  default y
+  help
+	usage: deallocvt [N]
+
+	Deallocate unused virtual terminal /dev/ttyN
+	default value of N is 0, deallocate all unused consoles
+*/
+
+#include "toys.h"
+#include <linux/vt.h>
+
+extern int find_console_fd(void);
+
+void deallocvt_main(void)
+{
+	int fd;
+
+	// 0 : deallocate all unused consoles
+	int vt_num = 0;
+
+	if (toys.optargs[0])
+		vt_num = atolx_range(toys.optargs[0], 1, 63);
+
+	fd = find_console_fd();
+	if (fd < 0)	error_exit("can't open console");
+
+	xioctl(fd, VT_DISALLOCATE, (void *)(ptrdiff_t)vt_num);
+}
-- 
1.7.0.4

