more work on managing four interfaces as separate PIDs, new makefile rules for buildi...
authorkremlin <ian@kremlin.cc>
Tue, 8 Jul 2014 08:15:51 +0000 (03:15 -0500)
committerkremlin <ian@kremlin.cc>
Tue, 8 Jul 2014 08:15:51 +0000 (03:15 -0500)
.gitignore
Makefile
TODO
src/interfaces/hostnamed/hostnamed.c
src/interfaces/localed/localed.c
src/main.c

index c2a04c0b5f5d0f0e13d25579979df13bdd3494a7..725f52f36dafee356eef89e210f8223b3d42c470 100644 (file)
@@ -1,4 +1,5 @@
 *.core
+bin/*
 bin/*.out
 bin/*.bin
 bin/*.o
index bcf9813e2d2ffd2eb80ef95e0696300e9e900447..2d0ad82c27dce6a417e1c9991df222338c8ddfeb 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -13,14 +13,27 @@ all: build
 build:
        gcc -o bin/out.bin $(DEBUGF) $(GLIBF) $(SANITY) $(SRCDIR)/main.c 
 
+build-interface-binaries:
+       gcc -o bin/systemd-hostnamed-handler $(DEBUGF) $(GLIBF) $(SANITY) -D COMPILE_HOSTNAMED_BINARY $(SRCDIR)/main.c
+       gcc -o bin/systemd-localed-handler $(DEBUGF) $(GLIBF) $(SANITY) -D COMPILE_LOCALED_BINARY $(SRCDIR)/main.c
+       gcc -o bin/systemd-timedated-handler $(DEBUGF) $(GLIBF) $(SANITY) -D COMPILE_TIMEDATED_BINARY $(SRCDIR)/main.c
+       gcc -o bin/systemd-logind-handler $(DEBUGF) $(GLIBF) $(SANITY) -D COMPILE_LOGIND_BINARY $(SRCDIR)/main.c
+
 publish:
        gcc -o bin/out.bin $(CFLAGS) $(GLIBF) $(SANITY) $(SRCDIR)/main.c
 
 clean:
        rm bin/*
 
-install: _install_conf
+install: _install_conf _install_interface_binaries
 
 _install_conf:
        cp conf/*-dbus.conf /etc/dbus-1/system.d/
        cp conf/systemd_compat.conf /etc/
+
+_install_interface_binaries:
+       cp bin/systemd-hostnamed-handler /usr/local/libexec/
+       cp bin/systemd-localed-handler /usr/local/libexec/
+       cp bin/systemd-timedated-handler /usr/local/libexec/
+       cp bin/systemd-logind-handler /usr/local/libexec/
+
diff --git a/TODO b/TODO
index 8463eba0eb407c926fdf3d8406fc549fbc7409cb..63128128c7f6a2e4e9778b3284e1d5b572f971d4 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,2 +1,3 @@
  * get autoconf stuff figured out
  * handle SIGINTs so file descriptors are dropped properly, otherwise we get bus errors next run
+ * document how gdbus-codegen files always generate the same 'typedef structs' per interface pair, and how those pairs must be snipped as they cause "already defined" compiler errors
index ad7df31fa55ba1badf37f2b7aa7d7742c314db18..f250aaab8b3c666b1776011e163151324325cd32 100644 (file)
@@ -196,22 +196,9 @@ static void hostnamed_on_name_lost(GDBusConnection *conn,
 }
 
 /* safe call to try and start hostnamed */
-GError *hostnamed_init() {
+void hostnamed_init() {
 
     guint bus_descriptor;
-    GError *err = NULL;
-    gchar **hostnamed_ispect_xml;
-    gchar  *hostnamed_joined_xml;
-
-    hostnamed_freeable = g_ptr_array_new();
-    hostnamed_ispect_xml = g_malloc(3000);
-
-    g_file_get_contents("conf/hostnamed-ispect.xml", hostnamed_ispect_xml, NULL, NULL);
-    hostnamed_joined_xml = g_strjoinv("\n", hostnamed_ispect_xml);
-    spect_data = g_dbus_node_info_new_for_xml(hostnamed_joined_xml, NULL);
-
-    g_free(hostnamed_ispect_xml);
-    g_ptr_array_add(hostnamed_freeable, hostnamed_joined_xml);
 
     bus_descriptor = g_bus_own_name(G_BUS_TYPE_SYSTEM,
                                     "org.freedesktop.hostname1",
@@ -223,7 +210,6 @@ GError *hostnamed_init() {
                                     NULL);
 
     /* TODO: malloc and return reference as if a main() closed */
-    return err;
 }
 
 /* free()'s */
index 910c1e1d78f444fd5ca1d9488db3340b4caea3c5..ef4fdea413be84de2ec0deba29f6f7cf64ef740b 100644 (file)
@@ -114,7 +114,7 @@ static void localed_on_name_lost(GDBusConnection *conn,
 }
 
 /* safe call to try and start localed */
-GError *localed_init() {
+void localed_init() {
 
     guint bus_descriptor;
     GError *err = NULL;
@@ -141,7 +141,6 @@ GError *localed_init() {
                                     NULL);
 
     /* TODO: malloc and return reference as if a main() closed */
-    return err;
 }
 
 /* free()'s */
index 3c30ae041be0bafdb6540fcca353d682187a6b50..3bc43447469fb9dc80caaf56caaee51241931094 100644 (file)
@@ -27,7 +27,8 @@
 #include "interfaces/logind/logind.c"
 
 gboolean systemd_utils_init() {
-    if(!config_init()) {
+
+       if(!config_init()) {
         gchar *tmp;
         tmp = "/etc/systemd_compat.conf"; 
 
@@ -39,20 +40,48 @@ gboolean systemd_utils_init() {
 
 int main() {
 
-    GMainLoop *mloop;
-    
-    if(!systemd_utils_init()) {
-        g_printf("failed to init, are you root?\n");
-        return 1; /* TODO errno properly. grep for all "return 1;"s, not TODO'ing each one */
-    }
+       GMainLoop *mloop;               
+       mloop = g_main_loop_new(NULL, TRUE);
+
+       #ifdef COMPILE_HOSTNAMED_BINARY
+               hostnamed_init();
+       #endif
+       #ifdef COMPILE_LOCALED_BINARY
+               localed_init();
+       #endif
+       #ifdef COMPILE_TIMEDATED_BINARY
+       #endif
+       #ifdef COMPILE_LOGIND_BINARY
+       #endif
+
+       #if !defined(COMPILE_HOSTNAMED_BINARY) && !defined(COMPILE_LOCALED_BINARY) && !defined(COMPILE_TIMEDATED_BINARY) && !defined(COMPILE_LOGIND_BINARY)
+               
+               if(!systemd_utils_init()) {
+                       g_printf("failed to init, are you root?\n");
+                       return 1; /* TODO errno properly. grep for all "return 1;"s, not TODO'ing each one */
+               }
+
+               gboolean hostnamed_init_ok, localed_init_ok;
+               GPid *hostnamed_pid, *localed_pid;
+               gchar *hostnamed_argv[0], *localed_argv[0];
+               GSource *hostnamed_source, *localed_source, *timedated_source, *logind_source;
+
+               hostnamed_argv[0] = "/usr/local/libexec/systemd-hostnamed-handler";
+               localed_argv[0] = "/usr/local/libexec/systemd-localed-handler";
+
+               hostnamed_init_ok = g_spawn_async(NULL, hostnamed_argv, NULL, G_SPAWN_DEFAULT, NULL, NULL, hostnamed_pid, NULL);
+               localed_init_ok = g_spawn_async(NULL, localed_argv, NULL, G_SPAWN_DEFAULT, NULL, NULL, localed_pid, NULL);
+
+               hostnamed_source = g_child_watch_source_new(*hostnamed_pid);
+               localed_source = g_child_watch_source_new(*localed_pid);
 
-    hostnamed_init();
-       localed_init();
+               /*g_source_attach(hostnamed_source, NULL);
+               g_source_attach(localed_source, NULL);*/
 
-    mloop = g_main_loop_new(NULL, TRUE);
+       #endif
 
-    g_main_loop_run(mloop);
-    g_main_loop_unref(mloop);
+       g_main_loop_run(mloop);
+       g_main_loop_unref(mloop);
 
-    return 0;
+       return 0;
 }