From 45d4c5ef6866f97b59e6a44e67ddc0e549b52162 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Wed, 18 May 2022 14:55:36 -0400 Subject: [PATCH] vere: link binary on boot --- pkg/urbit/daemon/main.c | 6 ++- pkg/urbit/include/vere/vere.h | 1 + pkg/urbit/vere/king.c | 79 +++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 1 deletion(-) diff --git a/pkg/urbit/daemon/main.c b/pkg/urbit/daemon/main.c index 5281c6e7f..ee3cda781 100644 --- a/pkg/urbit/daemon/main.c +++ b/pkg/urbit/daemon/main.c @@ -1271,8 +1271,12 @@ main(c3_i argc, return 1; } + u3_Host.dem_c = strdup(argv[0]); + + // XX add argument + // if ( !u3_Host.wrk_c ) { - u3_Host.wrk_c = strdup(argv[0]); + u3_Host.wrk_c = strdup(u3_Host.dem_c); } if ( c3y == u3_Host.ops_u.dem ) { diff --git a/pkg/urbit/include/vere/vere.h b/pkg/urbit/include/vere/vere.h index b567e69e0..5f40b64a3 100644 --- a/pkg/urbit/include/vere/vere.h +++ b/pkg/urbit/include/vere/vere.h @@ -318,6 +318,7 @@ typedef struct _u3_host { c3_w kno_w; // current executing stage c3_c* dir_c; // pier path (no trailing /) + c3_c* dem_c; // daemon executable path c3_c* wrk_c; // worker executable path c3_d now_d; // event tick uv_loop_t* lup_u; // libuv event loop diff --git a/pkg/urbit/vere/king.c b/pkg/urbit/vere/king.c index 09c19c69c..071df3e9b 100644 --- a/pkg/urbit/vere/king.c +++ b/pkg/urbit/vere/king.c @@ -1157,6 +1157,47 @@ _king_get_vere(c3_c* pac_c, c3_c* ver_c, c3_c* arc_c, c3_t lin_t) return 0; } +/* _king_link_vere(): link current binary into $pier/.bin +*/ +static c3_i +_king_link_vere(c3_c* pac_c, c3_c* ver_c, c3_c* arc_c, c3_t lin_t) +{ + c3_c* bin_c; + c3_i ret_i; + + if ( _king_make_pace(pac_c) ) { + return -1; // XX + } + + // XX windows .exe + // + ret_i = asprintf(&bin_c, "%s/.bin/%s/vere-v%s-%s", + u3_Host.dir_c, pac_c, ver_c, arc_c); + c3_assert( ret_i > 0 ); + + ret_i = link(u3_Host.dem_c, bin_c); + + if ( ret_i ) { + fprintf(stderr, "vere: link %s -> %s failed: %s\n", + bin_c, u3_Host.dem_c, strerror(errno)); + c3_free(bin_c); + return -1; + } + + // XX option + // + if ( lin_t ) { + if ( _king_link_run(bin_c) ) { + fprintf(stderr, "vere: link %s/.run failed\n", u3_Host.dir_c); + c3_free(bin_c); + return -1; + } + } + + c3_free(bin_c); + return 0; +} + /* _king_do_upgrade(): get arch-appropriate binary at [ver_c]. */ static void @@ -1183,6 +1224,32 @@ _king_do_upgrade(c3_c* pac_c, c3_c* ver_c) #endif } +/* _king_do_link(): link binary into pier on boot. +*/ +static void +_king_do_link(c3_c* pac_c) +{ +#ifdef U3_OS_ARCH +# ifdef U3_OS_mingw + c3_c* arc_c = U3_OS_ARCH ".exe"; // XX confirm +# else + c3_c* arc_c = U3_OS_ARCH; +# endif + + // XX get link option + // + if ( _king_link_vere(pac_c, URBIT_VERSION, arc_c, 1) ) { + u3l_log("vere: link failed\r\n"); + u3_king_bail(); + exit(1); + } + else { + u3l_log("vere: link succeeded\r\n"); + // XX print restart instructions + } +#endif +} + /* u3_king_done(): all piers closed. s/b callback */ void @@ -1221,6 +1288,18 @@ u3_king_done(void) c3_free(ver_c); } + if ( c3y == u3_Host.ops_u.nuu ) { + c3_c* pac_c; + + // hack to ensure we only try once + // + u3_Host.ops_u.nuu = c3n; + + pac_c = _king_get_pace(); + _king_do_link(pac_c); + c3_free(pac_c); + } + // XX hack, if pier's are still linked, we're not actually done // if ( !u3K.pir_u && !uv_is_closing(han_u) ) {