vere: link binary on boot

This commit is contained in:
Joe Bryan 2022-05-18 14:55:36 -04:00
parent f97e186e61
commit 45d4c5ef68
3 changed files with 85 additions and 1 deletions

View File

@ -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 ) {

View File

@ -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

View File

@ -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) ) {