LRN: Let gnunet-transport-certificate-creation be a program
authorChristian Grothoff <christian@grothoff.org>
Mon, 1 Aug 2011 20:38:50 +0000 (20:38 +0000)
committerChristian Grothoff <christian@grothoff.org>
Mon, 1 Aug 2011 20:38:50 +0000 (20:38 +0000)
src/transport/Makefile.am
src/transport/plugin_transport_http.c

index 2ce2a48be15f5055c84904005ec925954c046f99..06f09e227f93f867f48566786ba3a77956906f9a 100644 (file)
@@ -62,6 +62,11 @@ UNIX_QUOTA_TEST = test_quota_compliance_unix \
      test_quota_compliance_unix_asymmetric_recv_constant
 endif
 
+<<<<<<< HEAD
+=======
+noinst_PROGRAMS = ${check_PROGRAMS} gnunet-transport-certificate-creation
+
+>>>>>>> Let gnunet-transport-certificate-creation be a program
 lib_LTLIBRARIES = \
   libgnunettransport.la 
 
@@ -83,15 +88,20 @@ bin_PROGRAMS = \
  gnunet-transport \
  $(WLAN_BIN) \
  gnunet-service-transport \
- gnunet-transport-list-connections 
+ gnunet-transport-list-connections \
+ gnunet-transport-certificate-creation
 
 #noinst_PROGRAMS = ${check_PROGRAMS}
 noinst_PROGRAMS = \
  $(WLAN_BIN_DUMMY)
 
-bin_SCRIPTS = \
- gnunet-transport-certificate-creation
+#bin_SCRIPTS = \
+# gnunet-transport-certificate-creation
 
+gnunet_transport_certificate_creation_SOURCES = \
+ gnunet-transport-certificate-creation.c
+gnunet_transport_certificate_creation_LDADD = \
+  $(top_builddir)/src/util/libgnunetutil.la
 
 gnunet_transport_wlan_helper_SOURCES = \
  wlan/byteorder.h \
index 1c578d3f627eec7bf4a71165377fa1336608db9c..955b622b75dde5356dd559d6374bb6a742694c2a 100644 (file)
@@ -3482,33 +3482,42 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
 
   if ( (plugin->key==NULL) || (plugin->cert==NULL) )
     {
-      char * cmd;
+      struct GNUNET_OS_Process *certcreation = NULL;
+      enum GNUNET_OS_ProcessStatusType status_type = GNUNET_OS_PROCESS_UNKNOWN;
+      unsigned long code = 0;
       int ret = 0;
 
       GNUNET_free_non_null (plugin->key);
       plugin->key = NULL;
       GNUNET_free_non_null (plugin->cert);
       plugin->cert = NULL;
-      GNUNET_asprintf(&cmd,
-                     "gnunet-transport-certificate-creation %s %s", 
-                     key_file, cert_file);
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                  "No usable TLS certificate found, creating certificate\n");
-      ret = system(cmd);
-      if (ret != 0)
+      errno = 0;
+      certcreation = GNUNET_OS_start_process (NULL, NULL, "gnunet-transport-certificate-creation", "gnunet-transport-certificate-creation", key_file, cert_file, NULL);
+      if (certcreation == NULL
+          || (ret = 1) != 1 || GNUNET_OS_process_wait (certcreation) != GNUNET_OK
+          || (ret = 2) != 2 || (GNUNET_OS_process_status (certcreation, &status_type, &code) != GNUNET_OK
+              || (ret = 3) != 3 || status_type != GNUNET_OS_PROCESS_EXITED
+              || (ret = 4) != 4 || code != 0))
        {
          GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
                           "https",
-                          _("Could not create a new TLS certificate, shell script `%s' failed!\n"),
-                          cmd);
+                          _("Could not create a new TLS certificate, program `gnunet-transport-certificate-creation' failed with errno %d, if-code %d, status %d, return value %d!\n"),
+                          errno, ret, status_type, code);
          GNUNET_free (key_file);
          GNUNET_free (cert_file);
          GNUNET_free (component_name);
+          if (certcreation != NULL)
+          {
+            GNUNET_OS_process_kill (certcreation, SIGTERM);
+            GNUNET_OS_process_close (certcreation);
+          }
          LIBGNUNET_PLUGIN_TRANSPORT_DONE(api);
-         GNUNET_free (cmd);
          return NULL;
        }
-      GNUNET_free (cmd);      
+      GNUNET_OS_process_close (certcreation);
+
       plugin->key = load_certificate (key_file);
       plugin->cert = load_certificate (cert_file);
       if ((plugin->key==NULL) || (plugin->cert==NULL))