Commit Graph

156 Commits

Author SHA1 Message Date
Idan Horowitz
95bc8e4641 LibCore: Make DateTime's members signed
Core::DateTime is essentially a C++ wrapper of the tm struct, so we
should support the same signed range as the underlying tm.
2021-08-19 19:15:00 +01:00
Jean-Baptiste Boric
8cc8d72619 LibCore: Implement preserve flag for file/directory copy 2021-08-18 20:30:46 +02:00
Brian Gianforcaro
da51b8f39d LibCore: Move EventLoop to AK::Time 2021-08-15 12:20:38 +02:00
Nico Weber
f25be94487 LibCore: Make --version print same version as in LibGUI's About dialogs
Making every binary's behavior depend on the current git hash seems a
bit questionable to me, but we should be self-consistent about this.
2021-08-15 01:22:45 +02:00
Nico Weber
a45b6dbc07 LibCore: Include math.h instead of defining isnan() in ArgsParser.cpp 2021-08-15 01:22:45 +02:00
Nico Weber
1f71d7bf22 LibCore: Add --version flag to ArgsParser
`--version` always prints "git" for now.

The motivation is that the neofetch port calls `Shell --version` and
adds the output to its output. And if `Shell --version` prints a long
error message about it not knowing the flag, neofetch's output looks a
bit ugly. Per Discord discussion, just add the flag to ArgsParser
instead of only to Shell.
2021-08-14 22:46:34 +04:30
brapru
d456af1cd3 LibCore+LibHTTP: Check the status of the socket after EINPROGRESS
Previously the system would assume the socket was connected after the
file descriptor became writeable. Just because the fd is signaled as
ready for output does not necessarily indicate the socket is connected.
Instead, we should check the status of the socket with SO_ERROR and
handle successes/errors accordingly.
2021-08-13 20:30:19 +04:30
Andreas Kling
c94c15d45c Everywhere: Replace AK::Singleton => Singleton 2021-08-08 00:03:45 +02:00
Andreas Kling
f5c3225286 LibCore: Explicitly declare environ in Process.cpp to unbreak macOS 2021-08-06 01:29:09 +02:00
Andreas Kling
6e65b36973 LibCore: Add Core::Process::spawn()
This is a simple wrapper around posix_spawn() that will help us simplify
a bunch of very verbose posix_spawn() invocations.

This first version only supports the simplest case: executing an
executable without passing arguments or doing anything fancy. More
features can be added to cover more cases. :^)
2021-08-06 01:04:11 +02:00
Brian Gianforcaro
176e1cbca7 LibCore: Remove unused header includes 2021-08-01 08:10:16 +02:00
sin-ack
1e44a0c2d9 LibCore: Support registration of TextWrapping properties
This is basically a named boolean.
2021-07-29 22:33:34 +01:00
Peter Elliott
5d6bf83374 LibCore: Prevent LockFile fd from leaking into child process
Fixes #9059
2021-07-29 07:58:17 +02:00
Peter Elliott
fdcfd2816e LibCore: Add LockFile, a filesystem based mutex
This API wraps flock(2) and also handles the file creation and deletion
when the LockFile goes out of scope.
2021-07-22 23:34:15 +02:00
Tom
a635ff4e60 Everywhere: Make tracking cpu usage independent from system ticks
This switches tracking CPU usage to more accurately measure time in
user and kernel land using either the TSC or another time source.
This will also come in handy when implementing a tickless kernel mode.
2021-07-18 22:08:26 +02:00
Tom
7e77a2ec40 Everywhere: Improve CPU usage calculation
As threads come and go, we can't simply account for how many time
slices the threads at any given point may have been using. We need to
also account for threads that have since disappeared. This means we
also need to track how many time slices we have expired globally.

However, because this doesn't account for context switches outside of
the system timer tick values may still be under-reported. To solve this
we will need to track more accurate time information on each context
switch.

This also fixes top's cpu usage calculation which was still based on
the number of context switches.

