tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

slattach(8), attache line discipline by name



slattach(8) claims to attach tty line disciplines by name using the -t
option.  It does, however, only attach the slip or strip discpline (if
the latter is enabled).  It uses an ioctl to attach the line discipline
by number.  It is not possible to pass an arbitrary line discipline name.

NetBSD registers tty line disciplines internally by name (line
disciplines register themselved by calling ttyldisc_attach()), but
slattach(8) in its current form is not able to attach such named line
disciplines.

The attached patch to slattach(8) changes it to use the TIOCSLINED
ioctl, which passes a line discipline by name, instead of by number,
making slattach usable for any line discipline.  The default line
discipline remains at "slip".

ok?
Index: sbin/slattach/slattach.c
===================================================================
RCS file: /cvsroot/src/sbin/slattach/slattach.c,v
retrieving revision 1.32
diff -u -r1.32 slattach.c
--- sbin/slattach/slattach.c    30 Dec 2011 03:19:36 -0000      1.32
+++ sbin/slattach/slattach.c    19 Oct 2013 19:01:44 -0000
@@ -67,11 +67,10 @@
 #include <unistd.h>
 
 static int     speed = 9600;
-static int     slipdisc = SLIPDISC;
+static const char      *ldisc = "slip";
 
 static char    devicename[32];
 
-static int     ttydisc(char *);
 __dead static void     usage(void);
 
 int
@@ -105,8 +104,8 @@
                case 's':
                        speed = atoi(optarg);
                        break;
-               case 'r': case 't':
-                       slipdisc = ttydisc(optarg);
+               case 't':
+                       ldisc = optarg;
                        break;
                case '?':
                default:
@@ -138,8 +137,8 @@
                err(1, "tcsetattr");
        if (ioctl(fd, TIOCSDTR, 0) < 0 && errno != ENOTTY)
                err(1, "TIOCSDTR");
-       if (ioctl(fd, TIOCSETD, &slipdisc) < 0)
-               err(1, "TIOCSETD");
+       if (ioctl(fd, TIOCSLINED, ldisc) < 0)
+               err(1, "TIOCSLINED");
        if (opt_detach && daemon(0, 0) != 0)
                err(1, "couldn't detach");
        sigemptyset(&nsigset);
@@ -147,21 +146,6 @@
                sigsuspend(&nsigset);
 }
 
-static int
-ttydisc(char *name)
-{
-       if (strcmp(name, "slip") == 0)
-               return(SLIPDISC);
-#ifdef STRIPDISC
-       else if (strcmp(name, "strip") == 0)
-               return(STRIPDISC);
-#endif
-       else
-               usage();
-       /* NOTREACHED */
-       return -1;
-}
-
 static void
 usage(void)
 {


Home | Main Index | Thread Index | Old Index