# "chvt" analog



## dbi (Sep 12, 2010)

Hi,

There is a tool called "chvt" found in some (most?) GNU/Linux distros which changes the active terminal. It can be found in the sys-apps/kbd package (at least on Gentoo).

I find "chvt" very useful for switching to console when X becomes irresponsive by replacing the default command for "acpi button event" - when I press the power button the system switches to tty instead of doing "shutdown -h now".

Is there any way to implement the same functionality on FreeBSD?


----------



## Savagedlight (Sep 12, 2010)

Shouldn't you be able to reach the console by pressing ctrl+alt+Fx when in X?


----------



## dbi (Sep 12, 2010)

Savagedlight said:
			
		

> Shouldn't you be able to reach the console by pressing ctrl+alt+Fx when in X?



Not when X is "frozen". Which doesn't mean the system is dead - e.g. pressing the power button initiates a normal shut down. Typically that happens (to me) while there's excessive hdd I/O.


----------



## wblock@ (Sep 12, 2010)

dbi said:
			
		

> Hi,
> 
> There is a tool called "chvt" found in some (most?) GNU/Linux distros which changes the active terminal. It can be found in the sys-apps/kbd package (at least on Gentoo).
> 
> ...



(Seems like X should not be going away often enough to need a special button to get out of it, but maybe it depends on what you're doing.)

ACPI events can be recognized by devd(8).  There are a couple of examples in the default /etc/devd.conf.


----------



## dbi (Sep 12, 2010)

Well, I had figured out that pressing the power button executes /etc/rc.shutdown.
Hence my original question: is there an analog of chvt in FreeBSD, so I could use it in the script.


----------



## jasmine (Sep 12, 2010)

http://lists.debian.org/debian-bsd/2009/11/msg00006.html

Xserver does pretty much same thing for Ctrl+Alt+Fn if you attach ktrace(1) to its pid.


----------



## dbi (Sep 13, 2010)

http://lists.debian.org/debian-bsd/2009/11/msg00006.html


```
/* chvt.c - change virtual terminal for [k]freebsd
   Copyright (C) 2009 Werner Koch
...
*/
```

Doesn't compile here on 8.1-RELEASE. I'm not a programmer, so reading code, debugging, tracing, etc are beyond me.


----------



## jasmine (Sep 13, 2010)

If I'm not mistaken the code is written for some 7.2 kernel that Debian used during that time. I've tested on 9.0-CURRENT and it works. So, unless you give me an exact compiler error I don't care.


----------



## fronclynne (Sep 14, 2010)

Hmm, 8.1 amd64 gives 
	
	



```
> cc -o chvt chvt.c
> ./chvt
5
> ./chvt 1
```
which takes me to the equivalent of punching ctl-alt-F1.

I'd say it works.


----------



## dbi (Sep 14, 2010)

*[solved]*

Sorry, my mistake. I guess something went wrong while doing copy/paste yesterday. The program compiled w/o errors and works exactly as I need.

Thank you, guys!


----------

