Skip to content

Instantly share code, notes, and snippets.

@xfgusta
Created January 16, 2021 04:20
Show Gist options
  • Save xfgusta/d322b5a62d3411e6d57dcddcacbc394e to your computer and use it in GitHub Desktop.
Save xfgusta/d322b5a62d3411e6d57dcddcacbc394e to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <fcntl.h>
int main(int argc, char **argv) {
if(argc != 3 || getuid()) {
fprintf(stderr, "Run '%s <fd> <cmd>' as root\n", argv[0]);
return 1;
}
int fd = open(argv[1], O_RDWR);
if(!fd) {
fprintf(stderr, "Can't open %s\n", argv[1]);
return 1;
}
for(char *c = argv[2]; *c; c++)
if(ioctl(fd, TIOCSTI, c))
return 1;
return ioctl(fd, TIOCSTI, "\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment