aboutsummaryrefslogtreecommitdiffstats
path: root/ncpd
diff options
context:
space:
mode:
authorFritz Elfert <felfert@to.com>1999-07-04 19:12:50 +0000
committerFritz Elfert <felfert@to.com>1999-07-04 19:12:50 +0000
commitccc2e6cfe3a5936b0c72fa57faca5fb7b46c0b1d (patch)
treea9b3d6d93022dd1e625133931e1e03c71ed7f67d /ncpd
parent8f953dfc4c3349e7a022ea48dbc22feae34fc0f6 (diff)
downloadplptools-ccc2e6cfe3a5936b0c72fa57faca5fb7b46c0b1d.tar.gz
plptools-ccc2e6cfe3a5936b0c72fa57faca5fb7b46c0b1d.tar.bz2
plptools-ccc2e6cfe3a5936b0c72fa57faca5fb7b46c0b1d.zip
Forking, syslog and better error handling
Diffstat (limited to 'ncpd')
-rw-r--r--ncpd/link.cc4
-rw-r--r--ncpd/main.cc31
-rw-r--r--ncpd/ncp.cc5
-rw-r--r--ncpd/packet.cc25
-rw-r--r--ncpd/packet.h1
5 files changed, 54 insertions, 12 deletions
diff --git a/ncpd/link.cc b/ncpd/link.cc
index cc3781d..94a6f97 100644
--- a/ncpd/link.cc
+++ b/ncpd/link.cc
@@ -159,6 +159,10 @@ poll()
return ret;
}
}
+ if (p->linkFailed()) {
+ failed = true;
+ return ret;
+ }
if (!somethingToSend) {
countToResend = 0;
diff --git a/ncpd/main.cc b/ncpd/main.cc
index 1dc360f..7b46449 100644
--- a/ncpd/main.cc
+++ b/ncpd/main.cc
@@ -76,7 +76,7 @@ pollSocketConnections(int &numScp, socketChan ** scp)
void
usage()
{
- cerr << "Usage : ncpd [-V] [-v logclass] [-p <port>] [-d <device>] [-b <baudrate>]\n";
+ cerr << "Usage : ncpd [-V] [-v logclass] [-d] [-p <port>] [-s <device>] [-b <baudrate>]\n";
exit(1);
}
@@ -86,6 +86,7 @@ main(int argc, char **argv)
ppsocket skt;
IOWatch iow;
int pid;
+ bool dofork = true;
// Command line parameter processing
int sockNum = DPORT;
@@ -99,7 +100,7 @@ main(int argc, char **argv)
for (int i = 1; i < argc; i++) {
if (!strcmp(argv[i], "-p") && i + 1 < argc) {
sockNum = atoi(argv[++i]);
- } else if (!strcmp(argv[i], "-d") && i + 1 < argc) {
+ } else if (!strcmp(argv[i], "-s") && i + 1 < argc) {
serialDevice = argv[++i];
} else if (!strcmp(argv[i], "-v") && i + 1 < argc) {
i++;
@@ -119,6 +120,8 @@ main(int argc, char **argv)
verbose = true;
} else if (!strcmp(argv[i], "-b") && i + 1 < argc) {
baudRate = atoi(argv[++i]);
+ } else if (!strcmp(argv[i], "-d")) {
+ dofork = 0;
} else if (!strcmp(argv[i], "-V")) {
cout << "ncpd version " << VERSION << endl;
exit(0);
@@ -126,18 +129,24 @@ main(int argc, char **argv)
usage();
}
- switch ((pid = fork())) {
+ if (dofork)
+ pid = fork();
+ else
+ pid = 0;
+ switch (pid) {
case 0:
if (!skt.listen("127.0.0.1", sockNum))
cerr << "listen on port " << sockNum << ": " << strerror(errno) << endl;
else {
- logbuf dlog(LOG_DEBUG);
- logbuf elog(LOG_ERR);
- ostream lout(&dlog);
- ostream lerr(&elog);
- cout = lout;
- cerr = lerr;
- openlog("ncpd", LOG_CONS|LOG_PID, LOG_DAEMON);
+ if (dofork) {
+ logbuf dlog(LOG_DEBUG);
+ logbuf elog(LOG_ERR);
+ ostream lout(&dlog);
+ ostream lerr(&elog);
+ cout = lout;
+ cerr = lerr;
+ openlog("ncpd", LOG_CONS|LOG_PID, LOG_DAEMON);
+ }
ncp *a = new ncp(serialDevice, baudRate, iow);
int numScp = 0;
socketChan *scp[8];
@@ -157,7 +166,7 @@ main(int argc, char **argv)
if (a->stuffToSend())
iow.watch(0, 100000);
else
- iow.watch(100000, 0);
+ iow.watch(1, 0);
if (a->hasFailed()) {
if (verbose)
diff --git a/ncpd/ncp.cc b/ncpd/ncp.cc
index 2391586..90b188b 100644
--- a/ncpd/ncp.cc
+++ b/ncpd/ncp.cc
@@ -51,8 +51,11 @@ ncp::~ncp()
void ncp::
reset() {
- for (int i = 0; i < 8; i++)
+ for (int i = 0; i < 8; i++) {
+ if (channelPtr[i])
+ channelPtr[i]->terminateWhenAsked();
channelPtr[i] = NULL;
+ }
failed = false;
gotLinkChan = false;
l->reset();
diff --git a/ncpd/packet.cc b/ncpd/packet.cc
index 70006bc..9009f86 100644
--- a/ncpd/packet.cc
+++ b/ncpd/packet.cc
@@ -29,6 +29,7 @@
#include <fstream.h>
#include <iomanip.h>
#include <errno.h>
+#include <sys/ioctl.h>
extern "C" {
#include "mp_serial.h"
@@ -155,6 +156,8 @@ bool packet::
get(unsigned char &type, bufferStore & ret)
{
while (!terminated()) {
+ if (linkFailed())
+ return false;
int res = read(fd, inPtr, BUFFERLEN - inLen);
if (res > 0) {
if (verbose & PKT_DEBUG_LOG)
@@ -241,3 +244,25 @@ terminated()
termLen = l;
return false;
}
+
+bool packet::
+linkFailed()
+{
+ int arg;
+ bool failed = false;
+ int res = ioctl(fd, TIOCMGET, &arg);
+ if (res < 0)
+ failed = true;
+ if (verbose & PKT_DEBUG_DUMP)
+ cout << "packet: DTR:" << ((arg & TIOCM_DTR)?1:0)
+ << " RTS:" << ((arg & TIOCM_RTS)?1:0)
+ << " DCD:" << ((arg & TIOCM_CAR)?1:0)
+ << " DSR:" << ((arg & TIOCM_DSR)?1:0)
+ << " CTS:" << ((arg & TIOCM_CTS)?1:0) << endl;
+ if (((arg & TIOCM_DSR) == 0) || ((arg & TIOCM_CTS) == 0))
+ failed = true;
+ if ((verbose & PKT_DEBUG_LOG) && failed)
+ cout << "packet: linkFAILED\n";
+ return failed;
+}
+
diff --git a/ncpd/packet.h b/ncpd/packet.h
index 85a0a77..8348ba7 100644
--- a/ncpd/packet.h
+++ b/ncpd/packet.h
@@ -19,6 +19,7 @@ class packet {
bool get(unsigned char &type, bufferStore &b);
void setVerbose(short int);
short int getVerbose();
+ bool linkFailed();
private:
bool terminated();