]> git.ozlabs.org Git - petitboot/blobdiff - ui/ncurses/nc-cui.c
ui/ncurses: Display sysinfo type & identifier
[petitboot] / ui / ncurses / nc-cui.c
index 82e534db817e4f5f8e6252b25bb20fe5731d6658..35c9debfbe1113ff315eb0e9cc610b50641aea24 100644 (file)
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#include "config.h"
+
 #define _GNU_SOURCE
 
 #include <assert.h>
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
+#include <locale.h>
 #include <sys/ioctl.h>
 
 #include "log/log.h"
 #include "pb-protocol/pb-protocol.h"
 #include "talloc/talloc.h"
 #include "waiter/waiter.h"
+#include "process/process.h"
 #include "ui/common/discover-client.h"
 #include "nc-cui.h"
 
@@ -77,13 +81,13 @@ int cui_run_cmd(struct pmenu_item *item)
 {
        int result;
        struct cui *cui = cui_from_item(item);
-       const char *const *cmd_argv = item->data;
+       const char **cmd_argv = item->data;
 
        nc_scr_status_printf(cui->current, "Running %s...", cmd_argv[0]);
 
        def_prog_mode();
 
-       result = pb_run_cmd(cmd_argv, 1, 0);
+       result = process_run_simple_argv(item, cmd_argv);
 
        reset_prog_mode();
        redrawwin(cui->current->main_ncw);
@@ -158,6 +162,7 @@ static void cui_boot_editor_on_exit(struct boot_editor *boot_editor, enum boot_e
                pb_log("%s: updating opt '%s'\n", __func__, cod->name);
                pb_log(" image  '%s'\n", cod->bd->image);
                pb_log(" initrd '%s'\n", cod->bd->initrd);
+               pb_log(" dtb    '%s'\n", cod->bd->dtb);
                pb_log(" args   '%s'\n", cod->bd->args);
        }
 
@@ -375,6 +380,7 @@ static int cui_boot_option_add(struct device *dev, struct boot_option *opt,
 
        cod->bd->image = talloc_strdup(cod->bd, opt->boot_image_file);
        cod->bd->initrd = talloc_strdup(cod->bd, opt->initrd_file);
+       cod->bd->dtb = talloc_strdup(cod->bd, opt->dtb_file);
        cod->bd->args = talloc_strdup(cod->bd, opt->boot_args);
 
        pmenu_item_setup(cui->main, i, insert_pt, cod->name);
@@ -434,9 +440,8 @@ static void cui_device_remove(struct device *dev, void *arg)
 
        list_for_each_entry(&dev->boot_options, opt, list) {
                struct pmenu_item *i = pmenu_item_from_arg(opt->ui_info);
-               struct cui_opt_data *cod = cod_from_item(i);
 
-               assert(pb_protocol_device_cmp(dev, cod->dev));
+               assert(pb_protocol_device_cmp(dev, cod_from_item(i)->dev));
                pmenu_remove(cui->main, i);
        }
 
@@ -468,11 +473,34 @@ static void cui_update_status(struct boot_status *status, void *arg)
 
 }
 
+static void cui_update_mm_title(struct cui *cui)
+{
+       struct nc_frame *frame = &cui->main->scr.frame;
+
+       talloc_free(frame->rtitle);
+
+       frame->rtitle = talloc_strdup(cui->main, cui->sysinfo->type);
+       if (cui->sysinfo->identifier)
+               frame->rtitle = talloc_asprintf_append(frame->rtitle,
+                               " %s", cui->sysinfo->identifier);
+
+       if (cui->current == &cui->main->scr)
+               cui->current->post(cui->current);
+}
+
+static void cui_update_sysinfo(struct system_info *sysinfo, void *arg)
+{
+       struct cui *cui = cui_from_arg(arg);
+       cui->sysinfo = talloc_steal(cui, sysinfo);
+       cui_update_mm_title(cui);
+}
+
 static struct discover_client_ops cui_client_ops = {
        .device_add = NULL,
        .boot_option_add = cui_boot_option_add,
        .device_remove = cui_device_remove,
        .update_status = cui_update_status,
+       .update_sysinfo = cui_update_sysinfo,
 };
 
 /**
@@ -503,6 +531,10 @@ struct cui *cui_init(void* platform_info,
        cui->platform_info = platform_info;
        cui->waitset = waitset_create(cui);
 
+       process_init(cui, cui->waitset, false);
+
+       setlocale(LC_ALL, "");
+
        /* Loop here for scripts that just started the server. */
 
 retry_start:
@@ -520,7 +552,7 @@ retry_start:
 
                start_deamon = 0;
 
-               result = pb_start_daemon();
+               result = pb_start_daemon(cui);
 
                if (!result)
                        goto retry_start;
@@ -588,7 +620,7 @@ int cui_run(struct cui *cui, struct pmenu *main, unsigned int default_item)
        while (1) {
                int result = waiter_poll(cui->waitset);
 
-               if (result < 0 && errno != EINTR) {
+               if (result < 0) {
                        pb_log("%s: poll: %s\n", __func__, strerror(errno));
                        break;
                }