Commit Graph
3645 Commits
Author SHA1 Message Date
Yu Watanabe 52bcf45a6c sd-journal: use new() instead of newa() if too many items will be added
For safety, as the size may not be under our control.
2022-10-14 01:30:30 +09:00
Zbigniew Jędrzejewski-Szmek 31b5f92016 Merge pull request #24974 from yuwata/sd-journal
sd-journal: several cleanups and follow-ups for compact mode PR
2022-10-12 17:47:05 +02:00
Yu Watanabe df04b9ed86 sd-journal: add comments that journal_file_move_to() may break previous read data
We have already made similar mistakes several times, e.g.
b8478c14c7, and
b596d06c385e104fc330288b791a56661f0c2d17. Let's document the function
invalidates previously read objects.
2022-10-12 19:32:59 +09:00
Yu Watanabe a1640191b4 sd-journal: re-read object on next try
Otherwise, the object may be already altered by another cached entry.
2022-10-12 19:32:59 +09:00
Yu Watanabe 231741d355 sd-journal: re-read object from cache
Fixes a bug introduced by 0e35afff1d.

Replaces 3388a4b582.
2022-10-12 19:32:59 +09:00
Yu Watanabe 8f71023764 sd-journal: drop unused argument
Follow-up for a9089a6604.
2022-10-12 19:32:59 +09:00
Yu Watanabe cc938e4a0a sd-journal: several coding style updates
- rename `ret` -> `ret_object`,
- add missing assertions,
- add FIXME comments,
- wrap function arguments, etc., etc..
2022-10-12 19:32:59 +09:00
Yu Watanabe 8a77f21d29 sd-journal: rename next_hash_offset() -> get_next_hash_offset()
As the function name conflicts with one of its argument.
2022-10-12 15:37:04 +09:00
Luca Boccassi da60182759 Merge pull request #24933 from keszybz/erradicate-strerror
Erradicate strerror
2022-10-11 21:47:38 +02:00
Zbigniew Jędrzejewski-Szmek eaaf7465ee sd-bus: make bus_error_message() a thread-safe macro
strerror_r() is used instead of strerror(). The usual trick is employed: we
allocate a buffer that lives until the end of the surrounding block to provide
the scratch space. This change is particularly important forn sd-bus and the
pam modules, which may be called from threaded code.

I checked the codebase, and we only use bus_error_message() in log statements,
so the returned pointer is not used beyond its valid lifetime.
2022-10-11 16:59:00 +02:00
Zbigniew Jędrzejewski-Szmek f37508d506 tree-wide: get rid of lgtm annotations
We now use CodeQL, and LGTM itself is gone. Those old annotations are not
useful for anythign now.
2022-10-11 16:59:00 +02:00
Zbigniew Jędrzejewski-Szmek f69ae8585f tree-wide: define and use STRERROR_OR_EOF() 2022-10-11 16:58:21 +02:00
Zbigniew Jędrzejewski-Szmek a6e016af01 tree-wide: use STRERROR() 2022-10-11 16:39:09 +02:00
Zbigniew Jędrzejewski-Szmek b0fcb7c045 sd-bus: decrease indentation 2022-10-07 16:24:45 +02:00
Daan De Meyer e81710d3d0 journal: Store offsets to tail entry array objects in chain
Previously, we'd iterate an entry array from start to end every time
we added an entry offset to it. To speed up this operation, we cache
the last entry array in the chain and how many items it contains.
This allows the addition of an entry to the chain to be done in
constant time instead of linear time as we don't have to iterate
the entire chain anymore every time we add an entry.
2022-10-07 12:28:09 +02:00
Daan De Meyer 0e35afff1d journal: Introduce journal_file_data_payload()
journal_file_data_payload() retrieves the payload of a Data object,
optionally decompressing it and checking to see if matches a given
field. This function replaces all the decompression code in the sd-journal
codebase with a single function.

This commit should not introduce any changes in sd-journal behavior.
2022-10-07 12:28:05 +02:00
Daan De Meyer a9089a6604 journal: Use 32-bit entry item object offsets in compact mode
To do this, we move EntryItem out of journal-def.h and turn it into
a host only struct in native endian mode so we can still use it to
ship the necessary info around.

Aside from that, the changes are pretty simple, we introduce some
extra functions to access the right field depending on the mode and
convert all the other code to use those functions instead of
accessing the raw fields.

