*
* Connection Manager
*
- * Copyright (C) 2011 Intel Corporation. All rights reserved.
+ * Copyright (C) 2012 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
#include <config.h>
#endif
+#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
static guint install_watch = 0;
static guint uart_watch = 0;
-static gint install_count = 0;
+static int install_count = 0;
#define NCCS2 19
struct termios2 {
if (ioctl(uart_fd, TIOCSETD, &ldisc) < 0)
goto err;
- g_atomic_int_set(&install_count, 0);
+ install_count = 1;
+ __sync_synchronize();
return FALSE;
err:
- g_atomic_int_set(&install_count, 0);
+ install_count = 0;
+ __sync_synchronize();
+
g_io_channel_shutdown(channel, TRUE, NULL);
g_io_channel_unref(channel);
DBG("%d %p", install, uart_channel);
if (install == FALSE) {
- g_atomic_int_set(&install_count, 0);
+ install_count = 0;
+ __sync_synchronize();
if (uart_channel == NULL) {
DBG("UART channel is NULL");
DBG("opening %s custom baud %lu", uart_dev_name, baud_rate);
- uart_fd = open(uart_dev_name, O_RDWR);
+ uart_fd = open(uart_dev_name, O_RDWR | O_CLOEXEC);
if (uart_fd < 0)
return -EIO;
uart_channel = NULL;
}
- g_atomic_int_set(&install_count, 0);
+ install_count = 0;
+ __sync_synchronize();
return 0;
}
return FALSE;
}
- if (g_atomic_int_get(&install_count) != 0) {
+ __sync_synchronize();
+ if (install_count != 0) {
status = g_io_channel_seek_position(channel, 0, G_SEEK_SET, NULL);
if (status != G_IO_STATUS_NORMAL) {
g_io_channel_shutdown(channel, TRUE, NULL);
return TRUE;
} else {
- g_atomic_int_set(&install_count, 1);
+ install_count = 1;
+ __sync_synchronize();
}
status = g_io_channel_seek_position(channel, 0, G_SEEK_SET, NULL);
if (install_ldisc(channel, install) < 0) {
connman_error("ldisc installation failed");
- g_atomic_int_set(&install_count, 0);
+ install_count = 0;
+ __sync_synchronize();
return TRUE;
}
return err;
}
- fd = open(TIST_SYSFS_INSTALL, O_RDONLY);
+ fd = open(TIST_SYSFS_INSTALL, O_RDONLY | O_CLOEXEC);
if (fd < 0) {
connman_error("Failed to open TI ST sysfs install file");
return -EIO;
install_event, NULL, NULL);
if (install_state) {
- g_atomic_int_set(&install_count, 1);
+ install_count = 1;
+ __sync_synchronize();
+
err = install_ldisc(install_channel, TRUE);
if (err < 0) {
connman_error("ldisc installtion failed");