4 //expects valid input, always free() output
5 const gchar
**get_prefixs(gchar
*path
, gchar
*dname
) {
6 gsize size
= sizeof(path
) + sizeof(dname
) + 11; //11 extra bytes for file suffix
7 const gchar
**ret
= (gchar
**) g_malloc0(2 * size
);
9 g_snprintf(ret
[0], size
, "%s%s-ispect.xml", path
, dname
);
10 g_snprintf(ret
[1], size
, "%s%s-config.xml", path
, dname
);
15 const GString
*strjoin(gchar
*sep
, GString strings
[]) {
20 while((cur
= &strings
[n
]) != NULL
) {
21 g_string_append(out
, cur
);
28 gboolean
install_conf() {
29 gchar
*our_conf_uri
= "systemd-utl/xml-conf/";
30 gchar
**data_dir
= g_get_system_data_dirs();
32 if(g_strcmp0(data_dir
[0], NULL
)) {
33 const gchar our_conf_path
[256];
34 g_snprintf(our_conf_path
, sizeof our_conf_path
, "%s%s", *data_dir
, our_conf_uri
);
37 /*TODO permissions w/ this */
38 g_mkdir_with_parents(our_conf_path
, 0644);
40 const gchar
**hostnamed_prefixs
= get_prefixs(our_conf_path
, "hostnamed");
41 const GString
*hostnamed_ispect_xml
= strjoin("\n", hostnamed_ispect_xml_def
);
42 const GString
*hostnamed_config_xml
= strjoin("\n", hostnamed_config_xml_def
);
44 const gchar
**timedated_prefixs
= get_prefixs(our_conf_path
, "timedated");
45 const GString
*timedated_ispect_xml
= strjoin("\n", timedated_ispect_xml_def
);
46 const GString
*timedated_config_xml
= strjoin("\n", timedated_config_xml_def
);
48 const gchar
**localed_prefixs
= get_prefixs(our_conf_path
, "localed");
49 const GString
*localed_ispect_xml
= strjoin("\n", localed_ispect_xml_def
);
50 const GString
*localed_config_xml
= strjoin("\n", localed_config_xml_def
);
52 const gchar
**logind_prefixs
= get_prefixs(our_conf_path
, "logind");
53 const GString
*logind_ispect_xml
= strjoin("\n", logind_ispect_xml_def
);
54 const GString
*logind_config_xml
= strjoin("\n", logind_config_xml_def
);
56 g_file_set_contents(*hostnamed_prefixs
[0], hostnamed_config_xml
, -1, errors
);
57 g_file_set_contents(*hostnamed_prefixs
[1], hostnamed_config_xml
, -1, errors
);
59 g_file_set_contents(*timedated_prefixs
[0], timedated_config_xml
, -1, errors
);
60 g_file_set_contents(*timedated_prefixs
[1], timedated_config_xml
, -1, errors
);
62 g_file_set_contents(*localed_prefixs
[0], localed_config_xml
, -1, errors
);
63 g_file_set_contents(*localed_prefixs
[1], localed_config_xml
, -1, errors
);
65 g_file_set_contents(*logind_prefixs
[0], logind_config_xml
, -1, errors
);
66 g_file_set_contents(*logind_prefixs
[1], logind_config_xml
, -1, errors
);
68 /* TODO: free() strings */
70 return (errors
[0] == NULL
);