consoled.c revision ce7b9f50c3fadbad22feeb28e4429ad9bee02bcc
71092d70af35567dd154d3de2ce04ce62e157a7cLennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
7c66aeba0f28cb82027d6015405ed71afa3b6059Kay Sievers
7c66aeba0f28cb82027d6015405ed71afa3b6059Kay Sievers/***
c904f64d84db8c4eebedf210ba10893f19ba05edLennart Poettering This file is part of systemd.
c904f64d84db8c4eebedf210ba10893f19ba05edLennart Poettering
f957632b960a0a42999b38ded7089fa602b41745Kay Sievers Copyright 2014 David Herrmann <dh.herrmann@gmail.com>
f957632b960a0a42999b38ded7089fa602b41745Kay Sievers
f957632b960a0a42999b38ded7089fa602b41745Kay Sievers systemd is free software; you can redistribute it and/or modify it
f957632b960a0a42999b38ded7089fa602b41745Kay Sievers under the terms of the GNU Lesser General Public License as published by
9a36607584bbd1d78775353e022a51794b4e27b1Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
9a36607584bbd1d78775353e022a51794b4e27b1Lennart Poettering (at your option) any later version.
a40593a0d0d740efa387e35411e1e456a6c5aba7Lennart Poettering
20ffc4c4a9226b0e45cc02ad9c0108981626c0bbKay Sievers systemd is distributed in the hope that it will be useful, but
7bcd865d386d96caac83cb1c589fdb8f9ce3b081Zbigniew Jędrzejewski-Szmek WITHOUT ANY WARRANTY; without even the implied warranty of
7bcd865d386d96caac83cb1c589fdb8f9ce3b081Zbigniew Jędrzejewski-Szmek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7bcd865d386d96caac83cb1c589fdb8f9ce3b081Zbigniew Jędrzejewski-Szmek Lesser General Public License for more details.
2f8d077ece024b985f2501dc8c904c2d29967acbKay Sievers
2f8d077ece024b985f2501dc8c904c2d29967acbKay Sievers You should have received a copy of the GNU Lesser General Public License
2d19f95caef8668aeb5c05a18b39c6b79f710856Kay Sievers along with systemd; If not, see <http://www.gnu.org/licenses/>.
2f8d077ece024b985f2501dc8c904c2d29967acbKay Sievers***/
81d112a8f0522a09fcfe317f420363a2b728137cLennart Poettering
c0fe5db522b52f27e030655ce2c03e05cbbc1558Kay Sievers#include <errno.h>
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering#include <stdlib.h>
c0fe5db522b52f27e030655ce2c03e05cbbc1558Kay Sievers#include <string.h>
c3090674833c8bd34fbdb0e743f1c47d85dd14fbLennart Poettering#include "consoled.h"
81d112a8f0522a09fcfe317f420363a2b728137cLennart Poettering#include "log.h"
81d112a8f0522a09fcfe317f420363a2b728137cLennart Poettering#include "sd-daemon.h"
2d19f95caef8668aeb5c05a18b39c6b79f710856Kay Sievers#include "util.h"
2d19f95caef8668aeb5c05a18b39c6b79f710856Kay Sievers
a4cc3e5ccc0a3033d764a9eb3ae5ee90db560682Lennart Poetteringint main(int argc, char *argv[]) {
a4cc3e5ccc0a3033d764a9eb3ae5ee90db560682Lennart Poettering _cleanup_(manager_freep) Manager *m = NULL;
a4cc3e5ccc0a3033d764a9eb3ae5ee90db560682Lennart Poettering int r;
0028da22f194f7c0ca7169a48cf32e1bc0f9138aLennart Poettering
a4cc3e5ccc0a3033d764a9eb3ae5ee90db560682Lennart Poettering log_set_target(LOG_TARGET_AUTO);
7e2c2bcf1285d124c9c656ff46cafa4db0a987c9Lennart Poettering log_parse_environment();
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering log_open();
7e2c2bcf1285d124c9c656ff46cafa4db0a987c9Lennart Poettering
7e2c2bcf1285d124c9c656ff46cafa4db0a987c9Lennart Poettering umask(0022);
7e2c2bcf1285d124c9c656ff46cafa4db0a987c9Lennart Poettering
7e2c2bcf1285d124c9c656ff46cafa4db0a987c9Lennart Poettering if (argc != 1) {
7b4da18c1717f811bae67ea3d39290495857c03eLennart Poettering log_error("This program takes no arguments.");
7b4da18c1717f811bae67ea3d39290495857c03eLennart Poettering r = -EINVAL;
788f75a0e766738c052086e856b7c1b1b676de6bLennart Poettering goto out;
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering }
205b7fa46594b38901636b167b02a8725d915b79Lennart Poettering
b44be3ecf6326c27aa2c6c6d1fe34e22e22592a0Lennart Poettering r = manager_new(&m);
95b4be171988fc2ea33377b1b4450e5d410add7bLennart Poettering if (r < 0) {
81d112a8f0522a09fcfe317f420363a2b728137cLennart Poettering log_error("Could not create manager: %s", strerror(-r));
81d112a8f0522a09fcfe317f420363a2b728137cLennart Poettering goto out;
81d112a8f0522a09fcfe317f420363a2b728137cLennart Poettering }
81d112a8f0522a09fcfe317f420363a2b728137cLennart Poettering
f8aeee1f1fe432924b355f48f01f09c9a552ed97Lennart Poettering sd_notify(false,
f8aeee1f1fe432924b355f48f01f09c9a552ed97Lennart Poettering "READY=1\n"
f8aeee1f1fe432924b355f48f01f09c9a552ed97Lennart Poettering "STATUS=Processing requests...");
eb124a97fb72d076014253b1acde69d428f15ecfLennart Poettering
990ffbe5cffe7f11a8d3ab2258a85fc52b97bf60Lennart Poettering r = manager_run(m);
398a745c73cec10b1a669703644651d94eb37599Lennart Poettering if (r < 0) {
398a745c73cec10b1a669703644651d94eb37599Lennart Poettering log_error("Cannot run manager: %s", strerror(-r));
398a745c73cec10b1a669703644651d94eb37599Lennart Poettering goto out;
eb124a97fb72d076014253b1acde69d428f15ecfLennart Poettering }
eb124a97fb72d076014253b1acde69d428f15ecfLennart Poettering
eb124a97fb72d076014253b1acde69d428f15ecfLennart Poetteringout:
eb124a97fb72d076014253b1acde69d428f15ecfLennart Poettering sd_notify(false,
990ffbe5cffe7f11a8d3ab2258a85fc52b97bf60Lennart Poettering "STATUS=Shutting down...");
f8aeee1f1fe432924b355f48f01f09c9a552ed97Lennart Poettering
f8aeee1f1fe432924b355f48f01f09c9a552ed97Lennart Poettering return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
f8aeee1f1fe432924b355f48f01f09c9a552ed97Lennart Poettering}
f8aeee1f1fe432924b355f48f01f09c9a552ed97Lennart Poettering