home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / doc / console-tools / examples / spawn_console.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-04-08  |  944 b   |  42 lines

  1. /*
  2.  * Tiny test program for the `spawn console' key
  3.  * (should not use signal; should not use sleep)
  4.  * aeb - 941025
  5.  *
  6.  * Note: this functionality has become part of init.
  7.  * 
  8.  * Note: open(1) is now part of the `open' Debian package.
  9.  * 
  10.  * You should not use it on a system; if you want to do this, 
  11.  * be very careful.
  12.  * 
  13.  * If you have this in /etc/rc.local you should
  14.  * start getty, not open, or anybody will have a root shell
  15.  * with a single keystroke.
  16.  */
  17. #include <signal.h>
  18. #include <stdlib.h>               /* system */
  19. #include <fcntl.h>               /* open */
  20. #include <unistd.h>               /* sleep */
  21. #include <sys/ioctl.h>               /* ioctl */
  22. #include <linux/kd.h>
  23.  
  24. void
  25. sighup(){
  26.     system("open -s -l bash");
  27.     signal(SIGHUP, sighup);
  28. }
  29.  
  30. void
  31. main(){
  32.     int fd;
  33.  
  34.     fd = open("/dev/console", 0);
  35.     if (fd < 0)
  36.       fd = 0;
  37.     signal(SIGHUP, sighup);
  38.     ioctl(fd, KDSIGACCEPT, (long) SIGHUP);
  39.     while(1)
  40.       sleep(3600);
  41. }
  42.