mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 01:20:25 +00:00
Everywhere: Replace a bundle of dbg with dbgln.
These changes are arbitrarily divided into multiple commits to make it easier to find potentially introduced bugs with git bisect.
This commit is contained in:
parent
4e8fd0216b
commit
40b8e21115
Notes:
sideshowbarker
2024-07-18 23:59:06 +09:00
Author: https://github.com/asynts Commit: https://github.com/SerenityOS/serenity/commit/40b8e211159 Pull-request: https://github.com/SerenityOS/serenity/pull/4870
11 changed files with 54 additions and 54 deletions
|
@ -79,14 +79,14 @@ static void fork_into(void (*fn)(void*), void* arg)
|
||||||
const int disown_rc = disown(rc);
|
const int disown_rc = disown(rc);
|
||||||
if (disown_rc < 0) {
|
if (disown_rc < 0) {
|
||||||
perror("disown");
|
perror("disown");
|
||||||
dbg() << "This might cause PA1 to remain in the Zombie state, "
|
dbgln("This might cause PA1 to remain in the Zombie state, "
|
||||||
"and thus in the process list, meaning the leader is "
|
"and thus in the process list, meaning the leader is "
|
||||||
"still 'alive' for the purpose of lookup.";
|
"still 'alive' for the purpose of lookup.");
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fn(arg);
|
fn(arg);
|
||||||
dbg() << "child finished (?)";
|
dbgln("child finished (?)");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,19 +116,19 @@ int main(int, char**)
|
||||||
perror("pipe");
|
perror("pipe");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
dbg() << "PX starts with SID=" << getsid(0) << ", PGID=" << getpgid(0) << ", PID=" << getpid() << ".";
|
dbgln("PX starts with SID={}, PGID={}, PID={}.", getsid(0), getpgid(0), getpid());
|
||||||
dbg() << "PX forks into PA1";
|
dbgln("PX forks into PA1");
|
||||||
fork_into(run_pa1, nullptr);
|
fork_into(run_pa1, nullptr);
|
||||||
sleep_steps(4);
|
sleep_steps(4);
|
||||||
|
|
||||||
// Time 4: PX forks into PB1
|
// Time 4: PX forks into PB1
|
||||||
dbg() << "PX forks into PB1";
|
dbgln("PX forks into PB1");
|
||||||
fork_into(run_pb1, &(fds[1]));
|
fork_into(run_pb1, &(fds[1]));
|
||||||
sleep_steps(5);
|
sleep_steps(5);
|
||||||
|
|
||||||
// Time 9: If PX hasn't received any message yet through the pipe, it declares
|
// Time 9: If PX hasn't received any message yet through the pipe, it declares
|
||||||
// the test as failed (for lack of knowledge). Otherwise, it outputs accordingly.
|
// the test as failed (for lack of knowledge). Otherwise, it outputs accordingly.
|
||||||
dbg() << "PX reads from pipe";
|
dbgln("PX reads from pipe");
|
||||||
unsigned char buf = 42;
|
unsigned char buf = 42;
|
||||||
ssize_t rc = read(fds[0], &buf, 1);
|
ssize_t rc = read(fds[0], &buf, 1);
|
||||||
if (rc == 0) {
|
if (rc == 0) {
|
||||||
|
@ -166,36 +166,36 @@ static void run_pa1(void*)
|
||||||
sleep_steps(1);
|
sleep_steps(1);
|
||||||
|
|
||||||
// Time 1: PA1 creates a new session (SA) and pgrp (PGA)
|
// Time 1: PA1 creates a new session (SA) and pgrp (PGA)
|
||||||
dbg() << "PA1 starts with SID=" << getsid(0) << ", PGID=" << getpgid(0) << ", PID=" << getpid() << ".";
|
dbgln("PA1 starts with SID={}, PGID={}, PID={}.", getsid(0), getpgid(0), getpid());
|
||||||
dbg() << "PA1 calls setsid()";
|
dbgln("PA1 calls setsid()");
|
||||||
int rc = setsid();
|
int rc = setsid();
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
perror("setsid (PA)");
|
perror("setsid (PA)");
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
dbg() << "PA1 did setsid() -> PGA=" << rc << ", SA=" << getsid(0) << ", yay!";
|
dbgln("PA1 did setsid() -> PGA={}, SA={}, yay!", rc, getsid(0));
|
||||||
sleep_steps(1);
|
sleep_steps(1);
|
||||||
|
|
||||||
// Time 2: PA1 forks into PA2
|
// Time 2: PA1 forks into PA2
|
||||||
dbg() << "PA1 forks into PA2";
|
dbgln("PA1 forks into PA2");
|
||||||
fork_into(run_pa2, nullptr);
|
fork_into(run_pa2, nullptr);
|
||||||
sleep_steps(1);
|
sleep_steps(1);
|
||||||
|
|
||||||
// Time 3: PA1 dies (PGA now has no leader)
|
// Time 3: PA1 dies (PGA now has no leader)
|
||||||
dbg() << "PA1 dies. You should see a 'Reaped unparented process' "
|
dbgln("PA1 dies. You should see a 'Reaped unparented process' "
|
||||||
"message with my ID next, OR THIS TEST IS MEANINGLESS "
|
"message with my ID next, OR THIS TEST IS MEANINGLESS "
|
||||||
"(see fork_into()).";
|
"(see fork_into()).");
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void run_pa2(void*)
|
static void run_pa2(void*)
|
||||||
{
|
{
|
||||||
// Time 2: PA1 forks into PA2
|
// Time 2: PA1 forks into PA2
|
||||||
dbg() << "PA2 starts with SID=" << getsid(0) << ", PGID=" << getpgid(0) << ", PID=" << getpid() << ".";
|
dbgln("PA2 starts with SID={}, PGID={}, PID={}.", getsid(0), getpgid(0), getpid());
|
||||||
sleep_steps(18);
|
sleep_steps(18);
|
||||||
|
|
||||||
// pa_2 never *does* anything.
|
// pa_2 never *does* anything.
|
||||||
dbg() << "PA2 dies from boredom.";
|
dbgln("PA2 dies from boredom.");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,25 +205,25 @@ static void run_pb1(void* pipe_fd_ptr)
|
||||||
sleep_steps(1);
|
sleep_steps(1);
|
||||||
|
|
||||||
// Time 5: PB1 creates a new session (SB) and pgrp (PGB)
|
// Time 5: PB1 creates a new session (SB) and pgrp (PGB)
|
||||||
dbg() << "PB1 starts with SID=" << getsid(0) << ", PGID=" << getpgid(0) << ", PID=" << getpid() << ".";
|
dbgln("PB1 starts with SID={}, PGID={}, PID={}.", getsid(0), getpgid(0), getpid());
|
||||||
dbg() << "PB1 calls setsid()";
|
dbgln("PB1 calls setsid()");
|
||||||
int rc = setsid();
|
int rc = setsid();
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
perror("setsid (PB)");
|
perror("setsid (PB)");
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
dbg() << "PB1 did setsid() -> PGB=" << rc << ", SB=" << getsid(0) << ", yay!";
|
dbgln("PB1 did setsid() -> PGB={}, SB={}, yay!", rc, getsid(0));
|
||||||
sleep_steps(1);
|
sleep_steps(1);
|
||||||
|
|
||||||
// Time 6: PB1 forks into PB2
|
// Time 6: PB1 forks into PB2
|
||||||
dbg() << "PB1 forks into PB2";
|
dbgln("PB1 forks into PB2");
|
||||||
fork_into(run_pb2, pipe_fd_ptr);
|
fork_into(run_pb2, pipe_fd_ptr);
|
||||||
sleep_steps(1);
|
sleep_steps(1);
|
||||||
|
|
||||||
// Time 7: PB1 dies (PGB now has no leader)
|
// Time 7: PB1 dies (PGB now has no leader)
|
||||||
dbg() << "PB1 dies. You should see a 'Reaped unparented process' "
|
dbgln("PB1 dies. You should see a 'Reaped unparented process' "
|
||||||
"message with my ID next, OR THIS TEST IS MEANINGLESS "
|
"message with my ID next, OR THIS TEST IS MEANINGLESS "
|
||||||
"(see fork_into()).";
|
"(see fork_into()).");
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,9 +232,9 @@ static void simulate_sid_from_pgid(pid_t pgid)
|
||||||
pid_t rc = getpgid(pgid); // Same confusion as in the Kernel
|
pid_t rc = getpgid(pgid); // Same confusion as in the Kernel
|
||||||
int saved_errno = errno;
|
int saved_errno = errno;
|
||||||
if (rc < 0 && saved_errno == ESRCH) {
|
if (rc < 0 && saved_errno == ESRCH) {
|
||||||
dbg() << "The old get_sid_from_pgid(" << pgid << ") would return -1";
|
dbgln("The old get_sid_from_pgid({}) would return -1", pgid);
|
||||||
} else if (rc >= 0) {
|
} else if (rc >= 0) {
|
||||||
dbg() << "FAIL: Process " << pgid << " still exists?! PGID is " << rc << ".";
|
dbgln("FAIL: Process {} still exists?! PGID is {}.", pgid, rc);
|
||||||
} else {
|
} else {
|
||||||
perror("pgid (probably fail)");
|
perror("pgid (probably fail)");
|
||||||
}
|
}
|
||||||
|
@ -247,49 +247,49 @@ static void run_pb2(void* pipe_fd_ptr)
|
||||||
|
|
||||||
// Time 8: PB2 calls pgrp(0, PGA)
|
// Time 8: PB2 calls pgrp(0, PGA)
|
||||||
// Note: PB2 writes "1" (exploit successful) or "0" (bug is fixed) to a pipe
|
// Note: PB2 writes "1" (exploit successful) or "0" (bug is fixed) to a pipe
|
||||||
dbg() << "PB2 starts with SID=" << getsid(0) << ", PGID=" << getpgid(0) << ", PID=" << getpid() << ".";
|
dbgln("PB2 starts with SID={}, PGID={}, PID={}.", getsid(0), getpgid(0), getpid());
|
||||||
dbg() << "PB2 calls pgrp(0, PGA)";
|
dbgln("PB2 calls pgrp(0, PGA)");
|
||||||
int pga = getpid() - 3;
|
int pga = getpid() - 3;
|
||||||
dbg() << "PB2: Actually, what is PGA? I guess it's " << pga << "?";
|
dbgln("PB2: Actually, what is PGA? I guess it's {}?", pga);
|
||||||
simulate_sid_from_pgid(pga);
|
simulate_sid_from_pgid(pga);
|
||||||
int rc = setpgid(0, pga);
|
int rc = setpgid(0, pga);
|
||||||
unsigned char to_write = 123;
|
unsigned char to_write = 123;
|
||||||
if (rc == 0) {
|
if (rc == 0) {
|
||||||
dbg() << "PB2: setgpid SUCCESSFUL! CHANGED PGROUP!";
|
dbgln("PB2: setgpid SUCCESSFUL! CHANGED PGROUP!");
|
||||||
to_write = 1;
|
to_write = 1;
|
||||||
} else {
|
} else {
|
||||||
ASSERT(rc == -1);
|
ASSERT(rc == -1);
|
||||||
switch (errno) {
|
switch (errno) {
|
||||||
case EACCES:
|
case EACCES:
|
||||||
dbg() << "PB2: Failed with EACCES. Huh?!";
|
dbgln("PB2: Failed with EACCES. Huh?!");
|
||||||
to_write = 101;
|
to_write = 101;
|
||||||
break;
|
break;
|
||||||
case EINVAL:
|
case EINVAL:
|
||||||
dbg() << "PB2: Failed with EINVAL. Huh?!";
|
dbgln("PB2: Failed with EINVAL. Huh?!");
|
||||||
to_write = 102;
|
to_write = 102;
|
||||||
break;
|
break;
|
||||||
case ESRCH:
|
case ESRCH:
|
||||||
dbg() << "PB2: Failed with ESRCH. Huh?!";
|
dbgln("PB2: Failed with ESRCH. Huh?!");
|
||||||
to_write = 103;
|
to_write = 103;
|
||||||
break;
|
break;
|
||||||
case EPERM:
|
case EPERM:
|
||||||
dbg() << "PB2: Failed with EPERM. Aww, no exploit today :^)";
|
dbgln("PB2: Failed with EPERM. Aww, no exploit today :^)");
|
||||||
to_write = 0;
|
to_write = 0;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
dbg() << "PB2: Failed with errno=" << errno << "?!";
|
dbgln("PB2: Failed with errno={}?!", errno);
|
||||||
perror("setpgid");
|
perror("setpgid");
|
||||||
to_write = 104;
|
to_write = 104;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dbg() << "PB2 ends with SID=" << getsid(0) << ", PGID=" << getpgid(0) << ", PID=" << getpid() << ".";
|
dbgln("PB2 ends with SID={}, PGID={}, PID={}.", getsid(0), getpgid(0), getpid());
|
||||||
int* pipe_fd = static_cast<int*>(pipe_fd_ptr);
|
int* pipe_fd = static_cast<int*>(pipe_fd_ptr);
|
||||||
ASSERT(*pipe_fd);
|
ASSERT(*pipe_fd);
|
||||||
rc = write(*pipe_fd, &to_write, 1);
|
rc = write(*pipe_fd, &to_write, 1);
|
||||||
if (rc != 1) {
|
if (rc != 1) {
|
||||||
dbg() << "Wrote only " << rc << " bytes instead of 1?!";
|
dbgln("Wrote only {} bytes instead of 1?!", rc);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|
|
@ -62,7 +62,7 @@ static Options parse_options(int argc, char* argv[])
|
||||||
Core::File::ShouldCloseFileDescriptor::No);
|
Core::File::ShouldCloseFileDescriptor::No);
|
||||||
ASSERT(success);
|
ASSERT(success);
|
||||||
auto buffer = c_stdin->read_all();
|
auto buffer = c_stdin->read_all();
|
||||||
dbg() << "Read size " << buffer.size();
|
dbgln("Read size {}", buffer.size());
|
||||||
options.data = String((char*)buffer.data(), buffer.size());
|
options.data = String((char*)buffer.data(), buffer.size());
|
||||||
} else {
|
} else {
|
||||||
// Copy the rest of our command-line args.
|
// Copy the rest of our command-line args.
|
||||||
|
|
|
@ -66,13 +66,13 @@ static bool parse_name(StringView name, OpenFile& file)
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
if (!lexer.consume_specific('(')) {
|
if (!lexer.consume_specific('(')) {
|
||||||
dbg() << "parse_name: expected (";
|
dbgln("parse_name: expected (");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto component3 = lexer.consume_until(')');
|
auto component3 = lexer.consume_until(')');
|
||||||
if (lexer.tell_remaining() != 0) {
|
if (lexer.tell_remaining() != 0) {
|
||||||
dbg() << "parse_name: expected EOF";
|
dbgln("parse_name: expected EOF");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -107,7 +107,7 @@ int main(int argc, char* argv[])
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
dbg() << "Loading man page from " << file->filename();
|
dbgln("Loading man page from {}", file->filename());
|
||||||
auto buffer = file->read_all();
|
auto buffer = file->read_all();
|
||||||
auto source = String::copy(buffer);
|
auto source = String::copy(buffer);
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,7 @@ int main(int argc, char* argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
auto buffer = file->read_all();
|
auto buffer = file->read_all();
|
||||||
dbg() << "Read size " << buffer.size();
|
dbgln("Read size {}", buffer.size());
|
||||||
|
|
||||||
auto input = String::copy(buffer);
|
auto input = String::copy(buffer);
|
||||||
auto document = Markdown::Document::parse(input);
|
auto document = Markdown::Document::parse(input);
|
||||||
|
|
|
@ -33,7 +33,7 @@ int main(int, char**)
|
||||||
Core::EventLoop event_loop;
|
Core::EventLoop event_loop;
|
||||||
|
|
||||||
auto timer = Core::Timer::construct(10, [&] {
|
auto timer = Core::Timer::construct(10, [&] {
|
||||||
dbg() << "Now hanging!";
|
dbgln("Now hanging!");
|
||||||
while (true) {
|
while (true) {
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,7 @@ static int get_source_fd(const char* source)
|
||||||
static bool mount_all()
|
static bool mount_all()
|
||||||
{
|
{
|
||||||
// Mount all filesystems listed in /etc/fstab.
|
// Mount all filesystems listed in /etc/fstab.
|
||||||
dbg() << "Mounting all filesystems...";
|
dbgln("Mounting all filesystems...");
|
||||||
|
|
||||||
auto fstab = Core::File::construct("/etc/fstab");
|
auto fstab = Core::File::construct("/etc/fstab");
|
||||||
if (!fstab->open(Core::IODevice::OpenMode::ReadOnly)) {
|
if (!fstab->open(Core::IODevice::OpenMode::ReadOnly)) {
|
||||||
|
|
|
@ -244,7 +244,7 @@ int main(int argc, char** argv)
|
||||||
download->on_headers_received = [&](auto& response_headers, auto status_code) {
|
download->on_headers_received = [&](auto& response_headers, auto status_code) {
|
||||||
if (received_actual_headers)
|
if (received_actual_headers)
|
||||||
return;
|
return;
|
||||||
dbg() << "Received headers! response code = " << status_code.value_or(0);
|
dbgln("Received headers! response code = {}", status_code.value_or(0));
|
||||||
received_actual_headers = true; // And not trailers!
|
received_actual_headers = true; // And not trailers!
|
||||||
String output_name;
|
String output_name;
|
||||||
if (auto content_disposition = response_headers.get("Content-Disposition"); content_disposition.has_value()) {
|
if (auto content_disposition = response_headers.get("Content-Disposition"); content_disposition.has_value()) {
|
||||||
|
|
|
@ -83,7 +83,7 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
cmd_argv.append(nullptr);
|
cmd_argv.append(nullptr);
|
||||||
|
|
||||||
dbg() << "Enabling profiling for PID " << getpid();
|
dbgln("Enabling profiling for PID {}", getpid());
|
||||||
profiling_enable(getpid());
|
profiling_enable(getpid());
|
||||||
if (execvp(cmd_argv[0], const_cast<char**>(cmd_argv.data())) < 0) {
|
if (execvp(cmd_argv[0], const_cast<char**>(cmd_argv.data())) < 0) {
|
||||||
perror("execv");
|
perror("execv");
|
||||||
|
|
|
@ -193,7 +193,7 @@ static void cleanup_and_exit()
|
||||||
|
|
||||||
static void handle_sigabrt(int)
|
static void handle_sigabrt(int)
|
||||||
{
|
{
|
||||||
dbg() << "test-js: SIGABRT received, cleaning up.";
|
dbgln("test-js: SIGABRT received, cleaning up.");
|
||||||
cleanup_and_exit();
|
cleanup_and_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,11 +65,11 @@ int main(int argc, char** argv)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
dbg() << "Updating utmp from UID=" << getuid() << " GID=" << getgid() << " EGID=" << getegid() << " PID=" << pid;
|
dbgln("Updating utmp from UID={} GID={} EGID={} PID={}", getuid(), getgid(), getegid(), pid);
|
||||||
|
|
||||||
auto file_or_error = Core::File::open("/var/run/utmp", Core::IODevice::ReadWrite);
|
auto file_or_error = Core::File::open("/var/run/utmp", Core::IODevice::ReadWrite);
|
||||||
if (file_or_error.is_error()) {
|
if (file_or_error.is_error()) {
|
||||||
dbg() << "Error: " << file_or_error.error();
|
dbgln("Error: {}", file_or_error.error());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ int main(int argc, char** argv)
|
||||||
JsonObject json;
|
JsonObject json;
|
||||||
|
|
||||||
if (!previous_json.has_value() || !previous_json.value().is_object()) {
|
if (!previous_json.has_value() || !previous_json.value().is_object()) {
|
||||||
dbg() << "Error: Could not parse JSON";
|
dbgln("Error: Could not parse JSON");
|
||||||
} else {
|
} else {
|
||||||
json = previous_json.value().as_object();
|
json = previous_json.value().as_object();
|
||||||
}
|
}
|
||||||
|
@ -95,22 +95,22 @@ int main(int argc, char** argv)
|
||||||
json.set(tty_name, move(entry));
|
json.set(tty_name, move(entry));
|
||||||
} else {
|
} else {
|
||||||
ASSERT(flag_delete);
|
ASSERT(flag_delete);
|
||||||
dbg() << "Removing " << tty_name << " from utmp";
|
dbgln("Removing {} from utmp", tty_name);
|
||||||
json.remove(tty_name);
|
json.remove(tty_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!file.seek(0)) {
|
if (!file.seek(0)) {
|
||||||
dbg() << "Seek failed";
|
dbgln("Seek failed");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!file.truncate(0)) {
|
if (!file.truncate(0)) {
|
||||||
dbg() << "Truncation failed";
|
dbgln("Truncation failed");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!file.write(json.to_string())) {
|
if (!file.write(json.to_string())) {
|
||||||
dbg() << "Write failed";
|
dbgln("Write failed");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue