]> git.ozlabs.org Git - petitboot/blobdiff - ui/common/ui-system.c
pb-protocol: Don't allocate in deserialise functions
[petitboot] / ui / common / ui-system.c
index bd6dd310b13c50c67c5fb4bd0d8996adf8445b45..ad3bfba8a9d4534507f849925fd3e2b42bc26afd 100644 (file)
 #include "log/log.h"
 #include <system/system.h>
 #include "talloc/talloc.h"
-#include "loader.h"
 #include "ui-system.h"
 
 /**
- * run_kexec_local - Final kexec helper.
- * @l_image: The local image file for kexec to execute.
- * @l_initrd: Optional local initrd file for kexec --initrd, can be NULL.
- * @args: Optional command line args for kexec --append, can be NULL.
+ * pb_start_daemon - start the pb-discover daemon.
  */
 
-static int run_kexec_local(const char *l_image, const char *l_initrd,
-       const char *args)
+int pb_start_daemon(void)
 {
        int result;
-       const char *argv[6];
-       const char **p;
-       char *s_initrd = NULL;
-       char *s_args = NULL;
-
-       p = argv;
-       *p++ = pb_system_apps.kexec;            /* 1 */
-
-       if (l_initrd) {
-               s_initrd = talloc_asprintf(NULL, "--initrd=%s", l_initrd);
-               assert(s_initrd);
-               *p++ = s_initrd;                 /* 2 */
-       }
-
-       if (args) {
-               s_args = talloc_asprintf(NULL, "--append=%s", args);
-               assert(s_args);
-               *p++ = s_args;                   /* 3 */
-       }
-
-       /* First try by telling kexec to run shutdown */
+       const char *argv[2];
+       char *name = talloc_asprintf(NULL, "%s/sbin/pb-discover",
+               pb_system_apps.prefix);
 
-       *(p + 0) = l_image;
-       *(p + 1) = NULL;
+       argv[0] = name;
+       argv[1] =  NULL;
 
-       result = pb_run_cmd(argv);
+       result = pb_run_cmd(argv, 0, 0);
 
-       /* kexec will return zero on success */
-       /* On error, force a kexec with the -f option */
-
-       if (result) {
-               *(p + 0) = "-f";                /* 4 */
-               *(p + 1) = l_image;             /* 5 */
-               *(p + 2) = NULL;                /* 6 */
-
-               result = pb_run_cmd(argv);
-       }
+       talloc_free(name);
 
        if (result)
                pb_log("%s: failed: (%d)\n", __func__, result);
 
-       talloc_free(s_initrd);
-       talloc_free(s_args);
-
-       return result;
-}
-
-/**
- * pb_run_kexec - Run kexec with the supplied boot options.
- */
-
-int pb_run_kexec(const struct pb_kexec_data *kd)
-{
-       int result;
-       char *l_image = NULL;
-       char *l_initrd = NULL;
-
-       pb_log("%s: image:  '%s'\n", __func__, kd->image);
-       pb_log("%s: initrd: '%s'\n", __func__, kd->initrd);
-       pb_log("%s: args:   '%s'\n", __func__, kd->args);
-
-       if (kd->image) {
-               l_image = pb_load_file(NULL, kd->image);
-               if (!l_image)
-                       return -1;
-       }
-
-       if (kd->initrd) {
-               l_initrd = pb_load_file(NULL, kd->initrd);
-               if (!l_initrd)
-                       return -1;
-       }
-
-       if (!l_image && !l_initrd)
-               return -1;
-
-       result = run_kexec_local(l_image, l_initrd, kd->args);
-
-       talloc_free(l_image);
-       talloc_free(l_initrd);
-
        return result;
 }