Capture errors within uH / uL

This commit is contained in:
Jōshin 2018-12-27 17:22:50 -08:00
parent c7d2256e03
commit fbd5d4e2ad

View File

@ -40,18 +40,15 @@ u3_sist_pack(c3_w tem_w, c3_w typ_w, c3_w* bob_w, c3_w len_w)
lar_u.len_w = len_w; lar_u.len_w = len_w;
if ( -1 == lseek64(lug_u->fid_i, 4ULL * tar_d, SEEK_SET) ) { if ( -1 == lseek64(lug_u->fid_i, 4ULL * tar_d, SEEK_SET) ) {
perror("lseek"); uL(fprintf(uH, "sist_pack: seek failed, lseek: %s\n", strerror(errno)));
uL(fprintf(uH, "sist_pack: seek failed\n"));
c3_assert(0); c3_assert(0);
} }
if ( sizeof(lar_u) != write(lug_u->fid_i, &lar_u, sizeof(lar_u)) ) { if ( sizeof(lar_u) != write(lug_u->fid_i, &lar_u, sizeof(lar_u)) ) {
perror("write"); uL(fprintf(uH, "sist_pack: write failed, write: %s\n", strerror(errno)));
uL(fprintf(uH, "sist_pack: write failed\n"));
c3_assert(0); c3_assert(0);
} }
if ( -1 == lseek64(lug_u->fid_i, 4ULL * lug_u->len_d, SEEK_SET) ) { if ( -1 == lseek64(lug_u->fid_i, 4ULL * lug_u->len_d, SEEK_SET) ) {
perror("lseek"); uL(fprintf(uH, "sist_pack: seek failed, lseek: %s\n", strerror(errno)));
uL(fprintf(uH, "sist_pack: seek failed\n"));
c3_assert(0); c3_assert(0);
} }
#if 0 #if 0
@ -63,8 +60,7 @@ u3_sist_pack(c3_w tem_w, c3_w typ_w, c3_w* bob_w, c3_w len_w)
lar_u.mug_w)); lar_u.mug_w));
#endif #endif
if ( (4 * len_w) != write(lug_u->fid_i, bob_w, (4 * len_w)) ) { if ( (4 * len_w) != write(lug_u->fid_i, bob_w, (4 * len_w)) ) {
perror("write"); uL(fprintf(uH, "sist_pack: write failed, write: %s\n", strerror(errno)));
uL(fprintf(uH, "sist_pack: write failed\n"));
c3_assert(0); c3_assert(0);
} }
lug_u->len_d += (c3_d)(lar_u.len_w + c3_wiseof(lar_u)); lug_u->len_d += (c3_d)(lar_u.len_w + c3_wiseof(lar_u));
@ -100,20 +96,19 @@ u3_sist_put(const c3_c* key_c, const c3_y* val_y, size_t siz_i)
c3_assert(ret_i < 2048); c3_assert(ret_i < 2048);
if ( (fid_i = open(ful_c, O_CREAT | O_TRUNC | O_WRONLY, 0600)) < 0 ) { if ( (fid_i = open(ful_c, O_CREAT | O_TRUNC | O_WRONLY, 0600)) < 0 ) {
uL(fprintf(uH, "sist: could not put %s\n", key_c)); uL(fprintf(uH, "sist: could not put %s: %s\n", key_c, strerror(errno)));
perror("open");
u3_lo_bail(); u3_lo_bail();
} }
if ( (ret_i = write(fid_i, val_y, siz_i)) != siz_i ) { if ( (ret_i = write(fid_i, val_y, siz_i)) != siz_i ) {
uL(fprintf(uH, "sist: could not write %s\n", key_c)); uL(fprintf(uH, "sist: could not write %s\n", key_c));
if ( ret_i < 0 ) { if ( ret_i < 0 ) {
perror("write"); uL(fprintf(uH, "write: %s\n", strerror(errno)));
} }
u3_lo_bail(); u3_lo_bail();
} }
ret_i = c3_sync(fid_i); ret_i = c3_sync(fid_i);
if ( ret_i < 0 ) { if ( ret_i < 0 ) {
perror("sync"); uL(fprintf(uH, "sync: %s\n", strerror(errno)));
} }
ret_i = close(fid_i); ret_i = close(fid_i);
c3_assert(0 == ret_i); c3_assert(0 == ret_i);
@ -136,8 +131,7 @@ u3_sist_has(const c3_c* key_c)
return -1; return -1;
} }
else { else {
uL(fprintf(uH, "sist: could not stat %s\n", key_c)); uL(fprintf(uH, "sist: could not stat %s: %s\n", key_c, strerror(errno)));
perror("stat");
u3_lo_bail(); u3_lo_bail();
} }
} }
@ -161,19 +155,17 @@ u3_sist_get(const c3_c* key_c, c3_y* val_y)
c3_assert(ret_i < 2048); c3_assert(ret_i < 2048);
if ( (fid_i = open(ful_c, O_RDONLY)) < 0 ) { if ( (fid_i = open(ful_c, O_RDONLY)) < 0 ) {
uL(fprintf(uH, "sist: could not get %s\n", key_c)); uL(fprintf(uH, "sist: could not get %s: %s\n", key_c, strerror(errno)));
perror("open");
u3_lo_bail(); u3_lo_bail();
} }
if ( (ret_i = fstat(fid_i, &sat_u)) < 0 ) { if ( (ret_i = fstat(fid_i, &sat_u)) < 0 ) {
uL(fprintf(uH, "sist: could not stat %s\n", key_c)); uL(fprintf(uH, "sist: could not stat %s: %s\n", key_c, strerror(errno)));
perror("fstat");
u3_lo_bail(); u3_lo_bail();
} }
if ( (ret_i = read(fid_i, val_y, sat_u.st_size)) != sat_u.st_size ) { if ( (ret_i = read(fid_i, val_y, sat_u.st_size)) != sat_u.st_size ) {
uL(fprintf(uH, "sist: could not read %s\n", key_c)); uL(fprintf(uH, "sist: could not read %s\n", key_c));
if ( ret_i < 0 ) { if ( ret_i < 0 ) {
perror("read"); uL(fprintf(uH, "read: %s\n", strerror(errno)));
} }
u3_lo_bail(); u3_lo_bail();
} }
@ -197,8 +189,8 @@ u3_sist_nil(const c3_c* key_c)
return; return;
} }
else { else {
uL(fprintf(uH, "sist: could not unlink %s\n", key_c)); uL(fprintf(uH, "sist: could not unlink %s: %s\n", key_c,
perror("unlink"); strerror(errno)));
u3_lo_bail(); u3_lo_bail();
} }
} }
@ -620,8 +612,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')); c3_assert(led_u.mag_l == u3r_mug('f'));
if ( -1 == lseek64(fid_i, 4ULL * end_d, SEEK_SET) ) { if ( -1 == lseek64(fid_i, 4ULL * end_d, SEEK_SET) ) {
uL(fprintf(uH, "rest_nuu failed (a)\n")); uL(fprintf(uH, "rest_nuu failed (a), lseek64: %s\n", strerror(errno)));
perror("lseek64");
u3_lo_bail(); u3_lo_bail();
} }
@ -634,13 +625,11 @@ _sist_rest_nuu(u3_ulog* lug_u, u3_uled led_u, c3_c* old_c)
tar_d = (end_d - (c3_d)c3_wiseof(u3_olar)); tar_d = (end_d - (c3_d)c3_wiseof(u3_olar));
if ( -1 == lseek64(fid_i, 4ULL * tar_d, SEEK_SET) ) { if ( -1 == lseek64(fid_i, 4ULL * tar_d, SEEK_SET) ) {
uL(fprintf(uH, "rest_nuu failed (b)\n")); uL(fprintf(uH, "rest_nuu failed (b), lseek64: %s\n", strerror(errno)));
perror("lseek64");
u3_lo_bail(); u3_lo_bail();
} }
if ( sizeof(u3_olar) != read(fid_i, &lar_u, sizeof(u3_olar)) ) { if ( sizeof(u3_olar) != read(fid_i, &lar_u, sizeof(u3_olar)) ) {
uL(fprintf(uH, "rest_nuu failed (c)\n")); uL(fprintf(uH, "rest_nuu failed (c), read: %s\n", strerror(errno)));
perror("read");
u3_lo_bail(); u3_lo_bail();
} }
@ -653,13 +642,11 @@ _sist_rest_nuu(u3_ulog* lug_u, u3_uled led_u, c3_c* old_c)
end_d = (tar_d - (c3_d)lar_u.len_w); end_d = (tar_d - (c3_d)lar_u.len_w);
if ( -1 == lseek64(fid_i, 4ULL * end_d, SEEK_SET) ) { if ( -1 == lseek64(fid_i, 4ULL * end_d, SEEK_SET) ) {
uL(fprintf(uH, "rest_nuu failed (e)\n")); uL(fprintf(uH, "rest_nuu failed (e), lseek64: %s\n", strerror(errno)));
perror("lseek64");
u3_lo_bail(); u3_lo_bail();
} }
if ( (4 * lar_u.len_w) != read(fid_i, img_w, (4 * lar_u.len_w)) ) { if ( (4 * lar_u.len_w) != read(fid_i, img_w, (4 * lar_u.len_w)) ) {
uL(fprintf(uH, "rest_nuu failed (f)\n")); uL(fprintf(uH, "rest_nuu failed (f), read: %s\n", strerror(errno)));
perror("read");
u3_lo_bail(); u3_lo_bail();
} }
@ -675,8 +662,7 @@ _sist_rest_nuu(u3_ulog* lug_u, u3_uled led_u, c3_c* old_c)
} }
if ( 0 != close(fid_i) ) { if ( 0 != close(fid_i) ) {
uL(fprintf(uH, "rest: could not close\n")); uL(fprintf(uH, "rest: could not close, close: %s\n", strerror(errno)));
perror("close");
u3_lo_bail(); u3_lo_bail();
} }
@ -684,15 +670,14 @@ _sist_rest_nuu(u3_ulog* lug_u, u3_uled led_u, c3_c* old_c)
c3_assert(ret_i < 2048); c3_assert(ret_i < 2048);
if ( (fud_i = open(nuu_c, O_CREAT | O_TRUNC | O_RDWR, 0600)) < 0 ) { if ( (fud_i = open(nuu_c, O_CREAT | O_TRUNC | O_RDWR, 0600)) < 0 ) {
uL(fprintf(uH, "rest: can't open record (%s)\n", nuu_c)); uL(fprintf(uH, "rest: can't open record (%s), open: %s\n", nuu_c,
perror("open"); strerror(errno)));
u3_lo_bail(); u3_lo_bail();
} }
led_u.mag_l = u3r_mug('g'); led_u.mag_l = u3r_mug('g');
if ( (sizeof(led_u) != write(fud_i, &led_u, sizeof(led_u))) ) { if ( (sizeof(led_u) != write(fud_i, &led_u, sizeof(led_u))) ) {
uL(fprintf(uH, "rest: can't write header\n")); uL(fprintf(uH, "rest: can't write header, write: %s\n", strerror(errno)));
perror("write");
u3_lo_bail(); u3_lo_bail();
} }
@ -722,13 +707,11 @@ _sist_rest_nuu(u3_ulog* lug_u, u3_uled led_u, c3_c* old_c)
u3z(ovo); u3z(ovo);
if ( (lar_u.len_w << 2) != write(fud_i, img_w, lar_u.len_w << 2) ) { if ( (lar_u.len_w << 2) != write(fud_i, img_w, lar_u.len_w << 2) ) {
uL(fprintf(uH, "rest_nuu failed (h)\n")); uL(fprintf(uH, "rest_nuu failed (h), write: %s\n", strerror(errno)));
perror("write");
u3_lo_bail(); u3_lo_bail();
} }
if ( sizeof(u3_ular) != write(fud_i, &lar_u, sizeof(u3_ular)) ) { if ( sizeof(u3_ular) != write(fud_i, &lar_u, sizeof(u3_ular)) ) {
uL(fprintf(uH, "rest_nuu failed (i)\n")); uL(fprintf(uH, "rest_nuu failed (i), write: %s\n", strerror(errno)));
perror("write");
u3_lo_bail(); u3_lo_bail();
} }
@ -738,13 +721,11 @@ _sist_rest_nuu(u3_ulog* lug_u, u3_uled led_u, c3_c* old_c)
} }
} }
if ( 0 != rename(nuu_c, old_c) ) { if ( 0 != rename(nuu_c, old_c) ) {
uL(fprintf(uH, "rest_nuu failed (k)\n")); uL(fprintf(uH, "rest_nuu failed (k), rename: %s\n", strerror(errno)));
perror("rename");
u3_lo_bail(); u3_lo_bail();
} }
if ( -1 == lseek64(fud_i, sizeof(u3_uled), SEEK_SET) ) { if ( -1 == lseek64(fud_i, sizeof(u3_uled), SEEK_SET) ) {
uL(fprintf(uH, "rest_nuu failed (l)\n")); uL(fprintf(uH, "rest_nuu failed (l), lseek64: %s\n", strerror(errno)));
perror("lseek64");
u3_lo_bail(); u3_lo_bail();
} }
lug_u->fid_i = fud_i; lug_u->fid_i = fud_i;
@ -880,8 +861,8 @@ _sist_rest()
ent_d = 0; ent_d = 0;
if ( -1 == lseek64(fid_i, 4ULL * end_d, SEEK_SET) ) { if ( -1 == lseek64(fid_i, 4ULL * end_d, SEEK_SET) ) {
fprintf(stderr, "end_d %" PRIu64 "\n", end_d); uL(fprintf(uH, "end_d %" PRIu64 ", lseek64: %s\n", end_d,
perror("lseek"); strerror(errno)));
uL(fprintf(uH, "record (%s) is corrupt (c)\n", ful_c)); uL(fprintf(uH, "record (%s) is corrupt (c)\n", ful_c));
u3_lo_bail(); u3_lo_bail();
} }