fs/Charset: return Error on SetFSCharset() failure
Don't abort the process, let the caller decide instead.
This commit is contained in:
parent
5b1db917bc
commit
fd2c6b8a4b
@ -551,7 +551,10 @@ static int mpd_main_after_fork(struct options options)
|
|||||||
GlobalEvents::Register(GlobalEvents::SHUTDOWN, shutdown_event_emitted);
|
GlobalEvents::Register(GlobalEvents::SHUTDOWN, shutdown_event_emitted);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ConfigureFS();
|
if (!ConfigureFS(error)) {
|
||||||
|
LogError(error);
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
if (!glue_mapper_init(error)) {
|
if (!glue_mapper_init(error)) {
|
||||||
LogError(error);
|
LogError(error);
|
||||||
|
@ -21,9 +21,10 @@
|
|||||||
#include "Charset.hxx"
|
#include "Charset.hxx"
|
||||||
#include "Domain.hxx"
|
#include "Domain.hxx"
|
||||||
#include "Limits.hxx"
|
#include "Limits.hxx"
|
||||||
#include "system/FatalError.hxx"
|
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
#include "Traits.hxx"
|
#include "Traits.hxx"
|
||||||
|
#include "util/Error.hxx"
|
||||||
|
#include "util/Domain.hxx"
|
||||||
|
|
||||||
#ifdef HAVE_GLIB
|
#ifdef HAVE_GLIB
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
@ -36,6 +37,8 @@
|
|||||||
|
|
||||||
#ifdef HAVE_GLIB
|
#ifdef HAVE_GLIB
|
||||||
|
|
||||||
|
static constexpr Domain convert_domain("convert");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maximal number of bytes required to represent path name in UTF-8
|
* Maximal number of bytes required to represent path name in UTF-8
|
||||||
* (including nul-terminator).
|
* (including nul-terminator).
|
||||||
@ -50,29 +53,37 @@ static std::string fs_charset;
|
|||||||
|
|
||||||
gcc_pure
|
gcc_pure
|
||||||
static bool
|
static bool
|
||||||
IsSupportedCharset(const char *charset)
|
CheckCharset(const char *charset, Error &error)
|
||||||
{
|
{
|
||||||
/* convert a space to check if the charset is valid */
|
/* convert a space to check if the charset is valid */
|
||||||
char *test = g_convert(" ", 1, charset, "UTF-8", nullptr, nullptr, nullptr);
|
GError *error2 = nullptr;
|
||||||
if (test == nullptr)
|
char *test = g_convert(" ", 1, charset, "UTF-8", nullptr, nullptr, &error2);
|
||||||
|
if (test == nullptr) {
|
||||||
|
error.Set(convert_domain, error2->code, error2->message);
|
||||||
|
g_error_free(error2);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
g_free(test);
|
g_free(test);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
bool
|
||||||
SetFSCharset(const char *charset)
|
SetFSCharset(const char *charset, Error &error)
|
||||||
{
|
{
|
||||||
assert(charset != nullptr);
|
assert(charset != nullptr);
|
||||||
|
|
||||||
if (!IsSupportedCharset(charset))
|
if (!CheckCharset(charset, error)) {
|
||||||
FormatFatalError("invalid filesystem charset: %s", charset);
|
error.FormatPrefix("Failed to initialize filesystem charset '%s': ",
|
||||||
|
charset);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
fs_charset = charset;
|
fs_charset = charset;
|
||||||
|
|
||||||
FormatDebug(path_domain,
|
FormatDebug(path_domain,
|
||||||
"SetFSCharset: fs charset is: %s", fs_charset.c_str());
|
"SetFSCharset: fs charset is: %s", fs_charset.c_str());
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
class Error;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets file system character set name.
|
* Gets file system character set name.
|
||||||
*/
|
*/
|
||||||
@ -32,8 +34,8 @@ gcc_const
|
|||||||
const char *
|
const char *
|
||||||
GetFSCharset();
|
GetFSCharset();
|
||||||
|
|
||||||
void
|
bool
|
||||||
SetFSCharset(const char *charset);
|
SetFSCharset(const char *charset, Error &error);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert the path to UTF-8.
|
* Convert the path to UTF-8.
|
||||||
|
@ -29,8 +29,8 @@
|
|||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void
|
bool
|
||||||
ConfigureFS()
|
ConfigureFS(Error &error)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_GLIB
|
#ifdef HAVE_GLIB
|
||||||
const char *charset = nullptr;
|
const char *charset = nullptr;
|
||||||
@ -55,7 +55,9 @@ ConfigureFS()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (charset != nullptr)
|
return charset == nullptr || SetFSCharset(charset, error);
|
||||||
SetFSCharset(charset);
|
#else
|
||||||
|
(void)error;
|
||||||
|
return true;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -22,10 +22,12 @@
|
|||||||
|
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
|
|
||||||
|
class Error;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs global one-time initialization of this class.
|
* Performs global one-time initialization of this class.
|
||||||
*/
|
*/
|
||||||
void
|
bool
|
||||||
ConfigureFS();
|
ConfigureFS(Error &error);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user