Commit Graph

39 Commits

Author SHA1 Message Date
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
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
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 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 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 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
Alexander A. Klimov 768044a754 Replace std::shared_ptr<NamespaceValue> with NamespaceValue::Ptr
refs #7361
2019-10-21 17:10:51 +02:00
Michael Friedrich 804c00ece5
Merge pull request #6999 from Icinga/bugfix/compiler-warnings
Suppress or fix compiler warnings
2019-03-18 08:44:30 +01:00
Alexander A. Klimov bf92e32496 Suppress or fix compiler warnings 2019-03-08 14:07:29 +01:00
Michael Friedrich d14a88235d Replace Copyright header with a short version, part I
CLion -> replace in path
2019-02-25 14:48:22 +01:00
Michael Friedrich dab53448bc icinga.com: Update *.{h,c}pp 2018-10-18 09:27:04 +02:00
Michael Friedrich 19993df380 Fix static initializer priority for namespaces in LTO builds
fixes #6575
2018-09-04 16:36:22 +02:00
Gunnar Beutner e678fa1aa5 Refactor Application::*Const() 2018-08-13 15:27:05 +02:00
Gunnar Beutner 8fda8d72ac Implement support for the namespace and using keywords 2018-08-13 13:44:31 +02:00
Gunnar Beutner 621eed3f13 Apply clang-tidy fix 'modernize-pass-by-value' 2018-01-04 12:24:57 +01:00
Gunnar Beutner ac155d1dda Apply clang-tidy fix 'modernize-redundant-void-arg' 2018-01-04 12:24:57 +01:00
Gunnar Beutner abe3f8a959 Build fix for Debian wheezy 2018-01-03 10:32:33 +01:00
Michael Insel 158ae2188e Change copyright header for 2018 2018-01-02 12:08:55 +01:00
Gunnar Beutner 4866f777cc Avoid unnecessary allocations for script frames 2017-12-18 13:40:29 +01:00
Michael Friedrich b7caf0820d Ensure that *.icinga.com is used everywhere
fixes #13897
fixes #13277
2017-01-10 17:19:12 +01:00
Gunnar Beutner b5b09216c6 Use lambda functions for INITIALIZE_ONCE
fixes #12562
2016-08-27 09:48:36 +02:00
Gunnar Beutner afc1b9bdc5 Move type variables into the 'Types' namespace
refs #12408
2016-08-12 17:05:19 +02:00
Gunnar Beutner b74014fa5e Fix auto-completion suggestions for "icinga2 console"
refs #12408
2016-08-12 15:36:47 +02:00
Gunnar Beutner 491acb62ea Fix crash in ScriptFrame::AddImport
refs #12408
2016-08-12 15:22:10 +02:00
Gunnar Beutner 24431b3dab Register deprecated methods in the 'Deprecated' namespace
refs #12408
2016-08-12 13:42:22 +02:00
Gunnar Beutner 2a40a71ffa Change scoping mechanism for the __using keyword
refs #12408
2016-08-12 13:14:10 +02:00
Gunnar Beutner 9f67b185b8 Make sure all constructors properly initialize the ScriptFrame object
refs #12408
2016-08-12 11:42:59 +02:00
Gunnar Beutner c5a170a972 Implement support for namespaces
fixes #12408
2016-08-12 11:32:16 +02:00
Gunnar Beutner 546bdbcf6a 'Sandboxed' property isn't properly propagated to child frames
refs #12247
2016-07-29 14:11:52 +02:00
Gunnar Beutner 6ba0c5fe01 Implement recursion limit for AST expressions which don't use a separate stack frame
fixes #11106
2016-03-23 09:03:49 +01:00
Gunnar Beutner 599929b0f6 Update copyright headers for 2016 2016-01-12 08:29:59 +01:00
Gunnar Beutner c15c9cce5e Detect infinite recursion in user scripts
fixes #10198
2015-09-23 09:21:45 +02:00
Gunnar Beutner d93bcedaad Implement sandbox mode for the config parser
fixes #9068
2015-04-16 08:48:17 +02:00
Gunnar Beutner 339b8aef48 Avoid unnecessary allocations in ScriptFrame::SetCurrentFrame 2015-03-29 22:26:07 +02:00
Gunnar Beutner 111b154a6d Remove unused #includes 2015-03-29 00:03:47 +01:00
Michael Friedrich 78bfd0204c Update copyright year 2015-01-22 12:00:23 +01:00
Gunnar Beutner 1073f031c8 Build fix for Windows 2014-12-22 14:14:16 +01:00
Gunnar Beutner cfd775c948 Move the VMFrame class to libbase
refs #8065
2014-12-12 15:33:56 +01:00