Commit Graph

1913 Commits

Author SHA1 Message Date
Alexander A. Klimov 78b4dc6509 Remove unused Stream#Peek() 2023-03-24 18:18:13 +01:00
Julian Brost 66b039df9c
Merge pull request #9497 from Icinga/9249
Application::Exit(): don't exit(), but _exit(), even in debug build mode
2023-03-10 16:04:54 +01:00
Alexander Aleksandrovič Klimov 55930c8042
ProcessSpawnImpl(): remove redundant _exit(128);
Now this if doesn’t _exit(128) by itself, but "return" to the outer if which immediately _exit(128)s.
2023-03-02 12:45:15 +01:00
Julian Brost cf517050bc
Merge pull request #9711 from Icinga/connect-cancel
Connect(): don't try next DNS record if operation is canceled
2023-03-01 15:49:53 +01:00
Alexander A. Klimov 79f1e0666a Connect(): don't try next DNS record if operation is canceled
Instead return immediately to meet the caller's expectations.
2023-02-28 10:57:54 +01:00
Julian Brost bda8be343b
Merge pull request #9662 from Icinga/Repair#9627
Repair DSL Namespace values being constant broken in #9627
2023-02-20 16:35:36 +01:00
Julian Brost d9767cff3f
Merge pull request #9675 from Icinga/third-party/nlohmann_json
Update third-party/nlohmann_json to v3.9.1
2023-02-20 15:31:32 +01:00
Julian Brost 3023009804
Merge pull request #9653 from Icinga/9631
Setup all signal handlers with SA_RESTART flag
2023-02-14 17:55:09 +01:00
Alexander A. Klimov 34d0b942b9 Update third-party/nlohmann_json to v3.9.1
the latest version w/o Apache 2.0 licensed code which conflicts with GPL 2.
2023-02-14 16:19:44 +01:00
Julian Brost e074e892ce
Merge pull request #9658 from Icinga/unfreeze
Dictionary#*(): remove bool overrideFrozen if unused
2023-02-10 19:42:00 +01:00
Alexander A. Klimov f3f2c943c7 ScriptGlobal::Set(): don't explicitly give Namespace#Set() its default values 2023-02-10 15:55:10 +01:00
Alexander A. Klimov e61b380808 Call Namespace#Set(), not #SetFieldByName()
Namespace#SetFieldByName() calls #Set() anyway.
2023-02-10 15:53:30 +01:00
Alexander A. Klimov 683095a165 Make globals.Internal values non-const by default
That namespace is internal anyway.

Previous commit, icinga2 console:
Error: Constants must not be removed.

This commit fixes it.
2023-02-10 15:47:25 +01:00
Alexander A. Klimov 02df94a46a Repair DSL Namespace values being constant broken in #9627
master before #9627 (a0286e9c6):

<1> => namespace n { x = 42; x = 42 }
                             ^^^^^^
Constant must not be modified.
<2> =>

HEAD of #9627 (24b57f0d3):

<1> => namespace n { x = 42; x = 42 }
null
<2> =>
2023-02-10 15:43:01 +01:00
Julian Brost 0dd35bb960
Merge pull request #9657 from Icinga/shared_mutex-Dictionary
Use a shared_mutex for read `Dictionary` operations
2023-02-10 15:15:52 +01:00
Alexander A. Klimov e9846f1827 ScriptGlobal::Set(): remove unused bool overrideFrozen 2023-02-10 11:33:46 +01:00
Alexander A. Klimov cd78da13d3 Dictionary#Clear(): remove unused bool overrideFrozen 2023-02-10 11:33:46 +01:00
Alexander A. Klimov 270c6392d4 Dictionary#Remove(): remove unused bool overrideFrozen 2023-02-10 11:33:46 +01:00
Alexander A. Klimov ca547d0292 Use a shared_mutex for read `Dictionary` operations
This allows multiple parallel read operations resulting
in a overall speedup on systems with many cores.
2023-02-10 11:31:51 +01:00
Alexander A. Klimov a9341eb4a0 Setup all signal handlers with SA_RESTART flag
so interrupted syscalls get auto-restarted and callers
don't get or have to handle the EINTR error.
2023-02-03 14:46:45 +01:00
Julian Brost c51037725a
Merge pull request #9466 from Icinga/flush-temp-files
Deduplicate and stabilize fragile filesystem transactions
2023-02-02 16:29:11 +01:00
Julian Brost fd1aa73d25 Fix config sync after freezing namespaces
This was accidentally broken by #9627 because during config sync, a config
validation happens that uses `--define System.ZonesStageVarDir=...` which fails
on the now frozen namespace.

