aboutsummaryrefslogtreecommitdiff
path: root/src/mm-port-serial.c
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2014-10-07 15:53:53 -0500
committerDan Williams <dcbw@redhat.com>2014-10-07 16:01:54 -0500
commit41b7e7b048e67a0b329c820c81beccf42bf0957e (patch)
treec330a18bc14728da5f274c6cb0c6c6ce318fa402 /src/mm-port-serial.c
parent1e5ec7e1b147fc6dd2227d7ebf7510a96eb0503e (diff)
port-serial: fix forced closing after b28230411
b28230411 moved up the self->priv->forced_close = TRUE, which caused mm_port_serial_close() to just return without actually closing the port and cleaning up. Also, cancel the reopen separately from closing the port since the two operations are actually independent of each other.
Diffstat (limited to 'src/mm-port-serial.c')
-rw-r--r--src/mm-port-serial.c43
1 files changed, 23 insertions, 20 deletions
diff --git a/src/mm-port-serial.c b/src/mm-port-serial.c
index 9b749004..3af1b8e2 100644
--- a/src/mm-port-serial.c
+++ b/src/mm-port-serial.c
@@ -1274,25 +1274,23 @@ mm_port_serial_is_open (MMPortSerial *self)
return !!self->priv->open_count;
}
-void
-mm_port_serial_close (MMPortSerial *self)
+static void
+_close_internal (MMPortSerial *self, gboolean force)
{
const char *device;
int i;
g_return_if_fail (MM_IS_PORT_SERIAL (self));
- /* If we forced closing the port, open_count will be 0 already.
- * Just return without issuing any warning */
- if (self->priv->forced_close)
- return;
-
- g_return_if_fail (self->priv->open_count > 0);
+ if (force)
+ self->priv->open_count = 0;
+ else {
+ g_return_if_fail (self->priv->open_count > 0);
+ self->priv->open_count--;
+ }
device = mm_port_get_device (MM_PORT (self));
- self->priv->open_count--;
-
mm_dbg ("(%s) device open count is %d (close)", device, self->priv->open_count);
if (self->priv->open_count > 0)
@@ -1402,10 +1400,18 @@ mm_port_serial_close (MMPortSerial *self)
g_clear_object (&self->priv->cancellable);
}
+void
+mm_port_serial_close (MMPortSerial *self)
+{
+ g_return_if_fail (MM_IS_PORT_SERIAL (self));
+
+ if (!self->priv->forced_close)
+ _close_internal (self, FALSE);
+}
+
static void
port_serial_close_force (MMPortSerial *self)
{
- g_return_if_fail (self != NULL);
g_return_if_fail (MM_IS_PORT_SERIAL (self));
/* If already forced to close, return */
@@ -1418,19 +1424,16 @@ port_serial_close_force (MMPortSerial *self)
* open counts */
self->priv->forced_close = TRUE;
- /* If already closed, done */
- if (!self->priv->open_count && !self->priv->reopen_ctx)
- return;
-
/* Cancel port reopening if one is running */
port_serial_reopen_cancel (self);
- /* Force the port to close */
- self->priv->open_count = 1;
- mm_port_serial_close (self);
+ /* If already closed, done */
+ if (self->priv->open_count > 0) {
+ _close_internal (self, TRUE);
- /* Notify about the forced close status */
- g_signal_emit (self, signals[FORCED_CLOSE], 0);
+ /* Notify about the forced close status */
+ g_signal_emit (self, signals[FORCED_CLOSE], 0);
+ }
}
/*****************************************************************************/