- Use g_unix_fd_add() instead of g_io_channel_unix_fd().
- When calling the UnixFdFunc function, the function checks whether
the file descriptor is equal to the file descriptor of the IOChannel instance.
It's not equal, the function will remove the GSource.
Change-Id: I19ce6d18d11d175e33f250748de1f4a129cf7b07
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
channel_ = std::make_unique<IOChannel>(fd, IOChannel::IOCondition::IO_IN,
this);
- channel_->SetCloseOnDestroy(false);
handle_ = monitor_auto.release();
disposed_ = false;
}
}
channel_ = std::make_unique<IOChannel>(fd, G_IO_IN, this);
- channel_->SetCloseOnDestroy(false);
wd_ = wd;
fd_ = fd;
}
hydra_channel_.reset(
new IOChannel(
hydra_socket_->GetFd(), IOChannel::IOCondition::IO_IN, this));
- hydra_channel_->SetCloseOnDestroy(false);
} catch (const Exception& e) {
_E("Exception occurs. error: %s", e.what());
THROW(e.GetErrorCode());
new IOChannel(client_socket_->GetFd(),
IOChannel::IOCondition::IO_IN | IOChannel::IOCondition::IO_HUP,
this));
- client_channel_->SetCloseOnDestroy(false);
hydra_prepared_ = true;
SECURE_LOGI("Type %d hydra loader was connected. pid: %d",
GetType(), GetHydraPid());
channel_.reset(new IOChannel(socket_->GetFd(), IOChannel::IOCondition::IO_IN,
this));
- channel_->SetCloseOnDestroy(false);
}
HydraSigchldEvent::~HydraSigchldEvent() {
socket_.reset(GetLaunchpadSocket());
channel_.reset(
new IOChannel(socket_->GetFd(), IOChannel::IOCondition::IO_IN, this));
- channel_->SetCloseOnDestroy(false);
} catch (const Exception& e) {
_E("Exception occurs. error: %s", e.what());
return false;
server_channel_.reset(new IOChannel(server_socket_->GetFd(),
IOChannel::IOCondition::IO_IN, this));
- server_channel_->SetCloseOnDestroy(false);
} catch (const Exception& e) {
_E("Exception occurs. error: %s", e.what());
THROW(e.GetErrorCode());
client_socket_->GetFd(),
IOChannel::IOCondition::IO_IN | IOChannel::IOCondition::IO_HUP,
this));
- client_channel_->SetCloseOnDestroy(false);
if (IsHydraMode())
SetPid(peer_cred->GetPid());
auto peer_cred = PeerCredentials::Get(client_socket_->GetFd());
if (!peer_cred) return;
- if (peer_cred->GetPid() == pid_) {
- SECURE_LOGE("Type %d loader was disconnected. pid: %d", GetType(), pid_);
- Dispose();
- Prepare();
- } else {
- SECURE_LOGE("pid(%d) was disconnected", peer_cred->GetPid());
- }
+ SECURE_LOGE("Type %d loader was disconnected. pid: %d, peer_cred: %d",
+ GetType(), pid_, peer_cred->GetPid());
+ Dispose();
+ Prepare();
}
}
channel_(new IOChannel(sfd, IOChannel::IOCondition::IO_IN, this)),
listener_(listener) {
_W("SigchldEvent() ctor. sfd: %d", sfd);
- channel_->SetCloseOnDestroy(false);
}
SigchldEvent::~SigchldEvent() {
_E("socket() is failed. errno(%d)", errno);
THROW(error);
}
+ _W("fd(%d)", fd_);
}
-ClientSocket::ClientSocket(int fd) : fd_(fd) {}
+ClientSocket::ClientSocket(int fd) : fd_(fd) {
+ _W("fd(%d)", fd_);
+}
ClientSocket::~ClientSocket() {
Close();
void ClientSocket::Close() {
if (fd_ > -1) {
+ _W("fd(%d)", fd_);
close(fd_);
fd_ = -1;
}
IOChannel::IOChannel(int fd, int condition, IOChannel::IEvent* listener)
: fd_(fd), listener_(listener) {
- auto channel = g_io_channel_unix_new(fd_);
- if (channel == nullptr) {
- _E("g_io_channel_unix_new() is failed");
- THROW(-ENOMEM);
- }
- auto channel_auto =
- std::unique_ptr<GIOChannel, decltype(g_io_channel_unref)*>(
- channel, g_io_channel_unref);
-
- source_id_ = g_io_add_watch(channel, static_cast<GIOCondition>(condition),
- IOEventCb, this);
+ source_id_ = g_unix_fd_add(fd, static_cast<GIOCondition>(condition),
+ UnixFdFunc, this);
if (source_id_ == 0) {
- _E("g_io_add_watch() is failed");
+ _E("g_unix_fd_add() is failed");
THROW(-ENOMEM);
}
-
- channel_ = channel_auto.release();
}
IOChannel::~IOChannel() {
if (source_id_ != 0)
g_source_remove(source_id_);
-
- if (channel_ != nullptr)
- g_io_channel_unref(channel_);
}
-void IOChannel::SetCloseOnDestroy(bool do_close) {
- g_io_channel_set_close_on_unref(channel_, do_close);
-}
-
-gboolean IOChannel::IOEventCb(GIOChannel* channel, GIOCondition condition,
+gboolean IOChannel::UnixFdFunc(gint fd, GIOCondition condition,
gpointer user_data) {
auto* io_channel = static_cast<IOChannel*>(user_data);
+ if (io_channel->fd_ != fd) {
+ _E("fd(%d) is not equal to fd(%d) of io channel", fd, io_channel->fd_);
+ return G_SOURCE_REMOVE;
+ }
+
auto* listener = io_channel->listener_;
if (listener != nullptr)
listener->OnIOEventReceived(io_channel->fd_, static_cast<int>(condition));
#ifndef LIB_LAUNCHPAD_GLIB_IO_CHANNEL_HH_
#define LIB_LAUNCHPAD_GLIB_IO_CHANNEL_HH_
-#include <gio/gio.h>
+#include <glib-unix.h>
#include <exception.hh>
IOChannel(const IOChannel&) = delete;
IOChannel& operator = (const IOChannel&) = delete;
- void SetCloseOnDestroy(bool do_close);
-
private:
- static gboolean IOEventCb(GIOChannel* channel, GIOCondition condition,
+ static gboolean UnixFdFunc(gint fd, GIOCondition condition,
gpointer user_data);
private:
int fd_;
IEvent* listener_ = nullptr;
- GIOChannel* channel_ = nullptr;
guint source_id_ = 0;
};