From 082f07474da1803e08168913080540b168cc87d9 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Fri, 27 May 2022 16:34:02 -0400 Subject: [PATCH] vere: create $pier/.bin/pace automatically --- pkg/urbit/vere/king.c | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/pkg/urbit/vere/king.c b/pkg/urbit/vere/king.c index 8170aceaf7..290229c671 100644 --- a/pkg/urbit/vere/king.c +++ b/pkg/urbit/vere/king.c @@ -1031,6 +1031,52 @@ _king_make_pace(c3_c* pac_c) return 0; } +static c3_i +_king_write_raw(c3_i fid_i, c3_y* buf_y, size_t len_i); + +/* _king_init_pace(): save pace file if not present +*/ +static c3_i +_king_init_pace(c3_c* pac_c) +{ + c3_c* bin_c; + c3_i fid_i, ret_i = asprintf(&bin_c, "%s/.bin/pace", u3_Host.dir_c); + c3_assert( ret_i > 0 ); + + if ( (-1 == (fid_i = open(bin_c, O_WRONLY | O_CREAT | O_EXCL, 0644))) ) { + if ( EEXIST == errno ) { + c3_free(bin_c); + // XX print something here? + // + return 0; + } + else { + u3l_log("dock: init pace (%s): open %s\n", pac_c, strerror(errno)); + c3_free(bin_c); + return -1; + } + } + + if ( _king_write_raw(fid_i, (c3_y*)pac_c, strlen(pac_c)) ) { + u3l_log("dock: init pace (%s): write %s\n", pac_c, strerror(errno)); + close(fid_i); + c3_free(bin_c); + return -1; + } + // XX sync first? + // + else if ( close(fid_i) ) { + u3l_log("dock: init pace (%s): close %s\n", pac_c, strerror(errno)); + c3_free(bin_c); + return 1; + } + + u3l_log("dock: pace (%s): configured at %s/.bin/pace\r\n", + pac_c, u3_Host.dir_c); + + return 0; +} + /* _king_link_run(): ln [bin_c] $pier/.run */ static c3_i @@ -1423,6 +1469,9 @@ u3_king_dock(c3_c* pac_c) exit(1); } else { + // NB: failure ignored + // + _king_init_pace(pac_c); u3l_log("vere: binary copy succeeded\r\n"); // XX print restart instructions }