/* * uevent - zavai uevent handling * * Copyright (C) 2009 Enrico Zini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ using GLib; namespace zavai { namespace uevent { class UEvent : Service { protected IOChannel sock; protected uint sock_watch = 0; public Omhacks.UEvent.Event event_data; public signal void event(); public UEvent() { event_data = Omhacks.UEvent.Event(); } protected bool on_input_data(IOChannel source, IOCondition condition) { if (condition != IOCondition.IN) return true; Omhacks.UEvent.read(sock.unix_get_fd(), ref event_data); event(); return true; } /// Activate the service protected override void start() { if (started) return; int sock_fd = Omhacks.UEvent.open(); if (sock_fd < 0) { zavai.log.error("UEvent: error getting socket"); return; } sock = new IOChannel.unix_new(sock_fd); sock_watch = sock.add_watch(IOCondition.IN, on_input_data); base.start(); } /// Deactivate the service protected override void stop() { if (!started) return; Source.remove(sock_watch); try { sock.shutdown(false); } catch (IOChannelError e) { zavai.log.error("When closing UEvent socket: " + e.message); } sock = null; base.stop(); } } UEvent uevent; public void init() { if (Posix.getuid() == 0) uevent = new UEvent(); else uevent = null; } } }