git-svn-id: svn+ssh://svn.dolda2000.com/srv/svn/repos/src/utils@597
959494ce-11ee-0310-bf91-
de5d638817bd
--- /dev/null
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+
+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);
+}