Fixes #6473
2021-07-18 22:08:26 +02:00
Timothy
2eb93f2628 LibCore+LibIMAP: Move Promise to LibCore
This makes Promise available without having to link LibIMAP.
2021-07-15 11:11:14 +02:00
Timothy
3cc0283eac LibCore: Convert File to east-const style 2021-07-14 14:35:16 +04:30
Timothy
068802d58d LibCore: Add File method to determine absolute path
This will generate absolute paths lexically rather than through a call
to realpath. The motivation for this is to generate absolute paths for
non-existent files in unveil calls, as realpath will not work if the
file does not exist.
2021-07-14 14:35:16 +04:30
Timothy
3ae64c7c3d LibCore: Add File method to determine current working directory 2021-07-14 14:35:16 +04:30
brapru
5b6d2644bc LibCore: Generate new passwd file by checking pw_name
LibCore::Account::generate_passwd_file should follow
generate_shadow_file by conditionally checking for the username.
Previously, usermod's set_uid changes would not reflect in the updated
passwd file as m_uid had already been changed to the updated value.
2021-07-14 08:06:30 +02:00
brapru
6ef6bd1ccb LibCore: Add setters for all user account properties 2021-07-14 08:06:30 +02:00
Ariel Don
3289b6a887 LibCore: Implement File::is_link()
It was already possible to check if a path was a directory or a device.
Now, it is possible to check if a path is a link in a similar manner.
2021-07-12 19:15:19 +04:30
Andrew Kaster
f7c7954314 LibCore: Tolerate misaligned addresses in struct hostent
macOS's C library is not a good neighbor and doesn't ensure that
the entry in struct hostent's h_addr_list are aligned properly for
a char const*. In Socket::connect, use ByteReader instead of a c-style
cast to work around this possible misalignment.
2021-07-12 18:42:45 +04:30
Jean-Baptiste Boric
16983dbe8e LibCore: Add ability to not read shadow data for Account
This stops spamming the kernel logs with unveil violations if the
program didn't unveil /etc/shadow.
2021-07-09 20:15:40 +02:00
Jean-Baptiste Boric
fdf638dde0 LibCore: Implement Account::self() 2021-07-09 20:15:40 +02:00
Andreas Kling
b8a204c5b9 LibThreading: Rename Lock => Mutex 2021-07-09 11:15:50 +02:00
Andreas Kling
32654b340a LibCore: Remove overly informal language in ArgsParser error message 2021-07-08 01:17:06 +02:00
Andreas Kling
4cb0bbef9d LibCore: Make Core::AnonymousBuffer moveable 2021-07-07 18:02:43 +02:00
Aziz Berkay Yesilyurt
7db3e962f3 LibCore: Add unsigned option to ArgsParser
Unsigned options are used to return underflowed values for negative
inputs. With this change, we can verify that unsigned options only
accept unsigned inputs as arguments.
2021-07-07 20:05:43 +04:30
Timothy
60f84f3154 LibCore: Add method to leak fd from File
This will let other code use the fd while making sure the fd isn't
automatically closed by Core::File's destructor
2021-07-04 11:44:47 +04:30
Andreas Kling
e4a55404f1 LibCore: Avoid duplicate '/' in DirIterator::next_full_path()
When the root path of a DirIterator ends with '/', we don't need to
add another '/' before appending the file name.

Fixes an issue where files found by Assistant had 2 leading slashes.
2021-07-03 16:43:08 +02:00
Timothy
972e5d7292 LibCore: Add peer pid retrieval for LocalSocket
This will allow programs connected over unix sockets to retrieve the
pid of their peers in a nice way.
2021-07-01 17:49:18 +02:00
Max Wipfli
d8be530397 AK+Everywhere: Remove "null state" of LexicalPath
This removes the default constructor of LexicalPath, and subsequently
modifies all its users to accommodate the change.
2021-06-30 11:13:54 +02:00
Max Wipfli
7405536a1a AK+Everywhere: Use mostly StringView in LexicalPath
This changes the m_parts, m_dirname, m_basename, m_title and m_extension
member variables to StringViews onto the m_string String. It also
removes the m_is_absolute member in favour of computing if a path is
absolute in the is_absolute() getter. Due to this, the canonicalize()
method has been completely rewritten.

