2010-08-14 21:59:25 +04:00
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2010-03-31 18:29:55 +04:00
/***
This file is part of systemd .
Copyright 2010 Lennart Poettering
systemd 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 .
systemd 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 systemd ; If not , see < http : //www.gnu.org/licenses/>.
* * */
# include <dbus/dbus.h>
2010-08-31 23:05:54 +04:00
# include <stdlib.h>
2010-03-31 18:29:55 +04:00
# include "log.h"
2010-08-06 05:21:50 +04:00
# include "dbus-common.h"
2010-03-31 18:29:55 +04:00
int main ( int argc , char * argv [ ] ) {
DBusError error ;
DBusConnection * bus = NULL ;
DBusMessage * m = NULL ;
2010-08-31 23:05:54 +04:00
int r = EXIT_FAILURE ;
2010-03-31 18:29:55 +04:00
dbus_error_init ( & error ) ;
if ( argc ! = 2 ) {
log_error ( " Incorrect number of arguments. " ) ;
goto finish ;
}
2010-08-06 05:21:50 +04:00
log_set_target ( LOG_TARGET_SYSLOG_OR_KMSG ) ;
log_parse_environment ( ) ;
2010-08-17 00:39:02 +04:00
log_open ( ) ;
2010-08-06 05:21:50 +04:00
2010-09-03 03:45:14 +04:00
/* We send this event to the private D-Bus socket and then the
* system instance will forward this to the system bus . We do
2011-02-21 17:32:17 +03:00
* this to avoid an activation loop when we start dbus when we
2010-09-03 03:45:14 +04:00
* are called when the dbus service is shut down . */
if ( ! ( bus = dbus_connection_open_private ( " unix:abstract=/org/freedesktop/systemd1/private " , & error ) ) ) {
log_error ( " Failed to get D-Bus connection: %s " , bus_error_message ( & error ) ) ;
goto finish ;
}
if ( bus_check_peercred ( bus ) < 0 ) {
log_error ( " Bus owner not root. " ) ;
goto finish ;
2010-03-31 18:29:55 +04:00
}
if ( ! ( m = dbus_message_new_signal ( " /org/freedesktop/systemd1/agent " , " org.freedesktop.systemd1.Agent " , " Released " ) ) ) {
log_error ( " Could not allocate signal message. " ) ;
goto finish ;
}
if ( ! dbus_message_append_args ( m ,
DBUS_TYPE_STRING , & argv [ 1 ] ,
DBUS_TYPE_INVALID ) ) {
log_error ( " Could not attach group information to signal message. " ) ;
goto finish ;
}
if ( ! dbus_connection_send ( bus , m , NULL ) ) {
2010-09-03 03:45:14 +04:00
log_error ( " Failed to send signal message on private connection. " ) ;
2010-03-31 18:29:55 +04:00
goto finish ;
}
2010-08-31 23:05:54 +04:00
r = EXIT_SUCCESS ;
2010-03-31 18:29:55 +04:00
finish :
2010-07-11 06:10:28 +04:00
if ( bus ) {
2010-09-03 01:26:04 +04:00
dbus_connection_flush ( bus ) ;
2010-07-11 06:10:28 +04:00
dbus_connection_close ( bus ) ;
2010-03-31 18:29:55 +04:00
dbus_connection_unref ( bus ) ;
2010-07-11 06:10:28 +04:00
}
2010-03-31 18:29:55 +04:00
2010-09-03 03:45:14 +04:00
2010-03-31 18:29:55 +04:00
if ( m )
dbus_message_unref ( m ) ;
dbus_error_free ( & error ) ;
return r ;
}