X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;ds=sidebyside;f=src%2Fcore%2Fexecute.c;h=aad11c94aa4c6e883f1217c9229d9bb61e01c2be;hb=099a804b11072b6be9fd32b3aa1f90b393adef98;hp=c51049767d9e25524a7032837b0ce9a20f3f69c9;hpb=b92bea5d2a9481de69bb627a7b442a9f58fca43d;p=elogind.git diff --git a/src/core/execute.c b/src/core/execute.c index c51049767..aad11c94a 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -1036,15 +1036,21 @@ int exec_spawn(ExecCommand *command, return log_oom(); log_struct_unit(LOG_DEBUG, - unit_id, - "MESSAGE=About to execute %s", line, - NULL); + unit_id, + "EXECUTABLE=%s", command->path, + "MESSAGE=About to execute: %s", line, + NULL); free(line); r = cgroup_bonding_realize_list(cgroup_bondings); if (r < 0) return r; + /* We must initialize the attributes in the parent, before we + fork, because we really need them initialized before making + the process a member of the group (which we do in both the + child and the parent), and we cannot really apply them twice + (due to 'append' style attributes) */ cgroup_attribute_apply_list(cgroup_attributes, cgroup_bondings); if (context->private_tmp && !context->tmp_dir && !context->var_tmp_dir) { @@ -1267,7 +1273,12 @@ int exec_spawn(ExecCommand *command, if (cgroup_bondings && context->control_group_modify) { err = cgroup_bonding_set_group_access_list(cgroup_bondings, 0755, uid, gid); if (err >= 0) - err = cgroup_bonding_set_task_access_list(cgroup_bondings, 0644, uid, gid, context->control_group_persistent); + err = cgroup_bonding_set_task_access_list( + cgroup_bondings, + 0644, + uid, + gid, + context->control_group_persistent); if (err < 0) { r = EXIT_CGROUP; goto fail_child; @@ -1278,7 +1289,12 @@ int exec_spawn(ExecCommand *command, } if (cgroup_bondings && !set_access && context->control_group_persistent >= 0) { - err = cgroup_bonding_set_task_access_list(cgroup_bondings, (mode_t) -1, (uid_t) -1, (uid_t) -1, context->control_group_persistent); + err = cgroup_bonding_set_task_access_list( + cgroup_bondings, + (mode_t) -1, + (uid_t) -1, + (uid_t) -1, + context->control_group_persistent); if (err < 0) { r = EXIT_CGROUP; goto fail_child; @@ -1501,6 +1517,20 @@ int exec_spawn(ExecCommand *command, final_env = strv_env_clean(final_env); + if (_unlikely_(log_get_max_level() >= LOG_PRI(LOG_DEBUG))) { + line = exec_command_line(final_argv); + if (line) { + log_open(); + log_struct_unit(LOG_DEBUG, + unit_id, + "EXECUTABLE=%s", command->path, + "MESSAGE=Executing: %s", line, + NULL); + log_close(); + free(line); + line = NULL; + } + } execve(command->path, final_argv, final_env); err = -errno; r = EXIT_EXEC; @@ -1532,8 +1562,7 @@ int exec_spawn(ExecCommand *command, * outside of the cgroup) and in the parent (so that we can be * sure that when we kill the cgroup the process will be * killed too). */ - if (cgroup_bondings) - cgroup_bonding_install_list(cgroup_bondings, pid, cgroup_suffix); + cgroup_bonding_install_list(cgroup_bondings, pid, cgroup_suffix); exec_status_start(&command->exec_status, pid); @@ -1698,7 +1727,7 @@ int exec_context_load_environment(const ExecContext *c, char ***l) { int k; bool ignore = false; char **p; - glob_t pglob = {}; + glob_t _cleanup_globfree_ pglob = {}; int count, n; fn = *i; @@ -1709,7 +1738,6 @@ int exec_context_load_environment(const ExecContext *c, char ***l) { } if (!path_is_absolute(fn)) { - if (ignore) continue; @@ -1720,7 +1748,6 @@ int exec_context_load_environment(const ExecContext *c, char ***l) { /* Filename supports globbing, take all matching files */ errno = 0; if (glob(fn, 0, NULL, &pglob) != 0) { - globfree(&pglob); if (ignore) continue; @@ -1729,7 +1756,6 @@ int exec_context_load_environment(const ExecContext *c, char ***l) { } count = pglob.gl_pathc; if (count == 0) { - globfree(&pglob); if (ignore) continue; @@ -1743,9 +1769,10 @@ int exec_context_load_environment(const ExecContext *c, char ***l) { continue; strv_free(r); - globfree(&pglob); return k; } + /* Log invalid environment variables with filename */ + p = strv_env_clean_log(p, pglob.gl_pathv[n]); if (r == NULL) r = p; @@ -1755,16 +1782,12 @@ int exec_context_load_environment(const ExecContext *c, char ***l) { m = strv_env_merge(2, r, p); strv_free(r); strv_free(p); - - if (!m) { - globfree(&pglob); + if (!m) return -ENOMEM; - } r = m; } } - globfree(&pglob); } *l = r;