0

I would like to write to a tty from kernel space and only have access to the major and minor device numbers for that particular tty.

I am entering the kernel via a system call that works fine, and is capable of writing to the current tty through the usage of

my_tty = current->signal->tty;

(my_tty->driver->ops->write) (my_tty,"Text message", SIZE);

The problem is occasionally I wish to write to a different tty and have (as far as I know) only access to the tty defined by current->signal->tty.

What I do have are the major and minor devices numbers for the tty I wish to address, which I pass as parameters to the syscall.

Can anyone provide a suggestion on what is available as a solution that I could research?

I am not finding anything other than the solution described above using the current tty of the calling program. Perhaps I am using incorrect search terms.

I do not have example code yet, since I have not added anything to my existing syscall. I would be happy to once I have an idea of what to work with. Maybe there are already functions to achieve this? I am simply hoping for a pointer on what to use or where to look.

red0ct
  • 4,840
  • 3
  • 17
  • 44
rhg910
  • 23
  • 1
  • 6

1 Answers1

0

You don't do this by passing major/minor numbers to your syscall.

Instead, have the userspace side open the tty it wants then pass the resulting file descriptor to your syscall. You then use the sequence { fget(); kernel_write(); fput(); } to write to the supplied file descriptor.

caf
  • 233,326
  • 40
  • 323
  • 462
  • Yes, this worked. For the record, I used kernel_write(). – rhg910 May 21 '19 at 18:32
  • @rhg910: Those weren't supposed to be alternatives, `fget()` and `fput()` are required around the `kernel_write()` call to ensure the file isn't closed by a racing thread. I've updated the answer to hopefully make that clearer. – caf May 22 '19 at 00:22