We also drop the unused entry item hash field in compact mode. We
already stopped doing anything with this field a while ago, now we
actually drop it from the format in compact mode.
2022-10-07 12:20:57 +02:00
Daan De Meyer 99daf3ce03 journal: Use 32-bit entry array offsets in compact mode
Before:

OBJECT TYPE      ENTRIES SIZE
Unused           0       0B
Data             3610336 595.7M
Field            5310    285.2K
Entry            3498326 1.2G
Data Hash Table  29	 103.1M
Field Hash Table 29      151.3K
Entry Array      605991  1011.6M
Tag              0	 0B
Total            7720021 2.9G

After:

OBJECT TYPE      ENTRIES SIZE
Unused           0	 0B
Data             3562667 591.0M
Field            3971    213.6K
Entry            3498566 1.2G
Data Hash Table  20	 71.1M
Field Hash Table 20	 104.3K
Entry Array	 582647  505.0M
Tag              0	 0B
Total            7647891 2.4G
2022-10-07 12:20:08 +02:00
Daan De Meyer d06727aec2 journal: Don't allocate objects above UINT32_MAX in compact mode
To allow storing offsets as 32-bit, we should never allocate objects
outside of the 32-bit range.
2022-10-07 12:20:08 +02:00
Daan De Meyer 61297656c7 journal: Enable compact mode
We also add an environment variable $SYSTEMD_JOURNAL_COMPACT that
can be used to disable compact mode if needed (similar to
$SYSTEMD_JOURNAL_KEYED_HASH).
2022-10-07 11:28:12 +02:00
Daan De Meyer 87413812c9 journal: Add compact mode
This adds a new flag in preparation for incompatible journal changes
which will be gated behind this flag. The max file size of journal
files in compact mode is limited to 4 GiB.
2022-10-07 11:26:28 +02:00
Marius Vollmer 4e2baf2f0a bus: Process authentication after write
Once everything has been written, a server bus might now process a
pending "BEGIN" and start the bus.
2022-10-04 17:52:50 +02:00
Lennart Poettering baf3fdec27 sd-event: add helper for exiting event loop on SIGTERM/SIGINT
In many (most?) of our event loops we want to exit once SIGTERM/SIGINT
is seen. Add a common helper for that, that does the right things in a
single call.
2022-09-30 14:18:43 +02:00
Lennart Poettering 897448bd37 sd-event: if signal nr has high bit set sd_event_add_signal() auto-block it via sigprocmask()
So far we expected callers to block the signals manually. Which is
usually a good idea, since they should do that before forking off
threads and similar. But let's add a mode where we automatically block
it for the caller, to simplify things.
2022-09-30 14:17:46 +02:00
Lennart Poettering dd51b0f952 Merge pull request #24805 from yuwata/sd-network
sd-network: several cleanups
2022-09-27 11:28:25 +02:00
Yu Watanabe b577d5569d Merge pull request #24812 from yuwata/udev-drop-netlink
udev: drop workaround for slow read of phys_port_name sysattr
2022-09-27 14:10:02 +09:00
Yu Watanabe e05dd7718d sd-network: make sd_network_link_get_dns() or friends return -ENODATA
To make them consistent with other functions.
2022-09-27 10:42:31 +09:00
Yu Watanabe 778e3da95e sd-network: drop fallback values
This drops spurious lines in `networkctl status` for unmanaged interfaces.
Before:
```
$ networkctl status --lines 0 lo
● 1: lo
                     Link File: n/a
                  Network File: n/a
                          Type: loopback
                         State: carrier (unmanaged)
                  Online state: unknown
                    HW Address: 00:00:00:00:00:00
                           MTU: 65536
                         QDisc: noqueue
  IPv6 Address Generation Mode: eui64
          Queue Length (Tx/Rx): 1/1
                       Address: 127.0.0.1
                                ::1
             Activation Policy: up
           Required For Online: yes
```
After:
```
$ networkctl status --lines 0 lo
● 1: lo
                     Link File: n/a
                  Network File: n/a
                         State: carrier (unmanaged)
                  Online state: unknown
                          Type: loopback
              Hardware Address: 00:00:00:00:00:00
                           MTU: 65536
                         QDisc: noqueue
  IPv6 Address Generation Mode: eui64
      Number of Queues (Tx/Rx): 1/1
                       Address: 127.0.0.1
                                ::1
```

