chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
build-sys: set SYSTEMD_SKIP_API_MOUNTS=1 when generating introspection files
[elogind.git]
/
src
/
service.c
diff --git
a/src/service.c
b/src/service.c
index ecfd054105a2b07fa4784554711773158d17c68e..f173d8a2d5e8636dbbe3c4d14faf888beaeef61f 100644
(file)
--- a/
src/service.c
+++ b/
src/service.c
@@
-33,10
+33,10
@@
#include "unit-name.h"
#include "dbus-service.h"
#include "special.h"
#include "unit-name.h"
#include "dbus-service.h"
#include "special.h"
+#include "bus-errors.h"
#define COMMENTS "#;\n"
#define NEWLINES "\n\r"
#define COMMENTS "#;\n"
#define NEWLINES "\n\r"
-#define LINE_MAX 4096
typedef enum RunlevelType {
RUNLEVEL_UP,
typedef enum RunlevelType {
RUNLEVEL_UP,
@@
-527,7
+527,7
@@
static int service_load_sysv_path(Service *s, const char *path) {
state = LSB;
state = LSB;
- FOREACH_WORD(w, z, t+9, i) {
+ FOREACH_WORD
_QUOTED
(w, z, t+9, i) {
char *n, *m;
if (!(n = strndup(w, z))) {
char *n, *m;
if (!(n = strndup(w, z))) {
@@
-564,7
+564,7
@@
static int service_load_sysv_path(Service *s, const char *path) {
state = LSB;
state = LSB;
- FOREACH_WORD(w, z, strchr(t, ':')+1, i) {
+ FOREACH_WORD
_QUOTED
(w, z, strchr(t, ':')+1, i) {
char *n, *m;
if (!(n = strndup(w, z))) {
char *n, *m;
if (!(n = strndup(w, z))) {
@@
-686,6
+686,7
@@
static int service_load_sysv_path(Service *s, const char *path) {
s->valid_no_process = true;
s->kill_mode = KILL_PROCESS_GROUP;
s->restart = SERVICE_ONCE;
s->valid_no_process = true;
s->kill_mode = KILL_PROCESS_GROUP;
s->restart = SERVICE_ONCE;
+ s->exec_context.std_output = EXEC_OUTPUT_TTY;
u->meta.load_state = UNIT_LOADED;
r = 0;
u->meta.load_state = UNIT_LOADED;
r = 0;
@@
-1322,14
+1323,15
@@
static int service_spawn(
bool pass_fds,
bool apply_permissions,
bool apply_chroot,
bool pass_fds,
bool apply_permissions,
bool apply_chroot,
+ bool apply_tty_stdin,
bool set_notify_socket,
pid_t *_pid) {
pid_t pid;
int r;
int *fds = NULL, *fdsbuf = NULL;
bool set_notify_socket,
pid_t *_pid) {
pid_t pid;
int r;
int *fds = NULL, *fdsbuf = NULL;
- unsigned n_fds = 0;
- char **argv = NULL, **env = NULL;
+ unsigned n_fds = 0
, n_env = 0
;
+ char **argv = NULL, **
final_env = NULL, **our_
env = NULL;
assert(s);
assert(c);
assert(s);
assert(c);
@@
-1362,63
+1364,65
@@
static int service_spawn(
goto fail;
}
goto fail;
}
- if (set_notify_socket) {
- char *t;
+ if (!(our_env = new0(char*, 3))) {
+ r = -ENOMEM;
+ goto fail;
+ }
- if (asprintf(&t, "NOTIFY_SOCKET=@%s", s->meta.manager->notify_socket) < 0) {
+ if (set_notify_socket)
+ if (asprintf(our_env + n_env++, "NOTIFY_SOCKET=@%s", s->meta.manager->notify_socket) < 0) {
r = -ENOMEM;
goto fail;
}
r = -ENOMEM;
goto fail;
}
- env = strv_env_set(s->meta.manager->environment, t);
- free(t);
-
- if (!env) {
+ if (s->main_pid > 0)
+ if (asprintf(our_env + n_env++, "MAINPID=%lu", (unsigned long) s->main_pid) < 0) {
r = -ENOMEM;
goto fail;
}
r = -ENOMEM;
goto fail;
}
- } else
- env = s->meta.manager->environment;
+
+ if (!(final_env = strv_env_merge(2,
+ s->meta.manager->environment,
+ our_env,
+ NULL))) {
+ r = -ENOMEM;
+ goto fail;
+ }
r = exec_spawn(c,
argv,
&s->exec_context,
fds, n_fds,
r = exec_spawn(c,
argv,
&s->exec_context,
fds, n_fds,
- env,
+
final_
env,
apply_permissions,
apply_chroot,
apply_permissions,
apply_chroot,
+ apply_tty_stdin,
s->meta.manager->confirm_spawn,
s->meta.cgroup_bondings,
&pid);
s->meta.manager->confirm_spawn,
s->meta.cgroup_bondings,
&pid);
- strv_free(argv);
- argv = NULL;
-
- if (set_notify_socket)
- strv_free(env);
- env = NULL;
-
if (r < 0)
goto fail;
if (r < 0)
goto fail;
- if (fdsbuf)
- free(fdsbuf);
if ((r = unit_watch_pid(UNIT(s), pid)) < 0)
/* FIXME: we need to do something here */
goto fail;
if ((r = unit_watch_pid(UNIT(s), pid)) < 0)
/* FIXME: we need to do something here */
goto fail;
+ free(fdsbuf);
+ strv_free(argv);
+ strv_free(our_env);
+ strv_free(final_env);
+
*_pid = pid;
return 0;
fail:
*_pid = pid;
return 0;
fail:
- free(fds);
-
+ free(fdsbuf);
strv_free(argv);
strv_free(argv);
-
- if (set_notify_socket)
- strv_free(env);
+ strv_free(our_env);
+ strv_free(final_env);
if (timeout)
unit_unwatch_timer(UNIT(s), &s->timer_watch);
if (timeout)
unit_unwatch_timer(UNIT(s), &s->timer_watch);
@@
-1503,6
+1507,7
@@
static void service_enter_stop_post(Service *s, bool success) {
false,
!s->permissions_start_only,
!s->root_directory_start_only,
false,
!s->permissions_start_only,
!s->root_directory_start_only,
+ true,
false,
&s->control_pid)) < 0)
goto fail;
false,
&s->control_pid)) < 0)
goto fail;
@@
-1603,6
+1608,7
@@
static void service_enter_stop(Service *s, bool success) {
!s->permissions_start_only,
!s->root_directory_start_only,
false,
!s->permissions_start_only,
!s->root_directory_start_only,
false,
+ false,
&s->control_pid)) < 0)
goto fail;
&s->control_pid)) < 0)
goto fail;
@@
-1651,6
+1657,7
@@
static void service_enter_start_post(Service *s) {
!s->permissions_start_only,
!s->root_directory_start_only,
false,
!s->permissions_start_only,
!s->root_directory_start_only,
false,
+ false,
&s->control_pid)) < 0)
goto fail;
&s->control_pid)) < 0)
goto fail;
@@
-1685,6
+1692,7
@@
static void service_enter_start(Service *s) {
true,
true,
true,
true,
true,
true,
+ true,
s->notify_access != NOTIFY_NONE,
&pid)) < 0)
goto fail;
s->notify_access != NOTIFY_NONE,
&pid)) < 0)
goto fail;
@@
-1745,6
+1753,7
@@
static void service_enter_start_pre(Service *s) {
false,
!s->permissions_start_only,
!s->root_directory_start_only,
false,
!s->permissions_start_only,
!s->root_directory_start_only,
+ true,
false,
&s->control_pid)) < 0)
goto fail;
false,
&s->control_pid)) < 0)
goto fail;
@@
-1762,20
+1771,24
@@
fail:
static void service_enter_restart(Service *s) {
int r;
static void service_enter_restart(Service *s) {
int r;
+ DBusError error;
+
assert(s);
assert(s);
+ dbus_error_init(&error);
service_enter_dead(s, true, false);
service_enter_dead(s, true, false);
- if ((r = manager_add_job(s->meta.manager, JOB_START, UNIT(s), JOB_FAIL, false, NULL)) < 0)
+ if ((r = manager_add_job(s->meta.manager, JOB_START, UNIT(s), JOB_FAIL, false, NULL
, NULL
)) < 0)
goto fail;
log_debug("%s scheduled restart job.", s->meta.id);
return;
fail:
goto fail;
log_debug("%s scheduled restart job.", s->meta.id);
return;
fail:
-
- log_warning("%s failed to schedule restart job: %s", s->meta.id, strerror(-r));
+ log_warning("%s failed to schedule restart job: %s", s->meta.id, bus_error(&error, -r));
service_enter_dead(s, false, false);
service_enter_dead(s, false, false);
+
+ dbus_error_free(&error);
}
static void service_enter_reload(Service *s) {
}
static void service_enter_reload(Service *s) {
@@
-1794,6
+1807,7
@@
static void service_enter_reload(Service *s) {
!s->permissions_start_only,
!s->root_directory_start_only,
false,
!s->permissions_start_only,
!s->root_directory_start_only,
false,
+ false,
&s->control_pid)) < 0)
goto fail;
&s->control_pid)) < 0)
goto fail;
@@
-1829,6
+1843,7
@@
static void service_run_next(Service *s, bool success) {
!s->permissions_start_only,
!s->root_directory_start_only,
false,
!s->permissions_start_only,
!s->root_directory_start_only,
false,
+ false,
&s->control_pid)) < 0)
goto fail;
&s->control_pid)) < 0)
goto fail;
@@
-2085,28
+2100,28
@@
static int service_deserialize_item(Unit *u, const char *key, const char *value,
} else if (streq(key, "main-exec-status-start-realtime")) {
uint64_t k;
} else if (streq(key, "main-exec-status-start-realtime")) {
uint64_t k;
- if ((r = safe_ato
llu
(value, &k)) < 0)
+ if ((r = safe_ato
u64
(value, &k)) < 0)
log_debug("Failed to parse main-exec-status-start-realtime value %s", value);
else
s->main_exec_status.start_timestamp.realtime = (usec_t) k;
} else if (streq(key, "main-exec-status-start-monotonic")) {
uint64_t k;
log_debug("Failed to parse main-exec-status-start-realtime value %s", value);
else
s->main_exec_status.start_timestamp.realtime = (usec_t) k;
} else if (streq(key, "main-exec-status-start-monotonic")) {
uint64_t k;
- if ((r = safe_ato
llu
(value, &k)) < 0)
+ if ((r = safe_ato
u64
(value, &k)) < 0)
log_debug("Failed to parse main-exec-status-start-monotonic value %s", value);
else
s->main_exec_status.start_timestamp.monotonic = (usec_t) k;
} else if (streq(key, "main-exec-status-exit-realtime")) {
uint64_t k;
log_debug("Failed to parse main-exec-status-start-monotonic value %s", value);
else
s->main_exec_status.start_timestamp.monotonic = (usec_t) k;
} else if (streq(key, "main-exec-status-exit-realtime")) {
uint64_t k;
- if ((r = safe_ato
llu
(value, &k)) < 0)
+ if ((r = safe_ato
u64
(value, &k)) < 0)
log_debug("Failed to parse main-exec-status-exit-realtime value %s", value);
else
s->main_exec_status.exit_timestamp.realtime = (usec_t) k;
} else if (streq(key, "main-exec-status-exit-monotonic")) {
uint64_t k;
log_debug("Failed to parse main-exec-status-exit-realtime value %s", value);
else
s->main_exec_status.exit_timestamp.realtime = (usec_t) k;
} else if (streq(key, "main-exec-status-exit-monotonic")) {
uint64_t k;
- if ((r = safe_ato
llu
(value, &k)) < 0)
+ if ((r = safe_ato
u64
(value, &k)) < 0)
log_debug("Failed to parse main-exec-status-exit-monotonic value %s", value);
else
s->main_exec_status.exit_timestamp.monotonic = (usec_t) k;
log_debug("Failed to parse main-exec-status-exit-monotonic value %s", value);
else
s->main_exec_status.exit_timestamp.monotonic = (usec_t) k;
@@
-2374,7
+2389,7
@@
static void service_timer_event(Unit *u, uint64_t elapsed, Watch* w) {
break;
case SERVICE_AUTO_RESTART:
break;
case SERVICE_AUTO_RESTART:
- log_
debug
("%s holdoff time over, scheduling restart.", u->meta.id);
+ log_
info
("%s holdoff time over, scheduling restart.", u->meta.id);
service_enter_restart(s);
break;
service_enter_restart(s);
break;
@@
-2537,7
+2552,7
@@
static int service_enumerate(Manager *m) {
goto finish;
}
goto finish;
}
- if ((r = manager_load_unit_prepare(m, name, NULL, &service)) < 0) {
+ if ((r = manager_load_unit_prepare(m, name, NULL,
NULL,
&service)) < 0) {
log_warning("Failed to prepare unit %s: %s", name, strerror(-r));
continue;
}
log_warning("Failed to prepare unit %s: %s", name, strerror(-r));
continue;
}
@@
-2550,6
+2565,13
@@
static int service_enumerate(Manager *m) {
manager_dispatch_load_queue(m);
service = unit_follow_merge(service);
manager_dispatch_load_queue(m);
service = unit_follow_merge(service);
+ /* If this is a native service, rely
+ * on native ways to pull in a
+ * service, don't pull it in via sysv
+ * rcN.d links. */
+ if (service->meta.fragment_path)
+ continue;
+
if (de->d_name[0] == 'S') {
if ((r = unit_add_two_dependencies_by_name_inverse(service, UNIT_AFTER, UNIT_WANTS, rcnd_table[i].target, NULL, true)) < 0)
if (de->d_name[0] == 'S') {
if ((r = unit_add_two_dependencies_by_name_inverse(service, UNIT_AFTER, UNIT_WANTS, rcnd_table[i].target, NULL, true)) < 0)