man/pt_BR/ifconfig.8: remove untranslated paragraph
[platform/upstream/net-tools.git] / slattach.c
index cedae1b..2b7dde2 100644 (file)
 #include "util.h"
 
 #ifndef _PATH_LOCKD
-#define _PATH_LOCKD            "/var/lock"             /* lock files   */
+#define _PATH_LOCKD    "/var/lock"             /* lock files   */
 #endif
 #ifndef _UID_UUCP
-#define _UID_UUCP              "uucp"                  /* owns locks   */
+#define _UID_UUCP      "uucp"                  /* owns locks   */
+#endif
+#ifndef _PATH_DEVPTMX
+#define _PATH_DEVPTMX  "/dev/ptmx"             /* pseudo-terminal master */
 #endif
 
 
@@ -73,7 +76,7 @@
 
 
 const char *Release = RELEASE,
-          *Version = "@(#) slattach 1.21 (1999-11-21)",
+          *Version = "$Id: slattach.c,v 1.12 2009/09/06 22:59:43 vapier Exp $",
           *Signature = "net-tools, Fred N. van Kempen et al.";
 
 
@@ -108,6 +111,7 @@ struct termios      tty_saved,              /* saved TTY device state       */
 int            tty_sdisc,              /* saved TTY line discipline    */
                tty_ldisc,              /* current TTY line discipline  */
                tty_fd = -1;            /* TTY file descriptor          */
+char *         path_pts = NULL;        /* slave pseudo-terminal device */
 int            opt_c = 0;              /* "command" to run at exit     */
 int            opt_e = 0;              /* "activate only" flag         */
 int            opt_h = 0;              /* "hangup" on carrier loss     */
@@ -115,7 +119,7 @@ int         opt_h = 0;              /* "hangup" on carrier loss     */
 int            opt_k = 0;              /* "keepalive" value            */
 #endif
 int            opt_l = 0;              /* "lock it" flag               */
-int            opt_L = 0;              /* clocal flag                  */
+int            opt_L = 0;              /* 3-wire mode flag             */
 int            opt_m = 0;              /* "set RAW mode" flag          */
 int            opt_n = 0;              /* "set No Mesg" flag           */
 #ifdef SIOCSOUTFILL
@@ -195,15 +199,17 @@ tty_lock(char *path, int mode)
                return(-1);
        }
 
-       (void) close(fd);
-
        /* Make sure UUCP owns the lockfile.  Required by some packages. */
        if ((pw = getpwnam(_UID_UUCP)) == NULL) {
                if (opt_q == 0) fprintf(stderr, _("slattach: tty_lock: UUCP user %s unknown!\n"),
                                        _UID_UUCP);
+               (void) close(fd);
                return(0);      /* keep the lock anyway */
        }
-       (void) chown(saved_path, pw->pw_uid, pw->pw_gid);
+       (void) fchown(fd, pw->pw_uid, pw->pw_gid);
+
+       (void) close(fd);
+
        saved_lock = 1;
   } else {     /* unlock */
        if (saved_lock != 1) return(0);
@@ -342,9 +348,11 @@ tty_set_raw(struct termios *tty)
   tty->c_oflag = (0);                          /* output flags         */
   tty->c_lflag = (0);                          /* local flags          */
   speed = (tty->c_cflag & CBAUD);              /* save current speed   */
-  tty->c_cflag = (CRTSCTS | HUPCL | CREAD);    /* UART flags           */
+  tty->c_cflag = (HUPCL | CREAD);              /* UART flags           */
   if (opt_L) 
        tty->c_cflag |= CLOCAL;
+  else
+       tty->c_cflag |= CRTSCTS;
   tty->c_cflag |= speed;                       /* restore speed        */
   return(0);
 }
@@ -488,7 +496,28 @@ tty_open(char *name, const char *speed)
                return(-errno);
        }
        tty_fd = fd;
-       if (opt_d) printf("slattach: tty_open: %s (fd=%d) ", path_open, fd);
+       if (opt_d) printf("slattach: tty_open: %s (fd=%d)\n", path_open, fd);
+       if (!strcmp(path_open, _PATH_DEVPTMX)) {
+               if (opt_d) printf("slattach: tty_open: trying to grantpt and unlockpt\n");
+               if (grantpt(fd) < 0) {
+                   if (opt_q == 0) fprintf(stderr,
+                           "slattach: tty_open: grantpt: %s\n", strerror(errno));
+                   return(-errno);
+               }
+               if (unlockpt(fd) < 0) {
+                   if (opt_q == 0) fprintf(stderr,
+                           "slattach: tty_open: unlockpt: %s\n", strerror(errno));
+                   return(-errno);
+               }
+               path_pts = ptsname(fd);
+               if (path_pts == NULL) {
+                   if (opt_q == 0) fprintf(stderr,
+                           "slattach: tty_open: ptsname: %s\n", strerror(errno));
+                   return(-errno);
+               }
+               if (opt_d) printf("slattach: tty_open: %s: slave pseudo-terminal is %s\n",
+                                 path_open, path_pts);
+       }
   } else {
        tty_fd = 0;
   }
@@ -565,7 +594,7 @@ usage(void)
          "[-c cmd] [-s speed] [-p protocol] tty | -\n"
          "       slattach -V | --version\n";
 
-  fprintf(stderr, usage_msg);
+  fputs(usage_msg, stderr);
   exit(1);
 }
 
@@ -703,6 +732,7 @@ main(int argc, char *argv[])
         if (tty_get_name(buff)) { return(3); }
        printf(_("%s started"), proto);
        if (path_dev != NULL) printf(_(" on %s"), path_dev);
+       if (path_pts != NULL) printf(_(" ptsname %s"), path_pts);
        printf(_(" interface %s\n"), buff);
   }