diff options
author | Douglas Gilbert <dgilbert@interlog.com> | 2021-08-04 15:35:26 +0000 |
---|---|---|
committer | Douglas Gilbert <dgilbert@interlog.com> | 2021-08-04 15:35:26 +0000 |
commit | cbde70fafd0ab9353e79b708621adf73420fdded (patch) | |
tree | 907f91f8803a78d13acf373658cc655ce99c1bc6 /testing | |
parent | bfbefdf2d9aa12107d08d796d6fc78862ab85402 (diff) | |
download | sg3_utils-cbde70fafd0ab9353e79b708621adf73420fdded.tar.gz |
sg_ses: guard against small '--maxlen=' values
In several utilities guard against '--maxlen=' < 4 or < 16
as they seem to serve no useful purpose other than finding
awkward corner cases that may trip up these utilities.
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@908 6180dd3e-e324-4e3e-922d-17de1ae2f315
Diffstat (limited to 'testing')
-rw-r--r-- | testing/sg_mrq_dd.cpp | 15 | ||||
-rw-r--r-- | testing/sg_tst_excl.cpp | 80 | ||||
-rw-r--r-- | testing/sgh_dd.cpp | 9 |
3 files changed, 61 insertions, 43 deletions
diff --git a/testing/sg_mrq_dd.cpp b/testing/sg_mrq_dd.cpp index 4dc1f54c..65dc27fe 100644 --- a/testing/sg_mrq_dd.cpp +++ b/testing/sg_mrq_dd.cpp @@ -30,7 +30,7 @@ * */ -static const char * version_str = "1.33 20210730"; +static const char * version_str = "1.34 20210801"; #define _XOPEN_SOURCE 600 #ifndef _GNU_SOURCE @@ -1002,7 +1002,9 @@ calc_duration_throughput(int contin) static void print_stats(const char * str) { - bool show_slice = (gcoll.cp_ver_arr.size() > 1); + bool show_slice = ((gcoll.cp_ver_arr.size() > 1) && + (gcoll.cp_ver_arr[1].state != + cp_ver_pair_t::my_state::empty)); int k = 0; int64_t infull, outfull; @@ -1060,6 +1062,7 @@ siginfo_handler(int sig) print_stats(" "); } +#if 0 static void siginfo2_handler(int sig) { @@ -1069,6 +1072,7 @@ siginfo2_handler(int sig) calc_duration_throughput(1); print_stats(" "); } +#endif static void install_handler(int sig_num, void (*sig_handler) (int sig)) @@ -1502,10 +1506,12 @@ sig_listen_thread(struct global_collection * clp) raise(SIGINT); break; } + if (SIGUSR2 == sig_number) + break; if (shutting_down) break; } /* end of while loop */ - if (clp->verbose > 1) + if (clp->verbose > 3) pr2serr_lk("%s: exiting\n", __func__); } @@ -4200,7 +4206,7 @@ main(int argc, char * argv[]) install_handler(SIGQUIT, interrupt_handler); install_handler(SIGPIPE, interrupt_handler); install_handler(SIGUSR1, siginfo_handler); - install_handler(SIGUSR2, siginfo2_handler); + // install_handler(SIGUSR2, siginfo2_handler); num_ifiles = clp->inf_v.size(); num_ofiles = clp->outf_v.size(); @@ -4462,6 +4468,7 @@ main(int argc, char * argv[]) sigemptyset(&signal_set); sigaddset(&signal_set, SIGINT); + sigaddset(&signal_set, SIGUSR2); res = sigprocmask(SIG_BLOCK, &signal_set, &orig_signal_set); if (res < 0) { diff --git a/testing/sg_tst_excl.cpp b/testing/sg_tst_excl.cpp index b5a344d6..fba1d6a1 100644 --- a/testing/sg_tst_excl.cpp +++ b/testing/sg_tst_excl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2019 Douglas Gilbert. + * Copyright (c) 2013-2021 Douglas Gilbert. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -73,7 +73,7 @@ #include "sg_io_linux.h" #include "sg_unaligned.h" -static const char * version_str = "1.12 20190917"; +static const char * version_str = "1.13 20210801"; static const char * util_name = "sg_tst_excl"; /* This is a test program for checking O_EXCL on open() works. It uses @@ -117,7 +117,7 @@ using namespace std::chrono; #define DEF_WAIT_MS 0 /* 0: yield; -1: don't wait; -2: sleep(0) */ -#define DEF_LBA 1000 +#define DEF_LBA 1000U #define EBUFF_SZ 256 @@ -185,9 +185,8 @@ do_rd_inc_wr_twice_v3(const char * dev_name, unsigned int lba, int block, int excl, int wait_ms, int id, unsigned int & ebusy, unsigned int & eagains) { - int k, sg_fd, ok, res; - int odd = 0; - unsigned int u = 0; + bool odd = false; + int k, sg_fd; struct sg_io_hdr pt, pt2; unsigned char r16CmdBlk [READ16_CMD_LEN] = {0x88, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0}; @@ -195,7 +194,6 @@ do_rd_inc_wr_twice_v3(const char * dev_name, unsigned int lba, int block, {0x8a, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0}; unsigned char sense_buffer[64]; unsigned char lb[READ16_REPLY_LEN]; - char ebuff[EBUFF_SZ]; int open_flags = O_RDWR; sg_put_unaligned_be64(lba, r16CmdBlk + 2); @@ -216,6 +214,8 @@ do_rd_inc_wr_twice_v3(const char * dev_name, unsigned int lba, int block, sleep(0); // process yield ?? } if (sg_fd < 0) { + char ebuff[EBUFF_SZ]; + snprintf(ebuff, EBUFF_SZ, "%s: error opening file: %s", __func__, dev_name); perror(ebuff); @@ -223,6 +223,10 @@ do_rd_inc_wr_twice_v3(const char * dev_name, unsigned int lba, int block, } for (k = 0; k < 2; ++k) { + bool ok = false; + int res; + unsigned int u = 0; + /* Prepare READ_16 command */ memset(&pt, 0, sizeof(pt)); pt.interface_id = 'S'; @@ -277,10 +281,9 @@ do_rd_inc_wr_twice_v3(const char * dev_name, unsigned int lba, int block, return -1; } /* now for the error processing */ - ok = 0; switch (sg_err_category3(&pt)) { case SG_LIB_CAT_CLEAN: - ok = 1; + ok = true; break; case SG_LIB_CAT_RECOVERED: { @@ -288,7 +291,7 @@ do_rd_inc_wr_twice_v3(const char * dev_name, unsigned int lba, int block, fprintf(stderr, "Recovered error on READ_16, continuing\n"); } - ok = 1; + ok = true; break; default: /* won't bother decoding other categories */ { @@ -320,10 +323,10 @@ do_rd_inc_wr_twice_v3(const char * dev_name, unsigned int lba, int block, } pt = pt2; /* now for the error processing */ - ok = 0; + ok = false; switch (sg_err_category3(&pt)) { case SG_LIB_CAT_CLEAN: - ok = 1; + ok = true; break; case SG_LIB_CAT_RECOVERED: { @@ -332,7 +335,7 @@ do_rd_inc_wr_twice_v3(const char * dev_name, unsigned int lba, int block, fprintf(stderr, "%s: Recovered error on READ_16, " "continuing 2\n", __func__); } - ok = 1; + ok = true; break; default: /* won't bother decoding other categories */ { @@ -385,10 +388,10 @@ do_rd_inc_wr_twice_v3(const char * dev_name, unsigned int lba, int block, return -1; } /* now for the error processing */ - ok = 0; + ok = false; switch (sg_err_category3(&pt)) { case SG_LIB_CAT_CLEAN: - ok = 1; + ok = true; break; case SG_LIB_CAT_RECOVERED: { @@ -397,7 +400,7 @@ do_rd_inc_wr_twice_v3(const char * dev_name, unsigned int lba, int block, fprintf(stderr, "%s: Recovered error on WRITE_16, " "continuing\n", __func__); } - ok = 1; + ok = true; break; default: /* won't bother decoding other categories */ { @@ -413,7 +416,7 @@ do_rd_inc_wr_twice_v3(const char * dev_name, unsigned int lba, int block, } } close(sg_fd); - return odd; + return (int)odd; } /* Opens dev_name and spins if busy (i.e. gets EBUSY), sleeping for @@ -427,9 +430,8 @@ do_rd_inc_wr_twice_v4(const char * dev_name, unsigned int lba, int block, int excl, int wait_ms, int id, unsigned int & ebusy, unsigned int & eagains) { - int k, sg_fd, ok, res; - int odd = 0; - unsigned int u = 0; + bool odd = false; + int k, sg_fd; struct sg_io_v4 pt, pt2; unsigned char r16CmdBlk [READ16_CMD_LEN] = {0x88, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0}; @@ -437,7 +439,6 @@ do_rd_inc_wr_twice_v4(const char * dev_name, unsigned int lba, int block, {0x8a, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0}; unsigned char sense_buffer[64]; unsigned char lb[READ16_REPLY_LEN]; - char ebuff[EBUFF_SZ]; int open_flags = O_RDWR; sg_put_unaligned_be64(lba, r16CmdBlk + 2); @@ -458,6 +459,8 @@ do_rd_inc_wr_twice_v4(const char * dev_name, unsigned int lba, int block, sleep(0); // process yield ?? } if (sg_fd < 0) { + char ebuff[EBUFF_SZ]; + snprintf(ebuff, EBUFF_SZ, "%s: error opening file: %s", __func__, dev_name); perror(ebuff); @@ -465,6 +468,10 @@ do_rd_inc_wr_twice_v4(const char * dev_name, unsigned int lba, int block, } for (k = 0; k < 2; ++k) { + bool ok = false; + int res; + unsigned int u = 0; + /* Prepare READ_16 command */ memset(&pt, 0, sizeof(pt)); pt.guard = 'Q'; @@ -519,11 +526,10 @@ do_rd_inc_wr_twice_v4(const char * dev_name, unsigned int lba, int block, return -1; } /* now for the error processing */ - ok = 0; switch (sg_err_category_new(pt.device_status, pt.transport_status, pt.driver_status, sense_buffer, pt.response_len)) { case SG_LIB_CAT_CLEAN: - ok = 1; + ok = true; break; case SG_LIB_CAT_RECOVERED: { @@ -531,7 +537,7 @@ do_rd_inc_wr_twice_v4(const char * dev_name, unsigned int lba, int block, fprintf(stderr, "Recovered error on READ_16, continuing\n"); } - ok = 1; + ok = true; break; default: /* won't bother decoding other categories */ { @@ -567,11 +573,11 @@ do_rd_inc_wr_twice_v4(const char * dev_name, unsigned int lba, int block, } pt = pt2; /* now for the error processing */ - ok = 0; + ok = false; switch (sg_err_category_new(pt.device_status, pt.transport_status, pt.driver_status, sense_buffer, pt.response_len)) { case SG_LIB_CAT_CLEAN: - ok = 1; + ok = true; break; case SG_LIB_CAT_RECOVERED: { @@ -580,7 +586,7 @@ do_rd_inc_wr_twice_v4(const char * dev_name, unsigned int lba, int block, fprintf(stderr, "%s: Recovered error on READ_16, " "continuing 2\n", __func__); } - ok = 1; + ok = true; break; default: /* won't bother decoding other categories */ { @@ -638,11 +644,11 @@ do_rd_inc_wr_twice_v4(const char * dev_name, unsigned int lba, int block, return -1; } /* now for the error processing */ - ok = 0; + ok = false; switch (sg_err_category_new(pt.device_status, pt.transport_status, pt.driver_status, sense_buffer, pt.response_len)) { case SG_LIB_CAT_CLEAN: - ok = 1; + ok = true; break; case SG_LIB_CAT_RECOVERED: { @@ -651,7 +657,7 @@ do_rd_inc_wr_twice_v4(const char * dev_name, unsigned int lba, int block, fprintf(stderr, "%s: Recovered error on WRITE_16, " "continuing\n", __func__); } - ok = 1; + ok = true; break; default: /* won't bother decoding other categories */ { @@ -691,7 +697,6 @@ do_inquiry_prod_id(const char * dev_name, int block, int wait_ms, {0x12, 0, 0, 0, INQ_REPLY_LEN, 0}; unsigned char inqBuff[INQ_REPLY_LEN]; unsigned char sense_buffer[64]; - char ebuff[EBUFF_SZ]; int open_flags = O_RDWR; /* O_EXCL | O_RDONLY fails with EPERM */ if (! block) @@ -707,6 +712,8 @@ do_inquiry_prod_id(const char * dev_name, int block, int wait_ms, sleep(0); // process yield ?? } if (sg_fd < 0) { + char ebuff[EBUFF_SZ]; + snprintf(ebuff, EBUFF_SZ, "do_inquiry_prod_id: error opening file: %s", dev_name); perror(ebuff); @@ -821,7 +828,7 @@ work_thread(const char * dev_name, unsigned int lba, int id, int block, int main(int argc, char * argv[]) { - int k, res; + int k; int block = 0; int force = 0; unsigned int lba = DEF_LBA; @@ -830,7 +837,6 @@ main(int argc, char * argv[]) int wait_ms = DEF_WAIT_MS; int no_o_excl = 0; char * dev_name = NULL; - char b[64]; for (k = 1; k < argc; ++k) { if (0 == memcmp("-b", argv[k], 2)) @@ -914,8 +920,10 @@ main(int argc, char * argv[]) return 1; } if (! force) { - res = do_inquiry_prod_id(dev_name, block, wait_ms, ebusy_count, - b, sizeof(b)); + char b[64]; + int res = do_inquiry_prod_id(dev_name, block, wait_ms, + ebusy_count, b, sizeof(b)); + if (res) { fprintf(stderr, "INQUIRY failed on %s\n", dev_name); return 1; @@ -923,7 +931,7 @@ main(int argc, char * argv[]) // For safety, since <lba> written to, only permit scsi_debug // devices. Bypass this with '-f' option. if (0 != memcmp("scsi_debug", b, 10)) { - fprintf(stderr, "Since this utility writes to LBA %d, only " + fprintf(stderr, "Since this utility writes to LBA %u, only " "devices with scsi_debug\nproduct ID accepted.\n", lba); return 2; diff --git a/testing/sgh_dd.cpp b/testing/sgh_dd.cpp index c2d1e7ae..c421eb93 100644 --- a/testing/sgh_dd.cpp +++ b/testing/sgh_dd.cpp @@ -36,7 +36,7 @@ * renamed [20181221] */ -static const char * version_str = "2.13 20210730"; +static const char * version_str = "2.14 20210801"; #define _XOPEN_SOURCE 600 #ifndef _GNU_SOURCE @@ -1260,10 +1260,12 @@ sig_listen_thread(void * v_clp) raise(SIGINT); break; } + if (SIGUSR2 == sig_number) + break; if (shutting_down) break; } /* end of while loop */ - if (clp->verbose > 1) + if (clp->verbose > 3) pr2serr_lk("%s: exiting\n", __func__); return NULL; @@ -4841,6 +4843,7 @@ main(int argc, char * argv[]) sigemptyset(&signal_set); sigaddset(&signal_set, SIGINT); + sigaddset(&signal_set, SIGUSR2); status = pthread_sigmask(SIG_BLOCK, &signal_set, &orig_signal_set); if (0 != status) err_exit(status, "pthread_sigmask"); status = pthread_create(&sig_listen_thread_id, NULL, @@ -4897,7 +4900,7 @@ main(int argc, char * argv[]) shutting_down = true; /* pthread_cancel() has issues and is not supported in Android */ - status = pthread_kill(sig_listen_thread_id, SIGINT); + status = pthread_kill(sig_listen_thread_id, SIGUSR2); if (0 != status) err_exit(status, "pthread_kill"); if (do_time && (start_tm.tv_sec || start_tm.tv_usec)) |