]> git.ozlabs.org Git - petitboot/blobdiff - ui/common/ui-system.c
Simplify kexec
[petitboot] / ui / common / ui-system.c
index 3f54191bfd5671c4e92476353a30401a8741bab3..bd6dd310b13c50c67c5fb4bd0d8996adf8445b45 100644 (file)
@@ -43,20 +43,24 @@ static int run_kexec_local(const char *l_image, const char *l_initrd,
        const char *args)
 {
        int result;
-       const char *argv[8];
+       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) {
-               *p++ = "--initrd";              /* 2 */
-               *p++ = l_initrd;                /* 3 */
+               s_initrd = talloc_asprintf(NULL, "--initrd=%s", l_initrd);
+               assert(s_initrd);
+               *p++ = s_initrd;                 /* 2 */
        }
 
        if (args) {
-               *p++ = "--append";              /* 4 */
-               *p++ = args;                    /* 5 */
+               s_args = talloc_asprintf(NULL, "--append=%s", args);
+               assert(s_args);
+               *p++ = s_args;                   /* 3 */
        }
 
        /* First try by telling kexec to run shutdown */
@@ -70,9 +74,9 @@ static int run_kexec_local(const char *l_image, const char *l_initrd,
        /* On error, force a kexec with the -f option */
 
        if (result) {
-               *(p + 0) = "-f";                /* 6 */
-               *(p + 1) = l_image;             /* 7 */
-               *(p + 2) = NULL;                /* 8 */
+               *(p + 0) = "-f";                /* 4 */
+               *(p + 1) = l_image;             /* 5 */
+               *(p + 2) = NULL;                /* 6 */
 
                result = pb_run_cmd(argv);
        }
@@ -80,39 +84,42 @@ static int run_kexec_local(const char *l_image, const char *l_initrd,
        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.
- *
- * For the convenience of the user, tries to load both files before
- * returning error.
  */
 
 int pb_run_kexec(const struct pb_kexec_data *kd)
 {
        int result;
-       char *l_image;
-       char *l_initrd;
+       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)
+       if (kd->image) {
                l_image = pb_load_file(NULL, kd->image);
-       else {
-               l_image = NULL;
-               pb_log("%s: error null image\n", __func__);
+               if (!l_image)
+                       return -1;
+       }
+
+       if (kd->initrd) {
+               l_initrd = pb_load_file(NULL, kd->initrd);
+               if (!l_initrd)
+                       return -1;
        }
 
-       l_initrd = kd->initrd ? pb_load_file(NULL, kd->initrd) : NULL;
+       if (!l_image && !l_initrd)
+               return -1;
 
-       if (!l_image || (kd->initrd && !l_initrd))
-               result = -1;
-       else
-               result = run_kexec_local(l_image, l_initrd, kd->args);
+       result = run_kexec_local(l_image, l_initrd, kd->args);
 
        talloc_free(l_image);
        talloc_free(l_initrd);