summaryrefslogtreecommitdiffstats
path: root/kiss
diff options
context:
space:
mode:
authorCraig Small <csmall@enc.com.au>2001-08-27 22:19:48 +0000
committerCraig Small <csmall@enc.com.au>2001-08-27 22:19:48 +0000
commit6083a4e8b1980014cb84d1352da844a5aa6bd4f9 (patch)
treefca0b04b1a0acf4956d3e05923b702484a5d8072 /kiss
parent3290d9406a0402fc21e242dc5a8179d2d9a1baaa (diff)
Tomi patch for mkiss pid problem
Diffstat (limited to 'kiss')
-rw-r--r--kiss/kissattach.c88
-rw-r--r--kiss/mkiss.c43
2 files changed, 80 insertions, 51 deletions
diff --git a/kiss/kissattach.c b/kiss/kissattach.c
index 8da27f5..6906ae4 100644
--- a/kiss/kissattach.c
+++ b/kiss/kissattach.c
@@ -40,12 +40,15 @@
#endif
static char *callsign;
-static int speed = 0;
-static int mtu = 0;
-static int logging = FALSE;
-static char *progname;
-
-static char *kiss_bname(char *s)
+static int speed = 0;
+static int mtu = 0;
+static int logging = FALSE;
+static char *progname = NULL;
+static char *kttyname = NULL;
+static char *portname = NULL;
+static char *inetaddr = NULL;
+
+static char *kiss_basename(char *s)
{
char *p = strrchr(s, '/');
return p ? p + 1 : s;
@@ -58,6 +61,8 @@ static void terminate(int sig)
closelog();
}
+ tty_unlock(kttyname);
+
exit(0);
}
@@ -68,7 +73,8 @@ static int readconfig(char *port)
int n = 0;
if ((fp = fopen(CONF_AXPORTS_FILE, "r")) == NULL) {
- fprintf(stderr, "%s: cannot open axports file\n", progname);
+ fprintf(stderr, "%s: cannot open axports file %s\n",
+ progname, CONF_AXPORTS_FILE);
return FALSE;
}
@@ -205,8 +211,8 @@ static int startiface(char *dev, struct hostent *hp)
return TRUE;
}
-
-static void usage(char *progname)
+
+static void usage(void)
{
fprintf(stderr, "usage: %s [-l] [-m mtu] [-v] ttyinterface port inetaddr\n", progname);
}
@@ -219,7 +225,7 @@ int main(int argc, char *argv[])
int v = 4;
struct hostent *hp = NULL;
- progname = kiss_bname(argv[0]);
+ progname = kiss_basename(argv[0]);
if (!strcmp(progname, "spattach"))
disc = N_6PACK;
@@ -230,11 +236,8 @@ int main(int argc, char *argv[])
disc = N_6PACK;
break;
case 'i':
- fprintf(stderr,"%s: -i flag depreciated, use new command line format instead.\n", progname);
- if ((hp = gethostbyname(optarg)) == NULL) {
- fprintf(stderr, "%s: invalid internet name/address - %s\n", progname, optarg);
- return 1;
- }
+ fprintf(stderr, "%s: -i flag depreciated, use new command line format instead.\n", progname);
+ inetaddr = optarg;
break;
case 'l':
logging = TRUE;
@@ -250,39 +253,48 @@ int main(int argc, char *argv[])
return 0;
case ':':
case '?':
- usage(progname);
+ usage();
return 1;
}
}
- if ((argc - optind) != 3 && ((argc - optind) != 2 || hp == NULL)) {
- usage(progname);
+ if ((argc - optind) != 3 && ((argc - optind) != 2 || !inetaddr)) {
+ usage();
return 1;
}
- if (tty_is_locked(argv[optind])) {
- fprintf(stderr, "%s: device %s already in use\n", progname, argv[optind]);
+ kttyname = argv[optind++];
+ portname = argv[optind++];
+
+ if (!inetaddr)
+ inetaddr = argv[optind];
+
+ if (tty_is_locked(kttyname)) {
+ fprintf(stderr, "%s: device %s already in use\n", progname, kttyname);
return 1;
}
- if (!readconfig(argv[optind + 1]))
+ if (!readconfig(portname))
return 1;
- if ((argc - optind) == 3) {
- if ((hp = gethostbyname(argv[optind + 2])) == NULL) {
- fprintf(stderr, "%s: invalid internet name/address - %s\n", progname, argv[optind+2]);
- }
- }
+ if ((hp = gethostbyname(inetaddr)) == NULL) {
+ fprintf(stderr, "%s: invalid internet name/address - %s\n", progname, inetaddr);
+ return 1;
+ }
- if ((fd = open(argv[optind], O_RDONLY | O_NONBLOCK)) == -1) {
- fprintf(stderr, "%s: ", progname);
- perror("open");
+ if ((fd = open(kttyname, O_RDONLY | O_NONBLOCK)) == -1) {
+ if (errno == ENOENT) {
+ fprintf(stderr, "%s: Cannot find serial device %s, no such file or directory.\n", progname, kttyname);
+ } else {
+ fprintf(stderr, "%s: %s: ", progname, kttyname);
+ perror("open");
+ }
return 1;
}
if (speed != 0 && !tty_speed(fd, speed))
return 1;
-
+
if (ioctl(fd, TIOCSETD, &disc) == -1) {
fprintf(stderr, "%s: Error setting line discipline: ", progname);
perror("TIOCSETD");
@@ -291,13 +303,13 @@ int main(int argc, char *argv[])
fprintf(stderr, "or, if you made it a module, that the module is loaded?\n");
return 1;
}
-
+
if (ioctl(fd, SIOCGIFNAME, dev) == -1) {
fprintf(stderr, "%s: ", progname);
perror("SIOCGIFNAME");
return 1;
}
-
+
if (!setifcall(fd, callsign))
return 1;
@@ -307,17 +319,17 @@ int main(int argc, char *argv[])
perror("SIOCSIFENCAP");
return 1;
}
-
+
if (!startiface(dev, hp))
return 1;
- printf("AX.25 port %s bound to device %s\n", argv[optind + 1], dev);
+ printf("AX.25 port %s bound to device %s\n", portname, dev);
if (logging) {
openlog(progname, LOG_PID, LOG_DAEMON);
- syslog(LOG_INFO, "AX.25 port %s bound to device %s\n", argv[optind + 1], dev);
+ syslog(LOG_INFO, "AX.25 port %s bound to device %s\n", portname, dev);
}
-
+
signal(SIGHUP, SIG_IGN);
signal(SIGTERM, terminate);
@@ -329,12 +341,12 @@ int main(int argc, char *argv[])
return 1;
}
- if (!tty_lock(argv[optind]))
+ if (!tty_lock(kttyname))
return 1;
while (1)
sleep(10000);
-
+
/* NOT REACHED */
return 0;
}
diff --git a/kiss/mkiss.c b/kiss/mkiss.c
index ad1450f..d04c5bb 100644
--- a/kiss/mkiss.c
+++ b/kiss/mkiss.c
@@ -40,6 +40,7 @@
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
+#include <sys/time.h>
#include <time.h>
#include <sys/types.h>
#include <unistd.h>
@@ -108,6 +109,10 @@ struct iface
unsigned long txbytes; /* TX bytes count */
};
+static struct iface *tty = NULL;
+static struct iface *pty[16] = { NULL };
+static int numptys = 0;
+
static void init_crc(void)
{
short int i, j;
@@ -339,11 +344,23 @@ static int kiss_rx(struct iface *ifp, unsigned char c, int usecrc)
static void sigterm_handler(int sig)
{
+ int i;
+
if (logging) {
syslog(LOG_INFO, "terminating on SIGTERM\n");
closelog();
}
-
+
+ tty_unlock(tty->name);
+ close(tty->fd);
+ free(tty);
+
+ for (i = 0; i < numptys; i++) {
+ tty_unlock(pty[i]->name);
+ close(pty[i]->fd);
+ free(pty[i]);
+ }
+
exit(0);
}
@@ -353,7 +370,7 @@ static void sigusr1_handler(int sig)
dump_report = TRUE;
}
-static void report(struct iface *tty, struct iface **pty, int numptys)
+static void report(void)
{
int i;
long t;
@@ -397,13 +414,11 @@ static void report(struct iface *tty, struct iface **pty, int numptys)
int main(int argc, char *argv[])
{
- struct iface *pty[16];
- struct iface *tty;
unsigned char *icp;
int topfd;
fd_set readfd;
struct timeval timeout, pollinterval;
- int retval, numptys, i, size, len;
+ int retval, i, size, len;
int speed = -1;
while ((size = getopt(argc, argv, "cfhlp:s:v")) != -1) {
@@ -508,13 +523,6 @@ int main(int argc, char *argv[])
topfd = (pty[i]->fd > topfd) ? pty[i]->fd : topfd;
}
- /*
- * Now all the ports are open, lock them.
- */
- tty_lock(argv[optind]);
- for (i = 0; i < numptys; i++)
- tty_lock(argv[optind + i + 1]);
-
signal(SIGHUP, SIG_IGN);
signal(SIGUSR1, sigusr1_handler);
signal(SIGTERM, sigterm_handler);
@@ -524,6 +532,13 @@ int main(int argc, char *argv[])
return 1;
}
+ /*
+ * Now all the ports are open, lock them.
+ */
+ tty_lock(tty->name);
+ for (i = 0; i < numptys; i++)
+ tty_lock(pty[i]->name);
+
if (logging) {
openlog("mkiss", LOG_PID, LOG_DAEMON);
syslog(LOG_INFO, "starting");
@@ -547,7 +562,7 @@ int main(int argc, char *argv[])
if (retval == -1) {
if (dump_report) {
if (logging)
- report(tty, pty, numptys);
+ report();
dump_report = FALSE;
continue;
} else {
@@ -612,10 +627,12 @@ end:
if (logging)
closelog();
+ tty_unlock(tty->name);
close(tty->fd);
free(tty);
for (i = 0; i < numptys; i++) {
+ tty_unlock(pty[i]->name);
close(pty[i]->fd);
free(pty[i]);
}