53
#define HOSTS_FILE_PATH ETC_FOLDER "hosts"
54
#define LANG_ENV "LANG"
55
#define LOCALE_FILE_PATH ETC_DEFAULT_FOLDER "locale"
56
+#define LOCALE_CONF_FILE_PATH ETC_FOLDER "locale.conf"
57
#define PATH_ENV "PATH"
58
#define RESOLV_CONF_DIRECTORY_MODE 0755
59
#define RESOLV_CONF_FILE_MODE 0644
2515
2516
Routine Description:
2517
2517
- This routine queries the contents of the /etc/default/locale text file and
2518
+ This routine queries the contents of the locale configuration file and
2519
if present updates the $LANG environment variable in the environment block.
2520
2521
+ Different distributions store this file in different locations:
2522
+ - /etc/default/locale
2523
+ - /etc/locale.conf
2524
+ Both share the same "LANG=" line format, so the first file that exists is used.
2525
+
2526
Arguments:
2527
2528
Environment - Supplies the environment block pointer to update.
2536
try
2537
{
2538
//
2533
- // Attempt to open the /etc/default/locale file. If the file does not exist
2534
- // then the $LANG environment variable will not be updated.
2539
+ // Attempt to open the locale configuration file, trying each known path in turn.
2540
+ // If none of the files exist then the $LANG environment variable will not be updated.
2541
//
2536
- // N.B. This file is being opened by root. The only user-visible content
2542
+ // N.B. These files are being opened by root. The only user-visible content
2543
// will be the contents of the last line of the file that contains
2544
// "LANG=".
2545
//
2546
2541
- wil::unique_file LocaleFile{fopen(LOCALE_FILE_PATH, "r")};
2542
- if (!LocaleFile)
2547
+ constexpr const char* LocaleFilePaths[] = {LOCALE_FILE_PATH, LOCALE_CONF_FILE_PATH};
2548
+
2549
+ wil::unique_file LocaleFile;
2550
+ for (const auto* Path : LocaleFilePaths)
2551
{
2552
+ LocaleFile.reset(fopen(Path, "r"));
2553
+ if (LocaleFile)
2554
+ {
2555
+ break;
2556
+ }
2557
+
2558
if (errno != ENOENT)
2559
{
2546
- LOG_ERROR("fopen({}) failed {}", LOCALE_FILE_PATH, errno);
2560
+ LOG_ERROR("fopen({}) failed {}", Path, errno);
2561
}
2562
+ }
2563
2564
+ if (!LocaleFile)
2565
+ {
2566
return;
2567
}
2568