mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:18:11 +00:00
profile: Prevent crash when -p is supplied a non-integer value
Instead of crashing we give a helpful warning message to the user. This also removes a fixme! :^)
This commit is contained in:
parent
6811ab9c3b
commit
5563ebab5a
1 changed files with 18 additions and 2 deletions
|
@ -11,6 +11,8 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
static Optional<pid_t> determine_pid_to_profile(StringView pid_argument, bool all_processes);
|
||||||
|
|
||||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
{
|
{
|
||||||
Core::ArgsParser args_parser;
|
Core::ArgsParser args_parser;
|
||||||
|
@ -86,9 +88,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Handle error case.
|
auto pid_opt = determine_pid_to_profile(pid_argument, all_processes);
|
||||||
pid_t pid = all_processes ? -1 : pid_argument.to_int().release_value();
|
if (!pid_opt.has_value()) {
|
||||||
|
warnln("-p <PID> requires an integer value.");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pid_t pid = pid_opt.value();
|
||||||
if (wait || enable) {
|
if (wait || enable) {
|
||||||
TRY(Core::System::profiling_enable(pid, event_mask));
|
TRY(Core::System::profiling_enable(pid, event_mask));
|
||||||
|
|
||||||
|
@ -116,3 +122,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Optional<pid_t> determine_pid_to_profile(StringView pid_argument, bool all_processes)
|
||||||
|
{
|
||||||
|
if (all_processes) {
|
||||||
|
return { -1 };
|
||||||
|
}
|
||||||
|
|
||||||
|
// pid_argument is guaranteed to have a value
|
||||||
|
return pid_argument.to_int();
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue