More minor ksh stuff

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

More minor ksh stuff

Michael McConville-2
 * move tty_close() up so that we can call it in tty_init()
 * bump tfd's assignment into its own line
 * realize that those if conditions are identical

Index: tty.c
===================================================================
RCS file: /cvs/src/bin/ksh/tty.c,v
retrieving revision 1.10
diff -u -p -r1.10 tty.c
--- tty.c 10 Aug 2014 02:44:26 -0000 1.10
+++ tty.c 12 Sep 2015 05:19:50 -0000
@@ -6,6 +6,15 @@
 #include "tty.h"
 #undef EXTERN
 
+void
+tty_close(void)
+{
+ if (tty_fd >= 0) {
+ close(tty_fd);
+ tty_fd = -1;
+ }
+}
+
 /* Initialize tty_fd.  Used for saving/reseting tty modes upon
  * foreground job completion and for setting up tty process group.
  */
@@ -15,19 +24,15 @@ tty_init(int init_ttystate)
  int do_close = 1;
  int tfd;
 
- if (tty_fd >= 0) {
- close(tty_fd);
- tty_fd = -1;
- }
+ tty_close();
  tty_devtty = 1;
 
- if ((tfd = open("/dev/tty", O_RDWR, 0)) < 0) {
+ tfd = open("/dev/tty", O_RDWR, 0);
+ if (tfd < 0) {
  tty_devtty = 0;
  warningf(false, "No controlling tty (open /dev/tty: %s)",
     strerror(errno));
- }
 
- if (tfd < 0) {
  do_close = 0;
  if (isatty(0))
  tfd = 0;
@@ -45,13 +50,4 @@ tty_init(int init_ttystate)
  tcgetattr(tty_fd, &tty_state);
  if (do_close)
  close(tfd);
-}
-
-void
-tty_close(void)
-{
- if (tty_fd >= 0) {
- close(tty_fd);
- tty_fd = -1;
- }
 }

Reply | Threaded
Open this post in threaded view
|

Re: More minor ksh stuff

Nicholas Marriott-2
Hi

Why do you need to move tty_close? It is prototyped in tty.h which is
included at the start of your diff.

The other changes look good.


On Sat, Sep 12, 2015 at 03:17:53PM -0400, Michael McConville wrote:

>  * move tty_close() up so that we can call it in tty_init()
>  * bump tfd's assignment into its own line
>  * realize that those if conditions are identical
>
> Index: tty.c
> ===================================================================
> RCS file: /cvs/src/bin/ksh/tty.c,v
> retrieving revision 1.10
> diff -u -p -r1.10 tty.c
> --- tty.c 10 Aug 2014 02:44:26 -0000 1.10
> +++ tty.c 12 Sep 2015 05:19:50 -0000
> @@ -6,6 +6,15 @@
>  #include "tty.h"
>  #undef EXTERN
>  
> +void
> +tty_close(void)
> +{
> + if (tty_fd >= 0) {
> + close(tty_fd);
> + tty_fd = -1;
> + }
> +}
> +
>  /* Initialize tty_fd.  Used for saving/reseting tty modes upon
>   * foreground job completion and for setting up tty process group.
>   */
> @@ -15,19 +24,15 @@ tty_init(int init_ttystate)
>   int do_close = 1;
>   int tfd;
>  
> - if (tty_fd >= 0) {
> - close(tty_fd);
> - tty_fd = -1;
> - }
> + tty_close();
>   tty_devtty = 1;
>  
> - if ((tfd = open("/dev/tty", O_RDWR, 0)) < 0) {
> + tfd = open("/dev/tty", O_RDWR, 0);
> + if (tfd < 0) {
>   tty_devtty = 0;
>   warningf(false, "No controlling tty (open /dev/tty: %s)",
>      strerror(errno));
> - }
>  
> - if (tfd < 0) {
>   do_close = 0;
>   if (isatty(0))
>   tfd = 0;
> @@ -45,13 +50,4 @@ tty_init(int init_ttystate)
>   tcgetattr(tty_fd, &tty_state);
>   if (do_close)
>   close(tfd);
> -}
> -
> -void
> -tty_close(void)
> -{
> - if (tty_fd >= 0) {
> - close(tty_fd);
> - tty_fd = -1;
> - }
>  }
>

Reply | Threaded
Open this post in threaded view
|

Re: More minor ksh stuff

Michael McConville-2
Nicholas Marriott wrote:
> Why do you need to move tty_close? It is prototyped in tty.h which is
> included at the start of your diff.
>
> The other changes look good.

You're right. Here's a new diff:


Index: tty.c
===================================================================
RCS file: /cvs/src/bin/ksh/tty.c,v
retrieving revision 1.10
diff -u -p -r1.10 tty.c
--- tty.c 10 Aug 2014 02:44:26 -0000 1.10
+++ tty.c 13 Sep 2015 00:39:45 -0000
@@ -15,19 +15,14 @@ tty_init(int init_ttystate)
  int do_close = 1;
  int tfd;
 
- if (tty_fd >= 0) {
- close(tty_fd);
- tty_fd = -1;
- }
+ tty_close();
  tty_devtty = 1;
 
- if ((tfd = open("/dev/tty", O_RDWR, 0)) < 0) {
+ tfd = open("/dev/tty", O_RDWR, 0);
+ if (tfd < 0) {
  tty_devtty = 0;
  warningf(false, "No controlling tty (open /dev/tty: %s)",
     strerror(errno));
- }
-
- if (tfd < 0) {
  do_close = 0;
  if (isatty(0))
  tfd = 0;