network/varlink: return StorageReadOnly error

Addresses https://github.com/systemd/systemd/pull/30021#discussion_r1521595855.
This commit is contained in:
Yu Watanabe 2024-03-13 10:29:53 +09:00
parent 8cbc701ded
commit cac8e820d6
2 changed files with 8 additions and 3 deletions

View file

@ -188,8 +188,10 @@ static int vl_method_set_persistent_storage(Varlink *vlink, JsonVariant *paramet
r = path_is_read_only_fs("/var/lib/systemd/network/");
if (r < 0)
return log_warning_errno(r, "Failed to check if /var/lib/systemd/network/ is writable: %m");
if (r > 0)
return log_warning_errno(SYNTHETIC_ERRNO(EROFS), "The directory /var/lib/systemd/network/ is read-only.");
if (r > 0) {
log_warning("The directory /var/lib/systemd/network/ is read-only.");
return varlink_error(vlink, "io.systemd.Network.StorageReadOnly", NULL);
}
}
r = varlink_verify_polkit_async(

View file

@ -44,6 +44,8 @@ static VARLINK_DEFINE_METHOD(
SetPersistentStorage,
VARLINK_DEFINE_INPUT(Ready, VARLINK_BOOL, 0));
static VARLINK_DEFINE_ERROR(StorageReadOnly);
VARLINK_DEFINE_INTERFACE(
io_systemd_Network,
"io.systemd.Network",
@ -52,4 +54,5 @@ VARLINK_DEFINE_INTERFACE(
&vl_method_GetLLDPNeighbors,
&vl_method_SetPersistentStorage,
&vl_type_LLDPNeighbor,
&vl_type_LLDPNeighborsByInterface);
&vl_type_LLDPNeighborsByInterface,
&vl_error_StorageReadOnly);