mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-23 17:34:00 +03:00
Merge pull request #19590 from keszybz/comments-and-service-modernization
Comments and service modernization
This commit is contained in:
commit
7df7ba457c
@ -10,8 +10,8 @@ We welcome all contributions to systemd. If you notice a bug or a missing
|
||||
feature, please feel invited to fix it, and submit your work as a GitHub Pull
|
||||
Request (PR) at https://github.com/systemd/systemd/pull/new.
|
||||
|
||||
Please make sure to follow our [Coding Style](CODING_STYLE.md) when submitting patches.
|
||||
Also have a look at our [Contribution Guidelines](CONTRIBUTING.md).
|
||||
Please make sure to follow our [Coding Style](CODING_STYLE.md) when submitting
|
||||
patches. Also have a look at our [Contribution Guidelines](CONTRIBUTING.md).
|
||||
|
||||
When adding new functionality, tests should be added. For shared functionality
|
||||
(in `src/basic/` and `src/shared/`) unit tests should be sufficient. The general
|
||||
@ -22,8 +22,8 @@ test executable. For features at a higher level, tests in `src/test/` are very
|
||||
strongly recommended. If that is not possible, integration tests in `test/` are
|
||||
encouraged.
|
||||
|
||||
Please also have a look at our list of [code quality tools](CODE_QUALITY.md) we have setup for systemd,
|
||||
to ensure our codebase stays in good shape.
|
||||
Please also have a look at our list of [code quality tools](CODE_QUALITY.md) we
|
||||
have setup for systemd, to ensure our codebase stays in good shape.
|
||||
|
||||
Please always test your work before submitting a PR. For many of the components
|
||||
of systemd testing is straight-forward as you can simply compile systemd and
|
||||
@ -36,12 +36,12 @@ building clean OS images from an upstream distribution in combination with a
|
||||
fresh build of the project in the local working directory. To make use of this,
|
||||
please acquire `mkosi` from https://github.com/systemd/mkosi first, unless your
|
||||
distribution has packaged it already and you can get it from there. After the
|
||||
tool is installed, symlink the settings file for your distribution of choice from
|
||||
.mkosi/ to mkosi.default in the project root directory (note that the package
|
||||
manager for this distro needs to be installed on your host system). After doing
|
||||
that, it is sufficient to type `mkosi` in the systemd project directory to
|
||||
generate a disk image `image.raw` you can boot either in `systemd-nspawn` or in
|
||||
an UEFI-capable VM:
|
||||
tool is installed, symlink the settings file for your distribution of choice
|
||||
from .mkosi/ to mkosi.default in the project root directory (note that the
|
||||
package manager for this distro needs to be installed on your host system).
|
||||
After doing that, it is sufficient to type `mkosi` in the systemd project
|
||||
directory to generate a disk image `image.raw` you can boot either in
|
||||
`systemd-nspawn` or in an UEFI-capable VM:
|
||||
|
||||
```
|
||||
# mkosi boot
|
||||
|
@ -7,7 +7,6 @@
|
||||
#include <sys/mman.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/timerfd.h>
|
||||
#include <sys/timex.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@ -1245,21 +1244,6 @@ int parse_nsec(const char *t, nsec_t *nsec) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool ntp_synced(void) {
|
||||
struct timex txc = {};
|
||||
|
||||
if (adjtimex(&txc) < 0)
|
||||
return false;
|
||||
|
||||
/* Consider the system clock synchronized if the reported maximum error is smaller than the maximum
|
||||
* value (16 seconds). Ignore the STA_UNSYNC flag as it may have been set to prevent the kernel from
|
||||
* touching the RTC. */
|
||||
if (txc.maxerror >= 16000000)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int get_timezones(char ***ret) {
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
_cleanup_strv_free_ char **zones = NULL;
|
||||
|
@ -133,8 +133,6 @@ int parse_sec_def_infinity(const char *t, usec_t *usec);
|
||||
int parse_time(const char *t, usec_t *usec, usec_t default_unit);
|
||||
int parse_nsec(const char *t, nsec_t *nsec);
|
||||
|
||||
bool ntp_synced(void);
|
||||
|
||||
int get_timezones(char ***l);
|
||||
bool timezone_is_valid(const char *name, int log_level);
|
||||
|
||||
|
@ -1364,9 +1364,9 @@ static int service_allocate_exec_fd_event_source(
|
||||
static int service_allocate_exec_fd(
|
||||
Service *s,
|
||||
sd_event_source **ret_event_source,
|
||||
int* ret_exec_fd) {
|
||||
int *ret_exec_fd) {
|
||||
|
||||
_cleanup_close_pair_ int p[2] = { -1, -1 };
|
||||
_cleanup_close_pair_ int p[] = { -1, -1 };
|
||||
int r;
|
||||
|
||||
assert(s);
|
||||
@ -1380,7 +1380,7 @@ static int service_allocate_exec_fd(
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
p[0] = -1;
|
||||
TAKE_FD(p[0]);
|
||||
*ret_exec_fd = TAKE_FD(p[1]);
|
||||
|
||||
return 0;
|
||||
@ -1410,7 +1410,7 @@ static int service_spawn(
|
||||
ExecCommand *c,
|
||||
usec_t timeout,
|
||||
ExecFlags flags,
|
||||
pid_t *_pid) {
|
||||
pid_t *ret_pid) {
|
||||
|
||||
_cleanup_(exec_params_clear) ExecParameters exec_params = {
|
||||
.flags = flags,
|
||||
@ -1427,7 +1427,7 @@ static int service_spawn(
|
||||
|
||||
assert(s);
|
||||
assert(c);
|
||||
assert(_pid);
|
||||
assert(ret_pid);
|
||||
|
||||
r = unit_prepare_exec(UNIT(s)); /* This realizes the cgroup, among other things */
|
||||
if (r < 0)
|
||||
@ -1582,7 +1582,7 @@ static int service_spawn(
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
*_pid = pid;
|
||||
*ret_pid = pid;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -3455,16 +3455,14 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
|
||||
s->type == SERVICE_ONESHOT &&
|
||||
f == SERVICE_SUCCESS) {
|
||||
|
||||
/* There is another command to *
|
||||
* execute, so let's do that. */
|
||||
/* There is another command to execute, so let's do that. */
|
||||
|
||||
log_unit_debug(u, "Running next main command for state %s.", service_state_to_string(s->state));
|
||||
service_run_next_main(s);
|
||||
|
||||
} else {
|
||||
|
||||
/* The service exited, so the service is officially
|
||||
* gone. */
|
||||
/* The service exited, so the service is officially gone. */
|
||||
s->main_command = NULL;
|
||||
|
||||
switch (s->state) {
|
||||
@ -3481,8 +3479,7 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
|
||||
break;
|
||||
|
||||
case SERVICE_STOP:
|
||||
/* Need to wait until the operation is
|
||||
* done */
|
||||
/* Need to wait until the operation is done. */
|
||||
break;
|
||||
|
||||
case SERVICE_START:
|
||||
|
@ -3462,11 +3462,11 @@ static int source_dispatch(sd_event_source *s) {
|
||||
* invalidate the event. */
|
||||
saved_type = s->type;
|
||||
|
||||
/* Similar, store a reference to the event loop object, so that we can still access it after the
|
||||
/* Similarly, store a reference to the event loop object, so that we can still access it after the
|
||||
* callback might have invalidated/disconnected the event source. */
|
||||
saved_event = sd_event_ref(s->event);
|
||||
|
||||
/* Check if we hit the ratelimit for this event source, if so, let's disable it. */
|
||||
/* Check if we hit the ratelimit for this event source, and if so, let's disable it. */
|
||||
assert(!s->ratelimited);
|
||||
if (!ratelimit_below(&s->rate_limit)) {
|
||||
r = event_source_enter_ratelimited(s);
|
||||
@ -3485,8 +3485,7 @@ static int source_dispatch(sd_event_source *s) {
|
||||
if (s->type != SOURCE_POST) {
|
||||
sd_event_source *z;
|
||||
|
||||
/* If we execute a non-post source, let's mark all
|
||||
* post sources as pending */
|
||||
/* If we execute a non-post source, let's mark all post sources as pending. */
|
||||
|
||||
SET_FOREACH(z, s->event->post_sources) {
|
||||
if (event_source_is_offline(z))
|
||||
|
@ -261,7 +261,7 @@ static int test_bpf_cgroup_programs(Manager *m, const char *unit_name, const Tes
|
||||
cld_code = SERVICE(u)->exec_command[SERVICE_EXEC_START]->exec_status.code;
|
||||
if (cld_code != CLD_EXITED)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EBUSY),
|
||||
"ExecStart didn't exited, code='%s'", sigchld_code_to_string(cld_code));
|
||||
"Child didn't exit normally, code='%s'", sigchld_code_to_string(cld_code));
|
||||
|
||||
if (SERVICE(u)->state != SERVICE_DEAD)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EBUSY), "Service is not dead");
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/timex.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@ -556,6 +557,18 @@ static int unit_enable_or_disable(UnitStatusInfo *u, sd_bus *bus, sd_bus_error *
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool ntp_synced(void) {
|
||||
struct timex txc = {};
|
||||
|
||||
if (adjtimex(&txc) < 0)
|
||||
return false;
|
||||
|
||||
/* Consider the system clock synchronized if the reported maximum error is smaller than the maximum
|
||||
* value (16 seconds). Ignore the STA_UNSYNC flag as it may have been set to prevent the kernel from
|
||||
* touching the RTC. */
|
||||
return txc.maxerror < 16000000;
|
||||
}
|
||||
|
||||
static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_time, "t", now(CLOCK_REALTIME));
|
||||
static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_ntp_sync, "b", ntp_synced());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user