From 1c97747e7c1b5748826ff041b355f8c5840e5286 Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 16 Nov 2018 15:40:33 -0800 Subject: [PATCH 1/4] updates boot printfs --- noun/events.c | 10 +++++----- noun/vortex.c | 1 - vere/main.c | 15 +++++++++++++-- vere/sist.c | 42 +++++++++++++++++++++--------------------- 4 files changed, 39 insertions(+), 29 deletions(-) diff --git a/noun/events.c b/noun/events.c index 002ba96160..89201e0c02 100644 --- a/noun/events.c +++ b/noun/events.c @@ -858,16 +858,16 @@ u3e_live(c3_o nuu_o, c3_c* dir_c) /* Load any patch files; apply them to images. */ if ( 0 != (pat_u = _ce_patch_open()) ) { - printf("_ce_patch_apply\r\n"); + printf("boot: _ce_patch_apply\r\n"); _ce_patch_apply(pat_u); - printf("_ce_image_sync\r\n"); + printf("boot: _ce_image_sync\r\n"); _ce_image_sync(&u3P.nor_u); _ce_image_sync(&u3P.sou_u); - printf("_ce_patch_delete\r\n"); + printf("boot: _ce_patch_delete\r\n"); _ce_patch_delete(); - printf("_ce_patch_free\r\n"); + printf("boot: _ce_patch_free\r\n"); _ce_patch_free(pat_u); } @@ -886,7 +886,7 @@ u3e_live(c3_o nuu_o, c3_c* dir_c) perror("protect"); c3_assert(0); } - printf("protected loom\r\n"); + printf("boot: protected loom\r\n"); } /* If the images were empty, we are logically booting. diff --git a/noun/vortex.c b/noun/vortex.c index faec49d429..6b8b407ee4 100644 --- a/noun/vortex.c +++ b/noun/vortex.c @@ -42,7 +42,6 @@ u3v_jack(void) fprintf(stderr, "jack: kernel %x\r\n", u3r_mug(u3A->ken)); cor = u3n_nock_on(0, u3k(u3A->ken)); - fprintf(stderr, "jacked\r\n"); u3z(cor); } diff --git a/vere/main.c b/vere/main.c index c96cf8fcf6..c6c9d64b89 100644 --- a/vere/main.c +++ b/vere/main.c @@ -587,11 +587,22 @@ main(c3_i argc, printf("~\n"); // printf("welcome.\n"); printf("urbit %s\n", URBIT_VERSION); - printf("urbit: home is %s\n", u3_Host.dir_c); + int mprint_i = 1000; + c3_c* abs_c = (c3_c *)malloc(mprint_i); + + // allocates more memory as needed if the path is too large + // + while ( abs_c != getcwd(abs_c, mprint_i) ) { + free(abs_c); + mprint_i *= 2; + abs_c = (c3_c *)malloc(mprint_i); + } + printf("boot: home is %s/%s\n", abs_c, u3_Host.dir_c); + free(abs_c); // printf("vere: hostname is %s\n", u3_Host.ops_u.nam_c); if ( c3y == u3_Host.ops_u.dem && c3n == u3_Host.ops_u.bat ) { - printf("urbit: running as daemon\n"); + printf("boot: running as daemon\n"); } // Seed prng. Don't panic -- just for fuzz testing. diff --git a/vere/sist.c b/vere/sist.c index 9163dcd49f..a1c0635f9b 100644 --- a/vere/sist.c +++ b/vere/sist.c @@ -45,17 +45,17 @@ u3_sist_pack(c3_w tem_w, c3_w typ_w, c3_w* bob_w, c3_w len_w) if ( -1 == lseek64(lug_u->fid_i, 4ULL * tar_d, SEEK_SET) ) { perror("lseek"); - uL(fprintf(uH, "sist_pack: seek failed\n")); + uL(fprintf(uH, "sist: seek failed\n")); c3_assert(0); } if ( sizeof(lar_u) != write(lug_u->fid_i, &lar_u, sizeof(lar_u)) ) { perror("write"); - uL(fprintf(uH, "sist_pack: write failed\n")); + uL(fprintf(uH, "sist: write failed\n")); c3_assert(0); } if ( -1 == lseek64(lug_u->fid_i, 4ULL * lug_u->len_d, SEEK_SET) ) { perror("lseek"); - uL(fprintf(uH, "sist_pack: seek failed\n")); + uL(fprintf(uH, "sist: seek failed\n")); c3_assert(0); } #if 0 @@ -68,7 +68,7 @@ u3_sist_pack(c3_w tem_w, c3_w typ_w, c3_w* bob_w, c3_w len_w) #endif if ( (4 * len_w) != write(lug_u->fid_i, bob_w, (4 * len_w)) ) { perror("write"); - uL(fprintf(uH, "sist_pack: write failed\n")); + uL(fprintf(uH, "sist: write failed\n")); c3_assert(0); } lug_u->len_d += (c3_d)(lar_u.len_w + c3_wiseof(lar_u)); @@ -433,8 +433,8 @@ _sist_fast(u3_noun pas, c3_l key_l) u3_noun yek = u3dc("scot", 'p', pas); c3_c* yek_c = u3r_string(yek); - printf("saving passcode in %s/.urb/code.%s\r\n", hom_c, gum_c); - printf("(for real security, write it down and delete the file...)\r\n"); + printf("boot: saving passcode in %s/.urb/code.%s\r\n", hom_c, gum_c); + printf("boot: for real security, write it down and delete the file\r\n"); { c3_i fid_i; @@ -487,7 +487,7 @@ _sist_staf(c3_l key_l) u3z(say); return 0; } - uL(fprintf(uH, "loaded passcode from %s\n", ful_c)); + uL(fprintf(uH, "boot: loaded passcode from %s\n", ful_c)); pas = u3k(u3t(u3t(u3t(say)))); u3z(say); @@ -532,7 +532,7 @@ _sist_zest() if ( ((fid_i = open(ful_c, pig_i, 0600)) < 0) || (fstat(fid_i, &buf_b) < 0) ) { - uL(fprintf(uH, "can't create record (%s)\n", ful_c)); + uL(fprintf(uH, "zest: can't create record (%s)\n", ful_c)); u3_lo_bail(); } #ifdef F_NOCACHE @@ -613,7 +613,7 @@ _sist_rest_nuu(u3_ulog* lug_u, u3_uled led_u, c3_c* old_c) c3_assert(led_u.mag_l == u3r_mug('f')); if ( -1 == lseek64(fid_i, 4ULL * end_d, SEEK_SET) ) { - uL(fprintf(uH, "rest_nuu failed (a)\n")); + uL(fprintf(uH, "rest: rest_nuu failed (a)\n")); perror("lseek64"); u3_lo_bail(); } @@ -800,7 +800,7 @@ _sist_rest() u3_uled led_u; if ( sizeof(led_u) != read(fid_i, &led_u, sizeof(led_u)) ) { - uL(fprintf(uH, "record (%s) is corrupt (a)\n", ful_c)); + uL(fprintf(uH, "rest: record (%s) is corrupt (a)\n", ful_c)); u3_lo_bail(); } @@ -850,7 +850,7 @@ _sist_rest() key = _sist_fatt(sal_l, pas); if ( u3r_mug(key) != key_l ) { - uL(fprintf(uH, "incorrect passcode\n")); + uL(fprintf(uH, "rest: incorrect passcode\n")); u3z(key); pas = 0; } @@ -875,7 +875,7 @@ _sist_rest() if ( -1 == lseek64(fid_i, 4ULL * end_d, SEEK_SET) ) { fprintf(stderr, "end_d %" PRIu64 "\n", end_d); perror("lseek"); - uL(fprintf(uH, "record (%s) is corrupt (c)\n", ful_c)); + uL(fprintf(uH, "rest: record (%s) is corrupt (c)\n", ful_c)); u3_lo_bail(); } @@ -888,17 +888,17 @@ _sist_rest() // uL(fprintf(uH, "rest: reading event at %" PRIx64 "\n", end_d)); if ( -1 == lseek64(fid_i, 4ULL * tar_d, SEEK_SET) ) { - uL(fprintf(uH, "record (%s) is corrupt (d)\n", ful_c)); + uL(fprintf(uH, "rest: record (%s) is corrupt (d)\n", ful_c)); u3_lo_bail(); } if ( sizeof(u3_ular) != read(fid_i, &lar_u, sizeof(u3_ular)) ) { - uL(fprintf(uH, "record (%s) is corrupt (e)\n", ful_c)); + uL(fprintf(uH, "rest: record (%s) is corrupt (e)\n", ful_c)); u3_lo_bail(); } if ( lar_u.syn_w != u3r_mug_d(tar_d) ) { if ( c3n == rup ) { - uL(fprintf(uH, "corruption detected; attempting to fix\n")); + uL(fprintf(uH, "rest: corruption detected; attempting to fix\n")); rup = c3y; } uL(fprintf(uH, "lar:%x mug:%x\n", lar_u.syn_w, u3r_mug_d(tar_d))); @@ -906,7 +906,7 @@ _sist_rest() continue; } else if ( c3y == rup ) { - uL(fprintf(uH, "matched at %x\n", lar_u.syn_w)); + uL(fprintf(uH, "rest: matched at %x\n", lar_u.syn_w)); rup = c3n; } @@ -927,8 +927,8 @@ _sist_rest() } else { if ( lar_u.ent_d != (ent_d - 1ULL) ) { - uL(fprintf(uH, "record (%s) is corrupt (g)\n", ful_c)); - uL(fprintf(uH, "lar_u.ent_d %" PRIx64 ", ent_d %" PRIx64 "\n", lar_u.ent_d, ent_d)); + uL(fprintf(uH, "rest: record (%s) is corrupt (g)\n", ful_c)); + uL(fprintf(uH, "rest: lar_u.ent_d %" PRIx64 ", ent_d %" PRIx64 "\n", lar_u.ent_d, ent_d)); u3_lo_bail(); } ent_d -= 1ULL; @@ -943,11 +943,11 @@ _sist_rest() img_w = c3_malloc(4 * lar_u.len_w); if ( -1 == lseek64(fid_i, 4ULL * end_d, SEEK_SET) ) { - uL(fprintf(uH, "record (%s) is corrupt (h)\n", ful_c)); + uL(fprintf(uH, "rest: record (%s) is corrupt (h)\n", ful_c)); u3_lo_bail(); } if ( (4 * lar_u.len_w) != read(fid_i, img_w, (4 * lar_u.len_w)) ) { - uL(fprintf(uH, "record (%s) is corrupt (i)\n", ful_c)); + uL(fprintf(uH, "rest: record (%s) is corrupt (i)\n", ful_c)); u3_lo_bail(); } @@ -959,7 +959,7 @@ _sist_rest() u3r_mug_both(u3r_mug(lar_u.tem_w), u3r_mug(lar_u.typ_w))) ) { - uL(fprintf(uH, "record (%s) is corrupt (j)\n", ful_c)); + uL(fprintf(uH, "rest: record (%s) is corrupt (j)\n", ful_c)); u3_lo_bail(); } From e31ea32519fc7914edf55aadff2fb57145a3702d Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 10 Jan 2019 11:22:02 -0800 Subject: [PATCH 2/4] adds realpath() for printing absolute path --- vere/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vere/main.c b/vere/main.c index bcbb37029c..094f84c024 100644 --- a/vere/main.c +++ b/vere/main.c @@ -51,7 +51,7 @@ static c3_c hostbuf[2048]; // kill me /* _main_presig(): prefix optional sig. */ -c3_c* +c3_c* _main_presig(c3_c* txt_c) { c3_c* new_c = malloc(2 + strlen(txt_c)); @@ -554,7 +554,7 @@ main(c3_i argc, mprint_i *= 2; abs_c = (c3_c *)malloc(mprint_i); } - printf("boot: home is %s/%s\n", abs_c, u3_Host.dir_c); + printf("boot: home is %s/%s\n", realpath(abs_c, NULL), u3_Host.dir_c); free(abs_c); // printf("vere: hostname is %s\n", u3_Host.ops_u.nam_c); @@ -598,7 +598,7 @@ main(c3_i argc, if ( _(u3_Host.ops_u.qui) ) { u3C.wag_w |= u3o_quiet; } - + /* Set dry-run flag. */ if ( _(u3_Host.ops_u.dry) ) { From 4c3d9f2b1e8bdb441afcbd57d55e6e1e76b8ec3e Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 10 Jan 2019 14:23:02 -0800 Subject: [PATCH 3/4] adds better way to print absolute path --- vere/main.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/vere/main.c b/vere/main.c index 094f84c024..05c1ae2317 100644 --- a/vere/main.c +++ b/vere/main.c @@ -544,18 +544,31 @@ main(c3_i argc, printf("~\n"); // printf("welcome.\n"); printf("urbit %s\n", URBIT_VERSION); - int mprint_i = 1000; - c3_c* abs_c = (c3_c *)malloc(mprint_i); - // allocates more memory as needed if the path is too large + // prints the absolute path of the pier // - while ( abs_c != getcwd(abs_c, mprint_i) ) { + c3_c* abs_c = realpath(u3_Host.dir_c, 0); + + // if the ship is being booted, we use realpath(). Otherwise, we use getcwd() + // with a memory-allocation loop + // + if (abs_c == NULL) { + c3_i mprint_i = 1000; + abs_c = c3_malloc(mprint_i); + + // allocates more memory as needed if the path is too large + // + while ( abs_c != getcwd(abs_c, mprint_i) ) { + free(abs_c); + mprint_i *= 2; + abs_c = c3_malloc(mprint_i); + } + printf("boot: home is %s/%s\n", abs_c, u3_Host.dir_c); + free(abs_c); + } else { + printf("boot: home is %s\n", abs_c); free(abs_c); - mprint_i *= 2; - abs_c = (c3_c *)malloc(mprint_i); } - printf("boot: home is %s/%s\n", realpath(abs_c, NULL), u3_Host.dir_c); - free(abs_c); // printf("vere: hostname is %s\n", u3_Host.ops_u.nam_c); if ( c3y == u3_Host.ops_u.dem && c3n == u3_Host.ops_u.bat ) { From 85c697f87dc91000d6af4b9a6802bfe77968c2fb Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 10 Jan 2019 15:23:37 -0800 Subject: [PATCH 4/4] makes boot message clearer --- vere/sist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vere/sist.c b/vere/sist.c index 5a01d0062d..f94fd84224 100644 --- a/vere/sist.c +++ b/vere/sist.c @@ -443,7 +443,7 @@ _sist_fast(u3_noun pas, c3_l key_l) c3_c* yek_c = u3r_string(yek); printf("boot: saving passcode in %s/.urb/code.%s\r\n", hom_c, gum_c); - printf("boot: for real security, write it down and delete the file\r\n"); + printf("boot: for more security, write it down and delete the file\r\n"); { c3_i fid_i;