The parts() getter still returns a Vector<String>, although it is no
longer a const reference as m_parts is no longer a Vector<String>.
Rather, it is constructed from the StringViews in m_parts upon request.
The parts_view() getter has been added, which returns Vector<StringView>
const&. Most previous users of parts() have been changed to use
parts_view(), except where Strings are required.

Due to this change, it's is now no longer allow to create temporary
LexicalPath objects to call the dirname, basename, title, or extension
getters on them because the returned StringViews will point to possible
freed memory.
2021-06-30 11:13:54 +02:00
Max Wipfli
fc6d051dfd AK+Everywhere: Add and use static APIs for LexicalPath
The LexicalPath instance methods dirname(), basename(), title() and
extension() will be changed to return StringView const& in a further
commit. Due to this, users creating temporary LexicalPath objects just
to call one of those getters will recieve a StringView const& pointing
to a possible freed buffer.

To avoid this, static methods for those APIs have been added, which will
return a String by value to avoid those problems. All cases where
temporary LexicalPath objects have been used as described above haven
been changed to use the static APIs.
2021-06-30 11:13:54 +02:00
Max Wipfli
9b8f35259c AK: Remove the LexicalPath::is_valid() API
Since this is always set to true on the non-default constructor and
subsequently never modified, it is somewhat pointless. Furthermore,
there are arguably no invalid relative paths.
2021-06-30 11:13:54 +02:00
Andrew Kaster
b15fe2b926 LibCore: Add getter for how many groups exist in a Core::ConfigFile
This can be used by an application to find out if any config sections
were loaded from the file after a reparse.
2021-06-30 08:18:28 +04:30
kleines Filmröllchen
463a645d37 LibCore: Add InputFileStream::seek
As a file is able to seek(), InputFileStreams can delegate the seek()
easily. This allows for seeking to specific locations in the file.
2021-06-25 20:48:14 +04:30
Daniel Bertalan
2d2747cb15 LibCore+AK: Use proper atomics in Singleton 2021-06-24 17:35:49 +04:30
Ali Mohammad Pur
20c066b8e0 LibCore: Call optional did_construct() method when constucting objects
Some objects need to perform tasks during construction that require
the object to be fully constructed, which can't be done in the
constructor. This allows postponing such tasks into a did_construct
method that will be called right after the object was fully
constructed.
2021-06-20 14:57:26 +02:00
stelar7
63b1296821 LibCore: Allow TCPServer to be blocking 2021-06-16 09:10:48 +02:00
Andreas Kling
dc65f54c06 AK: Rename Vector::append(Vector) => Vector::extend(Vector)
Let's make it a bit more clear when we're appending the elements from
one vector to the end of another vector.
2021-06-12 13:24:45 +02:00
x-yl
904322e754 LibCore: Add a way to parse a DateTime from a string
DateTime can now be parsed from a string. Implements the same formatters
as strptime: https://linux.die.net/man/3/strptime (Well, some of them at
least).
2021-06-11 23:58:28 +04:30
Gunnar Beutner
764a41e284 LibCore: Fix building LibCore on FreeBSD 2021-06-09 09:24:58 +02:00
Ali Mohammad Pur
7ac196974d Everywhere: Replace Vector<T*> with nonnull entries with Vector<T&> 2021-06-08 19:14:24 +02:00
Jelle Raaijmakers
d7126fbbc2 LibCore/ArgsParser: Learn how to stop on first non-option
We need this for utilities like `env`, that do not gain anything by
parsing the options passed to the command they are supposed to
execute.
2021-06-08 11:30:58 +02:00
Jelle Raaijmakers
250f8eccf3 LibCore: Support fine-grained failure behavior for ArgsParser 2021-06-08 11:30:58 +02:00
Nick Miller
3938b56577 LibAudio+LibCore: Remove unnecessary IODeviceStreamReader.h
IODeviceStreamReader isn't pulling its weight.
It's essentially a subset of InputFileStream with only one user
(WavLoader).

This refactors WavLoader to use InputFileStream instead.
2021-06-08 00:38:54 +04:30
Andreas Kling
313e53dca0 LibCore: Add StringView overloads for Core::ArgsParser
These allow you to get StringView wrappers around on-stack string
arguments, which seems pretty nice. :^)
2021-06-01 09:02:43 +02:00