Commit Graph

33 Commits

Author SHA1 Message Date
Tim Schumacher
a96339b72b LibCore: Move Stream-based sockets into the Core namespace 2023-02-13 00:50:07 +00:00
MacDue
808f0c6837 Revert "ConfigServer: Unveil "/etc/passwd""
This reverts commit cd0b7656fa.
2023-02-05 16:40:51 +01:00
Lucas CHOLLET
cd0b7656fa ConfigServer: Unveil "/etc/passwd"
This is needed to use functions like `getpwuid()`.
2023-02-01 19:21:10 +01:00
Timothy Flynn
142abc0b2e LibCore+ConfigServer: Add FileWatcherFlags to replace InodeWatcherFlags
InodeWatcherFlags is an enumeration from the Kernel. To avoid using it
outside of Serenity, add a FileWatcherFlags for FileWatcher, much like
we already have FileWatcherEvent::Type.
2023-01-18 09:37:11 -05:00
Sam Atkins
a8cf0c9371 LibCore+Userland: Make Core::Timer::create_single_shot() return ErrorOr
clang-format sure has some interesting opinions about where to put a
method call that comes after a lambda. :thonk:
2023-01-12 11:25:51 +01:00
Timothy Flynn
69beda23c3 LibConfig+LibCore+ConfigServer: Support u32 configuration entries 2022-12-23 23:26:21 +01:00
Linus Groh
6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
2022-12-06 08:54:33 +01:00
Tim Schumacher
ce2f1b845f Everywhere: Mark dependencies of most targets as PRIVATE
Otherwise, we end up propagating those dependencies into targets that
link against that library, which creates unnecessary link-time
dependencies.

Also included are changes to readd now missing dependencies to tools
that actually need them.
2022-11-01 14:49:09 +00:00
Ali Mohammad Pur
166a905951 Userland: Properly populate GENERATED_SOURCES
We previously put the generated headers in SOURCES, which did not mark
them as GENERATED (and did not produce a proper dependency).
This commit moves all generated headers into GENERATED_SOURCES, and
removes useless header SOURCES.
2022-10-12 15:55:15 +01:00
thankyouverycool
c34f2e75e9 LibCore+LibConfig+ConfigServer: Add Config::{add,remove}_group()
Plumbs synchronous calls for adding and removing group entries to
config files. This is useful for services like SystemServer which
default to group names for executable paths, and for removing all
keys at once.
2022-10-01 13:39:10 +03:30
thankyouverycool
6f394d9ee2 LibConfig+ConfigServer: Make remove_key() synchronous
Previously, when removing keys, the config utility terminated its
connection before changes could be synced.
2022-10-01 13:39:10 +03:30
sin-ack
3f3f45580a Everywhere: Add sv suffix to strings relying on StringView(char const*)
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-12 23:11:35 +02:00
Moustafa Raafat
0a3467d665 LibConfig+ConfigServer: Write config values synchronously
This patch fixes the issue of pressing the ok button of a settings menu
without saving the changes, or not reverting the changes when pressing
the cancel button because the app has died before the new values make
it to the other end.
2022-04-26 22:51:49 +02:00
kleines Filmröllchen
0fd09b2381 LibCore: Automatically create config directories if necessary
If the .config directory (or its children, like lib) was deleted,
ConfigFile would crash because it would try to open or create a file in
a directory that didn't exist. Therefore, for user and library configs
(but not system configs), ensure that the parent directories exist. This
allows the user to delete the entire .config folder and all apps still
work. (Except those which can't handle missing config. That's a separate
issue though.)

Fixes #13555

Note: Some changes to pledges and unveils are necessary for this to
work. The only one who can recreate .config at the moment is
ConfigServer, as others probably don't pledge the user home directory.
2022-04-11 00:08:48 +02:00
Lenny Maiorani
0b7baa7e5a Services: Use default constructors/destructors
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules

"The compiler is more likely to get the default semantics right and
you cannot implement these functions better than the compiler."
2022-03-24 20:09:26 -07:00
Itamar
3a71748e5d Userland: Rename IPC ClientConnection => ConnectionFromClient
This was done with CLion's automatic rename feature and with:
find . -name ClientConnection.h
    | rename 's/ClientConnection\.h/ConnectionFromClient.h/'

find . -name ClientConnection.cpp
    | rename 's/ClientConnection\.cpp/ConnectionFromClient.cpp/'
2022-02-25 22:35:12 +01:00
Sam Atkins
cd0ffe5460 LibCore+Everywhere: Return ErrorOr from ConfigFile::sync()
Currently this method always succeeds, but that won't be true once we
switch to the Core::Stream API. :^)

Some of these places would ideally show an error message to the user,
since failure to save a file is significant, but let's not get
distracted right now.
2022-02-16 19:49:41 -05:00
Sam Atkins
8260135d4d LibCore+Everywhere: Return ErrorOr from ConfigFile factory methods
I've attempted to handle the errors gracefully where it was clear how to
do so, and simple, but a lot of this was just adding
`release_value_but_fixme_should_propagate_errors()` in places.
2022-02-16 19:49:41 -05:00
sin-ack
2e1bbcb0fa LibCore+LibIPC+Everywhere: Return Stream::LocalSocket from LocalServer
This change unfortunately cannot be atomically made without a single
commit changing everything.

Most of the important changes are in LibIPC/Connection.cpp,
LibIPC/ServerConnection.cpp and LibCore/LocalServer.cpp.

The notable changes are:
- IPCCompiler now generates the decode and decode_message functions such
  that they take a Core::Stream::LocalSocket instead of the socket fd.
- IPC::Decoder now uses the receive_fd method of LocalSocket instead of
  doing system calls directly on the fd.
