summaryrefslogtreecommitdiff
path: root/Userland/Utilities/flock.cpp
blob: 57d16092110c63faad346b7c63447ff6c2436ce6 (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
/*
 * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include <AK/Format.h>
#include <LibCore/System.h>
#include <LibMain/Main.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>

ErrorOr<int> serenity_main(Main::Arguments arguments)
{
    if (arguments.strings.size() < 3) {
        warnln("usage: flock <path> <command...>");
        return 1;
    }

    pid_t child_pid = TRY(Core::System::posix_spawnp(arguments.strings[2], nullptr, nullptr, &arguments.argv[2], environ));
    auto [_, status] = TRY(Core::System::waitpid(child_pid));

    return WEXITSTATUS(status);
}