mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 11:57:35 +00:00
watch: Port to LibMain
This commit is contained in:
parent
4178479ee5
commit
3d63e688f7
2 changed files with 10 additions and 13 deletions
|
@ -149,4 +149,5 @@ target_link_libraries(cpp-preprocessor LibCpp LibGUI)
|
||||||
target_link_libraries(w LibMain)
|
target_link_libraries(w LibMain)
|
||||||
target_link_libraries(wasm LibWasm LibLine)
|
target_link_libraries(wasm LibWasm LibLine)
|
||||||
target_link_libraries(whoami LibMain)
|
target_link_libraries(whoami LibMain)
|
||||||
|
target_link_libraries(watch LibMain)
|
||||||
target_link_libraries(wsctl LibGUI)
|
target_link_libraries(wsctl LibGUI)
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
#include <LibCore/FileWatcher.h>
|
#include <LibCore/FileWatcher.h>
|
||||||
|
#include <LibCore/System.h>
|
||||||
|
#include <LibMain/Main.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <spawn.h>
|
#include <spawn.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -105,13 +107,10 @@ static int run_command(Vector<char const*> const& command)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
{
|
{
|
||||||
signal(SIGINT, handle_signal);
|
TRY(Core::System::signal(SIGINT, handle_signal));
|
||||||
if (pledge("stdio proc exec rpath", nullptr) < 0) {
|
TRY(Core::System::pledge("stdio proc exec rpath", nullptr));
|
||||||
perror("pledge");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector<String> files_to_watch;
|
Vector<String> files_to_watch;
|
||||||
Vector<char const*> command;
|
Vector<char const*> command;
|
||||||
|
@ -134,7 +133,7 @@ int main(int argc, char** argv)
|
||||||
};
|
};
|
||||||
args_parser.add_option(move(file_arg));
|
args_parser.add_option(move(file_arg));
|
||||||
args_parser.add_positional_argument(command, "Command to run", "command");
|
args_parser.add_positional_argument(command, "Command to run", "command");
|
||||||
args_parser.parse(argc, argv);
|
args_parser.parse(arguments);
|
||||||
|
|
||||||
command.append(nullptr);
|
command.append(nullptr);
|
||||||
|
|
||||||
|
@ -169,8 +168,8 @@ int main(int argc, char** argv)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (!file_watcher.is_watching(file)) {
|
if (!file_watcher.is_watching(file)) {
|
||||||
auto success_or_error = file_watcher.add_watch(file, Core::FileWatcherEvent::Type::MetadataModified);
|
auto could_add_to_watch = TRY(file_watcher.add_watch(file, Core::FileWatcherEvent::Type::MetadataModified));
|
||||||
if (success_or_error.is_error() && !success_or_error.value()) {
|
if (!could_add_to_watch) {
|
||||||
warnln("Could not add '{}' to watch list.", file);
|
warnln("Could not add '{}' to watch list.", file);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -185,10 +184,7 @@ int main(int argc, char** argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (pledge("stdio proc exec", nullptr) < 0) {
|
TRY(Core::System::pledge("stdio proc exec", nullptr));
|
||||||
perror("pledge");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct timeval interval;
|
struct timeval interval;
|
||||||
if (opt_interval <= 0) {
|
if (opt_interval <= 0) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue