From 7cd2f3f149ec1a905b0effb2c46d19613acde887 Mon Sep 17 00:00:00 2001 From: fredrik Date: Sun, 23 Apr 2006 01:56:26 +0000 Subject: [PATCH] Initial import. git-svn-id: svn+ssh://svn.dolda2000.com/srv/svn/repos/src/utils@597 959494ce-11ee-0310-bf91-de5d638817bd --- notty.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 notty.c diff --git a/notty.c b/notty.c new file mode 100644 index 0000000..3595811 --- /dev/null +++ b/notty.c @@ -0,0 +1,53 @@ +#include +#include +#include +#include +#include + +void usage(void) +{ + fprintf(stderr, "usage: notty PROGRAM [-r] [ARGS...]\n"); +} + +int main(int argc, char **argv) +{ + int tty, retain; + int c; + + retain = 0; + while((c = getopt(argc, argv, "r")) >= 0) { + switch(c) { + case 'r': + retain = 1; + break; + case '?': + case ':': + default: + usage(); + exit(1); + } + } + if(argc - optind < 1) { + usage(); + exit(1); + } + if((tty = open("/dev/tty", O_RDWR)) < 0) { + perror("/dev/tty"); + exit(1); + } + if(ioctl(tty, TIOCNOTTY)) { + perror("TIOCNOTTY"); + exit(1); + } + if(retain) { + if(tty != 3) { + dup2(tty, 3); + close(tty); + } + } else { + close(tty); + } + execvp(argv[optind], argv + optind); + perror(argv[optind]); + return(127); +} -- 2.11.0