mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:58:11 +00:00
ntpquery: Port to LibMain
This commit is contained in:
parent
5d41f993cd
commit
73f431a7cb
2 changed files with 17 additions and 14 deletions
|
@ -141,6 +141,7 @@ target_link_libraries(netstat LibMain)
|
||||||
target_link_libraries(nl LibMain)
|
target_link_libraries(nl LibMain)
|
||||||
target_link_libraries(notify LibGUI LibMain)
|
target_link_libraries(notify LibGUI LibMain)
|
||||||
target_link_libraries(nproc LibMain)
|
target_link_libraries(nproc LibMain)
|
||||||
|
target_link_libraries(ntpquery LibMain)
|
||||||
target_link_libraries(open LibDesktop)
|
target_link_libraries(open LibDesktop)
|
||||||
target_link_libraries(pape LibGUI)
|
target_link_libraries(pape LibGUI)
|
||||||
target_link_libraries(passwd LibCrypt LibMain)
|
target_link_libraries(passwd LibCrypt LibMain)
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
#include <AK/Endian.h>
|
#include <AK/Endian.h>
|
||||||
#include <AK/Random.h>
|
#include <AK/Random.h>
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
|
#include <LibCore/System.h>
|
||||||
|
#include <LibMain/Main.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
@ -88,14 +90,14 @@ static String format_ntp_timestamp(NtpTimestamp ntp_timestamp)
|
||||||
buffer[written] = '\0';
|
buffer[written] = '\0';
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
#ifdef __serenity__
|
||||||
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
|
#else
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
#ifdef __serenity__
|
#ifdef __serenity__
|
||||||
if (pledge("stdio inet unix settime", nullptr) < 0) {
|
TRY(Core::System::pledge("stdio inet unix settime"));
|
||||||
perror("pledge");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool adjust_time = false;
|
bool adjust_time = false;
|
||||||
|
@ -117,7 +119,11 @@ int main(int argc, char** argv)
|
||||||
args_parser.add_option(set_time, "Immediately set system time (requires root)", "set", 's');
|
args_parser.add_option(set_time, "Immediately set system time (requires root)", "set", 's');
|
||||||
args_parser.add_option(verbose, "Verbose output", "verbose", 'v');
|
args_parser.add_option(verbose, "Verbose output", "verbose", 'v');
|
||||||
args_parser.add_positional_argument(host, "NTP server", "host", Core::ArgsParser::Required::No);
|
args_parser.add_positional_argument(host, "NTP server", "host", Core::ArgsParser::Required::No);
|
||||||
|
#ifdef __serenity__
|
||||||
|
args_parser.parse(arguments);
|
||||||
|
#else
|
||||||
args_parser.parse(argc, argv);
|
args_parser.parse(argc, argv);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (adjust_time && set_time) {
|
if (adjust_time && set_time) {
|
||||||
warnln("-a and -s are mutually exclusive");
|
warnln("-a and -s are mutually exclusive");
|
||||||
|
@ -126,10 +132,7 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
#ifdef __serenity__
|
#ifdef __serenity__
|
||||||
if (!adjust_time && !set_time) {
|
if (!adjust_time && !set_time) {
|
||||||
if (pledge("stdio inet unix", nullptr) < 0) {
|
TRY(Core::System::pledge("stdio inet unix"));
|
||||||
perror("pledge");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -140,11 +143,8 @@ int main(int argc, char** argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __serenity__
|
#ifdef __serenity__
|
||||||
if (pledge((adjust_time || set_time) ? "stdio inet settime" : "stdio inet", nullptr) < 0) {
|
TRY(Core::System::pledge((adjust_time || set_time) ? "stdio inet settime" : "stdio inet"));
|
||||||
perror("pledge");
|
TRY(Core::System::unveil(nullptr, nullptr));
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
unveil(nullptr, nullptr);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
int fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||||
|
@ -322,4 +322,6 @@ int main(int argc, char** argv)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue