From 4f126f690c17de00f44135f46acf0664ede61ab1 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Mon, 27 Sep 2021 18:38:03 -0400 Subject: [PATCH] mount_server: Connect on-demand to app_server. This is similar to with the registrar and debug_server, both of which are started before app_server, already do. In the case where we cannot connect to app_server for _SuggestMountFlags, we default to read-only. (This should however never happen, at present.) --- src/servers/mount/AutoMounter.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/servers/mount/AutoMounter.cpp b/src/servers/mount/AutoMounter.cpp index 1048eaaa23..e5605d862d 100644 --- a/src/servers/mount/AutoMounter.cpp +++ b/src/servers/mount/AutoMounter.cpp @@ -350,7 +350,7 @@ ArchiveVisitor::Visit(BPartition* partition, int32 level) AutoMounter::AutoMounter() : - BServer(kMountServerSignature, true, NULL), + BServer(kMountServerSignature, false, NULL), fNormalMode(kRestorePreviousVolumes), fRemovableMode(kAllVolumes), fEjectWhenUnmounting(true) @@ -597,7 +597,7 @@ AutoMounter::_MountVolume(const BMessage* message) return; status_t status = partition->Mount(NULL, mountFlags); - if (status < B_OK) { + if (status < B_OK && InitGUIContext() == B_OK) { char text[512]; snprintf(text, sizeof(text), B_TRANSLATE("Error mounting volume:\n\n%s"), strerror(status)); @@ -612,6 +612,9 @@ AutoMounter::_MountVolume(const BMessage* message) bool AutoMounter::_SuggestForceUnmount(const char* name, status_t error) { + if (InitGUIContext() != B_OK) + return false; + char text[1024]; snprintf(text, sizeof(text), B_TRANSLATE("Could not unmount disk \"%s\":\n\t%s\n\n" @@ -633,6 +636,9 @@ AutoMounter::_SuggestForceUnmount(const char* name, status_t error) void AutoMounter::_ReportUnmountError(const char* name, status_t error) { + if (InitGUIContext() != B_OK) + return; + char text[512]; snprintf(text, sizeof(text), B_TRANSLATE("Could not unmount disk " "\"%s\":\n\t%s"), name, strerror(error)); @@ -969,6 +975,12 @@ AutoMounter::_SuggestMountFlags(const BPartition* partition, uint32* _flags) if (partition->IsReadOnly()) askReadOnly = false; + if (askReadOnly && ((BServer*)be_app)->InitGUIContext() != B_OK) { + // Mount read-only, just to be safe. + mountFlags |= B_MOUNT_READ_ONLY; + askReadOnly = false; + } + if (askReadOnly) { // Suggest to the user to mount read-only until Haiku is more mature. BString string;