vere: adds dock subcommand for copying binary into pier

This commit is contained in:
Joe Bryan 2022-05-26 00:52:57 -04:00
parent e473beef41
commit 2643ee9405
4 changed files with 67 additions and 24 deletions

View File

@ -38,6 +38,31 @@ static u3_cue_xeno* sil_u; // cue handle
STATIC_ASSERT(( 0 == CHAR_MIN && UCHAR_MAX == CHAR_MAX ),
"unsigned char required");
/* _main_self_path(): get binary self-path.
*/
static void
_main_self_path(void)
{
c3_c* pat_c;
c3_i len_i, pat_i;
if ( 0 < (len_i = wai_getExecutablePath(NULL, 0, &pat_i)) ) {
pat_c = c3_malloc( 1 + len_i );
wai_getExecutablePath(pat_c, len_i, &pat_i);
pat_c[len_i] = 0;
u3_Host.dem_c = pat_c;
}
else {
fprintf(stderr, "unable to get binary self path\r\n");
exit(1);
// XX continue?
//
// u3_Host.dem_c = strdup(bin_c);
}
}
/* _main_readw(): parse a word from a string.
*/
static u3_noun
@ -574,6 +599,7 @@ _cw_usage(c3_c* bin_c)
c3_c *use_c[] = {
"utilities:\n",
" %s cram %.*s jam state:\n",
" %s dock %.*s copy binary:\n",
" %s grab %.*s measure memory usage:\n",
" %s info %.*s print pier info:\n",
" %s meld %.*s deduplicate snapshot:\n",
@ -1096,6 +1122,34 @@ _cw_disk_init(c3_c* dir_c)
return log_u;
}
/* _cw_dock(): copy binary into pier
*/
static void
_cw_dock(c3_i argc, c3_c* argv[])
{
switch ( argc ) {
case 2: {
if ( !(u3_Host.dir_c = _main_pier_run(argv[0])) ) {
fprintf(stderr, "unable to find pier\r\n");
exit (1);
}
} break;
case 3: {
u3_Host.dir_c = argv[2];
} break;
default: {
fprintf(stderr, "invalid command\r\n");
exit(1);
} break;
}
_main_self_path();
u3_king_dock(U3_VERE_PACE);
}
/* _cw_info(); print pier info
*/
static void
@ -1423,6 +1477,7 @@ _cw_utils(c3_i argc, c3_c* argv[])
//
// $@ ~ :: usage
// $% [%cram dir=@t] :: jam state
// [%dock dir=@t] :: copy binary
// [?(%grab %mass) dir=@t] :: gc
// [%info dir=@t] :: print
// [%meld dir=@t] :: deduplicate
@ -1451,6 +1506,7 @@ _cw_utils(c3_i argc, c3_c* argv[])
switch ( mot_m ) {
case c3__cram: _cw_cram(argc, argv); return 1;
case c3__dock: _cw_dock(argc, argv); return 1;
case c3__mass:
case c3__grab: _cw_grab(argc, argv); return 1;
@ -1505,26 +1561,7 @@ main(c3_i argc,
case 2: break;
}
{
c3_c* pat_c;
c3_i len_i, pat_i;
if ( 0 < (len_i = wai_getExecutablePath(NULL, 0, &pat_i)) ) {
pat_c = c3_malloc( 1 + len_i );
wai_getExecutablePath(pat_c, len_i, &pat_i);
pat_c[len_i] = 0;
u3_Host.dem_c = pat_c;
}
else {
fprintf(stderr, "unable to get binary self path\r\n");
exit(1);
// XX continue?
//
// u3_Host.dem_c = strdup(bin_c);
}
}
_main_self_path();
// XX add argument
//

View File

@ -328,6 +328,7 @@
# define c3__dmal c3_s4('d','m','a','l')
# define c3__do c3_s2('d','o')
# define c3__doc c3_s3('d','o','c')
# define c3__dock c3_s4('d','o','c','k')
# define c3__docs c3_s4('d','o','c','s')
# define c3__dogo c3_s4('d','o','g','o')
# define c3__dojo c3_s4('d','o','j','o')

View File

@ -1414,6 +1414,11 @@
void
u3_king_slog(void);
/* u3_king_dock(): copy binary into pier on boot.
*/
void
u3_king_dock(c3_c* pac_c);
/* u3_king_done(): all piers closed
*/
void

View File

@ -1397,10 +1397,10 @@ _king_do_upgrade(c3_c* pac_c, c3_c* ver_c)
}
}
/* _king_do_copy(): copy binary into pier on boot.
/* u3_king_dock(): copy binary into pier on boot.
*/
static void
_king_do_copy(c3_c* pac_c)
void
u3_king_dock(c3_c* pac_c)
{
c3_c* arc_c = "unknown";
@ -1472,7 +1472,7 @@ u3_king_done(void)
// hack to ensure we only try once
//
u3_Host.ops_u.nuu = c3n;
_king_do_copy(U3_VERE_PACE);
u3_king_dock(U3_VERE_PACE);
}
// XX hack, if pier's are still linked, we're not actually done