| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807 |
- /* service: init's CLI and GUI client.
- *
- * service list services
- * service status <name>
- * service start|stop|restart|kill <name>
- * service logs <name> last lines
- * service logtail <name> follow until Ctrl-C
- * service --gui
- *
- * State and logs are plain files in /share; actions are one-line requests on
- * init's control tty (see service_proto.c). The client never spawns or kills
- * a service itself.
- */
- #include <stdio.h>
- #include <string.h>
- #include "ngui.h"
- #include "service_proto.h"
- #include "ucmd_lib.h"
- #define LOG_LINES 40
- #define LOOP_MS 50
- #define POLL_MS 500
- static char log_buf[SVC_LOG_MAX + 1];
- /* ---- shared helpers -------------------------------------------------- */
- static int read_state_file(const char *name, struct svc_state *st)
- {
- char path[64], buf[512];
- int n;
- if (svc_make_state_path(path, sizeof(path), name) != 0)
- return -1;
- n = u_read_file(path, buf, sizeof(buf) - 1);
- if (n <= 0)
- return -1;
- buf[n] = '\0';
- return svc_parse_state(buf, (unsigned int)n, st);
- }
- static int read_init_file(struct init_state *is)
- {
- char buf[256];
- int n = u_read_file(SVC_INIT_STATE, buf, sizeof(buf) - 1);
- if (n <= 0)
- return -1;
- buf[n] = '\0';
- return svc_parse_init_state(buf, (unsigned int)n, is);
- }
- static int init_is_running(const struct init_state *is)
- {
- return is->valid && is->pid && u_alive(is->pid);
- }
- static int wm_is_running(const struct init_state *is)
- {
- return is->valid && is->wm && u_alive(is->wm);
- }
- static void trim_line(char *s)
- {
- unsigned int i = 0;
- while (s[i] && s[i] != '\n' && s[i] != '\r')
- i++;
- s[i] = '\0';
- }
- static void fmt_age(unsigned int started, char *out, unsigned int max)
- {
- unsigned int s, m, h;
- if (!started) {
- snprintf(out, max, "-");
- return;
- }
- s = (u_ticks_ms() - started) / 1000u;
- m = s / 60u;
- h = m / 60u;
- if (h)
- snprintf(out, max, "%uh%um", h, m % 60u);
- else if (m)
- snprintf(out, max, "%um%us", m, s % 60u);
- else
- snprintf(out, max, "%us", s);
- }
- static int read_log(const char *name)
- {
- char path[64];
- int n;
- if (strcmp(name, "init") == 0) {
- n = u_read_file(SVC_INIT_LOG, log_buf, SVC_LOG_MAX);
- } else if (strcmp(name, "wm") == 0) {
- return -1;
- } else {
- if (svc_make_log_path(path, sizeof(path), name) != 0)
- return -1;
- n = u_read_file(path, log_buf, SVC_LOG_MAX);
- }
- if (n < 0)
- n = 0;
- log_buf[n] = '\0';
- return n;
- }
- static void print_last_lines(int n, int want)
- {
- int i = n, lines = 0;
- while (i > 0 && lines < want) {
- i--;
- if (log_buf[i] == '\n' && i + 1 < n)
- lines++;
- }
- u_puts(log_buf + i);
- }
- static int request_action(const char *op, const char *name, char *msg,
- unsigned int msgmax, int *pid)
- {
- int code = 0;
- int r;
- if (pid)
- *pid = 0;
- r = svc_request(op, name, 2500, &code, pid, msg, msgmax);
- if (r == -2) {
- snprintf(msg, msgmax, "init is not running");
- return -2;
- }
- if (r != 0) {
- snprintf(msg, msgmax, "init is not responding");
- return -1;
- }
- trim_line(msg);
- return code;
- }
- /* ---- CLI ------------------------------------------------------------- */
- static void cli_list(void)
- {
- struct init_state is;
- struct svc_state st;
- char age[16], line[160];
- unsigned int i;
- if (read_init_file(&is) != 0)
- memset(&is, 0, sizeof(is));
- u_puts("NAME STATE PID AGE DESCRIPTION\n");
- if (init_is_running(&is)) {
- snprintf(line, sizeof(line), "%-10s %-10s %-5u %-7s %s\n",
- "init", "running", is.pid, "-", "service manager");
- } else {
- snprintf(line, sizeof(line), "%-10s %-10s %-5s %-7s %s\n",
- "init", "down", "-", "-", "service manager");
- }
- u_puts(line);
- if (wm_is_running(&is)) {
- snprintf(line, sizeof(line), "%-10s %-10s %-5u %-7s %s\n",
- "wm", "running", is.wm, "-",
- "window manager (system)");
- } else {
- snprintf(line, sizeof(line), "%-10s %-10s %-5s %-7s %s\n",
- "wm", "stopped", "-", "-",
- "window manager (system)");
- }
- u_puts(line);
- for (i = 0; i < svc_def_count; i++) {
- const char *state = "stopped";
- unsigned int pid = 0;
- unsigned int started = 0;
- if (read_state_file(svc_defs[i].name, &st) == 0) {
- pid = st.pid;
- started = st.started;
- if (pid && !u_alive(pid))
- pid = 0;
- if (pid)
- state = svc_state_name(st.state);
- }
- if (pid)
- fmt_age(started, age, sizeof(age));
- else
- snprintf(age, sizeof(age), "-");
- snprintf(line, sizeof(line), "%-10s %-10s %-5u %-7s %s\n",
- svc_defs[i].name, state, pid, age, svc_defs[i].desc);
- u_puts(line);
- }
- if (!is.valid)
- u_puts("service: init state is missing (use `service` after boot)\n");
- else if (!init_is_running(&is))
- u_puts("service: init is not running; the kernel will restart it\n");
- }
- static void cli_status(const char *name)
- {
- struct init_state is;
- struct svc_state st;
- char age[16];
- if (strcmp(name, "init") == 0) {
- if (read_init_file(&is) != 0) {
- u_puts("init: not running\n");
- return;
- }
- u_puts(init_is_running(&is) ? "init: running\n" : "init: down\n");
- u_puts(" pid "); u_putdec(is.pid);
- u_puts(", control tty "); u_putdec(is.ctl);
- u_puts(", wm "); u_putdec(wm_is_running(&is) ? is.wm : 0);
- u_puts("\n log " SVC_INIT_LOG "\n");
- return;
- }
- if (strcmp(name, "wm") == 0) {
- read_init_file(&is);
- if (wm_is_running(&is)) {
- u_puts("wm: running\n pid ");
- u_putdec(is.wm);
- u_puts("\n system service (restart/kill only)\n");
- } else {
- u_puts("wm: stopped\n");
- }
- return;
- }
- if (svc_find(name) < 0) {
- u_puts("service: unknown service\n");
- return;
- }
- if (read_state_file(name, &st) != 0) {
- u_puts(name); u_puts(": stopped (no state file)\n");
- return;
- }
- if (st.pid && !u_alive(st.pid))
- st.pid = 0;
- fmt_age(st.started, age, sizeof(age));
- u_puts(name); u_puts(": ");
- u_puts(st.pid ? svc_state_name(st.state) : "stopped");
- u_puts("\n pid "); u_putdec(st.pid);
- u_puts(", tty "); u_putdec(st.tty);
- u_puts(", age "); u_puts(age);
- u_puts("\n desired "); u_puts(st.desired ? "running" : "stopped");
- u_puts("\n ");
- {
- int i = svc_find(name);
- u_puts(svc_defs[i].desc);
- }
- u_puts("\n");
- }
- static int cli_action(const char *op, const char *name)
- {
- char msg[96];
- int pid = 0;
- int code = request_action(op, name, msg, sizeof(msg), &pid);
- if (code < 0) {
- u_puts("service: "); u_puts(msg); return 1;
- }
- u_puts(name); u_puts(": "); u_puts(msg);
- if (pid > 0) {
- u_puts(" (pid "); u_putdec((unsigned int)pid); u_puts(")");
- }
- u_puts("\n");
- if (code == 0 &&
- (strcmp(op, "start") == 0 || strcmp(op, "restart") == 0)) {
- struct svc_state st;
- u_sleep_ms(350);
- if (read_state_file(name, &st) == 0 &&
- (!st.pid || !u_alive(st.pid))) {
- int n = read_log(name);
- u_puts("service: "); u_puts(name);
- u_puts(" did not stay up; last log lines:\n");
- if (n > 0)
- print_last_lines(n, 12);
- return 1;
- }
- }
- return code ? 1 : 0;
- }
- static int cli_logs(const char *name, int follow)
- {
- unsigned int seen = 0;
- int n;
- if (strcmp(name, "wm") == 0) {
- u_puts("wm: no captured log (the WM writes to the serial console)\n");
- return 1;
- }
- if (read_log(name) < 0) {
- u_puts("service: no log for "); u_puts(name); u_puts("\n");
- return 1;
- }
- if (!follow) {
- n = (int)strlen(log_buf);
- if (!n) {
- u_puts("service: log is empty\n");
- return 0;
- }
- print_last_lines(n, LOG_LINES);
- return 0;
- }
- for (;;) {
- n = read_log(name);
- if (n < 0)
- n = 0;
- if ((unsigned int)n < seen)
- seen = 0;
- if ((unsigned int)n > seen) {
- u_puts(log_buf + seen);
- seen = (unsigned int)n;
- }
- u_sleep_ms(250);
- }
- }
- static void cli_usage(void)
- {
- u_puts("usage: service [list]\n"
- " service status <name>\n"
- " service start|stop|restart|kill <name>\n"
- " service logs <name> | logtail <name>\n"
- " service --gui\n");
- }
- static void cli(const char *arg)
- {
- char cmd[16], name[16];
- unsigned int i = 0, n;
- while (arg && (arg[i] == ' ' || arg[i] == '\t'))
- i++;
- n = 0;
- while (arg && arg[i] && arg[i] != ' ' && arg[i] != '\t' &&
- n + 1 < sizeof(cmd))
- cmd[n++] = arg[i++];
- cmd[n] = '\0';
- while (arg && (arg[i] == ' ' || arg[i] == '\t'))
- i++;
- n = 0;
- while (arg && arg[i] && arg[i] != ' ' && arg[i] != '\t' &&
- n + 1 < sizeof(name))
- name[n++] = arg[i++];
- name[n] = '\0';
- if (!cmd[0] || strcmp(cmd, "list") == 0) {
- cli_list();
- return;
- }
- if (strcmp(cmd, "help") == 0) {
- cli_usage();
- return;
- }
- if (strcmp(cmd, "status") == 0) {
- if (!name[0]) { cli_usage(); return; }
- cli_status(name);
- return;
- }
- if (strcmp(cmd, "logs") == 0 || strcmp(cmd, "logtail") == 0) {
- if (!name[0]) { cli_usage(); return; }
- cli_logs(name, strcmp(cmd, "logtail") == 0);
- return;
- }
- if (strcmp(cmd, "start") == 0 || strcmp(cmd, "stop") == 0 ||
- strcmp(cmd, "restart") == 0 || strcmp(cmd, "kill") == 0) {
- if (!name[0]) { cli_usage(); return; }
- cli_action(cmd, name);
- return;
- }
- cli_usage();
- }
- /* ---- GUI ------------------------------------------------------------- */
- #define VIEW_MAX (2 + SVC_MAX)
- #define ROW_H 52
- enum {
- ID_REFRESH = 1,
- ID_START,
- ID_STOP,
- ID_RESTART,
- ID_KILL,
- ID_ROW_BASE = 100
- };
- struct view {
- char name[16];
- char state[16];
- char desc[80];
- unsigned int pid;
- int running;
- int is_init;
- int is_wm;
- };
- static struct ngui ui;
- static struct win_info wi;
- static struct view views[VIEW_MAX];
- static int nviews;
- static int selected;
- static int pending_action;
- static int kill_arm;
- static unsigned int kill_arm_at;
- static char gui_status[96];
- static unsigned int gui_status_at;
- static unsigned int log_len;
- static struct ngui_scroll log_scroll;
- static int log_follow = 1;
- static void gui_refresh(void)
- {
- struct init_state is;
- struct svc_state st;
- unsigned int i;
- memset(&is, 0, sizeof(is));
- read_init_file(&is);
- nviews = 0;
- memset(&views[nviews], 0, sizeof(views[nviews]));
- snprintf(views[nviews].name, sizeof(views[nviews].name), "init");
- snprintf(views[nviews].state, sizeof(views[nviews].state),
- init_is_running(&is) ? "running" : "down");
- snprintf(views[nviews].desc, sizeof(views[nviews].desc),
- "service manager (pid 1)");
- views[nviews].pid = init_is_running(&is) ? is.pid : 0;
- views[nviews].running = init_is_running(&is);
- views[nviews].is_init = 1;
- nviews++;
- memset(&views[nviews], 0, sizeof(views[nviews]));
- snprintf(views[nviews].name, sizeof(views[nviews].name), "wm");
- snprintf(views[nviews].state, sizeof(views[nviews].state),
- wm_is_running(&is) ? "running" : "stopped");
- snprintf(views[nviews].desc, sizeof(views[nviews].desc),
- "window manager (system service)");
- views[nviews].pid = wm_is_running(&is) ? is.wm : 0;
- views[nviews].running = wm_is_running(&is);
- views[nviews].is_wm = 1;
- nviews++;
- for (i = 0; i < svc_def_count && i < SVC_MAX; i++) {
- struct view *v = &views[nviews];
- memset(v, 0, sizeof(*v));
- snprintf(v->name, sizeof(v->name), "%s", svc_defs[i].name);
- snprintf(v->desc, sizeof(v->desc), "%s", svc_defs[i].desc);
- snprintf(v->state, sizeof(v->state), "stopped");
- if (read_state_file(svc_defs[i].name, &st) == 0) {
- v->pid = st.pid;
- if (v->pid && !u_alive(v->pid))
- v->pid = 0;
- if (v->pid)
- snprintf(v->state, sizeof(v->state), "%s",
- svc_state_name(st.state));
- }
- v->running = v->pid != 0;
- nviews++;
- }
- if (selected >= nviews)
- selected = nviews - 1;
- if (selected < 0)
- selected = 0;
- }
- static void gui_read_log(void)
- {
- struct view *v = &views[selected];
- int n;
- if (v->is_wm) {
- log_len = 0;
- return;
- }
- n = read_log(v->name);
- if (n < 0)
- n = 0;
- log_len = (unsigned int)n;
- }
- static void gui_status_set(const char *s, int err)
- {
- snprintf(gui_status, sizeof(gui_status), "%s", s);
- gui_status_at = u_ticks_ms();
- (void)err;
- }
- static void gui_action(const char *op)
- {
- char msg[96];
- int pid = 0, code;
- code = request_action(op, views[selected].name, msg, sizeof(msg), &pid);
- if (code < 0) {
- gui_status_set(msg, 1);
- return;
- }
- if (pid > 0) {
- char b[80];
- snprintf(b, sizeof(b), "%s: %s (pid %d)", views[selected].name,
- msg, pid);
- gui_status_set(b, code != 0);
- } else {
- char b[80];
- snprintf(b, sizeof(b), "%s: %s", views[selected].name, msg);
- gui_status_set(b, code != 0);
- }
- gui_refresh();
- ngui_invalidate(&ui);
- }
- static int draw_button(unsigned int id, struct ngui_rect r,
- const char *label, int enabled)
- {
- if (enabled)
- return ngui_button(&ui, id, r, label);
- ngui_fill_rect(&ui, r, ui.theme.panel_alt);
- ngui_text(&ui, r.x + 10, r.y + (r.h - 16) / 2, label,
- ui.theme.text_dim);
- return 0;
- }
- static void gui_draw(void)
- {
- struct ngui_rect list = { 10, 52, 300, ui.h - 62 };
- struct ngui_rect right = { 320, 52, ui.w - 330, ui.h - 62 };
- struct ngui_rect btn;
- struct view *v = &views[selected];
- int i, enabled;
- unsigned int now = u_ticks_ms();
- int line_h = ngui_text_line_height(&ui, 12, 1);
- char sub[64], tr[16];
- ngui_fill_rect(&ui, (struct ngui_rect){ 0, 0, ui.w, ui.h },
- ui.theme.bg);
- {
- char head[96];
- if (views[0].running)
- snprintf(head, sizeof(head), "Init: running (pid %u)",
- views[0].pid);
- else
- snprintf(head, sizeof(head), "Init: not running");
- ngui_text(&ui, 12, 16, head, ui.theme.text);
- }
- for (i = 0; i < nviews; i++) {
- struct view *r = &views[i];
- struct ngui_row row;
- struct ngui_rect rr = { list.x, list.y + i * ROW_H,
- list.w, ROW_H };
- if (rr.y + rr.h > list.y + list.h)
- break;
- snprintf(tr, sizeof(tr), "%u", r->pid);
- snprintf(sub, sizeof(sub), "%s%s%s", r->state,
- r->pid ? " pid " : "", r->pid ? tr : "");
- row.title = r->name;
- row.subtitle = sub;
- row.trailing = r->desc;
- row.bars = -1;
- row.selected = (i == selected);
- if (ngui_list_row(&ui, ID_ROW_BASE + (unsigned int)i, rr, &row)) {
- selected = i;
- kill_arm = 0;
- log_scroll.offset = 0;
- log_follow = 1;
- gui_read_log();
- ngui_invalidate(&ui);
- }
- }
- btn = (struct ngui_rect){ right.x, right.y, 84, 30 };
- enabled = !v->is_init && !v->running;
- if (draw_button(ID_START, btn, "Start", enabled))
- pending_action = ID_START;
- btn.x += 92;
- enabled = !v->is_init && !v->is_wm && v->running;
- if (draw_button(ID_STOP, btn, "Stop", enabled))
- pending_action = ID_STOP;
- btn.x += 92;
- enabled = !v->is_init;
- if (draw_button(ID_RESTART, btn, "Restart", enabled))
- pending_action = ID_RESTART;
- btn.x += 92;
- enabled = !v->is_init && v->running;
- if (draw_button(ID_KILL, btn, "Kill", enabled))
- pending_action = ID_KILL;
- btn.x += 92;
- if (draw_button(ID_REFRESH, btn, "Refresh", 1))
- pending_action = ID_REFRESH;
- if (gui_status[0] && now - gui_status_at < 5000) {
- ngui_text_ellipsis(&ui, (struct ngui_rect){ right.x,
- right.y + 38, right.w, 20 }, right.x,
- right.y + 38, gui_status,
- ui.theme.text_dim);
- } else {
- ngui_text_ellipsis(&ui, (struct ngui_rect){ right.x,
- right.y + 38, right.w, 20 }, right.x,
- right.y + 38,
- v->is_wm ? "System service: restart/kill only"
- : v->desc,
- ui.theme.text_dim);
- }
- {
- struct ngui_rect body = { right.x, right.y + 64, right.w,
- right.h - 64 };
- int lines = 1, max, wheel;
- unsigned int i2;
- ngui_fill_rect(&ui, body, ui.theme.panel);
- if (v->is_wm) {
- ngui_text(&ui, body.x + 10, body.y + 10,
- "The WM writes to the serial console; no log.",
- ui.theme.text_dim);
- return;
- }
- if (!log_len) {
- ngui_text(&ui, body.x + 10, body.y + 10,
- "No log yet.", ui.theme.text_dim);
- return;
- }
- for (i2 = 0; i2 < log_len; i2++)
- if (log_buf[i2] == '\n')
- lines++;
- if (line_h < 10)
- line_h = 10;
- log_scroll.content_h = lines * line_h;
- log_scroll.view_h = body.h;
- log_scroll.hide_bar = 0;
- ngui_scroll_begin(&ui, body, &log_scroll);
- wheel = ngui_scroll_wheel(&ui, body, &log_scroll);
- max = log_scroll.content_h - log_scroll.view_h;
- if (max < 0)
- max = 0;
- if (wheel)
- log_follow = 0;
- if (log_follow)
- ngui_scroll_to(&log_scroll, max);
- if (log_scroll.offset >= max - 1)
- log_follow = 1;
- {
- unsigned int start = 0, end = 0;
- int idx = 0;
- int ly;
- while (end < log_len) {
- while (end < log_len && log_buf[end] != '\n')
- end++;
- ly = body.y + idx * line_h - log_scroll.offset;
- if (ly + line_h > body.y && ly < body.y + body.h)
- ngui_text_px(&ui, body.x + 6, ly,
- log_buf + start,
- end - start,
- ui.theme.text, 12, 0, 0, 1);
- idx++;
- if (end < log_len)
- end++;
- start = end;
- }
- }
- ngui_scroll_end(&ui, body, &log_scroll);
- }
- }
- static void gui_handle_action(int id)
- {
- unsigned int now = u_ticks_ms();
- struct view *v = &views[selected];
- if (id == ID_REFRESH) {
- gui_refresh();
- gui_read_log();
- ngui_invalidate(&ui);
- return;
- }
- if (id == ID_KILL) {
- if (v->is_wm) {
- gui_action("kill");
- return;
- }
- if (kill_arm && now - kill_arm_at < 3000) {
- kill_arm = 0;
- gui_action("kill");
- } else {
- kill_arm = 1;
- kill_arm_at = now;
- gui_status_set("Press Kill again to confirm", 1);
- ngui_invalidate(&ui);
- }
- return;
- }
- if (id == ID_START)
- gui_action("start");
- else if (id == ID_STOP)
- gui_action("stop");
- else if (id == ID_RESTART)
- gui_action("restart");
- }
- static void gui(const char *arg)
- {
- unsigned int sw = 0, sh = 0;
- unsigned int w = 820, h = 560;
- unsigned int last_poll = 0;
- int quit = 0;
- (void)arg;
- if (u_screen_size(&sw, &sh) == 0) {
- if (sw && w > sw - 30)
- w = sw - 30;
- if (sh && h > sh - 40)
- h = sh - 40;
- }
- if (w < 520)
- w = 520;
- if (h < 360)
- h = 360;
- if (u_win_create(w, h, "Services", &wi) != 0) {
- u_puts("service: no graphics window\n");
- u_exit(1);
- }
- ngui_init(&ui, (unsigned short *)wi.fb, (int)wi.width, (int)wi.height);
- ngui_font_attach(&ui);
- gui_refresh();
- gui_read_log();
- ngui_invalidate(&ui);
- for (;;) {
- unsigned int now = u_ticks_ms();
- if (now - last_poll >= POLL_MS) {
- last_poll = now;
- gui_refresh();
- gui_read_log();
- ngui_invalidate(&ui);
- }
- if (!ngui_begin(&ui)) {
- ngui_end_ex(&ui, 0);
- u_sleep_ms(LOOP_MS);
- continue;
- }
- {
- int k;
- while ((k = ngui_key(&ui)) != 0) {
- if (k == NGUI_KEY_ESC) {
- quit = 1;
- break;
- }
- if (k == NGUI_KEY_UP && selected > 0) {
- selected--;
- kill_arm = 0;
- log_scroll.offset = 0;
- log_follow = 1;
- gui_read_log();
- ngui_invalidate(&ui);
- } else if (k == NGUI_KEY_DOWN &&
- selected + 1 < nviews) {
- selected++;
- kill_arm = 0;
- log_scroll.offset = 0;
- log_follow = 1;
- gui_read_log();
- ngui_invalidate(&ui);
- }
- }
- }
- if (quit)
- break;
- pending_action = 0;
- gui_draw();
- ngui_end(&ui);
- if (pending_action)
- gui_handle_action(pending_action);
- u_sleep_ms(LOOP_MS);
- }
- u_win_close();
- u_exit(0);
- }
- void _start(const char *arg)
- {
- const char *a = arg;
- while (a && (*a == ' ' || *a == '\t'))
- a++;
- if (a && ((strncmp(a, "--gui", 5) == 0 &&
- (a[5] == '\0' || a[5] == ' ' || a[5] == '\t')) ||
- strcmp(a, "gui") == 0)) {
- gui(arg);
- return;
- }
- cli(arg);
- u_exit(0);
- }
|