cgroups-agent.c revision 0f8bd8debb0ff7f5bff7738841931f6c41e40bc1
76318284fc970b30e9dc4c079960807345331dadLennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
76318284fc970b30e9dc4c079960807345331dadLennart Poettering
76318284fc970b30e9dc4c079960807345331dadLennart Poettering/***
76318284fc970b30e9dc4c079960807345331dadLennart Poettering This file is part of systemd.
76318284fc970b30e9dc4c079960807345331dadLennart Poettering
76318284fc970b30e9dc4c079960807345331dadLennart Poettering Copyright 2010 Lennart Poettering
76318284fc970b30e9dc4c079960807345331dadLennart Poettering
76318284fc970b30e9dc4c079960807345331dadLennart Poettering systemd is free software; you can redistribute it and/or modify it
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering under the terms of the GNU Lesser General Public License as published by
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
76318284fc970b30e9dc4c079960807345331dadLennart Poettering (at your option) any later version.
76318284fc970b30e9dc4c079960807345331dadLennart Poettering
76318284fc970b30e9dc4c079960807345331dadLennart Poettering systemd is distributed in the hope that it will be useful, but
76318284fc970b30e9dc4c079960807345331dadLennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
76318284fc970b30e9dc4c079960807345331dadLennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering Lesser General Public License for more details.
76318284fc970b30e9dc4c079960807345331dadLennart Poettering
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering You should have received a copy of the GNU Lesser General Public License
76318284fc970b30e9dc4c079960807345331dadLennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
76318284fc970b30e9dc4c079960807345331dadLennart Poettering***/
76318284fc970b30e9dc4c079960807345331dadLennart Poettering
76318284fc970b30e9dc4c079960807345331dadLennart Poettering#include <stdlib.h>
76318284fc970b30e9dc4c079960807345331dadLennart Poettering
76318284fc970b30e9dc4c079960807345331dadLennart Poettering#include "sd-bus.h"
d77c25b1164f55fe3f9b5ad00c47c0e01243ad53Johan Ouwerkerk
d77c25b1164f55fe3f9b5ad00c47c0e01243ad53Johan Ouwerkerk#include "log.h"
d77c25b1164f55fe3f9b5ad00c47c0e01243ad53Johan Ouwerkerk#include "bus-util.h"
d77c25b1164f55fe3f9b5ad00c47c0e01243ad53Johan Ouwerkerk
d77c25b1164f55fe3f9b5ad00c47c0e01243ad53Johan Ouwerkerkint main(int argc, char *argv[]) {
d77c25b1164f55fe3f9b5ad00c47c0e01243ad53Johan Ouwerkerk _cleanup_bus_unref_ sd_bus *bus = NULL;
d77c25b1164f55fe3f9b5ad00c47c0e01243ad53Johan Ouwerkerk int r;
d77c25b1164f55fe3f9b5ad00c47c0e01243ad53Johan Ouwerkerk
d77c25b1164f55fe3f9b5ad00c47c0e01243ad53Johan Ouwerkerk if (argc != 2) {
d77c25b1164f55fe3f9b5ad00c47c0e01243ad53Johan Ouwerkerk log_error("Incorrect number of arguments.");
76318284fc970b30e9dc4c079960807345331dadLennart Poettering return EXIT_FAILURE;
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers }
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers log_set_target(LOG_TARGET_AUTO);
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers log_parse_environment();
958caa58c089037ffb8cd71bc342bb9d798a6dd3Zbigniew Jędrzejewski-Szmek log_open();
958caa58c089037ffb8cd71bc342bb9d798a6dd3Zbigniew Jędrzejewski-Szmek
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers /* We send this event to the private D-Bus socket and then the
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers * system instance will forward this to the system bus. We do
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers * this to avoid an activation loop when we start dbus when we
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers * are called when the dbus service is shut down. */
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek r = bus_open_system_systemd(&bus);
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek if (r < 0) {
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek log_warning("Failed to get D-Bus connection: %s", strerror(-r));
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek return EXIT_FAILURE;
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek }
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek r = sd_bus_emit_signal(bus,
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek "/org/freedesktop/systemd1/agent",
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek "org.freedesktop.systemd1.Agent",
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek "Released",
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek "s", argv[1]);
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek if (r < 0) {
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek log_error("Failed to send signal message on private connection: %s", strerror(-r));
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek return EXIT_FAILURE;
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek }
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek sd_bus_flush(bus);
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek return EXIT_SUCCESS;
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek}
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek