give tty_init() another argument for silent initialisation
This commit is contained in:
		
							
								
								
									
										6
									
								
								jobs.c
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								jobs.c
									
									
									
									
									
								
							| @@ -2,7 +2,7 @@ | |||||||
|  |  | ||||||
| #include "sh.h" | #include "sh.h" | ||||||
|  |  | ||||||
| __RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.42 2008/12/13 17:02:15 tg Exp $"); | __RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.43 2008/12/29 20:47:15 tg Exp $"); | ||||||
|  |  | ||||||
| /* Order important! */ | /* Order important! */ | ||||||
| #define PRUNNING	0 | #define PRUNNING	0 | ||||||
| @@ -155,7 +155,7 @@ j_init(int mflagset) | |||||||
| 	if (Flag(FMONITOR)) | 	if (Flag(FMONITOR)) | ||||||
| 		j_change(); | 		j_change(); | ||||||
| 	else if (Flag(FTALKING)) | 	else if (Flag(FTALKING)) | ||||||
| 		tty_init(true); | 		tty_init(true, true); | ||||||
| } | } | ||||||
|  |  | ||||||
| /* job cleanup before shell exit */ | /* job cleanup before shell exit */ | ||||||
| @@ -217,7 +217,7 @@ j_change(void) | |||||||
|  |  | ||||||
| 		/* Don't call tcgetattr() 'til we own the tty process group */ | 		/* Don't call tcgetattr() 'til we own the tty process group */ | ||||||
| 		if (use_tty) | 		if (use_tty) | ||||||
| 			tty_init(false); | 			tty_init(false, true); | ||||||
|  |  | ||||||
| 		/* no controlling tty, no SIGT* */ | 		/* no controlling tty, no SIGT* */ | ||||||
| 		if ((ttypgrp_ok = use_tty && tty_fd >= 0 && tty_devtty)) { | 		if ((ttypgrp_ok = use_tty && tty_fd >= 0 && tty_devtty)) { | ||||||
|   | |||||||
							
								
								
									
										21
									
								
								main.c
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								main.c
									
									
									
									
									
								
							| @@ -13,7 +13,7 @@ | |||||||
| #include <locale.h> | #include <locale.h> | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| __RCSID("$MirOS: src/bin/mksh/main.c,v 1.116 2008/12/13 17:02:15 tg Exp $"); | __RCSID("$MirOS: src/bin/mksh/main.c,v 1.117 2008/12/29 20:47:15 tg Exp $"); | ||||||
|  |  | ||||||
| extern char **environ; | extern char **environ; | ||||||
|  |  | ||||||
| @@ -735,9 +735,9 @@ remove_temps(struct temp *tp) | |||||||
|  * foreground job completion and for setting up tty process group. |  * foreground job completion and for setting up tty process group. | ||||||
|  */ |  */ | ||||||
| void | void | ||||||
| tty_init(int init_ttystate) | tty_init(bool init_ttystate, bool need_tty) | ||||||
| { | { | ||||||
| 	int do_close = 1; | 	bool do_close = true; | ||||||
| 	int tfd; | 	int tfd; | ||||||
|  |  | ||||||
| 	if (tty_fd >= 0) { | 	if (tty_fd >= 0) { | ||||||
| @@ -753,25 +753,32 @@ tty_init(int init_ttystate) | |||||||
| #endif | #endif | ||||||
| 	if ((tfd = open("/dev/tty", O_RDWR, 0)) < 0) { | 	if ((tfd = open("/dev/tty", O_RDWR, 0)) < 0) { | ||||||
| 		tty_devtty = 0; | 		tty_devtty = 0; | ||||||
| 		warningf(false, "No controlling tty (open /dev/tty: %s)", | 		if (need_tty) | ||||||
|  | 			warningf(false, | ||||||
|  | 			    "No controlling tty (open /dev/tty: %s)", | ||||||
| 			    strerror(errno)); | 			    strerror(errno)); | ||||||
| 	} | 	} | ||||||
| 	if (tfd < 0) { | 	if (tfd < 0) { | ||||||
| 		do_close = 0; | 		do_close = false; | ||||||
| 		if (isatty(0)) | 		if (isatty(0)) | ||||||
| 			tfd = 0; | 			tfd = 0; | ||||||
| 		else if (isatty(2)) | 		else if (isatty(2)) | ||||||
| 			tfd = 2; | 			tfd = 2; | ||||||
| 		else { | 		else { | ||||||
| 			warningf(false, "Can't find tty file descriptor"); | 			if (need_tty) | ||||||
|  | 				warningf(false, | ||||||
|  | 				    "Can't find tty file descriptor"); | ||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	if ((tty_fd = fcntl(tfd, F_DUPFD, FDBASE)) < 0) { | 	if ((tty_fd = fcntl(tfd, F_DUPFD, FDBASE)) < 0) { | ||||||
|  | 		if (need_tty) | ||||||
| 			warningf(false, "j_ttyinit: dup of tty fd failed: %s", | 			warningf(false, "j_ttyinit: dup of tty fd failed: %s", | ||||||
| 			    strerror(errno)); | 			    strerror(errno)); | ||||||
| 	} else if (fcntl(tty_fd, F_SETFD, FD_CLOEXEC) < 0) { | 	} else if (fcntl(tty_fd, F_SETFD, FD_CLOEXEC) < 0) { | ||||||
| 		warningf(false, "j_ttyinit: can't set close-on-exec flag: %s", | 		if (need_tty) | ||||||
|  | 			warningf(false, | ||||||
|  | 			    "j_ttyinit: can't set close-on-exec flag: %s", | ||||||
| 			    strerror(errno)); | 			    strerror(errno)); | ||||||
| 		close(tty_fd); | 		close(tty_fd); | ||||||
| 		tty_fd = -1; | 		tty_fd = -1; | ||||||
|   | |||||||
							
								
								
									
										4
									
								
								sh.h
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								sh.h
									
									
									
									
									
								
							| @@ -103,7 +103,7 @@ | |||||||
| #define __SCCSID(x)	__IDSTRING(sccsid,x) | #define __SCCSID(x)	__IDSTRING(sccsid,x) | ||||||
|  |  | ||||||
| #ifdef EXTERN | #ifdef EXTERN | ||||||
| __RCSID("$MirOS: src/bin/mksh/sh.h,v 1.268 2008/12/17 19:39:23 tg Exp $"); | __RCSID("$MirOS: src/bin/mksh/sh.h,v 1.269 2008/12/29 20:47:16 tg Exp $"); | ||||||
| #endif | #endif | ||||||
| #define MKSH_VERSION "R36 2008/12/17" | #define MKSH_VERSION "R36 2008/12/17" | ||||||
|  |  | ||||||
| @@ -1600,7 +1600,7 @@ EXTERN int tty_fd I__(-1);	/* dup'd tty file descriptor */ | |||||||
| EXTERN int tty_devtty;		/* true if tty_fd is from /dev/tty */ | EXTERN int tty_devtty;		/* true if tty_fd is from /dev/tty */ | ||||||
| EXTERN struct termios tty_state;	/* saved tty state */ | EXTERN struct termios tty_state;	/* saved tty state */ | ||||||
|  |  | ||||||
| extern void tty_init(int); | extern void tty_init(bool, bool); | ||||||
| extern void tty_close(void); | extern void tty_close(void); | ||||||
|  |  | ||||||
| /* be sure not to interfere with anyone else's idea about EXTERN */ | /* be sure not to interfere with anyone else's idea about EXTERN */ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user