summaryrefslogtreecommitdiff
path: root/Userland/Utilities/shutdown.cpp
blob: a6ab3ca7d3ec35063dcf7a0326ba055d01e1e3fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include <LibCore/ArgsParser.h>
#include <stdio.h>
#include <unistd.h>

int main(int argc, char** argv)
{
    bool now = false;

    Core::ArgsParser args_parser;
    args_parser.add_option(now, "Shut down now", "now", 'n');
    args_parser.parse(argc, argv);

    if (now) {
        if (halt() < 0) {
            perror("shutdown");
            return 1;
        }
    } else {
        args_parser.print_usage(stderr, argv[0]);
        return 1;
    }
}