Skip to content

Commit 3540f14

Browse files
authored
Gracefully handle ENOTSUP in ConfigFileManager.chattr0 (#523)
The `chattr0` method, which attempts to clear special file attributes (like 'i' for immutable) using `ioctl`, can fail with an `ErrnoException` and the error code `ENOTSUP` (Operation not supported) on certain filesystems or Android environments (e.g., noted on a Android 11 device). When `ioctl` fails with `ENOTSUP`, it means the underlying filesystem does not support the operation of setting/clearing these attributes. In this case, we can safely assume the file/directory is not immutable via this mechanism and treat the operation as a successful non-action. This commit updates `chattr0` to catch `ErrnoException` specifically and return `true` if the error is `OsConstants.ENOTSUP`, preventing unexpected failures in config file management.
1 parent 047ad98 commit 3540f14

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

daemon/src/main/java/org/lsposed/lspd/service/ConfigFileManager.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,18 @@ public FileVisitResult postVisitDirectory(Path dir, IOException e)
193193
public static boolean chattr0(Path path) {
194194
try {
195195
var dir = Os.open(path.toString(), OsConstants.O_RDONLY, 0);
196+
// Clear all special file attributes on the directory
196197
HiddenApiBridge.Os_ioctlInt(dir, Process.is64Bit() ? 0x40086602 : 0x40046602, 0);
197198
Os.close(dir);
198199
return true;
200+
} catch (ErrnoException e) {
201+
// If the operation is not supported (ENOTSUP), it means the filesystem doesn't support attributes.
202+
// We can assume the file is not immutable and proceed.
203+
if (e.errno == OsConstants.ENOTSUP) {
204+
return true;
205+
}
206+
Log.d(TAG, "chattr 0", e);
207+
return false;
199208
} catch (Throwable e) {
200209
Log.d(TAG, "chattr 0", e);
201210
return false;

0 commit comments

Comments
 (0)