Getting a SIGHUP for no carrier

I am trying to get a signal when the DCD (Carrier Detect) line changes. The
documentation says I can get a SIGHUP when the carrier goes away, but it
doesn’t seem to be working. I can poll the status and detect a change, but
I don’t get a signal. Below is a snippet of code. I get an ENOTTY from the
DCMD_CHR_LINESTATUS, which the docs say would indicate that /dev/ser1 is not
a terminal. An old version of tinit seems to support creating a terminal,
attaching it to a serial port and running a process. The current version
does not seem to do that. Any idea as to what I can do here to make it work
would be greatly appreciated.

pid_t self = setpgrp();

fd = open("/dev/ser1", O_RDWR);
if (fd == -1)
{
perror(“open:”);
return -1;
}

if (tcsetpgrp(fd, self) != 0)
{
perror(“tcsetpgrp:”);
printf(“Errno is 0x%x\n”, errno);
// return -1;
}

signal(SIGHUP, Handler);

for (int i=0; i<60; i++)
{
if (devctl(fd, DCMD_CHR_LINESTATUS, &data, sizeof(data), NULL) != 0)
{
perror(“devctl:”);
return -1;
}

printf(“Linestatus is 0x%x\n”, data);
sleep(1);
}

I should have said that I get an ENOTTY from tcsetpgrp. I have tried devctl
with DCMD_CHR_TCSETPGRP, but it fails with ENOTTY also.

Chris Elliott <Chris.P.Elliott@ieee.org> wrote:

I should have said that I get an ENOTTY from tcsetpgrp. I have tried devctl
with DCMD_CHR_TCSETPGRP, but it fails with ENOTTY also.

POSIX requires tcsetpgrp() to fail with an ENOTTY if the device is not
your controlling terminal.


Wojtek Lerch (wojtek@qnx.com) QNX Software Systems Ltd.

I have tried a number of things to make this so, including forking a child
process, calling setsid() and ioctl(TIOCSCTTY). Now these all return
successfully, but I still don’t get a SIGHUP when DCD changes.

Maybe I should back up. I have a one-pulse-per-second signal and want to be
notified at the pulse, but the timing doesn’t have to be very tight. The
DCD pin seemed to be a good idea, since I am reading from the serial port
anyway. Any suggestions as to how to make this work, either with the DCD
pin or through another route?

“Wojtek Lerch” <wojtek@qnx.com> wrote in message
news:9kronh$4l5$1@nntp.qnx.com

Chris Elliott <> Chris.P.Elliott@ieee.org> > wrote:
I should have said that I get an ENOTTY from tcsetpgrp. I have tried
devctl
with DCMD_CHR_TCSETPGRP, but it fails with ENOTTY also.

POSIX requires tcsetpgrp() to fail with an ENOTTY if the device is not
your controlling terminal.

for sighup you want to launch yourself on the device…
i usually use ‘on -t’ for this.
on -t spawns your app with setsid and tcsetpgroup flags

Chris Elliott <Chris.P.Elliott@ieee.org> wrote:

I have tried a number of things to make this so, including forking a child
process, calling setsid() and ioctl(TIOCSCTTY). Now these all return
successfully, but I still don’t get a SIGHUP when DCD changes.

Maybe I should back up. I have a one-pulse-per-second signal and want to be
notified at the pulse, but the timing doesn’t have to be very tight. The
DCD pin seemed to be a good idea, since I am reading from the serial port
anyway. Any suggestions as to how to make this work, either with the DCD
pin or through another route?

“Wojtek Lerch” <> wojtek@qnx.com> > wrote in message
news:9kronh$4l5$> 1@nntp.qnx.com> …
Chris Elliott <> Chris.P.Elliott@ieee.org> > wrote:
I should have said that I get an ENOTTY from tcsetpgrp. I have tried
devctl
with DCMD_CHR_TCSETPGRP, but it fails with ENOTTY also.

POSIX requires tcsetpgrp() to fail with an ENOTTY if the device is not
your controlling terminal.


Randy Martin randy@qnx.com
Manager of FAE Group, North America
QNX Software Systems www.qnx.com
175 Terence Matthews Crescent, Kanata, Ontario, Canada K2M 1W8
Tel: 613-591-0931 Fax: 613-591-3579