This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch main
in repository entrance.
View the commit online.
commit d55ce13b95fcce75dada3504dbd8f7f611cd5eda
Author: Alastair Poole <[email protected]>
AuthorDate: Sat Nov 28 02:37:47 2026 +0000
port: this is a wip don't use it atm.
---
README.md | 8 +-
meson.build | 1 +
services/entrance-tmpfiles.conf.in | 2 +-
src/common/ConfigReader.cpp | 167 -------------------------------
src/common/ConfigReader.h | 33 -------
src/common/Configuration.cpp | 1 -
src/common/Configuration.h | 13 ---
src/common/entrance_config_file.c | 85 ++++------------
src/common/entrance_config_file.h | 25 -----
src/common/entrance_state.c | 191 ++++++++++++++++++++++++++++++++++++
src/common/entrance_state.h | 28 ++++++
src/common/meson.build | 2 +
src/daemon/DaemonApp.cpp | 2 +
src/daemon/Display.cpp | 15 +--
src/daemon/Greeter.cpp | 3 +-
src/daemon/SavedState.cpp | 32 ++++++
src/daemon/SavedState.h | 21 ++++
src/daemon/SocketServer.cpp | 17 ++--
src/daemon/meson.build | 5 +-
src/greeter/entrance_greeter_data.c | 33 ++-----
src/greeter/meson.build | 3 +-
21 files changed, 338 insertions(+), 349 deletions(-)
diff --git a/README.md b/README.md
index 5df08f7..f4352fb 100644
--- a/README.md
+++ b/README.md
@@ -66,8 +66,12 @@ sudo systemctl enable --now entrance.service
```
To migrate SDDM settings, review PAM service names and move the configuration to
-`/etc/entrance.conf` or `/etc/entrance.conf.d/`. Place any migrated
-`state.conf` in `/var/lib/entrance` and give ownership to the `entrance` account.
+`/etc/entrance.conf` or `/etc/entrance.conf.d/`.
+
+Entrance saves the greeter theme, UI scale, and enabled login history in
+`/var/lib/entrance/state.eet` (or the `entrance` account’s configured home).
+A fresh install uses the configured theme (Elementary by default) and the
+greeter’s default scale, with an empty login history.
### Preview the greeter from source
diff --git a/meson.build b/meson.build
index 638fc67..a42455b 100644
--- a/meson.build
+++ b/meson.build
@@ -11,6 +11,7 @@ project('entrance', 'c', version: '0.1.0', meson_version: '>=1.1',
greeter_only = get_option('greeter_only')
elementary = dependency('elementary', version: '>=1.22')
+eet = dependency('eet', version: '>=1.22')
ecore_file = dependency('ecore-file', version: '>=1.22')
iconv = dependency('iconv')
systemd = disabler()
diff --git a/services/entrance-tmpfiles.conf.in b/services/entrance-tmpfiles.conf.in
index ea9baed..4e2ad6e 100644
--- a/services/entrance-tmpfiles.conf.in
+++ b/services/entrance-tmpfiles.conf.in
@@ -1,4 +1,4 @@
-# Home dir of the entrance user, also contains state.conf
+# Home dir of the entrance user, also contains state.eet
d @STATE_DIR@ 0750 entrance entrance
# This contains X11 auth files passed to Xorg and the greeter
d @RUNTIME_DIR@ 0711 root root
diff --git a/src/common/ConfigReader.cpp b/src/common/ConfigReader.cpp
index 9aaaf22..389c40a 100644
--- a/src/common/ConfigReader.cpp
+++ b/src/common/ConfigReader.cpp
@@ -25,12 +25,7 @@
#include <QtCore/QDebug>
#include <QtCore/QtGlobal>
-#include <algorithm>
#include <cstdlib>
-#include <string>
-#include <string_view>
-#include <vector>
-#include <cstring>
namespace Entrance {
template <> QString ConfigEntry<QString>::value() const { return m_value; }
@@ -45,7 +40,6 @@ namespace Entrance {
}
template <> void ConfigEntry<QStringList>::setValue(const QString &str) {
- m_isDefault = false;
m_value.clear();
auto text = str.toUtf8();
char **items = entrance_config_list_split(text.data());
@@ -57,12 +51,10 @@ namespace Entrance {
}
template <> void ConfigEntry<bool>::setValue(const QString &str) {
- m_isDefault = false;
m_value = entrance_config_boolean(qUtf8Printable(str.trimmed()));
}
template <> void ConfigEntry<int>::setValue(const QString &str) {
- m_isDefault = false;
m_value = entrance_config_integer(qUtf8Printable(str));
}
@@ -94,10 +86,6 @@ namespace Entrance {
return m_name;
}
- void ConfigSection::save(ConfigEntryBase *entry) {
- m_parent->save(this, entry);
- }
-
void ConfigSection::clear() {
for (const auto &entry : m_entries)
entry.second->setDefault();
@@ -110,12 +98,6 @@ namespace Entrance {
return final;
}
- QString ConfigSection::toConfigShort() const {
- return QStringLiteral("[%1]").arg(name());
- }
-
-
-
ConfigBase::ConfigBase(const QString &configPath, const QString &configDir, const QString &sysConfigDir) :
m_path(configPath),
m_configDir(configDir),
@@ -123,10 +105,6 @@ namespace Entrance {
{
}
- bool ConfigBase::hasUnused() const {
- return m_unusedSections || m_unusedVariables;
- }
-
QString ConfigBase::toConfigFull() const {
QString ret;
for (const auto §ion : m_sections) {
@@ -150,154 +128,9 @@ namespace Entrance {
return;
}
}
- config->m_unusedVariables = true;
}, this);
}
- void ConfigBase::save(const ConfigSection *section, const ConfigEntryBase *entry) {
- // to know if we should overwrite the config or not
- bool changed = false;
- // stores the order of the loaded sections
- // each one could be there only once - if it occurs more times in the config, the occurrences are merged
- std::vector<const ConfigSection *> sectionOrder;
- // the actual bytearray data for every section
- std::map<const ConfigSection *, std::string> sectionData;
- // map of nondefault entries which should be saved if they are not found in the current config file
- std::vector<std::pair<const ConfigSection *, const ConfigEntryBase *>> remainingEntries;
-
-
- const auto collectEntries = [&remainingEntries](const ConfigSection *group) {
- for (const auto &item : group->entries()) {
- if (!item.second->matchesDefault())
- remainingEntries.emplace_back(group, item.second);
- }
- };
- if (section) {
- if (entry && !entry->matchesDefault())
- remainingEntries.emplace_back(section, entry);
- else
- collectEntries(section);
- } else {
- for (const auto &item : m_sections)
- collectEntries(item.second);
- }
-
- const auto implicitSection = m_sections.find(QStringLiteral(IMPLICIT_SECTION));
- const ConfigSection *currentSection = implicitSection == m_sections.end()
- ? nullptr : implicitSection->second;
-
- // Keep leading comments with the section that follows them.
- std::string pendingComments;
- auto writeSectionData = [&](std::string_view data) {
- const auto inserted = sectionData.try_emplace(currentSection);
- if (currentSection && inserted.second)
- sectionOrder.push_back(currentSection);
- auto §ionBytes = inserted.first->second;
- sectionBytes.append(pendingComments);
- sectionBytes.append(data);
- pendingComments.clear();
- };
- const auto writeFormatted = [&](const QString &data) {
- const auto utf8 = data.toUtf8();
- writeSectionData(std::string_view(utf8.constData(), static_cast<size_t>(utf8.size())));
- };
-
- const auto path = QFile::encodeName(m_path);
- auto mergeLine = [&](std::string_view raw) {
- std::string scratch(raw);
- const auto parsed = entrance_config_parse_line(scratch.data());
-
- if (parsed.type == ENTRANCE_CONFIG_ASSIGNMENT) {
- const QString name = QString::fromUtf8(parsed.name);
- const QString value = QString::fromUtf8(parsed.value);
- const QString comment = parsed.comment
- ? QStringLiteral("#") + QString::fromUtf8(parsed.comment) : QString();
-
- const auto *currentEntry = currentSection ? currentSection->entry(name) : nullptr;
- if (currentEntry) {
- const bool selected = section == currentSection && (!entry || entry == currentEntry);
- if (selected || value != currentEntry->value()) {
- changed = true;
- writeFormatted(QStringLiteral("%1=%2 %3\n").arg(name).arg(currentEntry->value()).arg(comment));
- }
- else
- writeSectionData(raw);
- const auto saved = std::find(remainingEntries.begin(), remainingEntries.end(),
- std::make_pair(currentSection, currentEntry));
- if (saved != remainingEntries.end())
- remainingEntries.erase(saved);
- }
- else {
- if (currentSection)
- m_unusedVariables = true;
- writeFormatted(QStringLiteral("%1 %2\n").arg(QString::fromUtf8(raw.data() + parsed.text_offset, parsed.text_length)).arg(QStringLiteral(UNUSED_VARIABLE_COMMENT)));
- }
- }
-
- // section start
- else if (parsed.type == ENTRANCE_CONFIG_SECTION) {
- const QString name = QString::fromUtf8(parsed.name);
- auto sectionIterator = m_sections.find(name);
- if (sectionIterator != m_sections.end()) {
- currentSection = sectionIterator->second;
- if (sectionData.find(currentSection) == sectionData.end())
- writeSectionData(raw);
- }
- else {
- m_unusedSections = true;
- currentSection = nullptr;
- writeSectionData(raw);
- }
- }
-
- // other stuff, like comments and whatnot
- else {
- if (raw != UNUSED_SECTION_COMMENT)
- pendingComments.append(raw);
- }
- };
- const int readError = entrance_config_visit_lines(path.constData(),
- [](void *data, const char *line, size_t length) {
- (*static_cast<decltype(mergeLine) *>(data))(std::string_view(line, length));
- }, &mergeLine);
- if (readError) {
- qWarning() << "Cannot read configuration" << m_path << std::strerror(readError);
- return;
- }
-
- for (const auto &item : remainingEntries) {
- changed = true;
- currentSection = item.first;
- if (sectionData.find(currentSection) == sectionData.end())
- writeFormatted(currentSection->toConfigShort());
- writeFormatted(QStringLiteral("\n"));
- writeFormatted(item.second->toConfigFull());
- }
-
- if (!changed)
- return;
-
- std::string output;
- for (const ConfigSection *s : sectionOrder)
- output.append(sectionData.at(s));
-
- const auto unused = sectionData.find(nullptr);
- if (unused != sectionData.end()) {
- output.push_back('\n');
- output.append(UNUSED_SECTION_COMMENT);
- constexpr std::string_view whitespace = " \t\r\n\v\f";
- const auto first = unused->second.find_first_not_of(whitespace);
- if (first != std::string::npos) {
- const auto last = unused->second.find_last_not_of(whitespace);
- output.append(unused->second, first, last - first + 1);
- }
- output.push_back('\n');
- }
-
- if (const int error = entrance_config_write(path.constData(), output.data(), output.size()))
- qWarning() << "Cannot save configuration" << m_path << std::strerror(error);
- }
-
void ConfigBase::wipe() {
for (const auto §ion : m_sections)
section.second->clear();
diff --git a/src/common/ConfigReader.h b/src/common/ConfigReader.h
index 44948e4..3294093 100644
--- a/src/common/ConfigReader.h
+++ b/src/common/ConfigReader.h
@@ -28,8 +28,6 @@
#include <map>
#define IMPLICIT_SECTION "General"
-#define UNUSED_VARIABLE_COMMENT "# Unused variable"
-#define UNUSED_SECTION_COMMENT "### These sections and their variables were not used: ###\n"
///// convenience macros
// efficient qstring initializer
@@ -42,8 +40,6 @@
name() : Entrance::ConfigBase(file, dir, sysDir), Entrance::ConfigSection(this, QStringLiteral(IMPLICIT_SECTION)) { \
load(); \
} \
- void save() { Entrance::ConfigBase::save(nullptr, nullptr); } \
- void save(Entrance::ConfigEntryBase *) const = delete; \
QString toConfigFull() const { \
return Entrance::ConfigBase::toConfigFull(); \
} \
@@ -70,10 +66,7 @@ namespace Entrance {
virtual const QString &name() const = 0;
virtual QString value() const = 0;
virtual void setValue(const QString &str) = 0;
- virtual QString toConfigShort() const = 0;
virtual QString toConfigFull() const = 0;
- virtual bool matchesDefault() const = 0;
- virtual bool isDefault() const = 0;
virtual bool setDefault() = 0;
};
@@ -82,10 +75,8 @@ namespace Entrance {
ConfigSection(ConfigBase *parent, const QString &name);
ConfigEntryBase *entry(const QString &name);
const ConfigEntryBase *entry(const QString &name) const;
- void save(ConfigEntryBase *entry);
void clear();
const QString &name() const;
- QString toConfigShort() const;
QString toConfigFull() const;
const std::map<QString, ConfigEntryBase *> &entries() const;
private:
@@ -105,7 +96,6 @@ namespace Entrance {
m_description(description),
m_default(value),
m_value(value),
- m_isDefault(true),
m_parent(parent) {
m_parent->m_entries[name] = this;
}
@@ -116,29 +106,15 @@ namespace Entrance {
void set(const T val) {
m_value = val;
- m_isDefault = false;
- }
-
- bool matchesDefault() const {
- return m_value == m_default;
- }
-
- bool isDefault() const {
- return m_isDefault;
}
bool setDefault() {
- m_isDefault = true;
if (m_value == m_default)
return false;
m_value = m_default;
return true;
}
- void save() {
- m_parent->save(this);
- }
-
const QString &name() const {
return m_name;
}
@@ -146,10 +122,6 @@ namespace Entrance {
QString value() const;
void setValue(const QString &str);
- QString toConfigShort() const {
- return QStringLiteral("%1=%2").arg(m_name).arg(value());
- }
-
QString toConfigFull() const {
QString str;
for (const QString &line : m_description.split(QLatin1Char('\n')))
@@ -162,7 +134,6 @@ namespace Entrance {
const QString m_description;
T m_default;
T m_value;
- bool m_isDefault;
ConfigSection *m_parent;
};
@@ -181,13 +152,9 @@ namespace Entrance {
ConfigBase(const QString &configPath, const QString &configDir=QString(), const QString &sysConfigDir=QString());
void load();
- void save(const ConfigSection *section = nullptr, const ConfigEntryBase *entry = nullptr);
void wipe();
- bool hasUnused() const;
QString toConfigFull() const;
protected:
- bool m_unusedVariables { false };
- bool m_unusedSections { false };
QString m_path {};
QString m_configDir;
diff --git a/src/common/Configuration.cpp b/src/common/Configuration.cpp
index e24e232..0712b83 100644
--- a/src/common/Configuration.cpp
+++ b/src/common/Configuration.cpp
@@ -26,7 +26,6 @@
namespace Entrance {
MainConfig mainConfig;
- StateConfig stateConfig;
QString installedGreeterThemePath(const QString &name) {
if (name.isEmpty() || name != name.trimmed() || name == QStringLiteral(".")
diff --git a/src/common/Configuration.h b/src/common/Configuration.h
index 611bec3..f04357d 100644
--- a/src/common/Configuration.h
+++ b/src/common/Configuration.h
@@ -24,7 +24,6 @@
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QDir>
-#include <pwd.h>
#include "entrance_constants.h"
@@ -99,24 +98,12 @@ namespace Entrance {
);
);
- Config(StateConfig, []()->QString{auto tmp = getpwnam("entrance"); return tmp ? QString::fromLocal8Bit(tmp->pw_dir) : QStringLiteral(STATE_DIR);}().append(QStringLiteral("/state.conf")), QString(), QString(),
- Section(Last,
- Entry(Scale, int, 0, _S("Saved greeter UI scale in percent (0 uses the default)"));
- Entry(Theme, QString, QString(), _S("Last theme selected in the greeter Appearance menu"));
- Entry(Session, QString, QString(), _S("Name of the session for the last logged-in user.\n"
- "This session will be preselected when the login screen appears."));
- Entry(User, QString, QString(), _S("Name of the last logged-in user.\n"
- "This user will be preselected when the login screen appears"));
- );
- );
-
constexpr int minimumGreeterScale = ENTRANCE_GREETER_SCALE_MIN;
constexpr int maximumGreeterScale = ENTRANCE_GREETER_SCALE_MAX;
QString installedGreeterThemePath(const QString &name);
extern MainConfig mainConfig;
- extern StateConfig stateConfig;
}
diff --git a/src/common/entrance_config_file.c b/src/common/entrance_config_file.c
index 0b29753..42a3c79 100644
--- a/src/common/entrance_config_file.c
+++ b/src/common/entrance_config_file.c
@@ -8,7 +8,6 @@
#include "entrance_unicode_space.h"
#include <dirent.h>
-#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
@@ -149,8 +148,22 @@ entrance_config_integer(const char *text)
return (int)value;
}
-Entrance_Config_Line
-entrance_config_parse_line(char *line)
+typedef enum
+{
+ ENTRANCE_CONFIG_OTHER,
+ ENTRANCE_CONFIG_SECTION,
+ ENTRANCE_CONFIG_ASSIGNMENT,
+} Entrance_Config_Line_Type;
+
+typedef struct
+{
+ Entrance_Config_Line_Type type;
+ const char *name;
+ const char *value;
+} Entrance_Config_Line;
+
+static Entrance_Config_Line
+_parse_line(char *line)
{
char *comment, *text, *equals;
Entrance_Config_Line parsed;
@@ -159,17 +172,10 @@ entrance_config_parse_line(char *line)
parsed = (Entrance_Config_Line){ 0 };
comment = strchr(line, '#');
if (comment)
- {
- /* Keep the spacing after the marker while trimming trailing whitespace. */
- _trim(comment);
- *comment = '\0';
- parsed.comment = comment + 1;
- }
+ *comment = '\0';
text = _trim(line);
length = strlen(text);
- parsed.text_offset = (size_t)(text - line);
- parsed.text_length = length;
equals = strchr(text, '=');
if (equals)
@@ -189,61 +195,6 @@ entrance_config_parse_line(char *line)
return parsed;
}
-int
-entrance_config_visit_lines(const char *path, Entrance_Config_Raw_Line visit, void *data)
-{
- FILE *file;
- char *line;
- size_t capacity;
- int error;
- ssize_t length;
-
- file = fopen(path, "rb");
- if (!file)
-
- return errno == ENOENT ? 0 : errno;
-
- line = NULL;
- capacity = 0;
- error = 0;
- for (;;)
- {
- errno = 0;
- length = getline(&line, &capacity, file);
- if (length < 0)
- {
- if (!feof(file))
- error = errno ? errno : EIO;
- break;
- }
- visit(data, line, (size_t)length);
- }
- free(line);
- if (fclose(file) != 0 && !error)
- error = errno;
-
- return error;
-}
-
-int
-entrance_config_write(const char *path, const char *bytes, size_t length)
-{
- FILE *file;
- int error;
-
- file = fopen(path, "wb");
- if (!file)
-
- return errno;
-
- errno = 0;
- error = fwrite(bytes, 1, length, file) == length ? 0 : (errno ? errno : EIO);
- if (fclose(file) != 0 && !error)
- error = errno;
-
- return error;
-}
-
void
entrance_config_file_read(const char *path, Entrance_Config_Value apply, void *data)
{
@@ -264,7 +215,7 @@ entrance_config_file_read(const char *path, Entrance_Config_Value apply, void *d
while (getline(&line, &capacity, file) >= 0)
{
raw = !strncmp(line, "\xef\xbb\xbf", 3) ? line + 3 : line;
- parsed = entrance_config_parse_line(raw);
+ parsed = _parse_line(raw);
if (parsed.type == ENTRANCE_CONFIG_ASSIGNMENT)
{
name = section ? section : "General";
diff --git a/src/common/entrance_config_file.h b/src/common/entrance_config_file.h
index 9fc357c..f7dd3e8 100644
--- a/src/common/entrance_config_file.h
+++ b/src/common/entrance_config_file.h
@@ -10,31 +10,6 @@
extern "C" {
#endif
-typedef enum
-{
- ENTRANCE_CONFIG_OTHER,
- ENTRANCE_CONFIG_SECTION,
- ENTRANCE_CONFIG_ASSIGNMENT,
-} Entrance_Config_Line_Type;
-
-typedef struct
-{
- Entrance_Config_Line_Type type;
- const char *name;
- const char *value;
- const char *comment;
- size_t text_offset;
- size_t text_length;
-} Entrance_Config_Line;
-
-/* Splits a writable UTF-8 line in place. The offsets describe the original trimmed text. */
-Entrance_Config_Line entrance_config_parse_line(char *line);
-
-/* Raw line bytes are borrowed until the callback returns. A missing file is empty. */
-typedef void (*Entrance_Config_Raw_Line)(void *data, const char *line, size_t length);
-int entrance_config_visit_lines(const char *path, Entrance_Config_Raw_Line visit, void *data);
-int entrance_config_write(const char *path, const char *bytes, size_t length);
-
/* Splits in place and skips empty items. Free the returned pointer array with free(). */
char **entrance_config_list_split(char *text);
Eina_Bool entrance_config_boolean(const char *text);
diff --git a/src/common/entrance_state.c b/src/common/entrance_state.c
new file mode 100644
index 0000000..b0f4cfa
--- /dev/null
+++ b/src/common/entrance_state.c
@@ -0,0 +1,191 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+#define _POSIX_C_SOURCE 200809L
+#include "entrance_state.h"
+#include "entrance_constants.h"
+
+#include <Eet.h>
+#include <fcntl.h>
+#include <pwd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+static void
+_state_string_free(const char *string)
+{
+ free((void *)string);
+}
+
+static Eet_Data_Descriptor *
+_state_descriptor(void)
+{
+ Eet_Data_Descriptor_Class klass;
+ Eet_Data_Descriptor *descriptor;
+
+ if (!EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&klass, Entrance_State))
+ return NULL;
+ klass.func.str_alloc = strdup;
+ klass.func.str_free = _state_string_free;
+ descriptor = eet_data_descriptor_stream_new(&klass);
+ if (!descriptor)
+ return NULL;
+
+ EET_DATA_DESCRIPTOR_ADD_BASIC(descriptor, Entrance_State, "user", user, EET_T_STRING);
+ EET_DATA_DESCRIPTOR_ADD_BASIC(descriptor, Entrance_State, "session", session, EET_T_STRING);
+ EET_DATA_DESCRIPTOR_ADD_BASIC(descriptor, Entrance_State, "theme", theme, EET_T_STRING);
+ EET_DATA_DESCRIPTOR_ADD_BASIC(descriptor, Entrance_State, "scale", scale, EET_T_INT);
+ return descriptor;
+}
+
+Entrance_State *
+entrance_state_load(void)
+{
+ const struct passwd *account = getpwnam("entrance");
+ const char *directory = account ? account->pw_dir : STATE_DIR;
+ int directory_fd = open(directory, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
+ if (directory_fd < 0)
+ return NULL;
+
+ int fd = openat(directory_fd, "state.eet", O_RDONLY | O_NOFOLLOW | O_NONBLOCK | O_CLOEXEC);
+ close(directory_fd);
+ if (fd < 0)
+ return NULL;
+
+ struct stat info;
+ unsigned char buffer[64 * 1024];
+ FILE *stream = NULL;
+ size_t size = 0;
+ if (fstat(fd, &info) == 0 && S_ISREG(info.st_mode)
+ && info.st_size > 0 && info.st_size <= (off_t)sizeof(buffer))
+ stream = fdopen(fd, "rb");
+ if (!stream)
+ {
+ close(fd);
+ return NULL;
+ }
+ size = fread(buffer, 1, (size_t)info.st_size, stream);
+ fclose(stream);
+ if (size != (size_t)info.st_size || !eet_init())
+ return NULL;
+
+ Eet_Data_Descriptor *descriptor = _state_descriptor();
+ Eet_File *file = descriptor ? eet_memopen_read(buffer, size) : NULL;
+ Entrance_State *state = file ? eet_data_read(file, descriptor, "state") : NULL;
+ if (file)
+ eet_close(file);
+ if (descriptor)
+ eet_data_descriptor_free(descriptor);
+ eet_shutdown();
+ return state;
+}
+
+void
+entrance_state_free(Entrance_State *state)
+{
+ if (!state)
+ return;
+
+ free(state->user);
+ free(state->session);
+ free(state->theme);
+ free(state);
+}
+
+static bool
+_state_write(const char *path, const Entrance_State *state)
+{
+ if (!eet_init())
+ return false;
+
+ Eet_Data_Descriptor *descriptor = _state_descriptor();
+ Eet_File *file = descriptor ? eet_open(path, EET_FILE_MODE_WRITE) : NULL;
+ bool written = false;
+ if (file)
+ {
+ written = eet_data_write(file, descriptor, "state", state, 0) > 0;
+ if (eet_close(file) != EET_ERROR_NONE)
+ written = false;
+ }
+ if (descriptor)
+ eet_data_descriptor_free(descriptor);
+ eet_shutdown();
+ return written;
+}
+
+static bool
+_state_replace(const char *directory, FILE *encoded, uid_t owner, gid_t group)
+{
+ const size_t length = strlen(directory) + sizeof("/state.eet.XXXXXX");
+ char *temporary = malloc(length);
+ char *path = malloc(length);
+ bool saved = false;
+
+ if (temporary && path)
+ {
+ snprintf(temporary, length, "%s/state.eet.XXXXXX", directory);
+ snprintf(path, length, "%s/state.eet", directory);
+ int fd = mkstemp(temporary);
+ if (fd >= 0)
+ {
+ FILE *destination = fdopen(fd, "wb");
+ if (destination)
+ {
+ unsigned char buffer[8192];
+ size_t size;
+ bool copied = false;
+ while ((size = fread(buffer, 1, sizeof(buffer), encoded)) > 0)
+ {
+ copied = fwrite(buffer, 1, size, destination) == size;
+ if (!copied)
+ break;
+ }
+ saved = copied && !ferror(encoded) && fflush(destination) == 0
+ && (geteuid() == owner || fchown(fd, owner, group) == 0)
+ && fsync(fd) == 0;
+ if (fclose(destination) != 0)
+ saved = false;
+ saved = saved && rename(temporary, path) == 0;
+ }
+ else
+ close(fd);
+
+ if (!saved)
+ unlink(temporary);
+ }
+ }
+
+ free(path);
+ free(temporary);
+ return saved;
+}
+
+bool
+entrance_state_save(const Entrance_State *state)
+{
+ char staging[] = "/tmp/entrance-state.XXXXXX";
+ if (!mkdtemp(staging))
+ return false;
+
+ /* Eet opens its output by pathname. Encode in a private directory first. */
+ char path[sizeof(staging) + sizeof("/state.eet")];
+ snprintf(path, sizeof(path), "%s/state.eet", staging);
+ bool saved = false;
+ if (_state_write(path, state))
+ {
+ FILE *encoded = fopen(path, "rb");
+ if (encoded)
+ {
+ const struct passwd *account = getpwnam("entrance");
+ saved = _state_replace(account ? account->pw_dir : STATE_DIR, encoded,
+ account ? account->pw_uid : geteuid(),
+ account ? account->pw_gid : getegid());
+ fclose(encoded);
+ }
+ }
+
+ unlink(path);
+ rmdir(staging);
+ return saved;
+}
diff --git a/src/common/entrance_state.h b/src/common/entrance_state.h
new file mode 100644
index 0000000..ed0d607
--- /dev/null
+++ b/src/common/entrance_state.h
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+#ifndef ENTRANCE_STATE_H
+#define ENTRANCE_STATE_H
+
+#include <stdbool.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct
+{
+ char *user;
+ char *session;
+ char *theme;
+ int scale;
+} Entrance_State;
+
+Entrance_State *entrance_state_load(void);
+void entrance_state_free(Entrance_State *state);
+
+bool entrance_state_save(const Entrance_State *state);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/common/meson.build b/src/common/meson.build
index abb3524..307dae3 100644
--- a/src/common/meson.build
+++ b/src/common/meson.build
@@ -6,6 +6,8 @@ common_inc = include_directories('.')
desktop_entry_sources = files('entrance_desktop_entry.c')
config_file_sources = files('entrance_config_file.c')
+state_sources = files('entrance_state.c')
+
if not greeter_only
config_sources = files('ConfigReader.cpp', 'Configuration.cpp') + config_file_sources
session_sources = files('entrance_session.c') + desktop_entry_sources + config_sources
diff --git a/src/daemon/DaemonApp.cpp b/src/daemon/DaemonApp.cpp
index da5b814..03fba30 100644
--- a/src/daemon/DaemonApp.cpp
+++ b/src/daemon/DaemonApp.cpp
@@ -21,6 +21,7 @@
#include "entrance_daemon_main.h"
#include "Configuration.h"
+#include "SavedState.h"
#include "entrance_constants.h"
#include "DisplayManager.h"
#include "SeatManager.h"
@@ -80,6 +81,7 @@ namespace Entrance {
// log message
qDebug() << "Starting...";
+ savedState.load();
m_seatManager->initialize();
}
diff --git a/src/daemon/Display.cpp b/src/daemon/Display.cpp
index 6ec3cd7..e639872 100644
--- a/src/daemon/Display.cpp
+++ b/src/daemon/Display.cpp
@@ -22,6 +22,7 @@
#include "Display.h"
#include "Configuration.h"
+#include "SavedState.h"
#include "DaemonApp.h"
#include "DisplayManager.h"
#include "XorgDisplayServer.h"
@@ -151,7 +152,7 @@ namespace Entrance {
QString autologinSession = mainConfig.Autologin.Session.get();
// not configured: try last successful logged in
if (autologinSession.isEmpty()) {
- autologinSession = stateConfig.Last.Session.get();
+ autologinSession = savedState.session;
}
const SessionDirectories wayland(mainConfig.Wayland.SessionDir.get());
const SessionDirectories x11(mainConfig.X11.SessionDir.get());
@@ -332,7 +333,7 @@ namespace Entrance {
}
QString Display::findGreeterTheme() const {
- const QString savedTheme = installedGreeterThemePath(stateConfig.Last.Theme.get());
+ const QString savedTheme = installedGreeterThemePath(savedState.theme);
if (!savedTheme.isEmpty())
return savedTheme;
@@ -457,14 +458,14 @@ namespace Entrance {
// save last user and last session
if (mainConfig.Users.RememberLastUser.get())
- stateConfig.Last.User.set(m_auth->user());
+ savedState.user = m_auth->user();
else
- stateConfig.Last.User.setDefault();
+ savedState.user.clear();
if (mainConfig.Users.RememberLastSession.get())
- stateConfig.Last.Session.set(m_sessionName);
+ savedState.session = m_sessionName;
else
- stateConfig.Last.Session.setDefault();
- stateConfig.save();
+ savedState.session.clear();
+ savedState.save();
if (m_socket)
m_socketServer->loginSucceeded(m_socket);
diff --git a/src/daemon/Greeter.cpp b/src/daemon/Greeter.cpp
index 22a0b55..603e8aa 100644
--- a/src/daemon/Greeter.cpp
+++ b/src/daemon/Greeter.cpp
@@ -22,6 +22,7 @@
#include "entrance_greeter_environment.h"
#include "Configuration.h"
+#include "SavedState.h"
#include "entrance_command.h"
#include "entrance_process_environment.h"
#include "entrance_constants.h"
@@ -101,7 +102,7 @@ namespace Entrance {
if (!m_themePath.isEmpty())
args << QLatin1String("--theme") << m_themePath;
- const int scale = stateConfig.Last.Scale.get();
+ const int scale = savedState.scale;
if (scale >= minimumGreeterScale && scale <= maximumGreeterScale)
args << QLatin1String("--scale") << QString::number(scale);
Q_ASSERT(m_display);
diff --git a/src/daemon/SavedState.cpp b/src/daemon/SavedState.cpp
new file mode 100644
index 0000000..a9b4b53
--- /dev/null
+++ b/src/daemon/SavedState.cpp
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+#include "SavedState.h"
+#include "entrance_state.h"
+
+#include <QDebug>
+
+namespace Entrance {
+ SavedState savedState;
+
+ void SavedState::load() {
+ if (auto *state = entrance_state_load()) {
+ user = QString::fromUtf8(state->user);
+ session = QString::fromUtf8(state->session);
+ theme = QString::fromUtf8(state->theme);
+ scale = state->scale;
+ entrance_state_free(state);
+ }
+ }
+
+ bool SavedState::save() const {
+ auto userBytes = user.toUtf8();
+ auto sessionBytes = session.toUtf8();
+ auto themeBytes = theme.toUtf8();
+ const Entrance_State state{userBytes.data(), sessionBytes.data(), themeBytes.data(), scale};
+
+ if (entrance_state_save(&state))
+ return true;
+
+ qWarning() << "Could not save Entrance state";
+ return false;
+ }
+}
diff --git a/src/daemon/SavedState.h b/src/daemon/SavedState.h
new file mode 100644
index 0000000..5227bdd
--- /dev/null
+++ b/src/daemon/SavedState.h
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+#ifndef ENTRANCE_SAVED_STATE_H
+#define ENTRANCE_SAVED_STATE_H
+
+#include <QString>
+
+namespace Entrance {
+ struct SavedState {
+ QString user;
+ QString session;
+ QString theme;
+ int scale = 0;
+
+ void load();
+ bool save() const;
+ };
+
+ extern SavedState savedState;
+}
+
+#endif
diff --git a/src/daemon/SocketServer.cpp b/src/daemon/SocketServer.cpp
index e4b0360..13c181c 100644
--- a/src/daemon/SocketServer.cpp
+++ b/src/daemon/SocketServer.cpp
@@ -21,6 +21,7 @@
#include "SocketServer.h"
#include "Configuration.h"
+#include "SavedState.h"
#include "DaemonApp.h"
#include "Display.h"
#include "entrance_greeter_wire.h"
@@ -192,9 +193,11 @@ namespace Entrance {
if (message.opcode == ENTRANCE_GREETER_SAVE_THEME) {
const QString theme = decodeText(message.theme);
if (!daemonApp->testing() && !installedGreeterThemePath(theme).isEmpty()
- && stateConfig.Last.Theme.get() != theme) {
- stateConfig.Last.Theme.set(theme);
- stateConfig.Last.Theme.save();
+ && savedState.theme != theme) {
+ auto updated = savedState;
+ updated.theme = theme;
+ if (updated.save())
+ savedState = updated;
}
continue;
}
@@ -203,9 +206,11 @@ namespace Entrance {
static_assert(sizeof(percent) == sizeof(message.value));
std::memcpy(&percent, &message.value, sizeof(percent));
if (!daemonApp->testing() && percent >= minimumGreeterScale && percent <= maximumGreeterScale
- && stateConfig.Last.Scale.get() != percent) {
- stateConfig.Last.Scale.set(percent);
- stateConfig.Last.Scale.save();
+ && savedState.scale != percent) {
+ auto updated = savedState;
+ updated.scale = percent;
+ if (updated.save())
+ savedState = updated;
}
continue;
}
diff --git a/src/daemon/meson.build b/src/daemon/meson.build
index ddb5f6f..ce3db79 100644
--- a/src/daemon/meson.build
+++ b/src/daemon/meson.build
@@ -5,6 +5,7 @@ configure_file(input: 'entrance_daemon_config.h.in', output: 'entrance_daemon_co
daemon_sources = files([
'entrance_daemon_main.c',
'DaemonApp.cpp',
+ 'SavedState.cpp',
'Greeter.cpp',
'Display.cpp',
'SocketServer.cpp',
@@ -28,9 +29,9 @@ daemon_sources = files([
'../common/entrance_greeter_wire.c',
])
-daemon_deps = [qt_base, ecore_file, dependency('dbus-1'), iconv]
+daemon_deps = [qt_base, eet, ecore_file, dependency('dbus-1'), iconv]
-executable('entrance', daemon_sources, session_sources, safe_stream, child_sources,
+executable('entrance', daemon_sources, state_sources, session_sources, safe_stream, child_sources,
theme_sources, xauthority_sources, signal_sources, auth_sources, vt_sources,
command_sources, x11_display_sources,
dependencies: daemon_deps,
diff --git a/src/greeter/entrance_greeter_data.c b/src/greeter/entrance_greeter_data.c
index a962d5c..6d556a2 100644
--- a/src/greeter/entrance_greeter_data.c
+++ b/src/greeter/entrance_greeter_data.c
@@ -5,9 +5,9 @@
#include "entrance_config_file.h"
#include "entrance_desktop_entry.h"
#include "entrance_session_discovery.h"
+#include "entrance_state.h"
#include <ctype.h>
-#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -73,38 +73,25 @@ _apply_config(void *data, const char *section, const char *key, const char *valu
_replace(&config->wayland_dirs, value);
}
-static void
-_apply_state(void *data, const char *section, const char *key, const char *value)
-{
- Greeter_Config *config;
-
- config = data;
- if (strcmp(section, "Last"))
-
- return;
-
- if (!strcmp(key, "User"))
- _replace(&config->last_user, value);
- else if (!strcmp(key, "Session"))
- _replace(&config->last_session, value);
-}
-
void
greeter_config_load(Greeter_Config *config)
{
- const struct passwd *account;
- char *state;
+ Entrance_State *state;
config->theme_dir = strdup(DATA_INSTALL_DIR "/themes");
config->x11_dirs = strdup("/usr/local/share/xsessions,/usr/share/xsessions");
config->wayland_dirs = strdup("/usr/local/share/wayland-sessions,/usr/share/wayland-sessions");
config->remember_user = EINA_TRUE;
entrance_config_read(_apply_config, config);
- account = getpwnam("entrance");
- state = _join(account ? account->pw_dir : STATE_DIR, "state.conf");
+ state = entrance_state_load();
if (state)
- entrance_config_file_read(state, _apply_state, config);
- free(state);
+ {
+ if (state->user && *state->user)
+ _replace(&config->last_user, state->user);
+ if (state->session && *state->session)
+ _replace(&config->last_session, state->session);
+ entrance_state_free(state);
+ }
}
void
diff --git a/src/greeter/meson.build b/src/greeter/meson.build
index 1228b20..6e5ed84 100644
--- a/src/greeter/meson.build
+++ b/src/greeter/meson.build
@@ -2,6 +2,7 @@ edje_cc = find_program('edje_cc')
greeter_deps = [
elementary,
+ eet,
dependency('efreet', version: '>=1.22'),
ecore_file,
dependency('eio', version: '>=1.22'),
@@ -24,7 +25,7 @@ greeter_sources = files([
'entrance_session_picker.c',
])
-executable('entrance-greeter-efl', greeter_sources, desktop_entry_sources, config_file_sources,
+executable('entrance-greeter-efl', greeter_sources, desktop_entry_sources, config_file_sources, state_sources,
dependencies: greeter_deps,
include_directories: common_inc,
c_args: ['-D_POSIX_C_SOURCE=200809L', '-DEDJE_COMPILER="' + edje_cc.full_path() + '"'],
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.