diff --git a/src/main.cc b/src/main.cc index 5852773..db30105 100644 --- a/src/main.cc +++ b/src/main.cc @@ -97,7 +97,9 @@ provided you with this binary. Read the full license for all details. // We want the data visible in the log file asap! setbuf(stdout, NULL); startUsingCommandline(cmdline.get()); + exit(0); } + error("(main) internal error\n"); } bool startUsingCommandline(Configuration *config) @@ -372,7 +374,6 @@ LIST_OF_METERS } manager->waitForStop(); - if (config->daemon) { notice("(wmbusmeters) shutting down\n"); } diff --git a/src/serial.cc b/src/serial.cc index 6aa2fd8..6c760c4 100644 --- a/src/serial.cc +++ b/src/serial.cc @@ -969,6 +969,7 @@ static int openSerialTTY(const char *tty, int baud_rate) int rc = 0; speed_t speed = 0; struct termios tios; + //int DTR_flag = TIOCM_DTR; int fd = open(tty, O_RDWR | O_NOCTTY | O_NONBLOCK); if (fd == -1) { @@ -1021,6 +1022,11 @@ static int openSerialTTY(const char *tty, int baud_rate) rc = tcsetattr(fd, TCSANOW, &tios); if (rc < 0) goto err; + // This code can toggle DTR... maybe necessary + // for the pl2303 usb2serial driver/device. + //rc = ioctl(fd, TIOCMBIC, &DTR_flag); + //if (rc != 0) goto err; + return fd; err: diff --git a/src/shell.cc b/src/shell.cc index acc2ba5..e3b31d8 100644 --- a/src/shell.cc +++ b/src/shell.cc @@ -179,18 +179,9 @@ void stopBackgroundShell(int pid) { assert(pid > 0); - // This will actually stop the entire process group. - // But it is ok, for now, since this function is - // only called when wmbusmeters is exiting. - - // If we send sigint only to pid, then this will - // not always propagate properly to the child processes - // of the bgshell, ie rtl_sdr and rtl_wmbus, thus - // leaving those hanging in limbo and messing everything up. - // The solution for now is to send sigint to 0, which - // means send sigint to the whole process group that the - // sender belongs to. - int rc = kill(0, SIGINT); + // Sending SIGTERM to the pid will properly shut down the subshell + // and its contents. + int rc = kill(pid, SIGTERM); if (rc < 0) { debug("(bgshell) could not sigint pid %d, exited already?\n", pid); return;