That is, the lines for Activation Policy and Required For Online are
dropped.
2022-09-27 10:42:31 +09:00
Yu Watanabe c9d22489ca sd-network: introduce network_link_get_boolean() helper function 2022-09-27 10:42:31 +09:00
Yu Watanabe 27b13df45a sd-network: accept all space-like separators 2022-09-27 10:42:31 +09:00
Yu Watanabe ce2e75021c sd-network: propagate -ENOENT
On -ENOENT, it suggests that network-manager is not running, and
interfaces are not unmanaged. Such information may be useful for
callers.
2022-09-27 10:42:31 +09:00
Yu Watanabe e7c1b3f73a sd-network: rename function arguments for storing return value 2022-09-27 10:42:27 +09:00
Lennart Poettering d57e43ad28 Merge pull request #24757 from yuwata/sd-device-get-child-first
sd-device: introduce sd_device_get_child_first() and _next()
2022-09-26 19:03:15 +02:00
Yu Watanabe bb1bc2fcb0 sd-device: introduce device_get_sysattr_int() 2022-09-25 13:59:49 +09:00
Lennart Poettering 32e2767080 tree-wide: use the term "initrd" at most places we so far used "initramfs"
In most cases we refernced the concept as "initrd". Let's convert most
remaining uses of "initramfs" to "initrd" too, to stay internally
consistent.

This leaves "initramfs" only where it's relevant to explain historical
concepts or where "initramfs" is part of the API (i.e. in
/run/initramfs).

Follow-up for: b66a6e1a58
2022-09-23 15:10:53 +02:00
Yu Watanabe fadc8c48ac test-sd-device: add tests for sd_device_get_child_first() and _next() 2022-09-23 07:03:18 +09:00
Yu Watanabe ec9b4f2b92 sd-device: introduce sd_device_get_child_first() and _next()
These functions provide a high-level interface for enumerating
child devices.

Suggested at https://github.com/systemd/systemd/pull/24731#discussion_r973987065.
2022-09-23 07:03:15 +09:00
Yu Watanabe 10a2f90d02 sd-device: refuse to get a parent device by sd_device_new_child() 2022-09-23 06:53:09 +09:00
Yu Watanabe 83b94cf10e sd-device: use fd_reopen() at one more place
It provides recognizable error if /proc is not mounted.
2022-09-20 09:41:34 +02:00
Yu Watanabe 62ccd11d38 sd-device: use device_opendir() 2022-09-19 19:42:36 +09:00
Yu Watanabe db3049b6f0 sd-device: introduce device_opendir() 2022-09-19 19:42:02 +09:00
Yu Watanabe 4bc9d8165b sd-device: re-implement device_sysattrs_read_all() without recursion 2022-09-19 18:04:13 +09:00
Yu Watanabe 5b304c7052 sd-device: use faccessat()
No functional changes, just refactoring.
2022-09-19 18:04:13 +09:00
Yu Watanabe 65c0f14bc1 sd-device: use fstatat()
No functional changes, just refactoring.
2022-09-19 18:04:13 +09:00
Yu Watanabe bc5e8ebbfb sd-device: use path_hash_ops to store sysattrs
As the stored values are actually path. Just for safety.

This also drops unnecessary duplication of path.
2022-09-19 18:04:12 +09:00
Yu Watanabe 23d3dfc369 sd-device: refuse block device without subsystem
Previously, even if sd_device_get_subsystem() returns -ENOENT for block
device, we accepted that. This makes the check slightly stricter.
2022-09-18 15:35:56 +02:00
Yu Watanabe dd35a61caf sd-netlink: unexport sd-netlink
This effectively reverts 84e1001541.

The sd-netlink library has several issues, and we should not export it
without solving them. See issues #24258 and #24124.
2022-09-17 01:31:57 +09:00
Yu Watanabe 8dcc66cefc uid-range: tie up number and array of uid range entries
This renames UidRange -> UidRangeEntry, and reintroduces UidRange which
contains the array of UidRangeEntry and its size.
No fucntional changes, just refactoring.
2022-09-16 20:56:58 +09:00
Yu Watanabe f91c23f785 sd-device-monitor: do not trigger assertion when uid_map is not empty
Follow-up for c0aa23cf1e.
2022-09-16 13:05:51 +02:00
j00512545 365c2885f0 fix typo in log 2022-09-15 17:46:04 +02:00