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 */
37 gboolean
config_init() {
40 return TRUE
; //already init'd
42 config
= g_key_file_new();
44 const gchar
*config_path
;
45 GStatBuf
*config_lstat
;
47 config_path
= "/etc/systemd_compat.conf";
49 /* does conf exist? */
50 if(g_lstat(config_path
, config_lstat
)) {
52 /* if not, can we write it */
53 if(g_access("/etc/", W_OK
)) {
54 g_printf("%s\n", "no write permissions for /etc/! exiting..");
59 config_descr
= g_open(config_path
, O_CREAT
, 644);
61 gchar
*posix_hostname
;
62 posix_hostname
= g_malloc(255);
64 gethostname(posix_hostname
, 255);
66 g_key_file_set_string(config
, "hostnamed", "Hostname", posix_hostname
);
67 g_key_file_set_string(config
, "hostnamed", "PrettyHostname", "");
68 g_key_file_set_string(config
, "hostnamed", "IconName", "Computer");
69 g_key_file_set_string(config
, "hostnamed", "ChassisType", "laptop"); //TODO set these correctly
71 if(!g_key_file_save_to_file(config
, config_path
, NULL
)) {
72 g_printf("failed to write config to %s!\n", config_path
);
73 g_free(posix_hostname
);
77 g_printf("wrote config to %s\n", config_path
);
79 g_free(posix_hostname
);
83 /* it does exist, read it */
86 if(!g_access(config_path
, W_OK
)) {
87 g_printf("%s\n", "no write permissions for /etc/! exiting..");
89 } else if(g_key_file_load_from_file(config
, config_path
, G_KEY_FILE_KEEP_COMMENTS
, NULL
))
92 g_printf("could not read config at %s! exiting..", config_path
);