]> git.ozlabs.org Git - petitboot/blobdiff - ui/common/ui-system.c
ui/common/url: Fix multiple-preceeding-slash on pathnames
[petitboot] / ui / common / ui-system.c
index 0140f0e484eedfc2757795ebc2fe9abd4520ad95..b4ae8f8c101fd0cf1ea3b66dfe513656eb1e2691 100644 (file)
 #include "loader.h"
 #include "ui-system.h"
 
+/**
+ * pb_start_daemon - start the pb-discover daemon.
+ */
+
+int pb_start_daemon(void)
+{
+       int result;
+       const char *argv[2];
+       char *name = talloc_asprintf(NULL, "%s/sbin/pb-discover",
+               pb_system_apps.prefix);
+
+       argv[0] = name;
+       argv[1] =  NULL;
+
+       result = pb_run_cmd(argv, 0, 0);
+
+       talloc_free(name);
+
+       if (result)
+               pb_log("%s: failed: (%d)\n", __func__, result);
+
+       return result;
+}
+
 /**
  * kexec_load - kexec load helper.
  * @l_image: The local image file for kexec to execute.
@@ -40,7 +64,7 @@
  */
 
 static int kexec_load(const char *l_image, const char *l_initrd,
-       const char *args)
+       const char *args, int dry_run)
 {
        int result;
        const char *argv[6];
@@ -67,7 +91,7 @@ static int kexec_load(const char *l_image, const char *l_initrd,
        *p++ = l_image;                 /* 5 */
        *p++ = NULL;                    /* 6 */
 
-       result = pb_run_cmd(argv);
+       result = pb_run_cmd(argv, 1, dry_run);
 
        if (result)
                pb_log("%s: failed: (%d)\n", __func__, result);
@@ -84,9 +108,9 @@ static int kexec_load(const char *l_image, const char *l_initrd,
  * Must only be called after a successful call to kexec_load().
  */
 
-static int kexec_reboot(void)
+static int kexec_reboot(int dry_run)
 {
-       int result;
+       int result = 0;
        const char *argv[4];
        const char **p;
 
@@ -98,7 +122,7 @@ static int kexec_reboot(void)
        *p++ =  "now";                  /* 3 */
        *p++ =  NULL;                   /* 4 */
 
-       result = pb_run_cmd(argv);
+       result = pb_run_cmd(argv, 1, dry_run);
 
        /* On error, force a kexec with the -e option */
 
@@ -108,7 +132,7 @@ static int kexec_reboot(void)
                *p++ = "-e";                    /* 2 */
                *p++ = NULL;                    /* 3 */
 
-               result = pb_run_cmd(argv);
+               result = pb_run_cmd(argv, 1, 0);
        }
 
        if (result)
@@ -121,7 +145,7 @@ static int kexec_reboot(void)
  * pb_run_kexec - Run kexec with the supplied boot options.
  */
 
-int pb_run_kexec(const struct pb_kexec_data *kd)
+int pb_run_kexec(const struct pb_kexec_data *kd, int dry_run)
 {
        int result;
        char *l_image = NULL;
@@ -129,9 +153,9 @@ int pb_run_kexec(const struct pb_kexec_data *kd)
        unsigned int clean_image = 0;
        unsigned int clean_initrd = 0;
 
-       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);
+       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);
 
        result = -1;
 
@@ -150,7 +174,7 @@ int pb_run_kexec(const struct pb_kexec_data *kd)
        if (!l_image && !l_initrd)
                goto no_load;
 
-       result = kexec_load(l_image, l_initrd, kd->args);
+       result = kexec_load(l_image, l_initrd, kd->args, dry_run);
 
 no_load:
        if (clean_image)
@@ -162,7 +186,7 @@ no_load:
        talloc_free(l_initrd);
 
        if (!result)
-               result = kexec_reboot();
+               result = kexec_reboot(dry_run);
 
        return result;
 }