This commit changes this to use `Internal.ZonesStageVarDir` instead. After all,
this is used for internal functionality, users should not directly interact
with this flag.

Additionally, it no longer freezes the `Internal` namespace which actually
allows using `Internal.ZonesStageVarDir` in the first place. This also fixes
`--define Internal.Debug*` which was also broken by said PR. Freezing of the
`Internal` namespace is not necessary for performance reasons as it's not
searched implicitly (for example when accessing `globals.x`) and should users
actually interact with it, they should know by that name that they are on their
own.
2023-02-01 12:29:47 +01:00
Alexander A. Klimov d22fdf2a7a Introduce AtomicFile#GetTempFilename() 2023-01-27 12:03:59 +01:00
Alexander A. Klimov 0367c9e099 Remove unused Utility::CreateTempFile() 2023-01-27 12:03:59 +01:00
Alexander A. Klimov b92fe23469 Deduplicate and stabilize fragile filesystem transactions
by using AtomicFile so they ensure all or nothing of a file gets replaced.
2023-01-27 12:03:56 +01:00
Alexander A. Klimov a3e205b990 Introduce AtomicFile::Write() 2023-01-27 11:36:09 +01:00
Julian Brost 2d860a0f5e
Merge pull request #8118 from Icinga/feature/speed-object-registry-8112
Speed up config object lookup
2023-01-26 19:03:40 +01:00
Alexander Aleksandrovič Klimov 421ac1735c
Merge pull request #9608 from Icinga/move-types-namespace
Move Types namespace into type.cpp and simplify Type::GetByName()
2023-01-26 18:32:41 +01:00
Alexander A. Klimov b2fc49569c Make ConfigType#m_Mutex a std::shared_timed_mutex
refs #8112
2023-01-26 15:04:02 +01:00
Alexander A. Klimov 21759f015d ConfigType: store config objects in a hash map
refs #8112
2023-01-26 15:03:54 +01:00
Julian Brost 3dab46623b Move Types namespace into type.cpp and simplify Type::GetByName()
This commit moves the initialization of the globals.Types namespace to type.cpp
in order to keep a pointer to the Namespace object in Type::m_Namespace and
simplify Type::GetByName() using it.

The dynamic type check is moved into an assertion after freezing the namespace.
2023-01-26 14:26:41 +01:00
Yonas Habteab 7b91b200f5 Use simplified if conditions where applicable 2023-01-26 09:06:20 +01:00
Yonas Habteab 38313434d2 Avoid calling `GetDeferredInitializers()` repeatedly 2023-01-26 09:05:19 +01:00
Julian Brost 24b57f0d3a Namespace: don't acquire shared locks on frozen namespaces
This makes freezing a namespace an irrevocable operation but in return allows
omitting further lock operations. This results in a performance improvement as
reading an atomic bool is faster than acquiring and releasing a shared lock.

ObjectLocks on namespaces remain untouched as these mostly affect write
operations which there should be none of after freezing (if there are some,
they will throw exceptions anyways).
2023-01-19 17:56:44 +01:00
Julian Brost cc0e2ec181 Use a shared_mutex for read `Namespace` operations
This allows multiple parallel read operations resulting in a overall speedup on
systems with many cores.
2023-01-19 17:55:29 +01:00
Julian Brost 1c066fc02e Simplify NamespaceValue class hierarchy to one struct without member functions
This commit removes EmbeddedNamespaceValue and ConstEmbeddedNamespaceValue and
reduces NamespaceValue down to a simple struct without inheritance or member
functions. The code from these clases is inlined into the Namespace class. The
class hierarchy determining whether a value is const is moved to an attribute
of NamespaceValue.

This is done in preparation for changes to the locking in the Namespace class.
Currently, it relies on a recursive mutex. In the future, a shared mutex
(read/write lock) should be used instead, which cannot allow recursive locking
(without failing or risk deadlocking on lock upgrades). With this change, all
operations requiring a lock for one operation are within one function, no
recursive locking is not needed any more.
2023-01-19 17:55:11 +01:00
Julian Brost 0503ca1379 Initialize namespaces without using `overrideFrozen`
This commit adds a new initialization priority `FreezeNamespaces` that is run
last and moves all calls to `Namespace::Freeze()` there. This allows all other
initialization functions to still update namespaces without the use of the
`overrideFrozen` flag.

