189eb235f507788493b2e5bce8a2be97980c9078
5 static GKeyFile
*config
;
7 static const gchar
*CONFIG_KEYS
[] = {
13 /* NULL if key doesn't exist */
14 gchar
*get_option(gchar
*key
, gchar
*group
) {
19 return g_key_file_get_string(config
, group
, key
, NULL
);
22 /* false if key isn't already defined or value is invalid */
23 gboolean
set_option(gchar
*key
, gchar
*value
, gchar
*group
) {
28 if(!g_key_file_get_string(config
, group
, key
, NULL
))
31 //TODO safteycheck value
32 g_key_file_set_string(config
, group
, key
, value
);
36 /* initial load/check */
38 gboolean
config_init() {
40 static gchar
*config_path
;
42 /* config is already good to go */
46 /* does config file exist? if not, write one */
47 else if(!g_key_file_load_from_data(config
, "systemd_compat.conf", &config_path
, G_KEY_FILE_KEEP_COMMENTS
, NULL
)) {
49 tryopen
= g_open("/etc/systemd_compat.conf", O_CREAT
, 644);
51 //TODO clean this up, use g_data_dirs and g_exit
52 /* can we open it rw? */
53 if(!g_access("/etc/systemd_compat.conf", W_OK
) && !tryopen
) {
54 g_printf("%s\n", "ERROR: cannot open systemd_compat.conf as read/write!");
59 config_path
= "/etc/systemd_compat.conf";
60 g_close(tryopen
, NULL
);
63 //TODO set these properly
64 config
= g_key_file_new();
66 g_key_file_set_string(config
, "hostnamed", "PrettyHostname", "");
67 g_key_file_set_string(config
, "hostnamed", "IconName", "Computer");
68 g_key_file_set_string(config
, "hostnamed", "ChassisType", "laptop");
70 if(!g_key_file_save_to_file(config
, config_path
, NULL
))
75 /* it does it exist and was written to config var */