summaryrefslogtreecommitdiffstats
path: root/src/shared/bus-unit-util.h (follow)
Commit message (Collapse)AuthorAgeFilesLines
* sleep,home: always initialize UnitFreezer if usedMike Yuan2024-07-171-2/+0
| | | | | | | | | | | | | | | | Previously, unit_freezer_new_freeze() would only return UnitFreezer object if FreezeUnit() succeeds. This is not ideal though, as a failed bus call doesn't mean the action actually failed. E.g. a timeout might occur because pid1 is waiting for cgroup event from kernel, while the bus call timeout was exceeded (#33269). In such a case, ThawUnit() will never be called, resulting in frozen units remain that way after resuming from sleep. Therefore, let's get rid of unit_freezer_new_freeze(), and make sure as long as unit freezer is involved, we'll call ThawUnit() when we're done. This should make things a lot more robust.
* bus-unit-util: rework UnitFreezer, explicitly thaw unitMike Yuan2024-05-301-9/+6
| | | | | | | | | | | | | | | | | | | Currently, we don't explicitly call unit_freezer_thaw(), but rely on the destructor to thaw the frozen unit on return. This has several problems though, one of them being that we ignore the return value of ThawUnit(), which is something we really shouldn't do here, since such failure can easily leave the whole system in unusable state. Moreover, the logging is kinda messy, e.g. homed might log "Everything completed" yet immediately followed by "Failed to thaw unit". Instead, we should log consistently and at higher level, to make things more debuggable. Therefore, let's step away from the practice. Plus, make UnitFreezer object heap-allocated, to match with existing unit_freezer_new() and allow us to use NULL to denote that the freezer is disabled.
* tree-wide: Add allow_pidfd argument to bus_append_scope_pidref()Daan De Meyer2024-03-221-1/+1
|
* bus-unit-util: trivial follow-up for UnitFreezerMike Yuan2024-03-071-6/+4
| | | | | | | | Follow-up for 7483708131b474d92c9207c8c6340b450b58cb94 Make sure that function param names match between source and header. Also, place UnitFreezer params in front.
* bus-unit-util: Add utility to freeze/thaw unitsAdrian Vovk2024-03-051-0/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This utility lets us freeze units, and then automatically thaw them when via a _cleanup_ handler. For example, you can now write something like: ``` _cleanup_(unit_freezer_thaw) UnitFreezer freezer = UNIT_FREEZER_NULL; r = unit_freezer_freeze("myunit.service", &freezer); if (r < 0) return r; // Freeze is thawed once this scope ends ``` Aside from the basic _freeze and _thaw methods, there's also _cancel and _restore. Cancel destroys the UnitFreezer without thawing the unit. Restore creates a UnitFreezer without freezing it. The idea of these two methods is that it allows the freeze/thaw to be separated from each other (i.e. done in response to two separate DBus method calls). For example: ``` _cleanup_(unit_freezer_thaw) UnitFreezer freezer = UNIT_FREEZER_NULL; r = unit_freezer_freeze("myunit.service", &freezer); if (r < 0) return r; // Freeze is thawed once this scope ends r = do_something() if (r < 0) return r; // Freeze is thawed unit_freezer_cancel(&freezer); // Thaw is canceled. ``` Then in another scope: ``` // Bring back a UnitFreezer object for the already-frozen service _cleanup_(unit_freezer_thaw) UnitFreezer freezer = UNIT_FREEZER_NULL; r = unit_freezer_restore("myunit.service", &freezer); if (r < 0) return r; // Freeze is thawed once this scope ends ```
* tree-wide: prefer sending pifds over pids when creating scope unitsLennart Poettering2023-10-051-0/+3
|
* bus-unit-util: add common code for reloading PID 1Lennart Poettering2023-07-101-0/+2
| | | | | | We have this very similar code in various places, and it#s not entirely obvious (since we want a prolonged timeout for the reload), hence unify this at one place.
* tree-wide: drop unneeded output paramsDavid Tardon2023-04-121-1/+1
| | | | | | Neither of the callers of bus_deserialize_and_dump_unit_file_changes() touches the changes array, so let's simplify things and keep it internal to the function.
* shared/install: rename UnitFileChange to InstallChangeZbigniew Jędrzejewski-Szmek2022-10-131-1/+1
| | | | | It's shorter and more generic. The struct can contain info about changes to unit files, but also symlinks and errors.
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|
* systemctl: move compare_unit_info() to bus-unit-util.[ch]Lennart Poettering2020-10-071-0/+2
| | | | | | It's an auxiliary function to the UnitInfo structures, and very generic. Let's hence move it over to the other code operating with UnitInfo, even if it's not used by code outside of systemctl (yet).
* bus-unit-util: split out code that shows a unit's process treeLennart Poettering2019-03-131-4/+2
| | | | | The code is complex enough to deserve its own .c file. Let's split this out.
* shared: split out code to wait for jobs to complet into its own source fileLennart Poettering2019-03-131-10/+0
| | | | | | | It's complex enough and quite a few functions. Let's hence split this out. No code change, just some rearranging of source files.
* tree-wide: remove Lennart's copyright linesLennart Poettering2018-06-141-4/+0
| | | | | | | | | | | These lines are generally out-of-date, incomplete and unnecessary. With SPDX and git repository much more accurate and fine grained information about licensing and authorship is available, hence let's drop the per-file copyright notice. Of course, removing copyright lines of others is problematic, hence this commit only removes my own lines and leaves all others untouched. It might be nicer if sooner or later those could go away too, making git the only and accurate source of authorship information.
* tree-wide: drop 'This file is part of systemd' blurbLennart Poettering2018-06-141-2/+0
| | | | | | | | | | | | | | | | This part of the copyright blurb stems from the GPL use recommendations: https://www.gnu.org/licenses/gpl-howto.en.html The concept appears to originate in times where version control was per file, instead of per tree, and was a way to glue the files together. Ultimately, we nowadays don't live in that world anymore, and this information is entirely useless anyway, as people are very welcome to copy these files into any projects they like, and they shouldn't have to change bits that are part of our copyright header for that. hence, let's just get rid of this old cruft, and shorten our codebase a bit.
* tree-wide: be more careful with the type of array sizesLennart Poettering2018-04-271-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously we were a bit sloppy with the index and size types of arrays, we'd regularly use unsigned. While I don't think this ever resulted in real issues I think we should be more careful there and follow a stricter regime: unless there's a strong reason not to use size_t for array sizes and indexes, size_t it should be. Any allocations we do ultimately will use size_t anyway, and converting forth and back between unsigned and size_t will always be a source of problems. Note that on 32bit machines "unsigned" and "size_t" are equivalent, and on 64bit machines our arrays shouldn't grow that large anyway, and if they do we have a problem, however that kind of overly large allocation we have protections for usually, but for overflows we do not have that so much, hence let's add it. So yeah, it's a story of the current code being already "good enough", but I think some extra type hygiene is better. This patch tries to be comprehensive, but it probably isn't and I missed a few cases. But I guess we can cover that later as we notice it. Among smaller fixes, this changes: 1. strv_length()' return type becomes size_t 2. the unit file changes array size becomes size_t 3. DNS answer and query array sizes become size_t Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=76745
* Merge pull request #8700 from keszybz/hibernationLennart Poettering2018-04-111-0/+2
|\ | | | | Various improvements related to hibernation
| * Move utility function to query unit state from systemctl to shared/Zbigniew Jędrzejewski-Szmek2018-04-101-0/+2
| |
* | tree-wide: drop license boilerplateZbigniew Jędrzejewski-Szmek2018-04-061-13/+0
|/ | | | | | | | | | Files which are installed as-is (any .service and other unit files, .conf files, .policy files, etc), are left as is. My assumption is that SPDX identifiers are not yet that well known, so it's better to retain the extended header to avoid any doubt. I also kept any copyright lines. We can probably remove them, but it'd nice to obtain explicit acks from all involved authors before doing that.
* bus-unit-util: add socket unit related optionsYu Watanabe2017-12-231-5/+5
| | | | Also, split bus_append_unit_property_assignment().
* Add SPDX license identifiers to source files under the LGPLZbigniew Jędrzejewski-Szmek2017-11-191-0/+1
| | | | | This follows what the kernel is doing, c.f. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
* bus-util: unify loop around bus_append_unit_property_assignment()Lennart Poettering2016-08-181-0/+1
| | | | | This is done exactly the same way a couple of times at various places, let's unify this into one version.
* shared: move unit-specific code from bus-util.h to bus-unit-util.hLennart Poettering2016-04-221-0/+30
| | | | | | | Previously we'd have generally useful sd-bus utilities in bust-util.h, intermixed with code that is specifically for writing clients for PID 1, wrapping job and unit handling. Let's split the latter out and move it into bus-unit-util.c, to make the sources a bit short and easier to grok.
* core,systemctl: add bus API to retrieve processes of a unitLennart Poettering2016-04-221-0/+27
This adds a new GetProcesses() bus call to the Unit object which returns an array consisting of all PIDs, their process names, as well as their full cgroup paths. This is then used by "systemctl status" to show the per-unit process tree. This has the benefit that the client-side no longer needs to access the cgroupfs directly to show the process tree of a unit. Instead, it now uses this new API, which means it also works if -H or -M are used correctly, as the information from the specific host is used, and not the one from the local system. Fixes: #2945