2013-12-02 23:30:19 +01:00
|
|
|
/***
|
|
|
|
This file is part of systemd.
|
|
|
|
|
|
|
|
Copyright 2013 Lennart Poettering
|
|
|
|
|
|
|
|
systemd is free software; you can redistribute it and/or modify it
|
|
|
|
under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
systemd is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
***/
|
|
|
|
|
2014-11-25 19:32:48 +01:00
|
|
|
#include <sys/mman.h>
|
|
|
|
|
2015-10-27 03:01:06 +01:00
|
|
|
#include "alloc-util.h"
|
2013-12-02 23:30:19 +01:00
|
|
|
#include "bus-internal.h"
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "bus-kernel.h"
|
|
|
|
#include "bus-policy.h"
|
2013-12-02 23:30:19 +01:00
|
|
|
#include "bus-util.h"
|
2015-10-25 13:14:12 +01:00
|
|
|
#include "busname.h"
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "dbus-busname.h"
|
2015-10-25 13:14:12 +01:00
|
|
|
#include "fd-util.h"
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "formats-util.h"
|
2014-12-23 18:36:04 +01:00
|
|
|
#include "kdbus.h"
|
2015-10-26 16:18:16 +01:00
|
|
|
#include "parse-util.h"
|
2015-10-27 14:24:58 +01:00
|
|
|
#include "process-util.h"
|
2015-05-29 20:14:11 +02:00
|
|
|
#include "service.h"
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "signal-util.h"
|
|
|
|
#include "special.h"
|
2015-10-26 22:31:05 +01:00
|
|
|
#include "string-table.h"
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "string-util.h"
|
2013-12-02 23:30:19 +01:00
|
|
|
|
|
|
|
static const UnitActiveState state_translation_table[_BUSNAME_STATE_MAX] = {
|
|
|
|
[BUSNAME_DEAD] = UNIT_INACTIVE,
|
2014-06-05 12:24:03 +02:00
|
|
|
[BUSNAME_MAKING] = UNIT_ACTIVATING,
|
2014-03-17 11:41:21 +01:00
|
|
|
[BUSNAME_REGISTERED] = UNIT_ACTIVE,
|
2013-12-02 23:30:19 +01:00
|
|
|
[BUSNAME_LISTENING] = UNIT_ACTIVE,
|
|
|
|
[BUSNAME_RUNNING] = UNIT_ACTIVE,
|
2014-06-05 12:24:03 +02:00
|
|
|
[BUSNAME_SIGTERM] = UNIT_DEACTIVATING,
|
|
|
|
[BUSNAME_SIGKILL] = UNIT_DEACTIVATING,
|
2013-12-02 23:30:19 +01:00
|
|
|
[BUSNAME_FAILED] = UNIT_FAILED
|
|
|
|
};
|
|
|
|
|
|
|
|
static int busname_dispatch_io(sd_event_source *source, int fd, uint32_t revents, void *userdata);
|
2014-06-05 12:24:03 +02:00
|
|
|
static int busname_dispatch_timer(sd_event_source *source, usec_t usec, void *userdata);
|
2013-12-02 23:30:19 +01:00
|
|
|
|
|
|
|
static void busname_init(Unit *u) {
|
|
|
|
BusName *n = BUSNAME(u);
|
|
|
|
|
|
|
|
assert(u);
|
|
|
|
assert(u->load_state == UNIT_STUB);
|
|
|
|
|
|
|
|
n->starter_fd = -1;
|
2014-03-18 20:54:32 +01:00
|
|
|
n->accept_fd = true;
|
2014-03-19 03:09:51 +01:00
|
|
|
n->activating = true;
|
2014-06-05 12:24:03 +02:00
|
|
|
|
|
|
|
n->timeout_usec = u->manager->default_timeout_start_usec;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void busname_unwatch_control_pid(BusName *n) {
|
|
|
|
assert(n);
|
|
|
|
|
|
|
|
if (n->control_pid <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
unit_unwatch_pid(UNIT(n), n->control_pid);
|
|
|
|
n->control_pid = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void busname_free_policy(BusName *n) {
|
|
|
|
BusNamePolicy *p;
|
|
|
|
|
|
|
|
assert(n);
|
|
|
|
|
|
|
|
while ((p = n->policy)) {
|
|
|
|
LIST_REMOVE(policy, n->policy, p);
|
|
|
|
|
|
|
|
free(p->name);
|
|
|
|
free(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void busname_close_fd(BusName *n) {
|
|
|
|
assert(n);
|
|
|
|
|
|
|
|
n->starter_event_source = sd_event_source_unref(n->starter_event_source);
|
|
|
|
n->starter_fd = safe_close(n->starter_fd);
|
2013-12-02 23:30:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void busname_done(Unit *u) {
|
|
|
|
BusName *n = BUSNAME(u);
|
|
|
|
|
2014-06-05 12:24:03 +02:00
|
|
|
assert(n);
|
2013-12-02 23:30:19 +01:00
|
|
|
|
2015-09-08 18:43:11 +02:00
|
|
|
n->name = mfree(n->name);
|
2013-12-02 23:30:19 +01:00
|
|
|
|
2014-06-05 12:24:03 +02:00
|
|
|
busname_free_policy(n);
|
|
|
|
busname_unwatch_control_pid(n);
|
|
|
|
busname_close_fd(n);
|
|
|
|
|
2013-12-02 23:30:19 +01:00
|
|
|
unit_ref_unset(&n->service);
|
|
|
|
|
2014-06-05 12:24:03 +02:00
|
|
|
n->timer_event_source = sd_event_source_unref(n->timer_event_source);
|
|
|
|
}
|
|
|
|
|
core: rework unit timeout handling, and add new setting RuntimeMaxSec=
This clean-ups timeout handling in PID 1. Specifically, instead of storing 0 in internal timeout variables as
indication for a disabled timeout, use USEC_INFINITY which is in-line with how we do this in the rest of our code
(following the logic that 0 means "no", and USEC_INFINITY means "never").
This also replace all usec_t additions with invocations to usec_add(), so that USEC_INFINITY is properly propagated,
and sd-event considers it has indication for turning off the event source.
This also alters the deserialization of the units to restart timeouts from the time they were originally started from.
Before this patch timeouts would be restarted beginning with the time of the deserialization, which could lead to
artificially prolonged timeouts if a daemon reload took place.
Finally, a new RuntimeMaxSec= setting is introduced for service units, that specifies a maximum runtime after which a
specific service is forcibly terminated. This is useful to put time limits on time-intensive processing jobs.
This also simplifies the various xyz_spawn() calls of the various types in that explicit distruction of the timers is
removed, as that is done anyway by the state change handlers, and a state change is always done when the xyz_spawn()
calls fail.
Fixes: #2249
2016-02-01 21:48:10 +01:00
|
|
|
static int busname_arm_timer(BusName *n, usec_t usec) {
|
2014-06-05 12:24:03 +02:00
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(n);
|
|
|
|
|
|
|
|
if (n->timer_event_source) {
|
core: rework unit timeout handling, and add new setting RuntimeMaxSec=
This clean-ups timeout handling in PID 1. Specifically, instead of storing 0 in internal timeout variables as
indication for a disabled timeout, use USEC_INFINITY which is in-line with how we do this in the rest of our code
(following the logic that 0 means "no", and USEC_INFINITY means "never").
This also replace all usec_t additions with invocations to usec_add(), so that USEC_INFINITY is properly propagated,
and sd-event considers it has indication for turning off the event source.
This also alters the deserialization of the units to restart timeouts from the time they were originally started from.
Before this patch timeouts would be restarted beginning with the time of the deserialization, which could lead to
artificially prolonged timeouts if a daemon reload took place.
Finally, a new RuntimeMaxSec= setting is introduced for service units, that specifies a maximum runtime after which a
specific service is forcibly terminated. This is useful to put time limits on time-intensive processing jobs.
This also simplifies the various xyz_spawn() calls of the various types in that explicit distruction of the timers is
removed, as that is done anyway by the state change handlers, and a state change is always done when the xyz_spawn()
calls fail.
Fixes: #2249
2016-02-01 21:48:10 +01:00
|
|
|
r = sd_event_source_set_time(n->timer_event_source, usec);
|
2014-06-05 12:24:03 +02:00
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
return sd_event_source_set_enabled(n->timer_event_source, SD_EVENT_ONESHOT);
|
|
|
|
}
|
|
|
|
|
core: rework unit timeout handling, and add new setting RuntimeMaxSec=
This clean-ups timeout handling in PID 1. Specifically, instead of storing 0 in internal timeout variables as
indication for a disabled timeout, use USEC_INFINITY which is in-line with how we do this in the rest of our code
(following the logic that 0 means "no", and USEC_INFINITY means "never").
This also replace all usec_t additions with invocations to usec_add(), so that USEC_INFINITY is properly propagated,
and sd-event considers it has indication for turning off the event source.
This also alters the deserialization of the units to restart timeouts from the time they were originally started from.
Before this patch timeouts would be restarted beginning with the time of the deserialization, which could lead to
artificially prolonged timeouts if a daemon reload took place.
Finally, a new RuntimeMaxSec= setting is introduced for service units, that specifies a maximum runtime after which a
specific service is forcibly terminated. This is useful to put time limits on time-intensive processing jobs.
This also simplifies the various xyz_spawn() calls of the various types in that explicit distruction of the timers is
removed, as that is done anyway by the state change handlers, and a state change is always done when the xyz_spawn()
calls fail.
Fixes: #2249
2016-02-01 21:48:10 +01:00
|
|
|
if (usec == USEC_INFINITY)
|
|
|
|
return 0;
|
|
|
|
|
2015-06-08 20:53:16 +02:00
|
|
|
r = sd_event_add_time(
|
2014-06-05 12:24:03 +02:00
|
|
|
UNIT(n)->manager->event,
|
|
|
|
&n->timer_event_source,
|
|
|
|
CLOCK_MONOTONIC,
|
core: rework unit timeout handling, and add new setting RuntimeMaxSec=
This clean-ups timeout handling in PID 1. Specifically, instead of storing 0 in internal timeout variables as
indication for a disabled timeout, use USEC_INFINITY which is in-line with how we do this in the rest of our code
(following the logic that 0 means "no", and USEC_INFINITY means "never").
This also replace all usec_t additions with invocations to usec_add(), so that USEC_INFINITY is properly propagated,
and sd-event considers it has indication for turning off the event source.
This also alters the deserialization of the units to restart timeouts from the time they were originally started from.
Before this patch timeouts would be restarted beginning with the time of the deserialization, which could lead to
artificially prolonged timeouts if a daemon reload took place.
Finally, a new RuntimeMaxSec= setting is introduced for service units, that specifies a maximum runtime after which a
specific service is forcibly terminated. This is useful to put time limits on time-intensive processing jobs.
This also simplifies the various xyz_spawn() calls of the various types in that explicit distruction of the timers is
removed, as that is done anyway by the state change handlers, and a state change is always done when the xyz_spawn()
calls fail.
Fixes: #2249
2016-02-01 21:48:10 +01:00
|
|
|
usec, 0,
|
2014-06-05 12:24:03 +02:00
|
|
|
busname_dispatch_timer, n);
|
2015-04-29 16:05:32 +02:00
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
(void) sd_event_source_set_description(n->timer_event_source, "busname-timer");
|
|
|
|
|
|
|
|
return 0;
|
2013-12-02 23:30:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int busname_add_default_default_dependencies(BusName *n) {
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(n);
|
|
|
|
|
|
|
|
r = unit_add_dependency_by_name(UNIT(n), UNIT_BEFORE, SPECIAL_BUSNAMES_TARGET, NULL, true);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
2016-02-24 21:24:23 +01:00
|
|
|
if (MANAGER_IS_SYSTEM(UNIT(n)->manager)) {
|
2013-12-02 23:30:19 +01:00
|
|
|
r = unit_add_two_dependencies_by_name(UNIT(n), UNIT_AFTER, UNIT_REQUIRES, SPECIAL_SYSINIT_TARGET, NULL, true);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
return unit_add_two_dependencies_by_name(UNIT(n), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, NULL, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int busname_add_extras(BusName *n) {
|
|
|
|
Unit *u = UNIT(n);
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(n);
|
|
|
|
|
|
|
|
if (!n->name) {
|
2015-04-30 20:21:00 +02:00
|
|
|
r = unit_name_to_prefix(u->id, &n->name);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2013-12-02 23:30:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!u->description) {
|
|
|
|
r = unit_set_description(u, n->name);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2014-03-17 11:41:21 +01:00
|
|
|
if (n->activating) {
|
|
|
|
if (!UNIT_DEREF(n->service)) {
|
|
|
|
Unit *x;
|
2013-12-02 23:30:19 +01:00
|
|
|
|
2014-03-17 11:41:21 +01:00
|
|
|
r = unit_load_related_unit(u, ".service", &x);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
unit_ref_set(&n->service, x);
|
|
|
|
}
|
|
|
|
|
|
|
|
r = unit_add_two_dependencies(u, UNIT_BEFORE, UNIT_TRIGGERS, UNIT_DEREF(n->service), true);
|
2013-12-02 23:30:19 +01:00
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (u->default_dependencies) {
|
|
|
|
r = busname_add_default_default_dependencies(n);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int busname_verify(BusName *n) {
|
|
|
|
char *e;
|
|
|
|
|
|
|
|
assert(n);
|
|
|
|
|
|
|
|
if (UNIT(n)->load_state != UNIT_LOADED)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!service_name_is_valid(n->name)) {
|
core,network: major per-object logging rework
This changes log_unit_info() (and friends) to take a real Unit* object
insted of just a unit name as parameter. The call will now prefix all
logged messages with the unit name, thus allowing the unit name to be
dropped from the various passed romat strings, simplifying invocations
drastically, and unifying log output across messages. Also, UNIT= vs.
USER_UNIT= is now derived from the Manager object attached to the Unit
object, instead of getpid(). This has the benefit of correcting the
field for --test runs.
Also contains a couple of other logging improvements:
- Drops a couple of strerror() invocations in favour of using %m.
- Not only .mount units now warn if a symlinks exist for the mount
point already, .automount units do that too, now.
- A few invocations of log_struct() that didn't actually pass any
additional structured data have been replaced by simpler invocations
of log_unit_info() and friends.
- For structured data a new LOG_UNIT_MESSAGE() macro has been added,
that works like LOG_MESSAGE() but prefixes the message with the unit
name. Similar, there's now LOG_LINK_MESSAGE() and
LOG_NETDEV_MESSAGE().
- For structured data new LOG_UNIT_ID(), LOG_LINK_INTERFACE(),
LOG_NETDEV_INTERFACE() macros have been added that generate the
necessary per object fields. The old log_unit_struct() call has been
removed in favour of these new macros used in raw log_struct()
invocations. In addition to removing one more function call this
allows generated structured log messages that contain two object
fields, as necessary for example for network interfaces that are
joined into another network interface, and whose messages shall be
indexed by both.
- The LOG_ERRNO() macro has been removed, in favour of
log_struct_errno(). The latter has the benefit of ensuring that %m in
format strings is properly resolved to the specified error number.
- A number of logging messages have been converted to use
log_unit_info() instead of log_info()
- The client code in sysv-generator no longer #includes core code from
src/core/.
- log_unit_full_errno() has been removed, log_unit_full() instead takes
an errno now, too.
- log_unit_info(), log_link_info(), log_netdev_info() and friends, now
avoid double evaluation of their parameters
2015-05-11 20:38:21 +02:00
|
|
|
log_unit_error(UNIT(n), "Name= setting is not a valid service name Refusing.");
|
2013-12-02 23:30:19 +01:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2015-02-03 02:05:59 +01:00
|
|
|
e = strjoina(n->name, ".busname");
|
2013-12-02 23:30:19 +01:00
|
|
|
if (!unit_has_name(UNIT(n), e)) {
|
core,network: major per-object logging rework
This changes log_unit_info() (and friends) to take a real Unit* object
insted of just a unit name as parameter. The call will now prefix all
logged messages with the unit name, thus allowing the unit name to be
dropped from the various passed romat strings, simplifying invocations
drastically, and unifying log output across messages. Also, UNIT= vs.
USER_UNIT= is now derived from the Manager object attached to the Unit
object, instead of getpid(). This has the benefit of correcting the
field for --test runs.
Also contains a couple of other logging improvements:
- Drops a couple of strerror() invocations in favour of using %m.
- Not only .mount units now warn if a symlinks exist for the mount
point already, .automount units do that too, now.
- A few invocations of log_struct() that didn't actually pass any
additional structured data have been replaced by simpler invocations
of log_unit_info() and friends.
- For structured data a new LOG_UNIT_MESSAGE() macro has been added,
that works like LOG_MESSAGE() but prefixes the message with the unit
name. Similar, there's now LOG_LINK_MESSAGE() and
LOG_NETDEV_MESSAGE().
- For structured data new LOG_UNIT_ID(), LOG_LINK_INTERFACE(),
LOG_NETDEV_INTERFACE() macros have been added that generate the
necessary per object fields. The old log_unit_struct() call has been
removed in favour of these new macros used in raw log_struct()
invocations. In addition to removing one more function call this
allows generated structured log messages that contain two object
fields, as necessary for example for network interfaces that are
joined into another network interface, and whose messages shall be
indexed by both.
- The LOG_ERRNO() macro has been removed, in favour of
log_struct_errno(). The latter has the benefit of ensuring that %m in
format strings is properly resolved to the specified error number.
- A number of logging messages have been converted to use
log_unit_info() instead of log_info()
- The client code in sysv-generator no longer #includes core code from
src/core/.
- log_unit_full_errno() has been removed, log_unit_full() instead takes
an errno now, too.
- log_unit_info(), log_link_info(), log_netdev_info() and friends, now
avoid double evaluation of their parameters
2015-05-11 20:38:21 +02:00
|
|
|
log_unit_error(UNIT(n), "Name= setting doesn't match unit name. Refusing.");
|
2013-12-02 23:30:19 +01:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int busname_load(Unit *u) {
|
|
|
|
BusName *n = BUSNAME(u);
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(u);
|
|
|
|
assert(u->load_state == UNIT_STUB);
|
|
|
|
|
|
|
|
r = unit_load_fragment_and_dropin(u);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
if (u->load_state == UNIT_LOADED) {
|
|
|
|
/* This is a new unit? Then let's add in some extras */
|
|
|
|
r = busname_add_extras(n);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
return busname_verify(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void busname_dump(Unit *u, FILE *f, const char *prefix) {
|
|
|
|
BusName *n = BUSNAME(u);
|
|
|
|
|
|
|
|
assert(n);
|
|
|
|
assert(f);
|
|
|
|
|
|
|
|
fprintf(f,
|
|
|
|
"%sBus Name State: %s\n"
|
|
|
|
"%sResult: %s\n"
|
2014-03-18 20:54:32 +01:00
|
|
|
"%sName: %s\n"
|
2014-03-17 11:41:21 +01:00
|
|
|
"%sActivating: %s\n"
|
2014-03-18 20:54:32 +01:00
|
|
|
"%sAccept FD: %s\n",
|
2013-12-02 23:30:19 +01:00
|
|
|
prefix, busname_state_to_string(n->state),
|
|
|
|
prefix, busname_result_to_string(n->result),
|
2014-03-18 20:54:32 +01:00
|
|
|
prefix, n->name,
|
2014-03-17 11:41:21 +01:00
|
|
|
prefix, yes_no(n->activating),
|
2014-03-18 20:54:32 +01:00
|
|
|
prefix, yes_no(n->accept_fd));
|
2014-06-05 12:24:03 +02:00
|
|
|
|
|
|
|
if (n->control_pid > 0)
|
|
|
|
fprintf(f,
|
|
|
|
"%sControl PID: "PID_FMT"\n",
|
|
|
|
prefix, n->control_pid);
|
2013-12-02 23:30:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void busname_unwatch_fd(BusName *n) {
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(n);
|
|
|
|
|
2014-06-05 12:24:03 +02:00
|
|
|
if (!n->starter_event_source)
|
2013-12-02 23:30:19 +01:00
|
|
|
return;
|
|
|
|
|
2014-06-05 12:24:03 +02:00
|
|
|
r = sd_event_source_set_enabled(n->starter_event_source, SD_EVENT_OFF);
|
|
|
|
if (r < 0)
|
core,network: major per-object logging rework
This changes log_unit_info() (and friends) to take a real Unit* object
insted of just a unit name as parameter. The call will now prefix all
logged messages with the unit name, thus allowing the unit name to be
dropped from the various passed romat strings, simplifying invocations
drastically, and unifying log output across messages. Also, UNIT= vs.
USER_UNIT= is now derived from the Manager object attached to the Unit
object, instead of getpid(). This has the benefit of correcting the
field for --test runs.
Also contains a couple of other logging improvements:
- Drops a couple of strerror() invocations in favour of using %m.
- Not only .mount units now warn if a symlinks exist for the mount
point already, .automount units do that too, now.
- A few invocations of log_struct() that didn't actually pass any
additional structured data have been replaced by simpler invocations
of log_unit_info() and friends.
- For structured data a new LOG_UNIT_MESSAGE() macro has been added,
that works like LOG_MESSAGE() but prefixes the message with the unit
name. Similar, there's now LOG_LINK_MESSAGE() and
LOG_NETDEV_MESSAGE().
- For structured data new LOG_UNIT_ID(), LOG_LINK_INTERFACE(),
LOG_NETDEV_INTERFACE() macros have been added that generate the
necessary per object fields. The old log_unit_struct() call has been
removed in favour of these new macros used in raw log_struct()
invocations. In addition to removing one more function call this
allows generated structured log messages that contain two object
fields, as necessary for example for network interfaces that are
joined into another network interface, and whose messages shall be
indexed by both.
- The LOG_ERRNO() macro has been removed, in favour of
log_struct_errno(). The latter has the benefit of ensuring that %m in
format strings is properly resolved to the specified error number.
- A number of logging messages have been converted to use
log_unit_info() instead of log_info()
- The client code in sysv-generator no longer #includes core code from
src/core/.
- log_unit_full_errno() has been removed, log_unit_full() instead takes
an errno now, too.
- log_unit_info(), log_link_info(), log_netdev_info() and friends, now
avoid double evaluation of their parameters
2015-05-11 20:38:21 +02:00
|
|
|
log_unit_debug_errno(UNIT(n), r, "Failed to disable event source: %m");
|
2013-12-02 23:30:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int busname_watch_fd(BusName *n) {
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(n);
|
|
|
|
|
|
|
|
if (n->starter_fd < 0)
|
|
|
|
return 0;
|
|
|
|
|
2015-05-13 18:30:14 +02:00
|
|
|
if (n->starter_event_source) {
|
2014-06-05 12:24:03 +02:00
|
|
|
r = sd_event_source_set_enabled(n->starter_event_source, SD_EVENT_ON);
|
2015-05-13 18:30:14 +02:00
|
|
|
if (r < 0)
|
|
|
|
goto fail;
|
|
|
|
} else {
|
2014-06-05 12:24:03 +02:00
|
|
|
r = sd_event_add_io(UNIT(n)->manager->event, &n->starter_event_source, n->starter_fd, EPOLLIN, busname_dispatch_io, n);
|
2015-05-13 18:30:14 +02:00
|
|
|
if (r < 0)
|
|
|
|
goto fail;
|
2015-04-29 20:29:18 +02:00
|
|
|
|
2015-05-13 18:30:14 +02:00
|
|
|
(void) sd_event_source_set_description(n->starter_event_source, "busname-starter");
|
2013-12-02 23:30:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2015-05-13 18:30:14 +02:00
|
|
|
|
|
|
|
fail:
|
|
|
|
log_unit_warning_errno(UNIT(n), r, "Failed to watch starter fd: %m");
|
|
|
|
busname_unwatch_fd(n);
|
|
|
|
return r;
|
2013-12-02 23:30:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int busname_open_fd(BusName *n) {
|
2014-07-26 20:59:52 +02:00
|
|
|
_cleanup_free_ char *path = NULL;
|
|
|
|
const char *mode;
|
|
|
|
|
2013-12-02 23:30:19 +01:00
|
|
|
assert(n);
|
|
|
|
|
|
|
|
if (n->starter_fd >= 0)
|
|
|
|
return 0;
|
|
|
|
|
2016-02-24 21:24:23 +01:00
|
|
|
mode = MANAGER_IS_SYSTEM(UNIT(n)->manager) ? "system" : "user";
|
2014-07-26 20:59:52 +02:00
|
|
|
n->starter_fd = bus_kernel_open_bus_fd(mode, &path);
|
2014-11-28 18:23:20 +01:00
|
|
|
if (n->starter_fd < 0)
|
core,network: major per-object logging rework
This changes log_unit_info() (and friends) to take a real Unit* object
insted of just a unit name as parameter. The call will now prefix all
logged messages with the unit name, thus allowing the unit name to be
dropped from the various passed romat strings, simplifying invocations
drastically, and unifying log output across messages. Also, UNIT= vs.
USER_UNIT= is now derived from the Manager object attached to the Unit
object, instead of getpid(). This has the benefit of correcting the
field for --test runs.
Also contains a couple of other logging improvements:
- Drops a couple of strerror() invocations in favour of using %m.
- Not only .mount units now warn if a symlinks exist for the mount
point already, .automount units do that too, now.
- A few invocations of log_struct() that didn't actually pass any
additional structured data have been replaced by simpler invocations
of log_unit_info() and friends.
- For structured data a new LOG_UNIT_MESSAGE() macro has been added,
that works like LOG_MESSAGE() but prefixes the message with the unit
name. Similar, there's now LOG_LINK_MESSAGE() and
LOG_NETDEV_MESSAGE().
- For structured data new LOG_UNIT_ID(), LOG_LINK_INTERFACE(),
LOG_NETDEV_INTERFACE() macros have been added that generate the
necessary per object fields. The old log_unit_struct() call has been
removed in favour of these new macros used in raw log_struct()
invocations. In addition to removing one more function call this
allows generated structured log messages that contain two object
fields, as necessary for example for network interfaces that are
joined into another network interface, and whose messages shall be
indexed by both.
- The LOG_ERRNO() macro has been removed, in favour of
log_struct_errno(). The latter has the benefit of ensuring that %m in
format strings is properly resolved to the specified error number.
- A number of logging messages have been converted to use
log_unit_info() instead of log_info()
- The client code in sysv-generator no longer #includes core code from
src/core/.
- log_unit_full_errno() has been removed, log_unit_full() instead takes
an errno now, too.
- log_unit_info(), log_link_info(), log_netdev_info() and friends, now
avoid double evaluation of their parameters
2015-05-11 20:38:21 +02:00
|
|
|
return log_unit_warning_errno(UNIT(n), n->starter_fd, "Failed to open %s: %m", path ?: "kdbus");
|
2013-12-02 23:30:19 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void busname_set_state(BusName *n, BusNameState state) {
|
|
|
|
BusNameState old_state;
|
|
|
|
assert(n);
|
|
|
|
|
|
|
|
old_state = n->state;
|
|
|
|
n->state = state;
|
|
|
|
|
2014-06-05 12:24:03 +02:00
|
|
|
if (!IN_SET(state, BUSNAME_MAKING, BUSNAME_SIGTERM, BUSNAME_SIGKILL)) {
|
|
|
|
n->timer_event_source = sd_event_source_unref(n->timer_event_source);
|
|
|
|
busname_unwatch_control_pid(n);
|
|
|
|
}
|
|
|
|
|
2013-12-02 23:30:19 +01:00
|
|
|
if (state != BUSNAME_LISTENING)
|
|
|
|
busname_unwatch_fd(n);
|
|
|
|
|
2014-06-05 12:24:03 +02:00
|
|
|
if (!IN_SET(state, BUSNAME_LISTENING, BUSNAME_MAKING, BUSNAME_REGISTERED, BUSNAME_RUNNING))
|
2013-12-02 23:30:19 +01:00
|
|
|
busname_close_fd(n);
|
|
|
|
|
|
|
|
if (state != old_state)
|
core,network: major per-object logging rework
This changes log_unit_info() (and friends) to take a real Unit* object
insted of just a unit name as parameter. The call will now prefix all
logged messages with the unit name, thus allowing the unit name to be
dropped from the various passed romat strings, simplifying invocations
drastically, and unifying log output across messages. Also, UNIT= vs.
USER_UNIT= is now derived from the Manager object attached to the Unit
object, instead of getpid(). This has the benefit of correcting the
field for --test runs.
Also contains a couple of other logging improvements:
- Drops a couple of strerror() invocations in favour of using %m.
- Not only .mount units now warn if a symlinks exist for the mount
point already, .automount units do that too, now.
- A few invocations of log_struct() that didn't actually pass any
additional structured data have been replaced by simpler invocations
of log_unit_info() and friends.
- For structured data a new LOG_UNIT_MESSAGE() macro has been added,
that works like LOG_MESSAGE() but prefixes the message with the unit
name. Similar, there's now LOG_LINK_MESSAGE() and
LOG_NETDEV_MESSAGE().
- For structured data new LOG_UNIT_ID(), LOG_LINK_INTERFACE(),
LOG_NETDEV_INTERFACE() macros have been added that generate the
necessary per object fields. The old log_unit_struct() call has been
removed in favour of these new macros used in raw log_struct()
invocations. In addition to removing one more function call this
allows generated structured log messages that contain two object
fields, as necessary for example for network interfaces that are
joined into another network interface, and whose messages shall be
indexed by both.
- The LOG_ERRNO() macro has been removed, in favour of
log_struct_errno(). The latter has the benefit of ensuring that %m in
format strings is properly resolved to the specified error number.
- A number of logging messages have been converted to use
log_unit_info() instead of log_info()
- The client code in sysv-generator no longer #includes core code from
src/core/.
- log_unit_full_errno() has been removed, log_unit_full() instead takes
an errno now, too.
- log_unit_info(), log_link_info(), log_netdev_info() and friends, now
avoid double evaluation of their parameters
2015-05-11 20:38:21 +02:00
|
|
|
log_unit_debug(UNIT(n), "Changed %s -> %s", busname_state_to_string(old_state), busname_state_to_string(state));
|
2013-12-02 23:30:19 +01:00
|
|
|
|
|
|
|
unit_notify(UNIT(n), state_translation_table[old_state], state_translation_table[state], true);
|
|
|
|
}
|
|
|
|
|
2015-04-24 15:27:19 +02:00
|
|
|
static int busname_coldplug(Unit *u) {
|
2013-12-02 23:30:19 +01:00
|
|
|
BusName *n = BUSNAME(u);
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(n);
|
|
|
|
assert(n->state == BUSNAME_DEAD);
|
|
|
|
|
|
|
|
if (n->deserialized_state == n->state)
|
|
|
|
return 0;
|
|
|
|
|
2015-10-27 17:59:45 +01:00
|
|
|
if (n->control_pid > 0 &&
|
|
|
|
pid_is_unwaited(n->control_pid) &&
|
|
|
|
IN_SET(n->deserialized_state, BUSNAME_MAKING, BUSNAME_SIGTERM, BUSNAME_SIGKILL)) {
|
2014-06-05 12:24:03 +02:00
|
|
|
|
|
|
|
r = unit_watch_pid(UNIT(n), n->control_pid);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
core: rework unit timeout handling, and add new setting RuntimeMaxSec=
This clean-ups timeout handling in PID 1. Specifically, instead of storing 0 in internal timeout variables as
indication for a disabled timeout, use USEC_INFINITY which is in-line with how we do this in the rest of our code
(following the logic that 0 means "no", and USEC_INFINITY means "never").
This also replace all usec_t additions with invocations to usec_add(), so that USEC_INFINITY is properly propagated,
and sd-event considers it has indication for turning off the event source.
This also alters the deserialization of the units to restart timeouts from the time they were originally started from.
Before this patch timeouts would be restarted beginning with the time of the deserialization, which could lead to
artificially prolonged timeouts if a daemon reload took place.
Finally, a new RuntimeMaxSec= setting is introduced for service units, that specifies a maximum runtime after which a
specific service is forcibly terminated. This is useful to put time limits on time-intensive processing jobs.
This also simplifies the various xyz_spawn() calls of the various types in that explicit distruction of the timers is
removed, as that is done anyway by the state change handlers, and a state change is always done when the xyz_spawn()
calls fail.
Fixes: #2249
2016-02-01 21:48:10 +01:00
|
|
|
r = busname_arm_timer(n, usec_add(u->state_change_timestamp.monotonic, n->timeout_usec));
|
2014-06-05 12:24:03 +02:00
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IN_SET(n->deserialized_state, BUSNAME_MAKING, BUSNAME_LISTENING, BUSNAME_REGISTERED, BUSNAME_RUNNING)) {
|
2013-12-02 23:30:19 +01:00
|
|
|
r = busname_open_fd(n);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n->deserialized_state == BUSNAME_LISTENING) {
|
|
|
|
r = busname_watch_fd(n);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
busname_set_state(n, n->deserialized_state);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-05 12:24:03 +02:00
|
|
|
static int busname_make_starter(BusName *n, pid_t *_pid) {
|
|
|
|
pid_t pid;
|
|
|
|
int r;
|
|
|
|
|
core: rework unit timeout handling, and add new setting RuntimeMaxSec=
This clean-ups timeout handling in PID 1. Specifically, instead of storing 0 in internal timeout variables as
indication for a disabled timeout, use USEC_INFINITY which is in-line with how we do this in the rest of our code
(following the logic that 0 means "no", and USEC_INFINITY means "never").
This also replace all usec_t additions with invocations to usec_add(), so that USEC_INFINITY is properly propagated,
and sd-event considers it has indication for turning off the event source.
This also alters the deserialization of the units to restart timeouts from the time they were originally started from.
Before this patch timeouts would be restarted beginning with the time of the deserialization, which could lead to
artificially prolonged timeouts if a daemon reload took place.
Finally, a new RuntimeMaxSec= setting is introduced for service units, that specifies a maximum runtime after which a
specific service is forcibly terminated. This is useful to put time limits on time-intensive processing jobs.
This also simplifies the various xyz_spawn() calls of the various types in that explicit distruction of the timers is
removed, as that is done anyway by the state change handlers, and a state change is always done when the xyz_spawn()
calls fail.
Fixes: #2249
2016-02-01 21:48:10 +01:00
|
|
|
r = busname_arm_timer(n, usec_add(now(CLOCK_MONOTONIC), n->timeout_usec));
|
2014-06-05 12:24:03 +02:00
|
|
|
if (r < 0)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* We have to resolve the user/group names out-of-process,
|
|
|
|
* hence let's fork here. It's messy, but well, what can we
|
|
|
|
* do? */
|
|
|
|
|
|
|
|
pid = fork();
|
|
|
|
if (pid < 0)
|
|
|
|
return -errno;
|
|
|
|
|
|
|
|
if (pid == 0) {
|
|
|
|
int ret;
|
|
|
|
|
2015-05-31 23:55:55 +02:00
|
|
|
(void) default_signals(SIGNALS_CRASH_HANDLER, SIGNALS_IGNORE, -1);
|
|
|
|
(void) ignore_signals(SIGPIPE, -1);
|
2014-06-05 12:24:03 +02:00
|
|
|
log_forget_fds();
|
|
|
|
|
|
|
|
r = bus_kernel_make_starter(n->starter_fd, n->name, n->activating, n->accept_fd, n->policy, n->policy_world);
|
|
|
|
if (r < 0) {
|
|
|
|
ret = EXIT_MAKE_STARTER;
|
|
|
|
goto fail_child;
|
|
|
|
}
|
|
|
|
|
|
|
|
_exit(0);
|
|
|
|
|
|
|
|
fail_child:
|
|
|
|
log_open();
|
2014-11-28 13:19:16 +01:00
|
|
|
log_error_errno(r, "Failed to create starter connection at step %s: %m", exit_status_to_string(ret, EXIT_STATUS_SYSTEMD));
|
2014-06-05 12:24:03 +02:00
|
|
|
|
|
|
|
_exit(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
r = unit_watch_pid(UNIT(n), pid);
|
|
|
|
if (r < 0)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
*_pid = pid;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
n->timer_event_source = sd_event_source_unref(n->timer_event_source);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2013-12-02 23:30:19 +01:00
|
|
|
static void busname_enter_dead(BusName *n, BusNameResult f) {
|
|
|
|
assert(n);
|
|
|
|
|
core: remember first unit failure, not last unit failure
Previously, the result value of a unit was overriden with each failure that
took place, so that the result always reported the last failure that took
place.
With this commit this is changed, so that the first failure taking place is
stored instead. This should normally not matter much as multiple failures are
sufficiently uncommon. However, it improves one behaviour: if we send SIGABRT
to a service due to a watchdog timeout, then this currently would be reported
as "coredump" failure, rather than the "watchodg" failure it really is. Hence,
in order to report information about the type of the failure, and not about
the effect of it, let's change this from all unit type to store the first, not
the last failure.
This addresses the issue pointed out here:
https://github.com/systemd/systemd/pull/3818#discussion_r73433520
2016-08-04 21:14:27 +02:00
|
|
|
if (n->result == BUSNAME_SUCCESS)
|
2013-12-02 23:30:19 +01:00
|
|
|
n->result = f;
|
|
|
|
|
|
|
|
busname_set_state(n, n->result != BUSNAME_SUCCESS ? BUSNAME_FAILED : BUSNAME_DEAD);
|
|
|
|
}
|
|
|
|
|
2014-06-05 12:24:03 +02:00
|
|
|
static void busname_enter_signal(BusName *n, BusNameState state, BusNameResult f) {
|
|
|
|
KillContext kill_context = {};
|
2013-12-02 23:30:19 +01:00
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(n);
|
|
|
|
|
core: remember first unit failure, not last unit failure
Previously, the result value of a unit was overriden with each failure that
took place, so that the result always reported the last failure that took
place.
With this commit this is changed, so that the first failure taking place is
stored instead. This should normally not matter much as multiple failures are
sufficiently uncommon. However, it improves one behaviour: if we send SIGABRT
to a service due to a watchdog timeout, then this currently would be reported
as "coredump" failure, rather than the "watchodg" failure it really is. Hence,
in order to report information about the type of the failure, and not about
the effect of it, let's change this from all unit type to store the first, not
the last failure.
This addresses the issue pointed out here:
https://github.com/systemd/systemd/pull/3818#discussion_r73433520
2016-08-04 21:14:27 +02:00
|
|
|
if (n->result == BUSNAME_SUCCESS)
|
2014-06-05 12:24:03 +02:00
|
|
|
n->result = f;
|
|
|
|
|
|
|
|
kill_context_init(&kill_context);
|
|
|
|
|
|
|
|
r = unit_kill_context(UNIT(n),
|
|
|
|
&kill_context,
|
2014-10-28 16:35:40 +01:00
|
|
|
state != BUSNAME_SIGTERM ? KILL_KILL : KILL_TERMINATE,
|
2014-06-05 12:24:03 +02:00
|
|
|
-1,
|
|
|
|
n->control_pid,
|
|
|
|
false);
|
2013-12-02 23:30:19 +01:00
|
|
|
if (r < 0) {
|
core,network: major per-object logging rework
This changes log_unit_info() (and friends) to take a real Unit* object
insted of just a unit name as parameter. The call will now prefix all
logged messages with the unit name, thus allowing the unit name to be
dropped from the various passed romat strings, simplifying invocations
drastically, and unifying log output across messages. Also, UNIT= vs.
USER_UNIT= is now derived from the Manager object attached to the Unit
object, instead of getpid(). This has the benefit of correcting the
field for --test runs.
Also contains a couple of other logging improvements:
- Drops a couple of strerror() invocations in favour of using %m.
- Not only .mount units now warn if a symlinks exist for the mount
point already, .automount units do that too, now.
- A few invocations of log_struct() that didn't actually pass any
additional structured data have been replaced by simpler invocations
of log_unit_info() and friends.
- For structured data a new LOG_UNIT_MESSAGE() macro has been added,
that works like LOG_MESSAGE() but prefixes the message with the unit
name. Similar, there's now LOG_LINK_MESSAGE() and
LOG_NETDEV_MESSAGE().
- For structured data new LOG_UNIT_ID(), LOG_LINK_INTERFACE(),
LOG_NETDEV_INTERFACE() macros have been added that generate the
necessary per object fields. The old log_unit_struct() call has been
removed in favour of these new macros used in raw log_struct()
invocations. In addition to removing one more function call this
allows generated structured log messages that contain two object
fields, as necessary for example for network interfaces that are
joined into another network interface, and whose messages shall be
indexed by both.
- The LOG_ERRNO() macro has been removed, in favour of
log_struct_errno(). The latter has the benefit of ensuring that %m in
format strings is properly resolved to the specified error number.
- A number of logging messages have been converted to use
log_unit_info() instead of log_info()
- The client code in sysv-generator no longer #includes core code from
src/core/.
- log_unit_full_errno() has been removed, log_unit_full() instead takes
an errno now, too.
- log_unit_info(), log_link_info(), log_netdev_info() and friends, now
avoid double evaluation of their parameters
2015-05-11 20:38:21 +02:00
|
|
|
log_unit_warning_errno(UNIT(n), r, "Failed to kill control process: %m");
|
2013-12-02 23:30:19 +01:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2014-06-05 12:24:03 +02:00
|
|
|
if (r > 0) {
|
core: rework unit timeout handling, and add new setting RuntimeMaxSec=
This clean-ups timeout handling in PID 1. Specifically, instead of storing 0 in internal timeout variables as
indication for a disabled timeout, use USEC_INFINITY which is in-line with how we do this in the rest of our code
(following the logic that 0 means "no", and USEC_INFINITY means "never").
This also replace all usec_t additions with invocations to usec_add(), so that USEC_INFINITY is properly propagated,
and sd-event considers it has indication for turning off the event source.
This also alters the deserialization of the units to restart timeouts from the time they were originally started from.
Before this patch timeouts would be restarted beginning with the time of the deserialization, which could lead to
artificially prolonged timeouts if a daemon reload took place.
Finally, a new RuntimeMaxSec= setting is introduced for service units, that specifies a maximum runtime after which a
specific service is forcibly terminated. This is useful to put time limits on time-intensive processing jobs.
This also simplifies the various xyz_spawn() calls of the various types in that explicit distruction of the timers is
removed, as that is done anyway by the state change handlers, and a state change is always done when the xyz_spawn()
calls fail.
Fixes: #2249
2016-02-01 21:48:10 +01:00
|
|
|
r = busname_arm_timer(n, usec_add(now(CLOCK_MONOTONIC), n->timeout_usec));
|
2014-06-05 12:24:03 +02:00
|
|
|
if (r < 0) {
|
core,network: major per-object logging rework
This changes log_unit_info() (and friends) to take a real Unit* object
insted of just a unit name as parameter. The call will now prefix all
logged messages with the unit name, thus allowing the unit name to be
dropped from the various passed romat strings, simplifying invocations
drastically, and unifying log output across messages. Also, UNIT= vs.
USER_UNIT= is now derived from the Manager object attached to the Unit
object, instead of getpid(). This has the benefit of correcting the
field for --test runs.
Also contains a couple of other logging improvements:
- Drops a couple of strerror() invocations in favour of using %m.
- Not only .mount units now warn if a symlinks exist for the mount
point already, .automount units do that too, now.
- A few invocations of log_struct() that didn't actually pass any
additional structured data have been replaced by simpler invocations
of log_unit_info() and friends.
- For structured data a new LOG_UNIT_MESSAGE() macro has been added,
that works like LOG_MESSAGE() but prefixes the message with the unit
name. Similar, there's now LOG_LINK_MESSAGE() and
LOG_NETDEV_MESSAGE().
- For structured data new LOG_UNIT_ID(), LOG_LINK_INTERFACE(),
LOG_NETDEV_INTERFACE() macros have been added that generate the
necessary per object fields. The old log_unit_struct() call has been
removed in favour of these new macros used in raw log_struct()
invocations. In addition to removing one more function call this
allows generated structured log messages that contain two object
fields, as necessary for example for network interfaces that are
joined into another network interface, and whose messages shall be
indexed by both.
- The LOG_ERRNO() macro has been removed, in favour of
log_struct_errno(). The latter has the benefit of ensuring that %m in
format strings is properly resolved to the specified error number.
- A number of logging messages have been converted to use
log_unit_info() instead of log_info()
- The client code in sysv-generator no longer #includes core code from
src/core/.
- log_unit_full_errno() has been removed, log_unit_full() instead takes
an errno now, too.
- log_unit_info(), log_link_info(), log_netdev_info() and friends, now
avoid double evaluation of their parameters
2015-05-11 20:38:21 +02:00
|
|
|
log_unit_warning_errno(UNIT(n), r, "Failed to arm timer: %m");
|
2014-06-05 12:24:03 +02:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
busname_set_state(n, state);
|
|
|
|
} else if (state == BUSNAME_SIGTERM)
|
|
|
|
busname_enter_signal(n, BUSNAME_SIGKILL, BUSNAME_SUCCESS);
|
|
|
|
else
|
|
|
|
busname_enter_dead(n, BUSNAME_SUCCESS);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
busname_enter_dead(n, BUSNAME_FAILURE_RESOURCES);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void busname_enter_listening(BusName *n) {
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(n);
|
|
|
|
|
2014-03-17 11:41:21 +01:00
|
|
|
if (n->activating) {
|
|
|
|
r = busname_watch_fd(n);
|
|
|
|
if (r < 0) {
|
core,network: major per-object logging rework
This changes log_unit_info() (and friends) to take a real Unit* object
insted of just a unit name as parameter. The call will now prefix all
logged messages with the unit name, thus allowing the unit name to be
dropped from the various passed romat strings, simplifying invocations
drastically, and unifying log output across messages. Also, UNIT= vs.
USER_UNIT= is now derived from the Manager object attached to the Unit
object, instead of getpid(). This has the benefit of correcting the
field for --test runs.
Also contains a couple of other logging improvements:
- Drops a couple of strerror() invocations in favour of using %m.
- Not only .mount units now warn if a symlinks exist for the mount
point already, .automount units do that too, now.
- A few invocations of log_struct() that didn't actually pass any
additional structured data have been replaced by simpler invocations
of log_unit_info() and friends.
- For structured data a new LOG_UNIT_MESSAGE() macro has been added,
that works like LOG_MESSAGE() but prefixes the message with the unit
name. Similar, there's now LOG_LINK_MESSAGE() and
LOG_NETDEV_MESSAGE().
- For structured data new LOG_UNIT_ID(), LOG_LINK_INTERFACE(),
LOG_NETDEV_INTERFACE() macros have been added that generate the
necessary per object fields. The old log_unit_struct() call has been
removed in favour of these new macros used in raw log_struct()
invocations. In addition to removing one more function call this
allows generated structured log messages that contain two object
fields, as necessary for example for network interfaces that are
joined into another network interface, and whose messages shall be
indexed by both.
- The LOG_ERRNO() macro has been removed, in favour of
log_struct_errno(). The latter has the benefit of ensuring that %m in
format strings is properly resolved to the specified error number.
- A number of logging messages have been converted to use
log_unit_info() instead of log_info()
- The client code in sysv-generator no longer #includes core code from
src/core/.
- log_unit_full_errno() has been removed, log_unit_full() instead takes
an errno now, too.
- log_unit_info(), log_link_info(), log_netdev_info() and friends, now
avoid double evaluation of their parameters
2015-05-11 20:38:21 +02:00
|
|
|
log_unit_warning_errno(UNIT(n), r, "Failed to watch names: %m");
|
2014-03-17 11:41:21 +01:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
busname_set_state(n, BUSNAME_LISTENING);
|
|
|
|
} else
|
|
|
|
busname_set_state(n, BUSNAME_REGISTERED);
|
2013-12-02 23:30:19 +01:00
|
|
|
|
|
|
|
return;
|
|
|
|
|
2014-06-05 12:24:03 +02:00
|
|
|
fail:
|
|
|
|
busname_enter_signal(n, BUSNAME_SIGTERM, BUSNAME_FAILURE_RESOURCES);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void busname_enter_making(BusName *n) {
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(n);
|
|
|
|
|
|
|
|
r = busname_open_fd(n);
|
|
|
|
if (r < 0)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (n->policy) {
|
2014-06-28 00:48:28 +02:00
|
|
|
/* If there is a policy, we need to resolve user/group
|
2014-06-05 12:24:03 +02:00
|
|
|
* names, which we can't do from PID1, hence let's
|
|
|
|
* fork. */
|
|
|
|
busname_unwatch_control_pid(n);
|
|
|
|
|
|
|
|
r = busname_make_starter(n, &n->control_pid);
|
|
|
|
if (r < 0) {
|
core,network: major per-object logging rework
This changes log_unit_info() (and friends) to take a real Unit* object
insted of just a unit name as parameter. The call will now prefix all
logged messages with the unit name, thus allowing the unit name to be
dropped from the various passed romat strings, simplifying invocations
drastically, and unifying log output across messages. Also, UNIT= vs.
USER_UNIT= is now derived from the Manager object attached to the Unit
object, instead of getpid(). This has the benefit of correcting the
field for --test runs.
Also contains a couple of other logging improvements:
- Drops a couple of strerror() invocations in favour of using %m.
- Not only .mount units now warn if a symlinks exist for the mount
point already, .automount units do that too, now.
- A few invocations of log_struct() that didn't actually pass any
additional structured data have been replaced by simpler invocations
of log_unit_info() and friends.
- For structured data a new LOG_UNIT_MESSAGE() macro has been added,
that works like LOG_MESSAGE() but prefixes the message with the unit
name. Similar, there's now LOG_LINK_MESSAGE() and
LOG_NETDEV_MESSAGE().
- For structured data new LOG_UNIT_ID(), LOG_LINK_INTERFACE(),
LOG_NETDEV_INTERFACE() macros have been added that generate the
necessary per object fields. The old log_unit_struct() call has been
removed in favour of these new macros used in raw log_struct()
invocations. In addition to removing one more function call this
allows generated structured log messages that contain two object
fields, as necessary for example for network interfaces that are
joined into another network interface, and whose messages shall be
indexed by both.
- The LOG_ERRNO() macro has been removed, in favour of
log_struct_errno(). The latter has the benefit of ensuring that %m in
format strings is properly resolved to the specified error number.
- A number of logging messages have been converted to use
log_unit_info() instead of log_info()
- The client code in sysv-generator no longer #includes core code from
src/core/.
- log_unit_full_errno() has been removed, log_unit_full() instead takes
an errno now, too.
- log_unit_info(), log_link_info(), log_netdev_info() and friends, now
avoid double evaluation of their parameters
2015-05-11 20:38:21 +02:00
|
|
|
log_unit_warning_errno(UNIT(n), r, "Failed to fork 'making' task: %m");
|
2014-06-05 12:24:03 +02:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
busname_set_state(n, BUSNAME_MAKING);
|
|
|
|
} else {
|
2014-06-28 00:48:28 +02:00
|
|
|
/* If there is no policy, we can do everything
|
2014-06-05 12:24:03 +02:00
|
|
|
* directly from PID 1, hence do so. */
|
|
|
|
|
|
|
|
r = bus_kernel_make_starter(n->starter_fd, n->name, n->activating, n->accept_fd, NULL, n->policy_world);
|
|
|
|
if (r < 0) {
|
core,network: major per-object logging rework
This changes log_unit_info() (and friends) to take a real Unit* object
insted of just a unit name as parameter. The call will now prefix all
logged messages with the unit name, thus allowing the unit name to be
dropped from the various passed romat strings, simplifying invocations
drastically, and unifying log output across messages. Also, UNIT= vs.
USER_UNIT= is now derived from the Manager object attached to the Unit
object, instead of getpid(). This has the benefit of correcting the
field for --test runs.
Also contains a couple of other logging improvements:
- Drops a couple of strerror() invocations in favour of using %m.
- Not only .mount units now warn if a symlinks exist for the mount
point already, .automount units do that too, now.
- A few invocations of log_struct() that didn't actually pass any
additional structured data have been replaced by simpler invocations
of log_unit_info() and friends.
- For structured data a new LOG_UNIT_MESSAGE() macro has been added,
that works like LOG_MESSAGE() but prefixes the message with the unit
name. Similar, there's now LOG_LINK_MESSAGE() and
LOG_NETDEV_MESSAGE().
- For structured data new LOG_UNIT_ID(), LOG_LINK_INTERFACE(),
LOG_NETDEV_INTERFACE() macros have been added that generate the
necessary per object fields. The old log_unit_struct() call has been
removed in favour of these new macros used in raw log_struct()
invocations. In addition to removing one more function call this
allows generated structured log messages that contain two object
fields, as necessary for example for network interfaces that are
joined into another network interface, and whose messages shall be
indexed by both.
- The LOG_ERRNO() macro has been removed, in favour of
log_struct_errno(). The latter has the benefit of ensuring that %m in
format strings is properly resolved to the specified error number.
- A number of logging messages have been converted to use
log_unit_info() instead of log_info()
- The client code in sysv-generator no longer #includes core code from
src/core/.
- log_unit_full_errno() has been removed, log_unit_full() instead takes
an errno now, too.
- log_unit_info(), log_link_info(), log_netdev_info() and friends, now
avoid double evaluation of their parameters
2015-05-11 20:38:21 +02:00
|
|
|
log_unit_warning_errno(UNIT(n), r, "Failed to make starter: %m");
|
2014-06-05 12:24:03 +02:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
busname_enter_listening(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
2013-12-02 23:30:19 +01:00
|
|
|
fail:
|
|
|
|
busname_enter_dead(n, BUSNAME_FAILURE_RESOURCES);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void busname_enter_running(BusName *n) {
|
tree-wide: expose "p"-suffix unref calls in public APIs to make gcc cleanup easy
GLIB has recently started to officially support the gcc cleanup
attribute in its public API, hence let's do the same for our APIs.
With this patch we'll define an xyz_unrefp() call for each public
xyz_unref() call, to make it easy to use inside a
__attribute__((cleanup())) expression. Then, all code is ported over to
make use of this.
The new calls are also documented in the man pages, with examples how to
use them (well, I only added docs where the _unref() call itself already
had docs, and the examples, only cover sd_bus_unrefp() and
sd_event_unrefp()).
This also renames sd_lldp_free() to sd_lldp_unref(), since that's how we
tend to call our destructors these days.
Note that this defines no public macro that wraps gcc's attribute and
makes it easier to use. While I think it's our duty in the library to
make our stuff easy to use, I figure it's not our duty to make gcc's own
features easy to use on its own. Most likely, client code which wants to
make use of this should define its own:
#define _cleanup_(function) __attribute__((cleanup(function)))
Or similar, to make the gcc feature easier to use.
Making this logic public has the benefit that we can remove three header
files whose only purpose was to define these functions internally.
See #2008.
2015-11-27 19:13:45 +01:00
|
|
|
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
|
2013-12-02 23:30:19 +01:00
|
|
|
bool pending = false;
|
|
|
|
Unit *other;
|
|
|
|
Iterator i;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(n);
|
|
|
|
|
2014-03-17 11:41:21 +01:00
|
|
|
if (!n->activating)
|
|
|
|
return;
|
|
|
|
|
2015-04-10 23:39:13 +02:00
|
|
|
/* We don't take connections anymore if we are supposed to
|
2013-12-02 23:30:19 +01:00
|
|
|
* shut down anyway */
|
|
|
|
|
|
|
|
if (unit_stop_pending(UNIT(n))) {
|
core,network: major per-object logging rework
This changes log_unit_info() (and friends) to take a real Unit* object
insted of just a unit name as parameter. The call will now prefix all
logged messages with the unit name, thus allowing the unit name to be
dropped from the various passed romat strings, simplifying invocations
drastically, and unifying log output across messages. Also, UNIT= vs.
USER_UNIT= is now derived from the Manager object attached to the Unit
object, instead of getpid(). This has the benefit of correcting the
field for --test runs.
Also contains a couple of other logging improvements:
- Drops a couple of strerror() invocations in favour of using %m.
- Not only .mount units now warn if a symlinks exist for the mount
point already, .automount units do that too, now.
- A few invocations of log_struct() that didn't actually pass any
additional structured data have been replaced by simpler invocations
of log_unit_info() and friends.
- For structured data a new LOG_UNIT_MESSAGE() macro has been added,
that works like LOG_MESSAGE() but prefixes the message with the unit
name. Similar, there's now LOG_LINK_MESSAGE() and
LOG_NETDEV_MESSAGE().
- For structured data new LOG_UNIT_ID(), LOG_LINK_INTERFACE(),
LOG_NETDEV_INTERFACE() macros have been added that generate the
necessary per object fields. The old log_unit_struct() call has been
removed in favour of these new macros used in raw log_struct()
invocations. In addition to removing one more function call this
allows generated structured log messages that contain two object
fields, as necessary for example for network interfaces that are
joined into another network interface, and whose messages shall be
indexed by both.
- The LOG_ERRNO() macro has been removed, in favour of
log_struct_errno(). The latter has the benefit of ensuring that %m in
format strings is properly resolved to the specified error number.
- A number of logging messages have been converted to use
log_unit_info() instead of log_info()
- The client code in sysv-generator no longer #includes core code from
src/core/.
- log_unit_full_errno() has been removed, log_unit_full() instead takes
an errno now, too.
- log_unit_info(), log_link_info(), log_netdev_info() and friends, now
avoid double evaluation of their parameters
2015-05-11 20:38:21 +02:00
|
|
|
log_unit_debug(UNIT(n), "Suppressing activation request since unit stop is scheduled.");
|
2013-12-16 21:26:21 +01:00
|
|
|
|
|
|
|
/* Flush all queued activation reqeuest by closing and reopening the connection */
|
2014-01-22 23:36:06 +01:00
|
|
|
bus_kernel_drop_one(n->starter_fd);
|
2013-12-16 21:26:21 +01:00
|
|
|
|
|
|
|
busname_enter_listening(n);
|
2013-12-02 23:30:19 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If there's already a start pending don't bother to do
|
|
|
|
* anything */
|
|
|
|
SET_FOREACH(other, UNIT(n)->dependencies[UNIT_TRIGGERS], i)
|
|
|
|
if (unit_active_or_pending(other)) {
|
|
|
|
pending = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pending) {
|
2015-10-14 16:22:22 +02:00
|
|
|
if (!UNIT_ISSET(n->service)) {
|
|
|
|
log_unit_error(UNIT(n), "Service to activate vanished, refusing activation.");
|
|
|
|
r = -ENOENT;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2015-11-12 19:52:31 +01:00
|
|
|
r = manager_add_job(UNIT(n)->manager, JOB_START, UNIT_DEREF(n->service), JOB_REPLACE, &error, NULL);
|
2013-12-02 23:30:19 +01:00
|
|
|
if (r < 0)
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
busname_set_state(n, BUSNAME_RUNNING);
|
|
|
|
return;
|
|
|
|
|
|
|
|
fail:
|
core,network: major per-object logging rework
This changes log_unit_info() (and friends) to take a real Unit* object
insted of just a unit name as parameter. The call will now prefix all
logged messages with the unit name, thus allowing the unit name to be
dropped from the various passed romat strings, simplifying invocations
drastically, and unifying log output across messages. Also, UNIT= vs.
USER_UNIT= is now derived from the Manager object attached to the Unit
object, instead of getpid(). This has the benefit of correcting the
field for --test runs.
Also contains a couple of other logging improvements:
- Drops a couple of strerror() invocations in favour of using %m.
- Not only .mount units now warn if a symlinks exist for the mount
point already, .automount units do that too, now.
- A few invocations of log_struct() that didn't actually pass any
additional structured data have been replaced by simpler invocations
of log_unit_info() and friends.
- For structured data a new LOG_UNIT_MESSAGE() macro has been added,
that works like LOG_MESSAGE() but prefixes the message with the unit
name. Similar, there's now LOG_LINK_MESSAGE() and
LOG_NETDEV_MESSAGE().
- For structured data new LOG_UNIT_ID(), LOG_LINK_INTERFACE(),
LOG_NETDEV_INTERFACE() macros have been added that generate the
necessary per object fields. The old log_unit_struct() call has been
removed in favour of these new macros used in raw log_struct()
invocations. In addition to removing one more function call this
allows generated structured log messages that contain two object
fields, as necessary for example for network interfaces that are
joined into another network interface, and whose messages shall be
indexed by both.
- The LOG_ERRNO() macro has been removed, in favour of
log_struct_errno(). The latter has the benefit of ensuring that %m in
format strings is properly resolved to the specified error number.
- A number of logging messages have been converted to use
log_unit_info() instead of log_info()
- The client code in sysv-generator no longer #includes core code from
src/core/.
- log_unit_full_errno() has been removed, log_unit_full() instead takes
an errno now, too.
- log_unit_info(), log_link_info(), log_netdev_info() and friends, now
avoid double evaluation of their parameters
2015-05-11 20:38:21 +02:00
|
|
|
log_unit_warning(UNIT(n), "Failed to queue service startup job: %s", bus_error_message(&error, r));
|
2013-12-02 23:30:19 +01:00
|
|
|
busname_enter_dead(n, BUSNAME_FAILURE_RESOURCES);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int busname_start(Unit *u) {
|
|
|
|
BusName *n = BUSNAME(u);
|
core: move enforcement of the start limit into per-unit-type code again
Let's move the enforcement of the per-unit start limit from unit.c into the
type-specific files again. For unit types that know a concept of "result" codes
this allows us to hook up the start limit condition to it with an explicit
result code. Also, this makes sure that the state checks in clal like
service_start() may be done before the start limit is checked, as the start
limit really should be checked last, right before everything has been verified
to be in order.
The generic start limit logic is left in unit.c, but the invocation of it is
moved into the per-type files, in the various xyz_start() functions, so that
they may place the check at the right location.
Note that this change drops the enforcement entirely from device, slice, target
and scope units, since these unit types generally may not fail activation, or
may only be activated a single time. This is also documented now.
Note that restores the "start-limit-hit" result code that existed before
6bf0f408e4833152197fb38fb10a9989c89f3a59 already in the service code. However,
it's not introduced for all units that have a result code concept.
Fixes #3166.
2016-05-02 13:01:26 +02:00
|
|
|
int r;
|
2013-12-02 23:30:19 +01:00
|
|
|
|
|
|
|
assert(n);
|
|
|
|
|
2014-06-05 12:24:03 +02:00
|
|
|
/* We cannot fulfill this request right now, try again later
|
|
|
|
* please! */
|
|
|
|
if (IN_SET(n->state, BUSNAME_SIGTERM, BUSNAME_SIGKILL))
|
|
|
|
return -EAGAIN;
|
|
|
|
|
|
|
|
/* Already on it! */
|
|
|
|
if (n->state == BUSNAME_MAKING)
|
|
|
|
return 0;
|
|
|
|
|
2014-03-17 11:41:21 +01:00
|
|
|
if (n->activating && UNIT_ISSET(n->service)) {
|
2013-12-02 23:30:19 +01:00
|
|
|
Service *service;
|
|
|
|
|
|
|
|
service = SERVICE(UNIT_DEREF(n->service));
|
|
|
|
|
|
|
|
if (UNIT(service)->load_state != UNIT_LOADED) {
|
core,network: major per-object logging rework
This changes log_unit_info() (and friends) to take a real Unit* object
insted of just a unit name as parameter. The call will now prefix all
logged messages with the unit name, thus allowing the unit name to be
dropped from the various passed romat strings, simplifying invocations
drastically, and unifying log output across messages. Also, UNIT= vs.
USER_UNIT= is now derived from the Manager object attached to the Unit
object, instead of getpid(). This has the benefit of correcting the
field for --test runs.
Also contains a couple of other logging improvements:
- Drops a couple of strerror() invocations in favour of using %m.
- Not only .mount units now warn if a symlinks exist for the mount
point already, .automount units do that too, now.
- A few invocations of log_struct() that didn't actually pass any
additional structured data have been replaced by simpler invocations
of log_unit_info() and friends.
- For structured data a new LOG_UNIT_MESSAGE() macro has been added,
that works like LOG_MESSAGE() but prefixes the message with the unit
name. Similar, there's now LOG_LINK_MESSAGE() and
LOG_NETDEV_MESSAGE().
- For structured data new LOG_UNIT_ID(), LOG_LINK_INTERFACE(),
LOG_NETDEV_INTERFACE() macros have been added that generate the
necessary per object fields. The old log_unit_struct() call has been
removed in favour of these new macros used in raw log_struct()
invocations. In addition to removing one more function call this
allows generated structured log messages that contain two object
fields, as necessary for example for network interfaces that are
joined into another network interface, and whose messages shall be
indexed by both.
- The LOG_ERRNO() macro has been removed, in favour of
log_struct_errno(). The latter has the benefit of ensuring that %m in
format strings is properly resolved to the specified error number.
- A number of logging messages have been converted to use
log_unit_info() instead of log_info()
- The client code in sysv-generator no longer #includes core code from
src/core/.
- log_unit_full_errno() has been removed, log_unit_full() instead takes
an errno now, too.
- log_unit_info(), log_link_info(), log_netdev_info() and friends, now
avoid double evaluation of their parameters
2015-05-11 20:38:21 +02:00
|
|
|
log_unit_error(u, "Bus service %s not loaded, refusing.", UNIT(service)->id);
|
2013-12-02 23:30:19 +01:00
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(IN_SET(n->state, BUSNAME_DEAD, BUSNAME_FAILED));
|
|
|
|
|
core: move enforcement of the start limit into per-unit-type code again
Let's move the enforcement of the per-unit start limit from unit.c into the
type-specific files again. For unit types that know a concept of "result" codes
this allows us to hook up the start limit condition to it with an explicit
result code. Also, this makes sure that the state checks in clal like
service_start() may be done before the start limit is checked, as the start
limit really should be checked last, right before everything has been verified
to be in order.
The generic start limit logic is left in unit.c, but the invocation of it is
moved into the per-type files, in the various xyz_start() functions, so that
they may place the check at the right location.
Note that this change drops the enforcement entirely from device, slice, target
and scope units, since these unit types generally may not fail activation, or
may only be activated a single time. This is also documented now.
Note that restores the "start-limit-hit" result code that existed before
6bf0f408e4833152197fb38fb10a9989c89f3a59 already in the service code. However,
it's not introduced for all units that have a result code concept.
Fixes #3166.
2016-05-02 13:01:26 +02:00
|
|
|
r = unit_start_limit_test(u);
|
|
|
|
if (r < 0) {
|
|
|
|
busname_enter_dead(n, BUSNAME_FAILURE_START_LIMIT_HIT);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2016-08-30 23:18:46 +02:00
|
|
|
r = unit_acquire_invocation_id(u);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
2013-12-02 23:30:19 +01:00
|
|
|
n->result = BUSNAME_SUCCESS;
|
2014-06-05 12:24:03 +02:00
|
|
|
busname_enter_making(n);
|
2013-12-02 23:30:19 +01:00
|
|
|
|
2015-01-28 15:07:13 +01:00
|
|
|
return 1;
|
2013-12-02 23:30:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int busname_stop(Unit *u) {
|
|
|
|
BusName *n = BUSNAME(u);
|
|
|
|
|
|
|
|
assert(n);
|
2014-06-05 12:24:03 +02:00
|
|
|
|
|
|
|
/* Already on it */
|
|
|
|
if (IN_SET(n->state, BUSNAME_SIGTERM, BUSNAME_SIGKILL))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* If there's already something running, we go directly into
|
|
|
|
* kill mode. */
|
|
|
|
|
|
|
|
if (n->state == BUSNAME_MAKING) {
|
|
|
|
busname_enter_signal(n, BUSNAME_SIGTERM, BUSNAME_SUCCESS);
|
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
|
2014-03-17 11:41:21 +01:00
|
|
|
assert(IN_SET(n->state, BUSNAME_REGISTERED, BUSNAME_LISTENING, BUSNAME_RUNNING));
|
2013-12-02 23:30:19 +01:00
|
|
|
|
|
|
|
busname_enter_dead(n, BUSNAME_SUCCESS);
|
2015-01-28 15:07:13 +01:00
|
|
|
return 1;
|
2013-12-02 23:30:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int busname_serialize(Unit *u, FILE *f, FDSet *fds) {
|
|
|
|
BusName *n = BUSNAME(u);
|
2015-10-07 23:07:39 +02:00
|
|
|
int r;
|
2013-12-02 23:30:19 +01:00
|
|
|
|
|
|
|
assert(n);
|
|
|
|
assert(f);
|
|
|
|
assert(fds);
|
|
|
|
|
|
|
|
unit_serialize_item(u, f, "state", busname_state_to_string(n->state));
|
|
|
|
unit_serialize_item(u, f, "result", busname_result_to_string(n->result));
|
|
|
|
|
2014-06-05 12:24:03 +02:00
|
|
|
if (n->control_pid > 0)
|
|
|
|
unit_serialize_item_format(u, f, "control-pid", PID_FMT, n->control_pid);
|
|
|
|
|
2015-10-07 23:07:39 +02:00
|
|
|
r = unit_serialize_item_fd(u, f, fds, "starter-fd", n->starter_fd);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2013-12-02 23:30:19 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int busname_deserialize_item(Unit *u, const char *key, const char *value, FDSet *fds) {
|
|
|
|
BusName *n = BUSNAME(u);
|
|
|
|
|
|
|
|
assert(n);
|
|
|
|
assert(key);
|
|
|
|
assert(value);
|
|
|
|
|
|
|
|
if (streq(key, "state")) {
|
|
|
|
BusNameState state;
|
|
|
|
|
|
|
|
state = busname_state_from_string(value);
|
|
|
|
if (state < 0)
|
core,network: major per-object logging rework
This changes log_unit_info() (and friends) to take a real Unit* object
insted of just a unit name as parameter. The call will now prefix all
logged messages with the unit name, thus allowing the unit name to be
dropped from the various passed romat strings, simplifying invocations
drastically, and unifying log output across messages. Also, UNIT= vs.
USER_UNIT= is now derived from the Manager object attached to the Unit
object, instead of getpid(). This has the benefit of correcting the
field for --test runs.
Also contains a couple of other logging improvements:
- Drops a couple of strerror() invocations in favour of using %m.
- Not only .mount units now warn if a symlinks exist for the mount
point already, .automount units do that too, now.
- A few invocations of log_struct() that didn't actually pass any
additional structured data have been replaced by simpler invocations
of log_unit_info() and friends.
- For structured data a new LOG_UNIT_MESSAGE() macro has been added,
that works like LOG_MESSAGE() but prefixes the message with the unit
name. Similar, there's now LOG_LINK_MESSAGE() and
LOG_NETDEV_MESSAGE().
- For structured data new LOG_UNIT_ID(), LOG_LINK_INTERFACE(),
LOG_NETDEV_INTERFACE() macros have been added that generate the
necessary per object fields. The old log_unit_struct() call has been
removed in favour of these new macros used in raw log_struct()
invocations. In addition to removing one more function call this
allows generated structured log messages that contain two object
fields, as necessary for example for network interfaces that are
joined into another network interface, and whose messages shall be
indexed by both.
- The LOG_ERRNO() macro has been removed, in favour of
log_struct_errno(). The latter has the benefit of ensuring that %m in
format strings is properly resolved to the specified error number.
- A number of logging messages have been converted to use
log_unit_info() instead of log_info()
- The client code in sysv-generator no longer #includes core code from
src/core/.
- log_unit_full_errno() has been removed, log_unit_full() instead takes
an errno now, too.
- log_unit_info(), log_link_info(), log_netdev_info() and friends, now
avoid double evaluation of their parameters
2015-05-11 20:38:21 +02:00
|
|
|
log_unit_debug(u, "Failed to parse state value: %s", value);
|
2013-12-02 23:30:19 +01:00
|
|
|
else
|
|
|
|
n->deserialized_state = state;
|
|
|
|
|
|
|
|
} else if (streq(key, "result")) {
|
|
|
|
BusNameResult f;
|
|
|
|
|
|
|
|
f = busname_result_from_string(value);
|
|
|
|
if (f < 0)
|
core,network: major per-object logging rework
This changes log_unit_info() (and friends) to take a real Unit* object
insted of just a unit name as parameter. The call will now prefix all
logged messages with the unit name, thus allowing the unit name to be
dropped from the various passed romat strings, simplifying invocations
drastically, and unifying log output across messages. Also, UNIT= vs.
USER_UNIT= is now derived from the Manager object attached to the Unit
object, instead of getpid(). This has the benefit of correcting the
field for --test runs.
Also contains a couple of other logging improvements:
- Drops a couple of strerror() invocations in favour of using %m.
- Not only .mount units now warn if a symlinks exist for the mount
point already, .automount units do that too, now.
- A few invocations of log_struct() that didn't actually pass any
additional structured data have been replaced by simpler invocations
of log_unit_info() and friends.
- For structured data a new LOG_UNIT_MESSAGE() macro has been added,
that works like LOG_MESSAGE() but prefixes the message with the unit
name. Similar, there's now LOG_LINK_MESSAGE() and
LOG_NETDEV_MESSAGE().
- For structured data new LOG_UNIT_ID(), LOG_LINK_INTERFACE(),
LOG_NETDEV_INTERFACE() macros have been added that generate the
necessary per object fields. The old log_unit_struct() call has been
removed in favour of these new macros used in raw log_struct()
invocations. In addition to removing one more function call this
allows generated structured log messages that contain two object
fields, as necessary for example for network interfaces that are
joined into another network interface, and whose messages shall be
indexed by both.
- The LOG_ERRNO() macro has been removed, in favour of
log_struct_errno(). The latter has the benefit of ensuring that %m in
format strings is properly resolved to the specified error number.
- A number of logging messages have been converted to use
log_unit_info() instead of log_info()
- The client code in sysv-generator no longer #includes core code from
src/core/.
- log_unit_full_errno() has been removed, log_unit_full() instead takes
an errno now, too.
- log_unit_info(), log_link_info(), log_netdev_info() and friends, now
avoid double evaluation of their parameters
2015-05-11 20:38:21 +02:00
|
|
|
log_unit_debug(u, "Failed to parse result value: %s", value);
|
2013-12-02 23:30:19 +01:00
|
|
|
else if (f != BUSNAME_SUCCESS)
|
|
|
|
n->result = f;
|
|
|
|
|
2014-06-05 12:24:03 +02:00
|
|
|
} else if (streq(key, "control-pid")) {
|
|
|
|
pid_t pid;
|
|
|
|
|
|
|
|
if (parse_pid(value, &pid) < 0)
|
core,network: major per-object logging rework
This changes log_unit_info() (and friends) to take a real Unit* object
insted of just a unit name as parameter. The call will now prefix all
logged messages with the unit name, thus allowing the unit name to be
dropped from the various passed romat strings, simplifying invocations
drastically, and unifying log output across messages. Also, UNIT= vs.
USER_UNIT= is now derived from the Manager object attached to the Unit
object, instead of getpid(). This has the benefit of correcting the
field for --test runs.
Also contains a couple of other logging improvements:
- Drops a couple of strerror() invocations in favour of using %m.
- Not only .mount units now warn if a symlinks exist for the mount
point already, .automount units do that too, now.
- A few invocations of log_struct() that didn't actually pass any
additional structured data have been replaced by simpler invocations
of log_unit_info() and friends.
- For structured data a new LOG_UNIT_MESSAGE() macro has been added,
that works like LOG_MESSAGE() but prefixes the message with the unit
name. Similar, there's now LOG_LINK_MESSAGE() and
LOG_NETDEV_MESSAGE().
- For structured data new LOG_UNIT_ID(), LOG_LINK_INTERFACE(),
LOG_NETDEV_INTERFACE() macros have been added that generate the
necessary per object fields. The old log_unit_struct() call has been
removed in favour of these new macros used in raw log_struct()
invocations. In addition to removing one more function call this
allows generated structured log messages that contain two object
fields, as necessary for example for network interfaces that are
joined into another network interface, and whose messages shall be
indexed by both.
- The LOG_ERRNO() macro has been removed, in favour of
log_struct_errno(). The latter has the benefit of ensuring that %m in
format strings is properly resolved to the specified error number.
- A number of logging messages have been converted to use
log_unit_info() instead of log_info()
- The client code in sysv-generator no longer #includes core code from
src/core/.
- log_unit_full_errno() has been removed, log_unit_full() instead takes
an errno now, too.
- log_unit_info(), log_link_info(), log_netdev_info() and friends, now
avoid double evaluation of their parameters
2015-05-11 20:38:21 +02:00
|
|
|
log_unit_debug(u, "Failed to parse control-pid value: %s", value);
|
2014-06-05 12:24:03 +02:00
|
|
|
else
|
|
|
|
n->control_pid = pid;
|
2013-12-02 23:30:19 +01:00
|
|
|
} else if (streq(key, "starter-fd")) {
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
if (safe_atoi(value, &fd) < 0 || fd < 0 || !fdset_contains(fds, fd))
|
core,network: major per-object logging rework
This changes log_unit_info() (and friends) to take a real Unit* object
insted of just a unit name as parameter. The call will now prefix all
logged messages with the unit name, thus allowing the unit name to be
dropped from the various passed romat strings, simplifying invocations
drastically, and unifying log output across messages. Also, UNIT= vs.
USER_UNIT= is now derived from the Manager object attached to the Unit
object, instead of getpid(). This has the benefit of correcting the
field for --test runs.
Also contains a couple of other logging improvements:
- Drops a couple of strerror() invocations in favour of using %m.
- Not only .mount units now warn if a symlinks exist for the mount
point already, .automount units do that too, now.
- A few invocations of log_struct() that didn't actually pass any
additional structured data have been replaced by simpler invocations
of log_unit_info() and friends.
- For structured data a new LOG_UNIT_MESSAGE() macro has been added,
that works like LOG_MESSAGE() but prefixes the message with the unit
name. Similar, there's now LOG_LINK_MESSAGE() and
LOG_NETDEV_MESSAGE().
- For structured data new LOG_UNIT_ID(), LOG_LINK_INTERFACE(),
LOG_NETDEV_INTERFACE() macros have been added that generate the
necessary per object fields. The old log_unit_struct() call has been
removed in favour of these new macros used in raw log_struct()
invocations. In addition to removing one more function call this
allows generated structured log messages that contain two object
fields, as necessary for example for network interfaces that are
joined into another network interface, and whose messages shall be
indexed by both.
- The LOG_ERRNO() macro has been removed, in favour of
log_struct_errno(). The latter has the benefit of ensuring that %m in
format strings is properly resolved to the specified error number.
- A number of logging messages have been converted to use
log_unit_info() instead of log_info()
- The client code in sysv-generator no longer #includes core code from
src/core/.
- log_unit_full_errno() has been removed, log_unit_full() instead takes
an errno now, too.
- log_unit_info(), log_link_info(), log_netdev_info() and friends, now
avoid double evaluation of their parameters
2015-05-11 20:38:21 +02:00
|
|
|
log_unit_debug(u, "Failed to parse starter fd value: %s", value);
|
2013-12-02 23:30:19 +01:00
|
|
|
else {
|
2014-03-18 19:22:43 +01:00
|
|
|
safe_close(n->starter_fd);
|
2013-12-02 23:30:19 +01:00
|
|
|
n->starter_fd = fdset_remove(fds, fd);
|
|
|
|
}
|
|
|
|
} else
|
core,network: major per-object logging rework
This changes log_unit_info() (and friends) to take a real Unit* object
insted of just a unit name as parameter. The call will now prefix all
logged messages with the unit name, thus allowing the unit name to be
dropped from the various passed romat strings, simplifying invocations
drastically, and unifying log output across messages. Also, UNIT= vs.
USER_UNIT= is now derived from the Manager object attached to the Unit
object, instead of getpid(). This has the benefit of correcting the
field for --test runs.
Also contains a couple of other logging improvements:
- Drops a couple of strerror() invocations in favour of using %m.
- Not only .mount units now warn if a symlinks exist for the mount
point already, .automount units do that too, now.
- A few invocations of log_struct() that didn't actually pass any
additional structured data have been replaced by simpler invocations
of log_unit_info() and friends.
- For structured data a new LOG_UNIT_MESSAGE() macro has been added,
that works like LOG_MESSAGE() but prefixes the message with the unit
name. Similar, there's now LOG_LINK_MESSAGE() and
LOG_NETDEV_MESSAGE().
- For structured data new LOG_UNIT_ID(), LOG_LINK_INTERFACE(),
LOG_NETDEV_INTERFACE() macros have been added that generate the
necessary per object fields. The old log_unit_struct() call has been
removed in favour of these new macros used in raw log_struct()
invocations. In addition to removing one more function call this
allows generated structured log messages that contain two object
fields, as necessary for example for network interfaces that are
joined into another network interface, and whose messages shall be
indexed by both.
- The LOG_ERRNO() macro has been removed, in favour of
log_struct_errno(). The latter has the benefit of ensuring that %m in
format strings is properly resolved to the specified error number.
- A number of logging messages have been converted to use
log_unit_info() instead of log_info()
- The client code in sysv-generator no longer #includes core code from
src/core/.
- log_unit_full_errno() has been removed, log_unit_full() instead takes
an errno now, too.
- log_unit_info(), log_link_info(), log_netdev_info() and friends, now
avoid double evaluation of their parameters
2015-05-11 20:38:21 +02:00
|
|
|
log_unit_debug(u, "Unknown serialization key: %s", key);
|
2013-12-02 23:30:19 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
_pure_ static UnitActiveState busname_active_state(Unit *u) {
|
|
|
|
assert(u);
|
|
|
|
|
|
|
|
return state_translation_table[BUSNAME(u)->state];
|
|
|
|
}
|
|
|
|
|
|
|
|
_pure_ static const char *busname_sub_state_to_string(Unit *u) {
|
|
|
|
assert(u);
|
|
|
|
|
|
|
|
return busname_state_to_string(BUSNAME(u)->state);
|
|
|
|
}
|
|
|
|
|
2014-11-25 19:32:48 +01:00
|
|
|
static int busname_peek_message(BusName *n) {
|
|
|
|
struct kdbus_cmd_recv cmd_recv = {
|
2014-12-11 13:19:41 +01:00
|
|
|
.size = sizeof(cmd_recv),
|
2014-11-25 19:32:48 +01:00
|
|
|
.flags = KDBUS_RECV_PEEK,
|
|
|
|
};
|
2014-12-22 16:51:15 +01:00
|
|
|
struct kdbus_cmd_free cmd_free = {
|
|
|
|
.size = sizeof(cmd_free),
|
|
|
|
};
|
2014-11-25 19:32:48 +01:00
|
|
|
const char *comm = NULL;
|
|
|
|
struct kdbus_item *d;
|
|
|
|
struct kdbus_msg *k;
|
|
|
|
size_t start, ps, sz, delta;
|
|
|
|
void *p = NULL;
|
|
|
|
pid_t pid = 0;
|
|
|
|
int r;
|
|
|
|
|
2014-11-26 15:54:53 +01:00
|
|
|
/* Generate a friendly debug log message about which process
|
|
|
|
* caused triggering of this bus name. This simply peeks the
|
|
|
|
* metadata of the first queued message and logs it. */
|
|
|
|
|
2014-11-25 19:32:48 +01:00
|
|
|
assert(n);
|
|
|
|
|
2014-11-26 15:54:53 +01:00
|
|
|
/* Let's shortcut things a bit, if debug logging is turned off
|
|
|
|
* anyway. */
|
|
|
|
|
|
|
|
if (log_get_max_level() < LOG_DEBUG)
|
|
|
|
return 0;
|
2014-11-25 19:32:48 +01:00
|
|
|
|
2014-12-11 13:19:41 +01:00
|
|
|
r = ioctl(n->starter_fd, KDBUS_CMD_RECV, &cmd_recv);
|
2014-11-25 19:32:48 +01:00
|
|
|
if (r < 0) {
|
|
|
|
if (errno == EINTR || errno == EAGAIN)
|
|
|
|
return 0;
|
|
|
|
|
core,network: major per-object logging rework
This changes log_unit_info() (and friends) to take a real Unit* object
insted of just a unit name as parameter. The call will now prefix all
logged messages with the unit name, thus allowing the unit name to be
dropped from the various passed romat strings, simplifying invocations
drastically, and unifying log output across messages. Also, UNIT= vs.
USER_UNIT= is now derived from the Manager object attached to the Unit
object, instead of getpid(). This has the benefit of correcting the
field for --test runs.
Also contains a couple of other logging improvements:
- Drops a couple of strerror() invocations in favour of using %m.
- Not only .mount units now warn if a symlinks exist for the mount
point already, .automount units do that too, now.
- A few invocations of log_struct() that didn't actually pass any
additional structured data have been replaced by simpler invocations
of log_unit_info() and friends.
- For structured data a new LOG_UNIT_MESSAGE() macro has been added,
that works like LOG_MESSAGE() but prefixes the message with the unit
name. Similar, there's now LOG_LINK_MESSAGE() and
LOG_NETDEV_MESSAGE().
- For structured data new LOG_UNIT_ID(), LOG_LINK_INTERFACE(),
LOG_NETDEV_INTERFACE() macros have been added that generate the
necessary per object fields. The old log_unit_struct() call has been
removed in favour of these new macros used in raw log_struct()
invocations. In addition to removing one more function call this
allows generated structured log messages that contain two object
fields, as necessary for example for network interfaces that are
joined into another network interface, and whose messages shall be
indexed by both.
- The LOG_ERRNO() macro has been removed, in favour of
log_struct_errno(). The latter has the benefit of ensuring that %m in
format strings is properly resolved to the specified error number.
- A number of logging messages have been converted to use
log_unit_info() instead of log_info()
- The client code in sysv-generator no longer #includes core code from
src/core/.
- log_unit_full_errno() has been removed, log_unit_full() instead takes
an errno now, too.
- log_unit_info(), log_link_info(), log_netdev_info() and friends, now
avoid double evaluation of their parameters
2015-05-11 20:38:21 +02:00
|
|
|
return log_unit_error_errno(UNIT(n), errno, "Failed to query activation message: %m");
|
2014-11-25 19:32:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We map as late as possible, and unmap imemdiately after
|
|
|
|
* use. On 32bit address space is scarce and we want to be
|
|
|
|
* able to handle a lot of activator connections at the same
|
|
|
|
* time, and hence shouldn't keep the mmap()s around for
|
|
|
|
* longer than necessary. */
|
|
|
|
|
|
|
|
ps = page_size();
|
2015-01-12 18:15:18 +01:00
|
|
|
start = (cmd_recv.msg.offset / ps) * ps;
|
|
|
|
delta = cmd_recv.msg.offset - start;
|
|
|
|
sz = PAGE_ALIGN(delta + cmd_recv.msg.msg_size);
|
2014-11-25 19:32:48 +01:00
|
|
|
|
|
|
|
p = mmap(NULL, sz, PROT_READ, MAP_SHARED, n->starter_fd, start);
|
|
|
|
if (p == MAP_FAILED) {
|
core,network: major per-object logging rework
This changes log_unit_info() (and friends) to take a real Unit* object
insted of just a unit name as parameter. The call will now prefix all
logged messages with the unit name, thus allowing the unit name to be
dropped from the various passed romat strings, simplifying invocations
drastically, and unifying log output across messages. Also, UNIT= vs.
USER_UNIT= is now derived from the Manager object attached to the Unit
object, instead of getpid(). This has the benefit of correcting the
field for --test runs.
Also contains a couple of other logging improvements:
- Drops a couple of strerror() invocations in favour of using %m.
- Not only .mount units now warn if a symlinks exist for the mount
point already, .automount units do that too, now.
- A few invocations of log_struct() that didn't actually pass any
additional structured data have been replaced by simpler invocations
of log_unit_info() and friends.
- For structured data a new LOG_UNIT_MESSAGE() macro has been added,
that works like LOG_MESSAGE() but prefixes the message with the unit
name. Similar, there's now LOG_LINK_MESSAGE() and
LOG_NETDEV_MESSAGE().
- For structured data new LOG_UNIT_ID(), LOG_LINK_INTERFACE(),
LOG_NETDEV_INTERFACE() macros have been added that generate the
necessary per object fields. The old log_unit_struct() call has been
removed in favour of these new macros used in raw log_struct()
invocations. In addition to removing one more function call this
allows generated structured log messages that contain two object
fields, as necessary for example for network interfaces that are
joined into another network interface, and whose messages shall be
indexed by both.
- The LOG_ERRNO() macro has been removed, in favour of
log_struct_errno(). The latter has the benefit of ensuring that %m in
format strings is properly resolved to the specified error number.
- A number of logging messages have been converted to use
log_unit_info() instead of log_info()
- The client code in sysv-generator no longer #includes core code from
src/core/.
- log_unit_full_errno() has been removed, log_unit_full() instead takes
an errno now, too.
- log_unit_info(), log_link_info(), log_netdev_info() and friends, now
avoid double evaluation of their parameters
2015-05-11 20:38:21 +02:00
|
|
|
r = log_unit_error_errno(UNIT(n), errno, "Failed to map activation message: %m");
|
2014-11-25 19:32:48 +01:00
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
k = (struct kdbus_msg *) ((uint8_t *) p + delta);
|
|
|
|
KDBUS_ITEM_FOREACH(d, k, items) {
|
|
|
|
switch (d->type) {
|
|
|
|
|
|
|
|
case KDBUS_ITEM_PIDS:
|
|
|
|
pid = d->pids.pid;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KDBUS_ITEM_PID_COMM:
|
|
|
|
comm = d->str;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pid > 0)
|
core,network: major per-object logging rework
This changes log_unit_info() (and friends) to take a real Unit* object
insted of just a unit name as parameter. The call will now prefix all
logged messages with the unit name, thus allowing the unit name to be
dropped from the various passed romat strings, simplifying invocations
drastically, and unifying log output across messages. Also, UNIT= vs.
USER_UNIT= is now derived from the Manager object attached to the Unit
object, instead of getpid(). This has the benefit of correcting the
field for --test runs.
Also contains a couple of other logging improvements:
- Drops a couple of strerror() invocations in favour of using %m.
- Not only .mount units now warn if a symlinks exist for the mount
point already, .automount units do that too, now.
- A few invocations of log_struct() that didn't actually pass any
additional structured data have been replaced by simpler invocations
of log_unit_info() and friends.
- For structured data a new LOG_UNIT_MESSAGE() macro has been added,
that works like LOG_MESSAGE() but prefixes the message with the unit
name. Similar, there's now LOG_LINK_MESSAGE() and
LOG_NETDEV_MESSAGE().
- For structured data new LOG_UNIT_ID(), LOG_LINK_INTERFACE(),
LOG_NETDEV_INTERFACE() macros have been added that generate the
necessary per object fields. The old log_unit_struct() call has been
removed in favour of these new macros used in raw log_struct()
invocations. In addition to removing one more function call this
allows generated structured log messages that contain two object
fields, as necessary for example for network interfaces that are
joined into another network interface, and whose messages shall be
indexed by both.
- The LOG_ERRNO() macro has been removed, in favour of
log_struct_errno(). The latter has the benefit of ensuring that %m in
format strings is properly resolved to the specified error number.
- A number of logging messages have been converted to use
log_unit_info() instead of log_info()
- The client code in sysv-generator no longer #includes core code from
src/core/.
- log_unit_full_errno() has been removed, log_unit_full() instead takes
an errno now, too.
- log_unit_info(), log_link_info(), log_netdev_info() and friends, now
avoid double evaluation of their parameters
2015-05-11 20:38:21 +02:00
|
|
|
log_unit_debug(UNIT(n), "Activation triggered by process " PID_FMT " (%s)", pid, strna(comm));
|
2014-11-25 19:32:48 +01:00
|
|
|
|
|
|
|
r = 0;
|
|
|
|
|
|
|
|
finish:
|
|
|
|
if (p)
|
|
|
|
(void) munmap(p, sz);
|
|
|
|
|
2015-01-12 18:15:18 +01:00
|
|
|
cmd_free.offset = cmd_recv.msg.offset;
|
2014-11-26 15:54:53 +01:00
|
|
|
if (ioctl(n->starter_fd, KDBUS_CMD_FREE, &cmd_free) < 0)
|
core,network: major per-object logging rework
This changes log_unit_info() (and friends) to take a real Unit* object
insted of just a unit name as parameter. The call will now prefix all
logged messages with the unit name, thus allowing the unit name to be
dropped from the various passed romat strings, simplifying invocations
drastically, and unifying log output across messages. Also, UNIT= vs.
USER_UNIT= is now derived from the Manager object attached to the Unit
object, instead of getpid(). This has the benefit of correcting the
field for --test runs.
Also contains a couple of other logging improvements:
- Drops a couple of strerror() invocations in favour of using %m.
- Not only .mount units now warn if a symlinks exist for the mount
point already, .automount units do that too, now.
- A few invocations of log_struct() that didn't actually pass any
additional structured data have been replaced by simpler invocations
of log_unit_info() and friends.
- For structured data a new LOG_UNIT_MESSAGE() macro has been added,
that works like LOG_MESSAGE() but prefixes the message with the unit
name. Similar, there's now LOG_LINK_MESSAGE() and
LOG_NETDEV_MESSAGE().
- For structured data new LOG_UNIT_ID(), LOG_LINK_INTERFACE(),
LOG_NETDEV_INTERFACE() macros have been added that generate the
necessary per object fields. The old log_unit_struct() call has been
removed in favour of these new macros used in raw log_struct()
invocations. In addition to removing one more function call this
allows generated structured log messages that contain two object
fields, as necessary for example for network interfaces that are
joined into another network interface, and whose messages shall be
indexed by both.
- The LOG_ERRNO() macro has been removed, in favour of
log_struct_errno(). The latter has the benefit of ensuring that %m in
format strings is properly resolved to the specified error number.
- A number of logging messages have been converted to use
log_unit_info() instead of log_info()
- The client code in sysv-generator no longer #includes core code from
src/core/.
- log_unit_full_errno() has been removed, log_unit_full() instead takes
an errno now, too.
- log_unit_info(), log_link_info(), log_netdev_info() and friends, now
avoid double evaluation of their parameters
2015-05-11 20:38:21 +02:00
|
|
|
log_unit_warning(UNIT(n), "Failed to free peeked message, ignoring: %m");
|
2014-11-25 19:32:48 +01:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2013-12-02 23:30:19 +01:00
|
|
|
static int busname_dispatch_io(sd_event_source *source, int fd, uint32_t revents, void *userdata) {
|
|
|
|
BusName *n = userdata;
|
|
|
|
|
|
|
|
assert(n);
|
|
|
|
assert(fd >= 0);
|
|
|
|
|
|
|
|
if (n->state != BUSNAME_LISTENING)
|
|
|
|
return 0;
|
|
|
|
|
core,network: major per-object logging rework
This changes log_unit_info() (and friends) to take a real Unit* object
insted of just a unit name as parameter. The call will now prefix all
logged messages with the unit name, thus allowing the unit name to be
dropped from the various passed romat strings, simplifying invocations
drastically, and unifying log output across messages. Also, UNIT= vs.
USER_UNIT= is now derived from the Manager object attached to the Unit
object, instead of getpid(). This has the benefit of correcting the
field for --test runs.
Also contains a couple of other logging improvements:
- Drops a couple of strerror() invocations in favour of using %m.
- Not only .mount units now warn if a symlinks exist for the mount
point already, .automount units do that too, now.
- A few invocations of log_struct() that didn't actually pass any
additional structured data have been replaced by simpler invocations
of log_unit_info() and friends.
- For structured data a new LOG_UNIT_MESSAGE() macro has been added,
that works like LOG_MESSAGE() but prefixes the message with the unit
name. Similar, there's now LOG_LINK_MESSAGE() and
LOG_NETDEV_MESSAGE().
- For structured data new LOG_UNIT_ID(), LOG_LINK_INTERFACE(),
LOG_NETDEV_INTERFACE() macros have been added that generate the
necessary per object fields. The old log_unit_struct() call has been
removed in favour of these new macros used in raw log_struct()
invocations. In addition to removing one more function call this
allows generated structured log messages that contain two object
fields, as necessary for example for network interfaces that are
joined into another network interface, and whose messages shall be
indexed by both.
- The LOG_ERRNO() macro has been removed, in favour of
log_struct_errno(). The latter has the benefit of ensuring that %m in
format strings is properly resolved to the specified error number.
- A number of logging messages have been converted to use
log_unit_info() instead of log_info()
- The client code in sysv-generator no longer #includes core code from
src/core/.
- log_unit_full_errno() has been removed, log_unit_full() instead takes
an errno now, too.
- log_unit_info(), log_link_info(), log_netdev_info() and friends, now
avoid double evaluation of their parameters
2015-05-11 20:38:21 +02:00
|
|
|
log_unit_debug(UNIT(n), "Activation request");
|
2013-12-02 23:30:19 +01:00
|
|
|
|
|
|
|
if (revents != EPOLLIN) {
|
core,network: major per-object logging rework
This changes log_unit_info() (and friends) to take a real Unit* object
insted of just a unit name as parameter. The call will now prefix all
logged messages with the unit name, thus allowing the unit name to be
dropped from the various passed romat strings, simplifying invocations
drastically, and unifying log output across messages. Also, UNIT= vs.
USER_UNIT= is now derived from the Manager object attached to the Unit
object, instead of getpid(). This has the benefit of correcting the
field for --test runs.
Also contains a couple of other logging improvements:
- Drops a couple of strerror() invocations in favour of using %m.
- Not only .mount units now warn if a symlinks exist for the mount
point already, .automount units do that too, now.
- A few invocations of log_struct() that didn't actually pass any
additional structured data have been replaced by simpler invocations
of log_unit_info() and friends.
- For structured data a new LOG_UNIT_MESSAGE() macro has been added,
that works like LOG_MESSAGE() but prefixes the message with the unit
name. Similar, there's now LOG_LINK_MESSAGE() and
LOG_NETDEV_MESSAGE().
- For structured data new LOG_UNIT_ID(), LOG_LINK_INTERFACE(),
LOG_NETDEV_INTERFACE() macros have been added that generate the
necessary per object fields. The old log_unit_struct() call has been
removed in favour of these new macros used in raw log_struct()
invocations. In addition to removing one more function call this
allows generated structured log messages that contain two object
fields, as necessary for example for network interfaces that are
joined into another network interface, and whose messages shall be
indexed by both.
- The LOG_ERRNO() macro has been removed, in favour of
log_struct_errno(). The latter has the benefit of ensuring that %m in
format strings is properly resolved to the specified error number.
- A number of logging messages have been converted to use
log_unit_info() instead of log_info()
- The client code in sysv-generator no longer #includes core code from
src/core/.
- log_unit_full_errno() has been removed, log_unit_full() instead takes
an errno now, too.
- log_unit_info(), log_link_info(), log_netdev_info() and friends, now
avoid double evaluation of their parameters
2015-05-11 20:38:21 +02:00
|
|
|
log_unit_error(UNIT(n), "Got unexpected poll event (0x%x) on starter fd.", revents);
|
2013-12-02 23:30:19 +01:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2014-11-25 19:32:48 +01:00
|
|
|
busname_peek_message(n);
|
2013-12-02 23:30:19 +01:00
|
|
|
busname_enter_running(n);
|
|
|
|
return 0;
|
|
|
|
fail:
|
|
|
|
|
|
|
|
busname_enter_dead(n, BUSNAME_FAILURE_RESOURCES);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-05 12:24:03 +02:00
|
|
|
static void busname_sigchld_event(Unit *u, pid_t pid, int code, int status) {
|
|
|
|
BusName *n = BUSNAME(u);
|
|
|
|
BusNameResult f;
|
|
|
|
|
|
|
|
assert(n);
|
|
|
|
assert(pid >= 0);
|
|
|
|
|
|
|
|
if (pid != n->control_pid)
|
|
|
|
return;
|
|
|
|
|
|
|
|
n->control_pid = 0;
|
|
|
|
|
2016-10-10 22:07:30 +02:00
|
|
|
if (is_clean_exit(code, status, EXIT_CLEAN_COMMAND, NULL))
|
2014-06-05 12:24:03 +02:00
|
|
|
f = BUSNAME_SUCCESS;
|
|
|
|
else if (code == CLD_EXITED)
|
|
|
|
f = BUSNAME_FAILURE_EXIT_CODE;
|
|
|
|
else if (code == CLD_KILLED)
|
|
|
|
f = BUSNAME_FAILURE_SIGNAL;
|
2014-07-25 10:44:27 +02:00
|
|
|
else if (code == CLD_DUMPED)
|
2014-06-05 12:24:03 +02:00
|
|
|
f = BUSNAME_FAILURE_CORE_DUMP;
|
|
|
|
else
|
|
|
|
assert_not_reached("Unknown sigchld code");
|
|
|
|
|
core,network: major per-object logging rework
This changes log_unit_info() (and friends) to take a real Unit* object
insted of just a unit name as parameter. The call will now prefix all
logged messages with the unit name, thus allowing the unit name to be
dropped from the various passed romat strings, simplifying invocations
drastically, and unifying log output across messages. Also, UNIT= vs.
USER_UNIT= is now derived from the Manager object attached to the Unit
object, instead of getpid(). This has the benefit of correcting the
field for --test runs.
Also contains a couple of other logging improvements:
- Drops a couple of strerror() invocations in favour of using %m.
- Not only .mount units now warn if a symlinks exist for the mount
point already, .automount units do that too, now.
- A few invocations of log_struct() that didn't actually pass any
additional structured data have been replaced by simpler invocations
of log_unit_info() and friends.
- For structured data a new LOG_UNIT_MESSAGE() macro has been added,
that works like LOG_MESSAGE() but prefixes the message with the unit
name. Similar, there's now LOG_LINK_MESSAGE() and
LOG_NETDEV_MESSAGE().
- For structured data new LOG_UNIT_ID(), LOG_LINK_INTERFACE(),
LOG_NETDEV_INTERFACE() macros have been added that generate the
necessary per object fields. The old log_unit_struct() call has been
removed in favour of these new macros used in raw log_struct()
invocations. In addition to removing one more function call this
allows generated structured log messages that contain two object
fields, as necessary for example for network interfaces that are
joined into another network interface, and whose messages shall be
indexed by both.
- The LOG_ERRNO() macro has been removed, in favour of
log_struct_errno(). The latter has the benefit of ensuring that %m in
format strings is properly resolved to the specified error number.
- A number of logging messages have been converted to use
log_unit_info() instead of log_info()
- The client code in sysv-generator no longer #includes core code from
src/core/.
- log_unit_full_errno() has been removed, log_unit_full() instead takes
an errno now, too.
- log_unit_info(), log_link_info(), log_netdev_info() and friends, now
avoid double evaluation of their parameters
2015-05-11 20:38:21 +02:00
|
|
|
log_unit_full(u, f == BUSNAME_SUCCESS ? LOG_DEBUG : LOG_NOTICE, 0,
|
|
|
|
"Control process exited, code=%s status=%i", sigchld_code_to_string(code), status);
|
2014-06-05 12:24:03 +02:00
|
|
|
|
core: remember first unit failure, not last unit failure
Previously, the result value of a unit was overriden with each failure that
took place, so that the result always reported the last failure that took
place.
With this commit this is changed, so that the first failure taking place is
stored instead. This should normally not matter much as multiple failures are
sufficiently uncommon. However, it improves one behaviour: if we send SIGABRT
to a service due to a watchdog timeout, then this currently would be reported
as "coredump" failure, rather than the "watchodg" failure it really is. Hence,
in order to report information about the type of the failure, and not about
the effect of it, let's change this from all unit type to store the first, not
the last failure.
This addresses the issue pointed out here:
https://github.com/systemd/systemd/pull/3818#discussion_r73433520
2016-08-04 21:14:27 +02:00
|
|
|
if (n->result == BUSNAME_SUCCESS)
|
2014-06-05 12:24:03 +02:00
|
|
|
n->result = f;
|
|
|
|
|
|
|
|
switch (n->state) {
|
|
|
|
|
|
|
|
case BUSNAME_MAKING:
|
|
|
|
if (f == BUSNAME_SUCCESS)
|
|
|
|
busname_enter_listening(n);
|
|
|
|
else
|
|
|
|
busname_enter_signal(n, BUSNAME_SIGTERM, f);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BUSNAME_SIGTERM:
|
|
|
|
case BUSNAME_SIGKILL:
|
|
|
|
busname_enter_dead(n, f);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert_not_reached("Uh, control process died at wrong time.");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Notify clients about changed exit status */
|
|
|
|
unit_add_to_dbus_queue(u);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int busname_dispatch_timer(sd_event_source *source, usec_t usec, void *userdata) {
|
|
|
|
BusName *n = BUSNAME(userdata);
|
|
|
|
|
|
|
|
assert(n);
|
|
|
|
assert(n->timer_event_source == source);
|
|
|
|
|
|
|
|
switch (n->state) {
|
|
|
|
|
|
|
|
case BUSNAME_MAKING:
|
core,network: major per-object logging rework
This changes log_unit_info() (and friends) to take a real Unit* object
insted of just a unit name as parameter. The call will now prefix all
logged messages with the unit name, thus allowing the unit name to be
dropped from the various passed romat strings, simplifying invocations
drastically, and unifying log output across messages. Also, UNIT= vs.
USER_UNIT= is now derived from the Manager object attached to the Unit
object, instead of getpid(). This has the benefit of correcting the
field for --test runs.
Also contains a couple of other logging improvements:
- Drops a couple of strerror() invocations in favour of using %m.
- Not only .mount units now warn if a symlinks exist for the mount
point already, .automount units do that too, now.
- A few invocations of log_struct() that didn't actually pass any
additional structured data have been replaced by simpler invocations
of log_unit_info() and friends.
- For structured data a new LOG_UNIT_MESSAGE() macro has been added,
that works like LOG_MESSAGE() but prefixes the message with the unit
name. Similar, there's now LOG_LINK_MESSAGE() and
LOG_NETDEV_MESSAGE().
- For structured data new LOG_UNIT_ID(), LOG_LINK_INTERFACE(),
LOG_NETDEV_INTERFACE() macros have been added that generate the
necessary per object fields. The old log_unit_struct() call has been
removed in favour of these new macros used in raw log_struct()
invocations. In addition to removing one more function call this
allows generated structured log messages that contain two object
fields, as necessary for example for network interfaces that are
joined into another network interface, and whose messages shall be
indexed by both.
- The LOG_ERRNO() macro has been removed, in favour of
log_struct_errno(). The latter has the benefit of ensuring that %m in
format strings is properly resolved to the specified error number.
- A number of logging messages have been converted to use
log_unit_info() instead of log_info()
- The client code in sysv-generator no longer #includes core code from
src/core/.
- log_unit_full_errno() has been removed, log_unit_full() instead takes
an errno now, too.
- log_unit_info(), log_link_info(), log_netdev_info() and friends, now
avoid double evaluation of their parameters
2015-05-11 20:38:21 +02:00
|
|
|
log_unit_warning(UNIT(n), "Making timed out. Terminating.");
|
2014-06-05 12:24:03 +02:00
|
|
|
busname_enter_signal(n, BUSNAME_SIGTERM, BUSNAME_FAILURE_TIMEOUT);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BUSNAME_SIGTERM:
|
core,network: major per-object logging rework
This changes log_unit_info() (and friends) to take a real Unit* object
insted of just a unit name as parameter. The call will now prefix all
logged messages with the unit name, thus allowing the unit name to be
dropped from the various passed romat strings, simplifying invocations
drastically, and unifying log output across messages. Also, UNIT= vs.
USER_UNIT= is now derived from the Manager object attached to the Unit
object, instead of getpid(). This has the benefit of correcting the
field for --test runs.
Also contains a couple of other logging improvements:
- Drops a couple of strerror() invocations in favour of using %m.
- Not only .mount units now warn if a symlinks exist for the mount
point already, .automount units do that too, now.
- A few invocations of log_struct() that didn't actually pass any
additional structured data have been replaced by simpler invocations
of log_unit_info() and friends.
- For structured data a new LOG_UNIT_MESSAGE() macro has been added,
that works like LOG_MESSAGE() but prefixes the message with the unit
name. Similar, there's now LOG_LINK_MESSAGE() and
LOG_NETDEV_MESSAGE().
- For structured data new LOG_UNIT_ID(), LOG_LINK_INTERFACE(),
LOG_NETDEV_INTERFACE() macros have been added that generate the
necessary per object fields. The old log_unit_struct() call has been
removed in favour of these new macros used in raw log_struct()
invocations. In addition to removing one more function call this
allows generated structured log messages that contain two object
fields, as necessary for example for network interfaces that are
joined into another network interface, and whose messages shall be
indexed by both.
- The LOG_ERRNO() macro has been removed, in favour of
log_struct_errno(). The latter has the benefit of ensuring that %m in
format strings is properly resolved to the specified error number.
- A number of logging messages have been converted to use
log_unit_info() instead of log_info()
- The client code in sysv-generator no longer #includes core code from
src/core/.
- log_unit_full_errno() has been removed, log_unit_full() instead takes
an errno now, too.
- log_unit_info(), log_link_info(), log_netdev_info() and friends, now
avoid double evaluation of their parameters
2015-05-11 20:38:21 +02:00
|
|
|
log_unit_warning(UNIT(n), "Stopping timed out. Killing.");
|
2014-06-05 12:24:03 +02:00
|
|
|
busname_enter_signal(n, BUSNAME_SIGKILL, BUSNAME_FAILURE_TIMEOUT);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BUSNAME_SIGKILL:
|
core,network: major per-object logging rework
This changes log_unit_info() (and friends) to take a real Unit* object
insted of just a unit name as parameter. The call will now prefix all
logged messages with the unit name, thus allowing the unit name to be
dropped from the various passed romat strings, simplifying invocations
drastically, and unifying log output across messages. Also, UNIT= vs.
USER_UNIT= is now derived from the Manager object attached to the Unit
object, instead of getpid(). This has the benefit of correcting the
field for --test runs.
Also contains a couple of other logging improvements:
- Drops a couple of strerror() invocations in favour of using %m.
- Not only .mount units now warn if a symlinks exist for the mount
point already, .automount units do that too, now.
- A few invocations of log_struct() that didn't actually pass any
additional structured data have been replaced by simpler invocations
of log_unit_info() and friends.
- For structured data a new LOG_UNIT_MESSAGE() macro has been added,
that works like LOG_MESSAGE() but prefixes the message with the unit
name. Similar, there's now LOG_LINK_MESSAGE() and
LOG_NETDEV_MESSAGE().
- For structured data new LOG_UNIT_ID(), LOG_LINK_INTERFACE(),
LOG_NETDEV_INTERFACE() macros have been added that generate the
necessary per object fields. The old log_unit_struct() call has been
removed in favour of these new macros used in raw log_struct()
invocations. In addition to removing one more function call this
allows generated structured log messages that contain two object
fields, as necessary for example for network interfaces that are
joined into another network interface, and whose messages shall be
indexed by both.
- The LOG_ERRNO() macro has been removed, in favour of
log_struct_errno(). The latter has the benefit of ensuring that %m in
format strings is properly resolved to the specified error number.
- A number of logging messages have been converted to use
log_unit_info() instead of log_info()
- The client code in sysv-generator no longer #includes core code from
src/core/.
- log_unit_full_errno() has been removed, log_unit_full() instead takes
an errno now, too.
- log_unit_info(), log_link_info(), log_netdev_info() and friends, now
avoid double evaluation of their parameters
2015-05-11 20:38:21 +02:00
|
|
|
log_unit_warning(UNIT(n), "Processes still around after SIGKILL. Ignoring.");
|
2014-06-05 12:24:03 +02:00
|
|
|
busname_enter_dead(n, BUSNAME_FAILURE_TIMEOUT);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert_not_reached("Timeout at wrong time.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-12-02 23:30:19 +01:00
|
|
|
static void busname_reset_failed(Unit *u) {
|
|
|
|
BusName *n = BUSNAME(u);
|
|
|
|
|
|
|
|
assert(n);
|
|
|
|
|
|
|
|
if (n->state == BUSNAME_FAILED)
|
|
|
|
busname_set_state(n, BUSNAME_DEAD);
|
|
|
|
|
|
|
|
n->result = BUSNAME_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void busname_trigger_notify(Unit *u, Unit *other) {
|
|
|
|
BusName *n = BUSNAME(u);
|
|
|
|
|
|
|
|
assert(n);
|
|
|
|
assert(other);
|
|
|
|
|
|
|
|
if (!IN_SET(n->state, BUSNAME_RUNNING, BUSNAME_LISTENING))
|
|
|
|
return;
|
|
|
|
|
core: make the StartLimitXYZ= settings generic and apply to any kind of unit, not just services
This moves the StartLimitBurst=, StartLimitInterval=, StartLimitAction=, RebootArgument= from the [Service] section
into the [Unit] section of unit files, and thus support it in all unit types, not just in services.
This way we can enforce the start limit much earlier, in particular before testing the unit conditions, so that
repeated start-up failure due to failed conditions is also considered for the start limit logic.
For compatibility the four options may also be configured in the [Service] section still, but we only document them in
their new section [Unit].
This also renamed the socket unit failure code "service-failed-permanent" into "service-start-limit-hit" to express
more clearly what it is about, after all it's only triggered through the start limit being hit.
Finally, the code in busname_trigger_notify() and socket_trigger_notify() is altered to become more alike.
Fixes: #2467
2016-02-09 18:38:03 +01:00
|
|
|
if (other->start_limit_hit) {
|
|
|
|
busname_enter_dead(n, BUSNAME_FAILURE_SERVICE_START_LIMIT_HIT);
|
2013-12-02 23:30:19 +01:00
|
|
|
return;
|
core: make the StartLimitXYZ= settings generic and apply to any kind of unit, not just services
This moves the StartLimitBurst=, StartLimitInterval=, StartLimitAction=, RebootArgument= from the [Service] section
into the [Unit] section of unit files, and thus support it in all unit types, not just in services.
This way we can enforce the start limit much earlier, in particular before testing the unit conditions, so that
repeated start-up failure due to failed conditions is also considered for the start limit logic.
For compatibility the four options may also be configured in the [Service] section still, but we only document them in
their new section [Unit].
This also renamed the socket unit failure code "service-failed-permanent" into "service-start-limit-hit" to express
more clearly what it is about, after all it's only triggered through the start limit being hit.
Finally, the code in busname_trigger_notify() and socket_trigger_notify() is altered to become more alike.
Fixes: #2467
2016-02-09 18:38:03 +01:00
|
|
|
}
|
2013-12-02 23:30:19 +01:00
|
|
|
|
core: make the StartLimitXYZ= settings generic and apply to any kind of unit, not just services
This moves the StartLimitBurst=, StartLimitInterval=, StartLimitAction=, RebootArgument= from the [Service] section
into the [Unit] section of unit files, and thus support it in all unit types, not just in services.
This way we can enforce the start limit much earlier, in particular before testing the unit conditions, so that
repeated start-up failure due to failed conditions is also considered for the start limit logic.
For compatibility the four options may also be configured in the [Service] section still, but we only document them in
their new section [Unit].
This also renamed the socket unit failure code "service-failed-permanent" into "service-start-limit-hit" to express
more clearly what it is about, after all it's only triggered through the start limit being hit.
Finally, the code in busname_trigger_notify() and socket_trigger_notify() is altered to become more alike.
Fixes: #2467
2016-02-09 18:38:03 +01:00
|
|
|
if (other->load_state != UNIT_LOADED || other->type != UNIT_SERVICE)
|
|
|
|
return;
|
2013-12-02 23:30:19 +01:00
|
|
|
|
core: make the StartLimitXYZ= settings generic and apply to any kind of unit, not just services
This moves the StartLimitBurst=, StartLimitInterval=, StartLimitAction=, RebootArgument= from the [Service] section
into the [Unit] section of unit files, and thus support it in all unit types, not just in services.
This way we can enforce the start limit much earlier, in particular before testing the unit conditions, so that
repeated start-up failure due to failed conditions is also considered for the start limit logic.
For compatibility the four options may also be configured in the [Service] section still, but we only document them in
their new section [Unit].
This also renamed the socket unit failure code "service-failed-permanent" into "service-start-limit-hit" to express
more clearly what it is about, after all it's only triggered through the start limit being hit.
Finally, the code in busname_trigger_notify() and socket_trigger_notify() is altered to become more alike.
Fixes: #2467
2016-02-09 18:38:03 +01:00
|
|
|
if (IN_SET(SERVICE(other)->state,
|
|
|
|
SERVICE_DEAD, SERVICE_FAILED,
|
|
|
|
SERVICE_FINAL_SIGTERM, SERVICE_FINAL_SIGKILL,
|
|
|
|
SERVICE_AUTO_RESTART))
|
2013-12-02 23:30:19 +01:00
|
|
|
busname_enter_listening(n);
|
core: make the StartLimitXYZ= settings generic and apply to any kind of unit, not just services
This moves the StartLimitBurst=, StartLimitInterval=, StartLimitAction=, RebootArgument= from the [Service] section
into the [Unit] section of unit files, and thus support it in all unit types, not just in services.
This way we can enforce the start limit much earlier, in particular before testing the unit conditions, so that
repeated start-up failure due to failed conditions is also considered for the start limit logic.
For compatibility the four options may also be configured in the [Service] section still, but we only document them in
their new section [Unit].
This also renamed the socket unit failure code "service-failed-permanent" into "service-start-limit-hit" to express
more clearly what it is about, after all it's only triggered through the start limit being hit.
Finally, the code in busname_trigger_notify() and socket_trigger_notify() is altered to become more alike.
Fixes: #2467
2016-02-09 18:38:03 +01:00
|
|
|
|
|
|
|
if (SERVICE(other)->state == SERVICE_RUNNING)
|
|
|
|
busname_set_state(n, BUSNAME_RUNNING);
|
2013-12-02 23:30:19 +01:00
|
|
|
}
|
|
|
|
|
2014-06-05 12:24:03 +02:00
|
|
|
static int busname_kill(Unit *u, KillWho who, int signo, sd_bus_error *error) {
|
|
|
|
return unit_kill_common(u, who, signo, -1, BUSNAME(u)->control_pid, error);
|
|
|
|
}
|
|
|
|
|
2016-02-04 00:35:43 +01:00
|
|
|
static int busname_get_timeout(Unit *u, usec_t *timeout) {
|
2014-06-05 12:24:03 +02:00
|
|
|
BusName *n = BUSNAME(u);
|
2016-02-04 00:35:43 +01:00
|
|
|
usec_t t;
|
2014-06-05 12:24:03 +02:00
|
|
|
int r;
|
|
|
|
|
|
|
|
if (!n->timer_event_source)
|
|
|
|
return 0;
|
|
|
|
|
2016-02-04 00:35:43 +01:00
|
|
|
r = sd_event_source_get_time(n->timer_event_source, &t);
|
2014-06-05 12:24:03 +02:00
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2016-02-04 00:35:43 +01:00
|
|
|
if (t == USEC_INFINITY)
|
|
|
|
return 0;
|
2014-06-05 12:24:03 +02:00
|
|
|
|
2016-02-04 00:35:43 +01:00
|
|
|
*timeout = t;
|
2014-06-05 12:24:03 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-04-30 01:29:00 +02:00
|
|
|
static bool busname_supported(void) {
|
2016-06-10 15:50:16 +02:00
|
|
|
return false;
|
2014-12-12 21:05:32 +01:00
|
|
|
}
|
|
|
|
|
2016-04-20 15:28:28 +02:00
|
|
|
static int busname_control_pid(Unit *u) {
|
|
|
|
BusName *n = BUSNAME(u);
|
|
|
|
|
|
|
|
assert(n);
|
|
|
|
|
|
|
|
return n->control_pid;
|
|
|
|
}
|
|
|
|
|
2013-12-02 23:30:19 +01:00
|
|
|
static const char* const busname_result_table[_BUSNAME_RESULT_MAX] = {
|
|
|
|
[BUSNAME_SUCCESS] = "success",
|
|
|
|
[BUSNAME_FAILURE_RESOURCES] = "resources",
|
2014-06-05 12:24:03 +02:00
|
|
|
[BUSNAME_FAILURE_TIMEOUT] = "timeout",
|
|
|
|
[BUSNAME_FAILURE_EXIT_CODE] = "exit-code",
|
|
|
|
[BUSNAME_FAILURE_SIGNAL] = "signal",
|
|
|
|
[BUSNAME_FAILURE_CORE_DUMP] = "core-dump",
|
core: move enforcement of the start limit into per-unit-type code again
Let's move the enforcement of the per-unit start limit from unit.c into the
type-specific files again. For unit types that know a concept of "result" codes
this allows us to hook up the start limit condition to it with an explicit
result code. Also, this makes sure that the state checks in clal like
service_start() may be done before the start limit is checked, as the start
limit really should be checked last, right before everything has been verified
to be in order.
The generic start limit logic is left in unit.c, but the invocation of it is
moved into the per-type files, in the various xyz_start() functions, so that
they may place the check at the right location.
Note that this change drops the enforcement entirely from device, slice, target
and scope units, since these unit types generally may not fail activation, or
may only be activated a single time. This is also documented now.
Note that restores the "start-limit-hit" result code that existed before
6bf0f408e4833152197fb38fb10a9989c89f3a59 already in the service code. However,
it's not introduced for all units that have a result code concept.
Fixes #3166.
2016-05-02 13:01:26 +02:00
|
|
|
[BUSNAME_FAILURE_START_LIMIT_HIT] = "start-limit-hit",
|
core: make the StartLimitXYZ= settings generic and apply to any kind of unit, not just services
This moves the StartLimitBurst=, StartLimitInterval=, StartLimitAction=, RebootArgument= from the [Service] section
into the [Unit] section of unit files, and thus support it in all unit types, not just in services.
This way we can enforce the start limit much earlier, in particular before testing the unit conditions, so that
repeated start-up failure due to failed conditions is also considered for the start limit logic.
For compatibility the four options may also be configured in the [Service] section still, but we only document them in
their new section [Unit].
This also renamed the socket unit failure code "service-failed-permanent" into "service-start-limit-hit" to express
more clearly what it is about, after all it's only triggered through the start limit being hit.
Finally, the code in busname_trigger_notify() and socket_trigger_notify() is altered to become more alike.
Fixes: #2467
2016-02-09 18:38:03 +01:00
|
|
|
[BUSNAME_FAILURE_SERVICE_START_LIMIT_HIT] = "service-start-limit-hit",
|
2013-12-02 23:30:19 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
DEFINE_STRING_TABLE_LOOKUP(busname_result, BusNameResult);
|
|
|
|
|
|
|
|
const UnitVTable busname_vtable = {
|
|
|
|
.object_size = sizeof(BusName),
|
|
|
|
|
|
|
|
.sections =
|
|
|
|
"Unit\0"
|
|
|
|
"BusName\0"
|
|
|
|
"Install\0",
|
|
|
|
.private_section = "BusName",
|
|
|
|
|
|
|
|
.init = busname_init,
|
|
|
|
.done = busname_done,
|
|
|
|
.load = busname_load,
|
|
|
|
|
|
|
|
.coldplug = busname_coldplug,
|
|
|
|
|
|
|
|
.dump = busname_dump,
|
|
|
|
|
|
|
|
.start = busname_start,
|
|
|
|
.stop = busname_stop,
|
|
|
|
|
2014-06-05 12:24:03 +02:00
|
|
|
.kill = busname_kill,
|
|
|
|
|
|
|
|
.get_timeout = busname_get_timeout,
|
|
|
|
|
2013-12-02 23:30:19 +01:00
|
|
|
.serialize = busname_serialize,
|
|
|
|
.deserialize_item = busname_deserialize_item,
|
|
|
|
|
|
|
|
.active_state = busname_active_state,
|
|
|
|
.sub_state_to_string = busname_sub_state_to_string,
|
|
|
|
|
2014-06-05 12:24:03 +02:00
|
|
|
.sigchld_event = busname_sigchld_event,
|
|
|
|
|
2013-12-02 23:30:19 +01:00
|
|
|
.trigger_notify = busname_trigger_notify,
|
|
|
|
|
|
|
|
.reset_failed = busname_reset_failed,
|
|
|
|
|
2014-12-12 21:05:32 +01:00
|
|
|
.supported = busname_supported,
|
|
|
|
|
2016-04-20 15:28:28 +02:00
|
|
|
.control_pid = busname_control_pid,
|
|
|
|
|
2013-12-02 23:30:19 +01:00
|
|
|
.bus_vtable = bus_busname_vtable,
|
|
|
|
|
|
|
|
.status_message_formats = {
|
|
|
|
.finished_start_job = {
|
|
|
|
[JOB_DONE] = "Listening on %s.",
|
|
|
|
[JOB_FAILED] = "Failed to listen on %s.",
|
|
|
|
},
|
|
|
|
.finished_stop_job = {
|
|
|
|
[JOB_DONE] = "Closed %s.",
|
|
|
|
[JOB_FAILED] = "Failed stopping %s.",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|