dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmo-abis/+/32402 )
Change subject: e1d: fix logic to detect if a timeslot is in use ......................................................................
e1d: fix logic to detect if a timeslot is in use
When we check bfd->fd, we also treat 0 as "not in use". This is not correct since 0 is a valid file descriptor (STDIN). Since we reliably initialize the file descriptor numbers to -1 on startup we can fix this. So let's treat all positive file descriptor numbers, including zero as an open timeslot.
Change-Id: I67bc5ca25620ff96441391798f761144570c8306 --- M src/input/e1d.c 1 file changed, 22 insertions(+), 7 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmo-abis refs/changes/02/32402/1
diff --git a/src/input/e1d.c b/src/input/e1d.c index 216575e..7b70dfe 100644 --- a/src/input/e1d.c +++ b/src/input/e1d.c @@ -427,17 +427,17 @@ lapd_instance_free(e1i_ts->lapd); e1i_ts->lapd = NULL; } - if (bfd->fd) { + if (bfd->fd >= 0) { close(bfd->fd); bfd->fd = -1; } continue; case E1INP_TS_TYPE_SIGN: - if (bfd->fd > 0 && ts_info[ts].cfg.mode != E1DP_TSMODE_HDLCFCS) { + if (bfd->fd >= 0 && ts_info[ts].cfg.mode != E1DP_TSMODE_HDLCFCS) { close(bfd->fd); bfd->fd = -1; } - if (bfd->fd <= 0) { + if (bfd->fd < 0) { bfd->fd = osmo_e1dp_client_ts_open(g_e1d, e1d_intf, e1d_line, ts, E1DP_TSMODE_HDLCFCS, D_BCHAN_TX_GRAN); } @@ -463,11 +463,11 @@ e1i_ts->lapd = NULL; } /* close, if old timeslot mode doesn't match new config */ - if (bfd->fd > 0 && ts_info[ts].cfg.mode != E1DP_TSMODE_HDLCFCS) { + if (bfd->fd >= 0 && ts_info[ts].cfg.mode != E1DP_TSMODE_HDLCFCS) { close(bfd->fd); bfd->fd = -1; } - if (bfd->fd <= 0) { + if (bfd->fd < 0) { bfd->fd = osmo_e1dp_client_ts_open(g_e1d, e1d_intf, e1d_line, ts, E1DP_TSMODE_HDLCFCS, D_BCHAN_TX_GRAN); } @@ -487,11 +487,11 @@ e1i_ts->lapd = NULL; } /* close, if old timeslot mode doesn't match new config */ - if (bfd->fd > 0 && ts_info[ts].cfg.mode != E1DP_TSMODE_RAW) { + if (bfd->fd >= 0 && ts_info[ts].cfg.mode != E1DP_TSMODE_RAW) { close(bfd->fd); bfd->fd = -1; } - if (bfd->fd <= 0) { + if (bfd->fd < 0) { bfd->fd = osmo_e1dp_client_ts_open(g_e1d, e1d_intf, e1d_line, ts, E1DP_TSMODE_RAW, D_BCHAN_TX_GRAN); }