} else if (streq(name, "WorkingDirectory")) {
_cleanup_free_ char *simplified = NULL;
- bool missing_ok, is_home;
+ bool missing_ok = false, is_home = false;
const char *s;
r = sd_bus_message_read(message, "s", &s);
if (r < 0)
return r;
- if (s[0] == '-') {
- missing_ok = true;
- s++;
- } else
- missing_ok = false;
-
- if (isempty(s))
- is_home = false;
- else if (streq(s, "~"))
- is_home = true;
- else {
- if (!path_is_absolute(s))
- return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "WorkingDirectory= expects an absolute path or '~'");
+ if (!isempty(s)) {
+ if (s[0] == '-') {
+ missing_ok = true;
+ s++;
+ }
- r = path_simplify_alloc(s, &simplified);
- if (r < 0)
- return r;
+ if (streq(s, "~"))
+ is_home = true;
+ else {
+ if (!path_is_absolute(s))
+ return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS,
+ "WorkingDirectory= expects an absolute path or '~'");
- if (!path_is_normalized(simplified))
- return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "WorkingDirectory= expects a normalized path or '~'");
+ r = path_simplify_alloc(s, &simplified);
+ if (r < 0)
+ return r;
- if (path_below_api_vfs(simplified))
- return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "WorkingDirectory= may not be below /proc/, /sys/ or /dev/.");
+ if (!path_is_normalized(simplified))
+ return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS,
+ "WorkingDirectory= expects a normalized path or '~'");
- is_home = false;
+ if (path_below_api_vfs(simplified))
+ return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS,
+ "WorkingDirectory= may not be below /proc/, /sys/ or /dev/");
+ }
}
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
c->working_directory_home = is_home;
c->working_directory_missing_ok = missing_ok;
- unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name, "WorkingDirectory=%s%s", missing_ok ? "-" : "", c->working_directory_home ? "~" : ASSERT_PTR(c->working_directory));
+ unit_write_settingf(u, flags|UNIT_ESCAPE_SPECIFIERS, name,
+ "WorkingDirectory=%s%s",
+ c->working_directory_missing_ok ? "-" : "",
+ c->working_directory_home ? "~" : strempty(c->working_directory));
}
return 1;