view toys/pending/deallocvt.c @ 1241:3c855d5a75be draft

openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
author Isaac Dunham <>
date Thu, 03 Apr 2014 22:43:28 -0500
parents a31d747b0017
line wrap: on
line source

/* deallocvt.c - Deallocate virtual terminal(s)
 * Copyright 2014 Vivek Kumar Bhagat <>
 * No Standard.


  bool "deallocvt"
  depends on OPENVT
  default n
    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>

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);