- IPC::ConnectionBase and related classes now use the Stream API
  functions.
- IPC::ServerConnection no longer constructs the socket itself; instead,
  a convenience macro, IPC_CLIENT_CONNECTION, is used in place of
  C_OBJECT and will generate a static try_create factory function for
  the ServerConnection subclass. The subclass is now responsible for
  passing the socket constructed in this function to its
  ServerConnection base; the socket is passed as the first argument to
  the constructor (as a NonnullOwnPtr<Core::Stream::LocalServer>) before
  any other arguments.
- The functionality regarding taking over sockets from SystemServer has
  been moved to LibIPC/SystemServerTakeover.cpp. The Core::LocalSocket
  implementation of this functionality hasn't been deleted due to my
  intention of removing this class in the near future and to reduce
  noise on this (already quite noisy) PR.
2022-01-15 13:29:48 +03:30
Andreas Kling
6d0f504822 LibIPC: Add IPC::MultiServer convenience class
This encapsulates what our multi-client IPC servers typically do on
startup:

    1. Create a Core::LocalServer
    2. Take over a listening socket file descriptor from SystemServer
    3. Set up an accept handler for incoming connections

IPC::MultiServer does all this for you! All you have to do is provide
the relevant client connection type as a template argument.
2021-12-06 19:22:16 +01:00
Andreas Kling
81047d8f9c LibCore: Make LocalServer::take_over_from_system_server() return ErrorOr
This allows us to use TRY() or MUST() when calling it.
2021-12-06 19:22:16 +01:00
Sam Atkins
92f8514a85 Services: Cast unused IPC::new_client_connection() results to void
These ones all manage their storage internally, whereas the WebContent
and ImageDecoder ones require the caller to manage their lifetime. This
distinction is not obvious to the user without looking through the code,
so an API that makes this clearer would be nice.
2021-12-05 15:31:03 +01:00
Andreas Kling
fe00393941 LibCore: Change Core::LocalServer::on_ready_to_accept => on_accept
Everyone used this hook in the same way: immediately accept() on the
socket and then do something with the newly accepted fd.

This patch simplifies the hook by having LocalServer do the accepting
automatically.
2021-11-30 23:34:40 +01:00
Brian Gianforcaro
cf4fa936be Everywhere: Use default execpromises argument for Core::System::pledge 2021-11-28 08:04:57 +01:00
Andreas Kling
70b1312fd4 ConfigServer: Port to LibMain :^) 2021-11-23 15:44:59 +01:00
faxe1008
116d89eec6 ConfigServer: Add methods to list groups and keys
Applications that make use of LibConfig anyway have now a way of listing
the groups and keys without resorting to using Core::ConfigFile
directly.
2021-11-18 09:08:51 +01:00
faxe1008
a4a89a63cb ConfigServer: Add method and notification for key removal
This addresses the FIXME of detecting ConfigFile key removal.
2021-11-13 12:55:46 +01:00
Valtteri Koskivuori
a38983dc0c ConfigServer: Sync config files to disk automatically
At the risk of introducing premature optimization, it only syncs to disk
5 seconds after the latest valid configuration update, to handle cases
where programs might send frequent updates that would go to disk every
time otherwise.
Also syncs to disk when the client connection closes.

Co-authored-by: Timothy Flynn <trflynn@pm.me>
2021-10-14 21:41:48 +02:00
Andreas Kling
317f55bb25 ConfigServer: Update the configuration cache on file changes
We were only notifying clients about the change, but didn't actually
update the internal cache in ConfigServer itself.

Thanks to "The Grey One" for pointing this out. :^)
2021-08-27 13:31:45 +02:00
Andreas Kling
83d3720842 ConfigServer: Monitor opened config files for changes
After opening a domain configuration and putting into our configuration
cache, we now monitor the underlying file for changes and send out
notifications to monitoring clients as needed.

This patch has three FIXME's:

- We create a new Core::FileWatcher for each domain.
- We don't yet detect removed keys.
- We don't know the type of key, so we assume everything is a string.

There are a number of ways we can solve those problems but let's not
hold up this patch while we wait for solutions. :^)
2021-08-26 23:41:38 +02:00
Andreas Kling
edf7843409 ConfigServer+LibConfig: Add way for clients to listen for config changes
This patch adds a Config::Listener abstract class that anyone can
inherit from and receive notifications when configuration values change.

We don't yet monitor file system changes, so these only work for changes
made by ConfigServer itself.

In order to receive these notifications, clients must monitor the domain
by calling monitor_domain(). Only pledged domains can be monitored.

Note that the client initiating the change does not get notified.
2021-08-26 23:41:38 +02:00
Andreas Kling
eeddaa988a ConfigServer+LibConfig: Add pledge_domains() API
This API lets applications specify which configuration domains they
will be accessing throughout their lifetime. It works similarly in
spirit to the kernel's pledge().

You cannot pledge_domains() more than once, and once you have used it,
it's no longer possible to access any other configuration domain.

This is obviously just a first cut of this mechanism, and we may need
to tweak it further as we go.
2021-08-26 00:54:28 +02:00
Andreas Kling
bdcd0abf9d Userland: Introduce ConfigServer and LibConfig
ConfigServer is an IPC service that provides access to application
configuration and settings. The idea is to replace all uses of
Core::ConfigFile with IPC requests to ConfigServer.

This first cut of the API is pretty similar to Core::ConfigFile.

The old:

    auto config = Core::ConfigFile::open_for_app("App");
    auto value = config->read_entry("Group", "Key");

The new:

    auto value = Config::read_string("App", "Group", "Key");

ConfigServer uses the ~/.config directory as its backing store
and all the files remain human-editable. :^)
2021-08-26 00:54:27 +02:00