mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-09 17:44:56 +09:00
test-unveil: Port to LibMain
This commit is contained in:
parent
0015040ebd
commit
3df8c9e9de
Notes:
sideshowbarker
2024-07-17 16:30:58 +09:00
Author: https://github.com/kennethmyhra
Commit: 3df8c9e9de
Pull-request: https://github.com/SerenityOS/serenity/pull/13341
Issue: https://github.com/SerenityOS/serenity/issues/11609
Reviewed-by: https://github.com/kleinesfilmroellchen ✅
2 changed files with 17 additions and 14 deletions
|
@ -200,6 +200,7 @@ target_link_libraries(test-bindtodevice LibMain)
|
|||
target_link_libraries(test-fuzz LibCore LibGemini LibGfx LibHTTP LibIPC LibJS LibMarkdown LibShell LibMain)
|
||||
target_link_libraries(test-imap LibIMAP LibMain)
|
||||
target_link_libraries(test-pthread LibThreading LibMain)
|
||||
target_link_libraries(test-unveil LibMain)
|
||||
target_link_libraries(timezone LibMain)
|
||||
target_link_libraries(top LibMain)
|
||||
target_link_libraries(touch LibMain)
|
||||
|
|
|
@ -1,20 +1,19 @@
|
|||
/*
|
||||
* Copyright (c) 2020, the SerenityOS developers.
|
||||
* Copyright (c) 2020-2022, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <errno.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibMain/Main.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
{
|
||||
Vector<StringView> paths_to_test;
|
||||
const char* permissions = "r";
|
||||
StringView permissions = "r"sv;
|
||||
bool should_sleep = false;
|
||||
|
||||
Core::ArgsParser parser;
|
||||
|
@ -30,8 +29,9 @@ int main(int argc, char** argv)
|
|||
StringView path { s };
|
||||
if (path.is_empty())
|
||||
return false;
|
||||
if (unveil(s, permissions) < 0) {
|
||||
perror("unveil");
|
||||
auto maybe_error = Core::System::unveil(path, permissions);
|
||||
if (maybe_error.is_error()) {
|
||||
warnln("{}", maybe_error.error());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -42,8 +42,9 @@ int main(int argc, char** argv)
|
|||
.long_name = "lock",
|
||||
.short_name = 'l',
|
||||
.accept_value = [&](auto*) {
|
||||
if (unveil(nullptr, nullptr) < 0) {
|
||||
perror("unveil(nullptr, nullptr)");
|
||||
auto maybe_error = Core::System::unveil(nullptr, nullptr);
|
||||
if (maybe_error.is_error()) {
|
||||
warnln("unveil(nullptr, nullptr): {}", maybe_error.error());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -54,14 +55,15 @@ int main(int argc, char** argv)
|
|||
.min_values = 0,
|
||||
.max_values = INT_MAX,
|
||||
.accept_value = [&](auto* s) {
|
||||
if (access(s, X_OK) == 0)
|
||||
warnln("'{}' - ok", s);
|
||||
auto maybe_error = Core::System::access(s, X_OK);
|
||||
if (maybe_error.is_error())
|
||||
warnln("'{}' - fail: {}", s, maybe_error.error());
|
||||
else
|
||||
warnln("'{}' - fail: {}", s, strerror(errno));
|
||||
warnln("'{}' - ok", s);
|
||||
return true;
|
||||
} });
|
||||
|
||||
parser.parse(argc, argv);
|
||||
parser.parse(arguments);
|
||||
if (should_sleep)
|
||||
sleep(INT_MAX);
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue