* [PATCH] cec tools: exit when CEC device is disconnected
@ 2016-08-24 10:31 Johan Fjeldtvedt
2016-08-24 10:31 ` [PATCH] cec tools: exit if " Johan Fjeldtvedt
0 siblings, 1 reply; 3+ messages in thread
From: Johan Fjeldtvedt @ 2016-08-24 10:31 UTC (permalink / raw)
To: linux-media; +Cc: Johan Fjeldtvedt
When devices are disconnected, -EIO is currently returned by ioctl, but
this will be replaced by -ENODEV. When ioctl returns that, there is no
reason to let cec-ctl, cec-follower or cec-compliance run, so just exit
them.
This patch must be applied when the CEC framework has been changed to return
ENODEV instead of EIO when devices are disconnected.
Johan Fjeldtvedt (1):
cec tools: exit if device is disconnected
utils/cec-compliance/cec-compliance.h | 9 +++++++--
utils/cec-ctl/cec-ctl.cpp | 7 ++++++-
utils/cec-follower/cec-processing.cpp | 14 ++++++++++++--
3 files changed, 25 insertions(+), 5 deletions(-)
--
2.7.4
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] cec tools: exit if device is disconnected
2016-08-24 10:31 [PATCH] cec tools: exit when CEC device is disconnected Johan Fjeldtvedt
@ 2016-08-24 10:31 ` Johan Fjeldtvedt
2016-08-24 10:47 ` Hans Verkuil
0 siblings, 1 reply; 3+ messages in thread
From: Johan Fjeldtvedt @ 2016-08-24 10:31 UTC (permalink / raw)
To: linux-media; +Cc: Johan Fjeldtvedt
If the CEC device is disconnected, ioctl will return ENODEV. This is
checked for in cec-ctl (when monitoring), cec-follower and
cec-compliance, to make these exit when the CEC device disappears.
Signed-off-by: Johan Fjeldtvedt <jaffe1@gmail.com>
---
utils/cec-compliance/cec-compliance.h | 9 +++++++--
utils/cec-ctl/cec-ctl.cpp | 7 ++++++-
utils/cec-follower/cec-processing.cpp | 14 ++++++++++++--
3 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/utils/cec-compliance/cec-compliance.h b/utils/cec-compliance/cec-compliance.h
index cb236fd..6b180c1 100644
--- a/utils/cec-compliance/cec-compliance.h
+++ b/utils/cec-compliance/cec-compliance.h
@@ -334,10 +334,15 @@ static inline bool transmit_timeout(struct node *node, struct cec_msg *msg,
unsigned timeout = 2000)
{
struct cec_msg original_msg = *msg;
+ int res;
msg->timeout = timeout;
- if (doioctl(node, CEC_TRANSMIT, msg) ||
- !(msg->tx_status & CEC_TX_STATUS_OK))
+ res = doioctl(node, CEC_TRANSMIT, msg);
+ if (res == ENODEV) {
+ printf("No device.\n");
+ exit(1);
+ }
+ if (res || !(msg->tx_status & CEC_TX_STATUS_OK))
return false;
if (((msg->rx_status & CEC_RX_STATUS_OK) || (msg->rx_status & CEC_RX_STATUS_FEATURE_ABORT))
diff --git a/utils/cec-ctl/cec-ctl.cpp b/utils/cec-ctl/cec-ctl.cpp
index 2d0d9e5..10efcbd 100644
--- a/utils/cec-ctl/cec-ctl.cpp
+++ b/utils/cec-ctl/cec-ctl.cpp
@@ -1945,7 +1945,12 @@ skip_la:
struct cec_msg msg = { };
__u8 from, to;
- if (doioctl(&node, CEC_RECEIVE, &msg))
+ res = doioctl(&node, CEC_RECEIVE, &msg);
+ if (res == ENODEV) {
+ printf("No device.\n");
+ break;
+ }
+ if (res)
continue;
from = cec_msg_initiator(&msg);
diff --git a/utils/cec-follower/cec-processing.cpp b/utils/cec-follower/cec-processing.cpp
index 34d65e4..bbe80c5 100644
--- a/utils/cec-follower/cec-processing.cpp
+++ b/utils/cec-follower/cec-processing.cpp
@@ -979,7 +979,12 @@ void testProcessing(struct node *node)
if (FD_ISSET(fd, &ex_fds)) {
struct cec_event ev;
- if (doioctl(node, CEC_DQEVENT, &ev))
+ res = doioctl(node, CEC_DQEVENT, &ev);
+ if (res == ENODEV) {
+ printf("No device.\n");
+ break;
+ }
+ if (res)
continue;
log_event(ev);
if (ev.event == CEC_EVENT_STATE_CHANGE) {
@@ -995,7 +1000,12 @@ void testProcessing(struct node *node)
if (FD_ISSET(fd, &rd_fds)) {
struct cec_msg msg = { };
- if (doioctl(node, CEC_RECEIVE, &msg))
+ res = doioctl(node, CEC_RECEIVE, &msg);
+ if (res == ENODEV) {
+ printf("No device.\n");
+ break;
+ }
+ if (res)
continue;
__u8 from = cec_msg_initiator(&msg);
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] cec tools: exit if device is disconnected
2016-08-24 10:31 ` [PATCH] cec tools: exit if " Johan Fjeldtvedt
@ 2016-08-24 10:47 ` Hans Verkuil
0 siblings, 0 replies; 3+ messages in thread
From: Hans Verkuil @ 2016-08-24 10:47 UTC (permalink / raw)
To: Johan Fjeldtvedt, linux-media
On 08/24/16 12:31, Johan Fjeldtvedt wrote:
> If the CEC device is disconnected, ioctl will return ENODEV. This is
> checked for in cec-ctl (when monitoring), cec-follower and
> cec-compliance, to make these exit when the CEC device disappears.
>
> Signed-off-by: Johan Fjeldtvedt <jaffe1@gmail.com>
> ---
> utils/cec-compliance/cec-compliance.h | 9 +++++++--
> utils/cec-ctl/cec-ctl.cpp | 7 ++++++-
> utils/cec-follower/cec-processing.cpp | 14 ++++++++++++--
> 3 files changed, 25 insertions(+), 5 deletions(-)
>
> diff --git a/utils/cec-compliance/cec-compliance.h b/utils/cec-compliance/cec-compliance.h
> index cb236fd..6b180c1 100644
> --- a/utils/cec-compliance/cec-compliance.h
> +++ b/utils/cec-compliance/cec-compliance.h
> @@ -334,10 +334,15 @@ static inline bool transmit_timeout(struct node *node, struct cec_msg *msg,
> unsigned timeout = 2000)
> {
> struct cec_msg original_msg = *msg;
> + int res;
>
> msg->timeout = timeout;
> - if (doioctl(node, CEC_TRANSMIT, msg) ||
> - !(msg->tx_status & CEC_TX_STATUS_OK))
> + res = doioctl(node, CEC_TRANSMIT, msg);
> + if (res == ENODEV) {
> + printf("No device.\n");
I think that "Device was disconnected." would be a better text to use. It's a bit more
descriptive.
Regards,
Hans
> + exit(1);
> + }
> + if (res || !(msg->tx_status & CEC_TX_STATUS_OK))
> return false;
>
> if (((msg->rx_status & CEC_RX_STATUS_OK) || (msg->rx_status & CEC_RX_STATUS_FEATURE_ABORT))
> diff --git a/utils/cec-ctl/cec-ctl.cpp b/utils/cec-ctl/cec-ctl.cpp
> index 2d0d9e5..10efcbd 100644
> --- a/utils/cec-ctl/cec-ctl.cpp
> +++ b/utils/cec-ctl/cec-ctl.cpp
> @@ -1945,7 +1945,12 @@ skip_la:
> struct cec_msg msg = { };
> __u8 from, to;
>
> - if (doioctl(&node, CEC_RECEIVE, &msg))
> + res = doioctl(&node, CEC_RECEIVE, &msg);
> + if (res == ENODEV) {
> + printf("No device.\n");
> + break;
> + }
> + if (res)
> continue;
>
> from = cec_msg_initiator(&msg);
> diff --git a/utils/cec-follower/cec-processing.cpp b/utils/cec-follower/cec-processing.cpp
> index 34d65e4..bbe80c5 100644
> --- a/utils/cec-follower/cec-processing.cpp
> +++ b/utils/cec-follower/cec-processing.cpp
> @@ -979,7 +979,12 @@ void testProcessing(struct node *node)
> if (FD_ISSET(fd, &ex_fds)) {
> struct cec_event ev;
>
> - if (doioctl(node, CEC_DQEVENT, &ev))
> + res = doioctl(node, CEC_DQEVENT, &ev);
> + if (res == ENODEV) {
> + printf("No device.\n");
> + break;
> + }
> + if (res)
> continue;
> log_event(ev);
> if (ev.event == CEC_EVENT_STATE_CHANGE) {
> @@ -995,7 +1000,12 @@ void testProcessing(struct node *node)
> if (FD_ISSET(fd, &rd_fds)) {
> struct cec_msg msg = { };
>
> - if (doioctl(node, CEC_RECEIVE, &msg))
> + res = doioctl(node, CEC_RECEIVE, &msg);
> + if (res == ENODEV) {
> + printf("No device.\n");
> + break;
> + }
> + if (res)
> continue;
>
> __u8 from = cec_msg_initiator(&msg);
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-08-24 10:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-24 10:31 [PATCH] cec tools: exit when CEC device is disconnected Johan Fjeldtvedt
2016-08-24 10:31 ` [PATCH] cec tools: exit if " Johan Fjeldtvedt
2016-08-24 10:47 ` Hans Verkuil
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).