Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
10-19-2010, 02:21 PM
|
#1
|
Senior Member
Registered: Mar 2010
Distribution: Slackware
Posts: 2,268
|
how do i stuff a keystroke into another virtual terminal's stdin?
echo p > /dev/tty7
causes a 'p' to appear in tty7 but not the program running in 7 to react as though a 'p' had been pressed.
|
|
|
10-19-2010, 02:37 PM
|
#2
|
LQ Guru
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594
|
What is the application or program that you're trying to "stuff a p" into? Can it be told to listen to a pipe for commands? If so, send the keystroke or message through the pipe into the program. Look up the `mkfifo` command for info on this.
Also look up the `write` command. There's another command too for sending messages to other tty's but I think they're intended for sending messages to humans using the terminals, not to programs running in the terminals.
Anyhow, if the pipe idea is no good or you still want more info, maybe tell us a bit more about the situation and requirements, i.e. the program(s) involved and desired functionality you're trying to accomplish, etc. More detail might give someone an idea.
|
|
|
10-19-2010, 05:53 PM
|
#3
|
Senior Member
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,281
|
Writing to console does not send keystrokes to standard input of running programs, only to the terminal. But it can be achieved by simple C program:
Code:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
int main(void)
{
int hTTY = open("/dev/tty1", O_WRONLY|O_NONBLOCK);
ioctl(hTTY, TIOCSTI, "p");
close(hTTY);
return 0;
}
Name it 'tty_send.c' Compile by
Code:
gcc -o tty_send tty_send.c
And run 'tty_send'.
Last edited by eSelix; 10-19-2010 at 05:54 PM.
|
|
|
10-19-2010, 07:32 PM
|
#4
|
LQ Guru
Registered: Apr 2005
Location: /dev/null
Posts: 5,818
|
Oooo, looks cool. I just stumbled across this thread, and sounds interesting. Once I get home from work, I am going to try this out, and possibly extend the code a bit and have fun with it. If I do, I will gladly post what I have come up with =D
|
|
|
10-20-2010, 01:43 PM
|
#5
|
Senior Member
Registered: Mar 2010
Distribution: Slackware
Posts: 2,268
Original Poster
|
eSelix's program returns an 'operation not permitted' error, even after I make /dev/tty7's permissions 777
|
|
|
10-20-2010, 04:55 PM
|
#6
|
Senior Member
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,281
|
And other consoles works? Usually on the console tty7 is runnig xserver, this program will not work with such code. Also the program can work without connected console. For me, I must be root, to execute ioctl function, you may suid to root your program, but this is some insecure solution.
Anyway you can move this thread to Programming forum. Those people should give you better answers.
|
|
|
10-20-2010, 07:14 PM
|
#7
|
Senior Member
Registered: Mar 2010
Distribution: Slackware
Posts: 2,268
Original Poster
|
I rewrote the program to take arguments for the target terminal and string to pass. It fails on any target terminal but the one in which it runs.
|
|
|
10-20-2010, 09:26 PM
|
#8
|
Member
Registered: Mar 2010
Distribution: Debian
Posts: 180
Rep:
|
A simple solution for what you what to do is a bad idea security wise, so the system probably won't allow it. You probably need to learn some form of IPC like corba or sending messages on dbus.
|
|
|
10-21-2010, 01:29 PM
|
#9
|
Senior Member
Registered: Mar 2010
Distribution: Slackware
Posts: 2,268
Original Poster
|
Making the owner root and setting the sticky bit works. It's a personal system so I don't mind. It would be nice to limit its effectiveness to processes owned by the caller.
|
|
|
10-22-2010, 12:16 AM
|
#10
|
LQ Guru
Registered: Apr 2005
Location: /dev/null
Posts: 5,818
|
The code doesn't work for me either. I don't get any error message or such, but when I try to do the terminal injection, nothing happens at all.
|
|
|
10-22-2010, 08:42 AM
|
#11
|
Senior Member
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,281
|
This is only sample. You need add to this code error checking routines, etc. You must run it as root to work, due ioctl function (maybe there are other methods).
|
|
|
10-31-2010, 03:53 PM
|
#12
|
Senior Member
Registered: Mar 2010
Distribution: Slackware
Posts: 2,268
Original Poster
|
Quote:
Originally Posted by corp769
The code doesn't work for me either. I don't get any error message or such, but when I try to do the terminal injection, nothing happens at all.
|
It works for me if I run it as root. I made root the owner and set the sticky bit so anyone can use it. This is a huge security hole but I'm the only user of my computer. I added reading input for a string to pass and a target terminal and report the outcome of the calls. It works as non-root to the terminal in which I run it. Tell us what your error is.
|
|
|
01-19-2011, 03:48 PM
|
#13
|
LQ Guru
Registered: Apr 2005
Location: /dev/null
Posts: 5,818
|
Sorry for digging this up, but I did not even realize that you replied back man. My bad... I will post what happens tonight once I get home from work. I know for sure though that it was something to do with a ioctl function or error....
|
|
|
10-14-2014, 02:27 PM
|
#14
|
LQ Newbie
Registered: Nov 2013
Posts: 4
Rep: 
|
TTY/PTS send
This was one of the most awesome threads. Thanks to whoever still gets this.
|
|
|
All times are GMT -5. The time now is 09:14 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|