2020-07-17 01:35:50 +03:00
|
|
|
/*
|
2021-09-01 05:32:46 +03:00
|
|
|
* Copyright (c) 2020, Peter Elliott <pelliott@serenityos.org>
|
2020-07-17 01:35:50 +03:00
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-07-17 01:35:50 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <LibCore/ArgsParser.h>
|
2022-04-17 07:43:34 +03:00
|
|
|
#include <LibCore/FilePermissionsMask.h>
|
2022-01-14 12:14:26 +03:00
|
|
|
#include <LibCore/System.h>
|
|
|
|
#include <LibMain/Main.h>
|
2020-07-17 01:35:50 +03:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2022-01-14 12:14:26 +03:00
|
|
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
2020-07-17 01:35:50 +03:00
|
|
|
{
|
2022-01-14 12:14:26 +03:00
|
|
|
TRY(Core::System::pledge("stdio dpath"));
|
2020-07-17 01:35:50 +03:00
|
|
|
|
2023-12-16 17:19:34 +03:00
|
|
|
ByteString mode_string;
|
2022-04-17 07:43:34 +03:00
|
|
|
mode_t mask_reference_mode = 0777;
|
2020-07-17 01:35:50 +03:00
|
|
|
mode_t mode = 0666;
|
2022-01-14 12:14:26 +03:00
|
|
|
Vector<StringView> paths;
|
2020-07-17 01:35:50 +03:00
|
|
|
|
|
|
|
Core::ArgsParser args_parser;
|
2022-04-17 07:43:34 +03:00
|
|
|
args_parser.add_option(mode_string, "Set FIFO permissions", "mode", 'm', "mode");
|
2020-07-17 01:35:50 +03:00
|
|
|
args_parser.add_positional_argument(paths, "Paths of FIFOs to create", "paths");
|
2022-01-14 12:14:26 +03:00
|
|
|
args_parser.parse(arguments);
|
2020-07-17 01:35:50 +03:00
|
|
|
|
2022-04-17 07:43:34 +03:00
|
|
|
if (!mode_string.is_empty()) {
|
|
|
|
auto mask = TRY(Core::FilePermissionsMask::parse(mode_string));
|
|
|
|
mode = mask.apply(mask_reference_mode);
|
|
|
|
}
|
|
|
|
|
2020-07-17 01:35:50 +03:00
|
|
|
int exit_code = 0;
|
|
|
|
for (auto path : paths) {
|
2022-01-14 12:14:26 +03:00
|
|
|
auto error_or_void = Core::System::mkfifo(path, mode);
|
|
|
|
if (error_or_void.is_error()) {
|
2023-05-22 10:22:10 +03:00
|
|
|
warnln("mkfifo: Couldn't create fifo '{}': {}", path, error_or_void.error());
|
2020-07-17 01:35:50 +03:00
|
|
|
exit_code = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return exit_code;
|
|
|
|
}
|