summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Osterried <thomas@osterried.de>2008-09-26 16:48:11 +0000
committerThomas Osterried <thomas@osterried.de>2008-09-26 16:48:11 +0000
commit7ab8e1e5d2470b8c914ae8f526f4185db5d88222 (patch)
treedf4abb99a955a6c9741da0c0a16caae4395b48a2
parent98883e6860458db8031690e1dd99ae2e4cc94263 (diff)
kissattach now supports Unix98 pseudo terminals (/dev/ptmx).
Thanks to Christoph Rueckert <dk2crn>.
-rw-r--r--kiss/kissattach.816
-rw-r--r--kiss/kissattach.c46
2 files changed, 48 insertions, 14 deletions
diff --git a/kiss/kissattach.8 b/kiss/kissattach.8
index 9b81e40..e4fbf5b 100644
--- a/kiss/kissattach.8
+++ b/kiss/kissattach.8
@@ -20,13 +20,19 @@ command line.
.LP
The tty argument will typically be that of a serial port with a KISS or 6PACK
TNC attached, although it could be a pseudo tty or a KISS port emulator such as
-an SCC card. The port arguments is the name of a port as given in the
+an SCC card. Kissattach supports BSD-style pseudo-terminals as well as
+the Unix98 pty's. If the tty argument is "/dev/ptmx", then Unix98 behaviour
+will automaticaly take effekt. With Unix98 pty's, the slave tty name
+could not be forseen. That's why kissattach will print the corresponding slave
+pty name as a separate line on stdout.
+.LP
+The port argument is the name of a port as given in the
axports(5) file.
.LP
-The inetaddr argument is the IP address of the new interface. Some time it
-was mandatory argument (although due to historical reasons this restriction is
-lifted if the old -i option is used). But there's really not a need for
-the interface to have an IP address assigned to.
+The optional inetaddr argument is the IP address of the new interface. Some
+time it was mandatory argument (although due to historical reasons this
+restriction is lifted if the old -i option is used). But there's really not
+a need for the interface to have an IP address assigned to.
.SH OPTIONS
.TP 16
.BI "\-6"
diff --git a/kiss/kissattach.c b/kiss/kissattach.c
index a148b7b..d4bfd26 100644
--- a/kiss/kissattach.c
+++ b/kiss/kissattach.c
@@ -1,4 +1,5 @@
#include <stdio.h>
+#define __USE_XOPEN
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@@ -48,6 +49,7 @@ static char *kttyname = NULL;
static char *portname = NULL;
static char *inetaddr = NULL;
static int allow_broadcast = 0;
+static int i_am_unix98_pty_master = 0; /* unix98 ptmx support */
static char *kiss_basename(char *s)
{
@@ -62,7 +64,8 @@ static void terminate(int sig)
closelog();
}
- tty_unlock(kttyname);
+ if (!i_am_unix98_pty_master)
+ tty_unlock(kttyname);
exit(0);
}
@@ -228,6 +231,8 @@ int main(int argc, char *argv[])
int disc = N_AX25;
char dev[64];
int v = 4;
+ char *namepts = NULL; /* name of the unix98 pts slave, which
+ * the client has to use */
struct hostent *hp = NULL;
progname = kiss_basename(argv[0]);
@@ -281,9 +286,14 @@ int main(int argc, char *argv[])
if (argc-1 >= optind && !inetaddr)
inetaddr = argv[optind];
- if (tty_is_locked(kttyname)) {
- fprintf(stderr, "%s: device %s already in use\n", progname, kttyname);
- return 1;
+ if (!strcmp("/dev/ptmx", kttyname))
+ i_am_unix98_pty_master = 1;
+
+ if (!i_am_unix98_pty_master) {
+ if (tty_is_locked(kttyname)) {
+ fprintf(stderr, "%s: device %s already in use\n", progname, kttyname);
+ return 1;
+ }
}
if (!readconfig(portname))
@@ -304,6 +314,19 @@ int main(int argc, char *argv[])
return 1;
}
+ if (i_am_unix98_pty_master) {
+ /* get name of pts-device */
+ if ((namepts = ptsname(fd)) == NULL) {
+ fprintf(stderr, "%s: Cannot get name of pts-device.\n", progname);
+ return 1;
+ }
+ /* unlock pts-device */
+ if (unlockpt(fd) == -1) {
+ fprintf(stderr, "%s: Cannot unlock pts-device %s\n", progname, namepts);
+ return 1;
+ }
+ }
+
if (speed != 0 && !tty_speed(fd, speed))
return 1;
@@ -337,10 +360,14 @@ int main(int argc, char *argv[])
return 1;
printf("AX.25 port %s bound to device %s\n", portname, dev);
-
+ if (i_am_unix98_pty_master) {
+ /* Users await the slave pty to be referenced in the 3d line */
+ printf("Awaiting client connects on\n%s\n", namepts);
+ }
if (logging) {
openlog(progname, LOG_PID, LOG_DAEMON);
- syslog(LOG_INFO, "AX.25 port %s bound to device %s\n", portname, dev);
+ syslog(LOG_INFO, "AX.25 port %s bound to device %s%s%s\n", portname, dev, (i_am_unix98_pty_master ? " with slave pty " : ""), (i_am_unix98_pty_master ? namepts : ""));
+
}
signal(SIGHUP, SIG_IGN);
@@ -353,9 +380,10 @@ int main(int argc, char *argv[])
fprintf(stderr, "%s: cannot become a daemon\n", progname);
return 1;
}
-
- if (!tty_lock(kttyname))
- return 1;
+ if (!i_am_unix98_pty_master) {
+ if (!tty_lock(kttyname))
+ return 1;
+ }
while (1)
sleep(10000);