summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCore
AgeCommit message (Collapse)Author
2022-09-15LibCore: Rewrite Core::Stream::read_all_implsin-ack
The previous version relied on manually setting the amount of data to read for the next chunk and was overall unclear. The new version uses the Bytes API to vastly improve readability, and fixes a bug where reading from files where a single read that wasn't of equal size to the block size would cause the byte buffer to be incorrectly resized causing corrupted output.
2022-09-15LibCore: Add documentation to Stream functions + make parameter clearersin-ack
file_size was not very clear about what it was being used for, so I switched it to say expected_file_size to make it clear that it's just a heuristic.
2022-09-12Everywhere: Use my very shiny serenityos.org email :^)networkException
2022-09-09LibCore: Add File::open_file_or_standard_stream()demostanis
2022-08-23Userland: Consolidate most PATH resolving into a single implementationTim Schumacher
We previously had at least three different implementations for resolving executables in the PATH, all of which had slightly different characteristics. Merge those into a single implementation to keep the behaviour consistent, and maybe to make that implementation more configurable in the future.
2022-08-23Userland: Rely on a single authoritative source for the default `PATH`Tim Schumacher
2022-08-23LibCore: Fix deadlock in SharedSingleProducerCircularQueuekleines Filmröllchen
This deadlock would incorrectly change the queue from almost empty to full on dequeue because someone else could empty the queue after we had checked its non-emptyness. The test would deadlock on this, which doesn't happen anymore.
2022-08-17LibCore: Make EventLoop's connection to InspectorServer work againkleines Filmröllchen
This path was changed to the uid templated version without actually using the template resolver function in Account.
2022-08-16LibCore: Add MIME sniffing for MP3 and WAVkleines Filmröllchen
2022-08-16LibCore: The MIME type is 'audio/flac', not 'extra/flac'kleines Filmröllchen
2022-08-15LibCore: Add Directory::chown() API and use it in Core::AccountAndreas Kling
Since we already have the directory open, let's have an API to fchown() the underlying file descriptor instead of forcing clients to do another path lookup.
2022-08-15LoginServer+LibCore: Only create user temp directory from LoginServerAndreas Kling
Other programs use Core::Account::login(), notably su(1), which stopped working due to a missing "cpath" pledge promise. This patch moves the /tmp/user/ creation logic to a separate function that LoginServer can call.
2022-08-14Base: Launch InspectorServer at session start-upLucas CHOLLET
2022-08-14LibCore: Make LocalServer aware of %uid in pathLucas CHOLLET
2022-08-14LibCore: Make `Core::System::unveil` aware of %uid in pathLucas CHOLLET
This brings support for user-dependent paths in `unveil`.
2022-08-14LibCore+LibIPC: Recognise %uid in pathLucas CHOLLET
This patch allows to insert "%uid" in `IPC_CLIENT_CONNECTION` declaration and in SystemServer's ini files. This pattern is replaced then replaced by the UID of the owner of the service. It opens a path for seamlessly managed, per-user portal.
2022-08-14LibCore+LaunchServer: Move portal directory to `/tmp/user/%uid`Lucas CHOLLET
The `/tmp/user` directory is owned by root, this solution prevents malicious users to interfere with other users' portals. This commit also moves `launch`'s portal in the user directory.
2022-08-02LibC+LibCore: Use tm_isdst to handle time zone offsets in DSTTimothy Flynn
Previously, we were incorrectly assuming that the daylight global variable indicated whether the current time zone is in DST. In reality, the daylight variable only indicates whether a time zone *can* be in DST. Instead, the tm structure has a tm_isdst member that should be used for this purpose. Ensure our LibC handles tm_isdst, and avoid errant usage of the daylight variable in Core::DateTime.
2022-08-01AK: Prefix CACHE_ALIGNED & SYSTEM_CACHE_ALIGNMENT_SIZEBrian Gianforcaro
2022-07-27LibCore: Implement four-digit modes for `FilePermissionsMask` parsingTim Schumacher
2022-07-27LibCore: Implement the 'X' modifier into `FilePermissionMask`Tim Schumacher
2022-07-25LibCore: Add `System::link()`Tim Schumacher
2022-07-22LibAudio: Prevent racy eternal deadlock of the audio enqueue threadkleines Filmröllchen
The audio enqueuer thread goes to sleep when there is no more audio data present, and through normal Core::EventLoop events it can be woken up. However, that waking up only happens when the thread is not currently running, so that the wake-up events don't queue up and cause weirdness. The atomic variable responsible for keeping track of whether the thread is active can lead to a racy deadlock however, where the audio enqueuer thread will never wake up again despite there being audio data to enqueue. Consider this scenario: - Main thread calls into async_enqueue. It detects that according to the atomic variable, the other thread is still running, skipping the event queue wake. - Enqueuer thread has just finished playing the last chunk of audio and detects that there is no audio left. It enters the if block with the dbgln "Reached end of provided audio data..." - Main thread enqueues audio, making the user sample queue non-empty. - Enqueuer thread does not check this condition again, instead setting the atomic variable to indicate that it is not running. It exits into an event loop sleep. - Main thread exits async_enqueue. The calling audio enqueuing system (see e.g. Piano, but all of them function similarly) will wait until the enqueuer thread has played enough samples before async_enqueue is called again. However, since the enqueuer thread will never play any audio, this condition is never fulfilled and audio playback deadlocks This commit fixes that by allowing the event loop to not enqueue an event that already exists, therefore overloading the audio enqueuer event loop by at maximum one message in weird situations. We entirely get rid of the atomic variable and the race condition is prevented.
2022-07-21LibCore: Add File::is_{block,char}_device() helpersSamuel Bowman
The existing File::is_device() helpers don't distinguish between block and char devices. This commit adds File::is_block_device() and File::is_char_device() helpers which are more specific.
2022-07-21LibCore: Add function for searching a file in $PATHItamar
This extracts the logic of searching for a file in $PATH from System::exec to a separate function.
2022-07-21LibCore: Add support for long integral types to ArgsParserTim Schumacher
2022-07-21LibCore: Implement integral ArgsParser options through a templateTim Schumacher
This keeps us from having to duplicate code for each data type we add.
2022-07-19LibCore: Do not refer to `extern int daylight` in DateTime::to_stringDaniel Bertalan
This variable does not exist on FreeBSD. Co-Authored-By: Al Hoang <13622+hoanga@users.noreply.github.com>
2022-07-19LibCore: Port System::anon_create to FreeBSDDaniel Bertalan
FreeBSD implements the Linux API, so this was very simple luckily.
2022-07-19LaunchServer+SystemServer: Move the portal to a user-specific directoryLucas CHOLLET
Various changes are needed to support this: - The directory is created by Core::Account on login (and located in /tmp). - Service's sockets are now deleted on exit (to allow re-creation) - SystemServer needs to handle SIGTERM to correctly destroy services.
2022-07-19LibCore: Add Core::debounce(function, timeout)MacDue
This is a simple helper to debounce a function call, such as an event handler. It avoids the function being called until the event as settled down (i.e. after the timeout).
2022-07-19LibCore: Add support for compiling for Android with API Version >= 30Andrew Kaster
Most changes are around user and group management, which are exposed in the Android NDK differently than other Unices. We require version 30 for memfd_create, version 28 for posix_spawn, and so on. It's possible a shim for memfd_create could be used, but since Google is mandating new apps use API level 30 as of Nov 2022, this seems suitable.
2022-07-15LibCore: InspectorServerConnection send responses with multiple writesFrHun
2022-07-14LibCore: Make copying permissions, ownership and timestamps combineableTim Schumacher
2022-07-14LibCore: Introduce support for optional ArgsParser option valuesTim Schumacher
2022-07-14LibCore: Replace the ArgsParser option argument setting with an enumTim Schumacher
Replacement conditions for `requires_argument` have been chosen based on what would be most convenient for implementing an eventual optional argument mode.
2022-07-14LibCore: Don't print optional arguments in ArgsParser help messagesTim Schumacher
This fixes a misconception in our current `ArgsParser` implementation. If `requires_argument` is false, it doesn't mean that the argument is optional (i.e. "not required"). It means that there is no argument at all.
2022-07-12LibCore: Add FIXME note about converting Core::Account to use StringViewsin-ack
This prevents a bunch of utilities from using StringView for their arguments.
2022-07-12Everywhere: Replace single-char StringView op. arguments with charssin-ack
This prevents us from needing a sv suffix, and potentially reduces the need to run generic code for a single character (as contains, starts_with, ends_with etc. for a char will be just a length and equality check). No functional changes.
2022-07-12Everywhere: Add sv suffix to strings relying on StringView(char const*)sin-ack
Each of these strings would previously rely on StringView's char const* constructor overload, which would call __builtin_strlen on the string. Since we now have operator ""sv, we can replace these with much simpler versions. This opens the door to being able to remove StringView(char const*). No functional changes.
2022-07-12Everywhere: Split Error::from_string_literal and Error::from_string_viewsin-ack
Error::from_string_literal now takes direct char const*s, while Error::from_string_view does what Error::from_string_literal used to do: taking StringViews. This change will remove the need to insert `sv` after error strings when returning string literal errors once StringView(char const*) is removed. No functional changes.
2022-07-12Everywhere: Explicitly specify the size in StringView constructorssin-ack
This commit moves the length calculations out to be directly on the StringView users. This is an important step towards the goal of removing StringView(char const*), as it moves the responsibility of calculating the size of the string to the user of the StringView (which will prevent naive uses causing OOB access).
2022-07-12LibCore: Add convenience templates for System::{unveil,pledge}sin-ack
These convenience templates allow the following to be written as before: TRY(Core::System::pledge("promises...")); TRY(Core::System::pledge("promises...", "execpromises...")); TRY(Core::System::unveil("path", "permissions")); TRY(Core::System::unveil(nullptr, nullptr)); Other uses must now append sv to any literal string passed to pledge and unveil.
2022-07-12Userland: Remove erroneous String -> char* -> StringView conversionssin-ack
These were accidental (or leftover) uses of String::characters() to construct StringViews through its StringView(char const*) constructor. Since this constructor is due to be removed, this will no longer work. Plus this prevents strlen from being run on these strings unnecessarily.
2022-07-12Meta+Userland: Simplify some formatterssin-ack
These are mostly minor mistakes I've encountered while working on the removal of StringView(char const*). The usage of builder.put_string over Format<FormatString>::format is preferrable as it will avoid the indirection altogether when there's no formatting to be done. Similarly, there is no need to do format(builder, "{}", number) when builder.put_u64(number) works equally well. Additionally a few Strings where only constant strings were used are replaced with StringViews.
2022-07-12AK: Explicitly calculate length of char* when printingsin-ack
This moves out the calculation of the char* out to the formatter. Additionally, we now print (null) when a null pointer is passed.
2022-07-10Kernel+LibC+LibCore: Pass fcntl extra argument as pointer-sized variablegggggg-gggggg
The extra argument to fcntl is a pointer in the case of F_GETLK/F_SETLK and we were pulling out a u32, leading to pointer truncation on x86_64. Among other things, this fixes Assistant on x86_64 :^)
2022-07-09LibCore+Userland: Use StringViews when calling Core::System::openkleines Filmröllchen
For some reason we used raw char pointers sometimes, which caused at least one heap buffer overflow detected in fuzzing.
2022-07-06LibCore: Stub out pledge and unveil for non-serenity systemsAndrew Kaster
2022-07-06LibCore: Stub out FileWatcher for Lagom platformsAndrew Kaster
Stub out the FileWatcher class with ENOTSUP stubs to let Services that require it to compile for Lagom. Later we should add real code for this using techniques like Linux's inotify(7).