2 * Copyright (c) 2014 Ian Sutton <ian@kremlin.cc>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 static GKeyFile
*config
;
23 static int config_descr
;
24 static gchar
*data_dir
;
26 /* NULL if key doesn't exist */
27 gchar
*get_option(gchar
*key
, gchar
*group
) {
32 return g_key_file_get_string(config
, group
, key
, NULL
);
35 /* false if key isn't already defined or value is invalid */
36 gboolean
set_option(gchar
*key
, gchar
*value
, gchar
*group
) {
41 if(!g_key_file_get_string(config
, group
, key
, NULL
))
44 /* TODO safteycheck value */
45 g_key_file_set_string(config
, group
, key
, value
);
49 /* initial load/check */
50 gboolean
config_init() {
52 /* config is already set */
56 config
= g_key_file_new();
58 const gchar
*config_path
;
59 GStatBuf
*config_lstat
;
62 config_path
= "/etc/systemd_compat.conf";
63 config_lstat_ret
= g_lstat(config_path
, config_lstat
);
65 if(g_access(config_path
, W_OK
)) {
67 g_printf("%s\n", "no write permissions for /etc/! exiting..");
70 } else if(g_key_file_load_from_file(config
, config_path
, G_KEY_FILE_KEEP_COMMENTS
, NULL
))
73 g_printf("could not read config at %s! exiting..", config_path
);
79 /* TODO g_ptr_array all of this */
82 g_close(config_descr
, NULL
);