Commit
…xecuted by Exec*= should be found Closes systemd#6308
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1090,6 +1090,7 @@ const sd_bus_vtable bus_exec_vtable[] = { | |
SD_BUS_PROPERTY("LimitRTPRIOSoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST), | ||
SD_BUS_PROPERTY("LimitRTTIME", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST), | ||
SD_BUS_PROPERTY("LimitRTTIMESoft", "t", bus_property_get_rlimit, offsetof(ExecContext, rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST), | ||
SD_BUS_PROPERTY("BinaryDirectory", "s", NULL, 0, SD_BUS_VTABLE_PROPERTY_CONST), | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
anitazha
|
||
SD_BUS_PROPERTY("WorkingDirectory", "s", property_get_working_directory, 0, SD_BUS_VTABLE_PROPERTY_CONST), | ||
SD_BUS_PROPERTY("RootDirectory", "s", NULL, offsetof(ExecContext, root_directory), SD_BUS_VTABLE_PROPERTY_CONST), | ||
SD_BUS_PROPERTY("RootImage", "s", NULL, offsetof(ExecContext, root_image), SD_BUS_VTABLE_PROPERTY_CONST), | ||
|
@@ -2635,6 +2636,22 @@ int bus_exec_context_set_transient_property( | |
|
||
return 1; | ||
|
||
} else if (streq(name, "BinaryDirectory")) { | ||
const char *s; | ||
bool missing_ok; | ||
This comment has been minimized.
Sorry, something went wrong.
anitazha
|
||
|
||
r = sd_bus_message_read(message, "s", &s); | ||
if (r < 0) | ||
return r; | ||
|
||
if (!UNIT_WRITE_FLAGS_NOOP(flags)) { | ||
r = free_and_strdup(&c->binary_directory, empty_to_null(s)); | ||
if (r < 0) | ||
return r; | ||
unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "BinaryDirectory=%s%s", missing_ok ? "-" : "", s); | ||
} | ||
|
||
return 1; | ||
} else if (streq(name, "WorkingDirectory")) { | ||
const char *s; | ||
bool missing_ok; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
{%- macro EXEC_CONTEXT_CONFIG_ITEMS(type) -%} | ||
{# Define the context options only once #} | ||
{{type}}.BinaryDirectory, config_parse_binary_directory, 0, offsetof({{type}}, exec_context) | ||
This comment has been minimized.
Sorry, something went wrong.
anitazha
|
||
{{type}}.WorkingDirectory, config_parse_working_directory, 0, offsetof({{type}}, exec_context) | ||
{{type}}.RootDirectory, config_parse_unit_path_printf, true, offsetof({{type}}, exec_context.root_directory) | ||
{{type}}.RootImage, config_parse_unit_path_printf, true, offsetof({{type}}, exec_context.root_image) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2509,6 +2509,49 @@ int config_parse_user_group_strv_compat( | |
} | ||
} | ||
|
||
int config_parse_binary_directory( | ||
const char *unit, | ||
const char *filename, | ||
unsigned line, | ||
const char *section, | ||
unsigned section_line, | ||
const char *lvalue, | ||
int ltype, | ||
const char *rvalue, | ||
void *data, | ||
void *userdata) { | ||
|
||
ExecContext *c = data; | ||
const Unit *u = userdata; | ||
bool missing_ok; | ||
This comment has been minimized.
Sorry, something went wrong.
anitazha
|
||
int r; | ||
|
||
assert(filename); | ||
assert(lvalue); | ||
assert(rvalue); | ||
assert(c); | ||
assert(u); | ||
|
||
|
||
_cleanup_free_ char *k = NULL; | ||
|
||
r = unit_path_printf(u, rvalue, &k); | ||
if (r < 0) { | ||
log_syntax(unit, missing_ok ? LOG_WARNING : LOG_ERR, filename, line, r, | ||
"Failed to resolve unit specifiers in binary directory path '%s'%s: %m", | ||
rvalue, missing_ok ? ", ignoring" : ""); | ||
return missing_ok ? 0 : -ENOEXEC; | ||
} | ||
|
||
r = path_simplify_and_warn(k, PATH_CHECK_ABSOLUTE | (missing_ok ? 0 : PATH_CHECK_FATAL), unit, filename, line, lvalue); | ||
if (r < 0) | ||
return missing_ok ? 0 : -ENOEXEC; | ||
|
||
free_and_replace(c->binary_directory, k); | ||
|
||
return 0; | ||
} | ||
|
||
int config_parse_working_directory( | ||
const char *unit, | ||
const char *filename, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -204,12 +204,12 @@ static void test_find_executable_full(void) { | |
|
||
log_info("/* %s */", __func__); | ||
|
||
assert_se(find_executable_full("sh", true, &p, NULL) == 0); | ||
assert_se(find_executable_full("sh", NULL, true, &p, NULL) == 0); | ||
puts(p); | ||
assert_se(streq(basename(p), "sh")); | ||
free(p); | ||
|
||
assert_se(find_executable_full("sh", false, &p, NULL) == 0); | ||
assert_se(find_executable_full("sh", NULL, false, &p, NULL) == 0); | ||
puts(p); | ||
assert_se(streq(basename(p), "sh")); | ||
free(p); | ||
|
@@ -221,18 +221,31 @@ static void test_find_executable_full(void) { | |
|
||
assert_se(unsetenv("PATH") == 0); | ||
|
||
assert_se(find_executable_full("sh", true, &p, NULL) == 0); | ||
assert_se(find_executable_full("sh", NULL, true, &p, NULL) == 0); | ||
puts(p); | ||
assert_se(streq(basename(p), "sh")); | ||
free(p); | ||
|
||
assert_se(find_executable_full("sh", false, &p, NULL) == 0); | ||
assert_se(find_executable_full("sh", NULL, false, &p, NULL) == 0); | ||
puts(p); | ||
assert_se(streq(basename(p), "sh")); | ||
free(p); | ||
|
||
if (oldpath) | ||
assert_se(setenv("PATH", oldpath, true) >= 0); | ||
|
||
system("touch /tmp/temp_file"); | ||
This comment has been minimized.
Sorry, something went wrong.
anitazha
|
||
system("chmod +x /tmp/temp_file"); | ||
This comment has been minimized.
Sorry, something went wrong.
anitazha
|
||
|
||
assert_se(find_executable_full("temp_file", "/tmp", false, &p, NULL) == 0); | ||
puts(p); | ||
assert_se(streq(p, "/tmp/temp_file")); | ||
free(p); | ||
|
||
system("rm /tmp/temp_file"); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
assert_se(find_executable_full("temp_file", "/tmp", false, &p, NULL) != 0); | ||
puts(p); | ||
|
||
} | ||
|
||
static void test_find_executable(const char *self) { | ||
|
@@ -277,7 +290,7 @@ static void test_find_executable_exec_one(const char *path) { | |
pid_t pid; | ||
int r; | ||
|
||
r = find_executable_full(path, false, &t, &fd); | ||
r = find_executable_full(path, NULL, false, &t, &fd); | ||
|
||
log_info_errno(r, "%s: %s → %s: %d/%m", __func__, path, t ?: "-", fd); | ||
|
||
|
Did changing this to
SD_BUS_PROPERTY("BinaryDirectory", "s", NULL, offsetof(ExecContext, binary_directory), SD_BUS_VTABLE_PROPERTY_CONST),
not work?