LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Desktop (http://www.linuxquestions.org/questions/linux-desktop-74/)
-   -   bash# "chvt N" as non-root says 'Operation not permitted' (http://www.linuxquestions.org/questions/linux-desktop-74/bash-chvt-n-as-non-root-says-operation-not-permitted-584904/)

GrapefruiTgirl 09-15-2007 12:06 PM

bash# "chvt N" as non-root says 'Operation not permitted'
 
Hiya folks :)

OK, the basic details first: I have a video card with THREE connectors (DVI, VGA, S-VIDEO), but it will only run any TWO displays at a time.
My main X configuration uses two monitors (DVI & VGA), but I wanted an alternate X configuration I could switch to easily, with output to DVI + SVIDEO, so I could watch movies on the television sometimes.
Rather than do a lot of messing around with multiple xorg.confs, logging-out/in again, or unplugging things, I made two 'ServerLayouts' in my xorg.conf;

Now, by clicking a desktop-link to a one line script like so:

#!/bin/bash
startx -- :1 -layout "television"


A second X session starts using the "television" ServerLayout and displays video on my main monitor, plus the TV. The second monitor turns off. I switch back using CTRL-ALT-F7.
This is cool, and works from my user desktop, but here's the issue(s):

A) Regardless of whether I use a :1 or :2 or :6 or :<any-number> in the command above, the new session starts on CTRL-ALT-F2 (which is technically TTY2 I guess). What do I have to do to get the new session to start on CTRL-ALT-F6 for example? I'd prefer using F7 & F6 than F7 & F2. Just makes better sense to me.

B) More importantly, I have learned that if I want a similarly clickable (bash) method of switching back to CTRL-ALT-F7 (my default X session) it seems I need to use the chvt N command. However, as a regular user, chvt 7 returns a 'Operation Not Permitted' error. As root, it works fine, but I'm not running as root.
The binary chvt is rwx r-x r-x so I should be able to execute it.

I'm sure there is a VERY simple item I am overlooking, but keep coming back to such things as inittab, init, .bashrc, .bash_profile, and similar files, but it doesn't look like the answer lies in one of these files.
Google mostly gives me the same bash and X tutorials paraphrased 100 different ways, but all they focus on are CTRL-ALT-Fn (not a mouse click) and chvt N (works in the tutorials, but not for me).

Guidance is appreciated :)
Thanks.

osor 09-15-2007 12:40 PM

Quote:

Originally Posted by GrapefruiTgirl (Post 2892805)
A) Regardless of whether I use a :1 or :2 or :6 or :<any-number> in the command above, the new session starts on CTRL-ALT-F2 (which is technically TTY2 I guess). What do I have to do to get the new session to start on CTRL-ALT-F6 for example? I'd prefer using F7 & F6 than F7 & F2. Just makes better sense to me.

The :1 :2 or :6 has nothing to do with which terminal X starts on. It only serves to id the X server so clients may write to its local domain sockets. By default X will start in the first unused tty (i.e., the same as if you ran the command openvt as root).
Quote:

Originally Posted by GrapefruiTgirl (Post 2892805)
B) More importantly, I have learned that if I want a similarly clickable (bash) method of switching back to CTRL-ALT-F7 (my default X session) it seems I need to use the chvt N command. However, as a regular user, chvt 7 returns a 'Operation Not Permitted' error. As root, it works fine, but I'm not running as root.
The binary chvt is rwx r-x r-x so I should be able to execute it.

chvt, much like the X binary, must be run as root since it does some permission-requiring ioctls on device nodes. Imagine if any (unprivileged) remote user could play with the root terminal! Fortunately, the solution is simple: use sudo with NOPASSWD for that particular command.

GrapefruiTgirl 09-15-2007 12:55 PM

Interesting; thank you Osor for the quick and concise reply.

So, kinda funny how I can start an X on another terminal, but then can't use chvn just the same to switch back to my default session.. Well, perhaps I will have to settle on using the CTRL-ALT-F7 method, or right click desktop and switch to my other logon. No big deal. (Note: I don't use SUDO for anything.)

As to the first issue, I was indeed aware that the "DEFAULT" is to open the new session on the first available console, BUT, is there no way to specify an alternate?

Thanks again :)

osor 09-15-2007 02:16 PM

Quote:

Originally Posted by osor (Post 2892839)
must be run as root since it does some permission-requiring ioctls on device nodes.

On second thought, it might work for an ordinary user if that user has write permission on the tty to which you are changing (i.e., /dev/tty7 permissions are 0666). This can be made to occur with clever udev rules. See if you can get that to work.
Quote:

Originally Posted by GrapefruiTgirl (Post 2892854)
As to the first issue, I was indeed aware that the "DEFAULT" is to open the new session on the first available console, BUT, is there no way to specify an alternate?

I am not aware of any way to specify an alternate terminal. Well, you could open up tty[2-6] (with openvt) prior to running X, then close them after X has launched (with deallocvt).

GrapefruiTgirl 09-16-2007 04:44 PM

Solved - chvt an unnecessary luxury; X session #2 starts on TTY6
 
Well, here's the situation currently:

I can use the chvt command to change to whatever console I want, ONLY IF I set the SUID bit on chvt.
Despite that I feel chvt is a relatively benign binary, and this is a fairly well hardened desktop system with no (known) remote access or other users, I'd just as soon NOT use SUID for anything not really necessary. This issue isn't that big a deal. I can get by by either logging out of my second X session after the movie, or hitting CTRL-ALT-Fn to switch.

However, I did figure out a way to get my second X session to start up on TTY6 :) , by changing the following section of my inittab file like so:
Code:


# Standard console login getties in multiuser mode:
c1:1235:respawn:/sbin/agetty 38400 tty1 linux
c2:12345:respawn:/sbin/agetty 38400 tty2 linux
c3:12345:respawn:/sbin/agetty 38400 tty3 linux
c4:12345:respawn:/sbin/agetty 38400 tty4 linux
c5:12345:respawn:/sbin/agetty 38400 tty5 linux
c6:1235:respawn:/sbin/agetty 38400 tty6 linux

This way, the system still boots up on TTY1, and X starts up on TTY7, as usual, but I've made TTY[2..5] into login gettys in run-level 4, so I can actually use them. As such, this leaves TTY6 unused, and so my second X session opens there.

Thanks for the input Osor; I think I will be content with this setup.

P.S. - I also had tried earlier to make sure I had RW permissions to the TTYs. All VC/TTYs are in the group TTY, to which I added my user account, and the permissions of the TTYs were RW-RW---- so should be sufficient, but still, chvt wouldn't let me switch to one.


All times are GMT -5. The time now is 06:41 AM.