It also moves the initialization of `System.Platform*` and `System.Build*` to
an initialize function so that these can also be set without setting
`overrideFrozen`.

This is preparation for a following commit that will make the frozen flag in
namespaces finial, no longer allowing it to be overriden (freezing the
namespace will disable locking, so performing further updates would be unsafe).
2023-01-19 09:53:36 +01:00
Julian Brost 6229f4d9bf InitializePriority: don't explicitly specify values
Now that all values are in one place, there is no reason for this numbering
with gaps anymore. If you need to insert a new value in between, you can just
do so in the enum.

This reverses the sort order of the enum, thereby requiring a change to the
sort order of the std::priority_queue containing the elements.
2023-01-18 15:57:32 +01:00
Julian Brost 99bb687350 INITIALIZE_ONCE_WITH_PRIORITY: use enum for priority values
Change the type of the priority values from int to a new enum. By replacing the
magic int values throughout the code base with named values, there is now a
single place where all priority values are defined and you get an overview over
the initialization order.
2023-01-18 15:57:27 +01:00
Julian Brost 61285adcae InitializeOnceHelper: use std::function instead of C function pointer
InitializeOnceHelper calls Loader::AddDeferredInitializer which takes a
std::function, so it's eventually converted to that anyways. This commit just
does this a bit earlier, and by saving the step of the intermediate C function
pointer, this would now also work for capturing lambdas (which there are none
of at the moment).
2023-01-18 15:52:42 +01:00
Julian Brost c019f8c04a
Merge pull request #9603 from Icinga/remove-namespace-behavior
Namespace: replace behavior classes with a bool
2023-01-18 15:48:34 +01:00
Julian Brost 9590c176e3
Merge pull request #9491 from Icinga/9488
Fix compile error on Solaris 11.4
2023-01-12 14:22:52 +01:00
Julian Brost dd51997c73
Merge pull request #9624 from Icinga/9618
Make compilable on Boost v1.81
2023-01-05 15:32:22 +01:00
Alexander A. Klimov 5bcbc96e22 Handle boost::beast::http::basic_fields#set() signature change (v1.81)
Make String convertible to boost::beast::string_view (always working),
not boost::string_view (broken).
2023-01-05 11:18:20 +01:00
Julian Brost fbb68dbcd0 Namespace: replace behavior classes with a bool
In essence, namespace behaviors acted as hooks for update operations on
namespaces. Two behaviors were implemented:

- `NamespaceBehavior`: allows the update operation unless it acts on a value
  that itself was explicitly marked as constant.
- `ConstNamespaceBehavior`: initially allows insert operations but marks the
  individual values as const. Additionally provides a `Freeze()` member
  function. After this was called, updates are rejected unless a special
  `overrideFrozen` flag is set explicitly.

This marvel of object-oriented programming can be replaced with a simple bool.
This commit basically replaces `Namespace::m_Behavior` with
`Namespace::m_ConstValues` and inlines the behavior functions where they were
called. While doing so, the code was slightly simplified by assuming that
`m_ConstValues` is true if `m_Frozen` is true. This is similar to what the API
allowed in the old code as you could only freeze a `ConstNamespaceBehavior`.
However, this PR moves the `Freeze()` member function and the related
`m_Freeze` member variable to the `Namespace` class. So now the API allows any
namespace to be frozen. The new code also makes sense with the previously
mentioned simplification: a `Namespace` with `m_ConstValues = false` can be
modified without restrictions until `Freeze()` is called. When this is done, it
becomes read-only.

The changes outside of `namespace.*` just adapt the code to the slightly
changed API.
2022-12-09 09:25:46 +01:00
Julian Brost a8cc5dff89 Prevent ObjectLock from being copied
Copying an ObjectLock results in the underlying mutex being unlocked too often.
There's also no good reason for copying a scoped locking class (if at all, it
should be moved).
2022-12-08 15:48:01 +01:00
Alexander Aleksandrovič Klimov b585e20a4c
Merge pull request #9591 from Icinga/circular-refs
icinga2 daemon: w/o --dump-objects just check for circular refs
2022-11-30 21:41:21 +01:00
Alexander A. Klimov 83021f8231 CONTEXT: use << everywhere to unify usages 2022-11-30 11:06:51 +01:00
Alexander A. Klimov b82814fb29 CONTEXT: lazily evaluate frames to only actually assemble when needed 2022-11-30 11:06:45 +01:00
Alexander A. Klimov 0b46e0aeab CONTEXT: use l_Frames as stack to reduce modification complexity 2022-11-30 10:56:24 +01:00