mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:37:44 +00:00
utmpupdate: Port to Core::Stream
This commit is contained in:
parent
6d7435d251
commit
8d798c2716
1 changed files with 6 additions and 17 deletions
|
@ -10,7 +10,7 @@
|
||||||
#include <AK/JsonValue.h>
|
#include <AK/JsonValue.h>
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/DateTime.h>
|
#include <LibCore/DateTime.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/Stream.h>
|
||||||
#include <LibCore/System.h>
|
#include <LibCore/System.h>
|
||||||
#include <LibMain/Main.h>
|
#include <LibMain/Main.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -42,9 +42,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
|
|
||||||
dbgln("Updating utmp from UID={} GID={} EGID={} PID={}", getuid(), getgid(), getegid(), pid);
|
dbgln("Updating utmp from UID={} GID={} EGID={} PID={}", getuid(), getgid(), getegid(), pid);
|
||||||
|
|
||||||
auto file = TRY(Core::File::open("/var/run/utmp", Core::OpenMode::ReadWrite));
|
auto file = TRY(Core::Stream::File::open("/var/run/utmp"sv, Core::Stream::OpenMode::ReadWrite));
|
||||||
|
|
||||||
auto file_contents = file->read_all();
|
auto file_contents = TRY(file->read_all());
|
||||||
auto previous_json = TRY(JsonValue::from_string(file_contents));
|
auto previous_json = TRY(JsonValue::from_string(file_contents));
|
||||||
|
|
||||||
JsonObject json;
|
JsonObject json;
|
||||||
|
@ -70,20 +70,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
json.remove(tty_name);
|
json.remove(tty_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!file->seek(0)) {
|
TRY(file->seek(0, Core::Stream::SeekMode::SetPosition));
|
||||||
dbgln("Seek failed");
|
TRY(file->truncate(0));
|
||||||
return 1;
|
TRY(file->write(json.to_string().bytes()));
|
||||||
}
|
|
||||||
|
|
||||||
if (!file->truncate(0)) {
|
|
||||||
dbgln("Truncation failed");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!file->write(json.to_string())) {
|
|
||||||
dbgln("Write failed");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue