diff options
author | Justin T. Gibbs <gibbs@FreeBSD.org> | 1999-08-16 22:52:17 +0000 |
---|---|---|
committer | Justin T. Gibbs <gibbs@FreeBSD.org> | 1999-08-16 22:52:17 +0000 |
commit | 87609397183c7a61eecf30af0ee8e0b8e3c9a563 (patch) | |
tree | 0b84af5561c25a272739a0c308e19132cd9f7046 /share/examples/scsi_target | |
parent | 99cfa26a691e0394c8f1e30d00eb5e8ae730902f (diff) |
Add a cleanup handler called "atexit" to make sure we free up target
mode instances.
Print out exception information passed out from the kernel target mode
driver to this userland daemon.
Notes
Notes:
svn path=/head/; revision=49935
Diffstat (limited to 'share/examples/scsi_target')
-rw-r--r-- | share/examples/scsi_target/scsi_target.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/share/examples/scsi_target/scsi_target.c b/share/examples/scsi_target/scsi_target.c index 798c30b3463c..cad82c31e40a 100644 --- a/share/examples/scsi_target/scsi_target.c +++ b/share/examples/scsi_target/scsi_target.c @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: scsi_target.c,v 1.2 1998/12/10 04:00:03 gibbs Exp $ + * $Id: scsi_target.c,v 1.3 1999/03/05 23:12:02 gibbs Exp $ */ #include <sys/types.h> @@ -63,6 +63,7 @@ struct ioc_alloc_unit alloc_unit = { }; static void pump_events(); +static void cleanup(); static void handle_exception(); static void quit_handler(); static void usage(); @@ -154,8 +155,16 @@ main(int argc, char *argv[]) signal(SIGINT, quit_handler); signal(SIGTERM, quit_handler); + atexit(cleanup); + pump_events(); + return (0); +} + +static void +cleanup() +{ close(targfd); if (ioctl(targctlfd, TARGCTLIOFREEUNIT, &alloc_unit) == -1) { @@ -164,7 +173,6 @@ main(int argc, char *argv[]) } close(targctlfd); - return (0); } static void @@ -207,6 +215,8 @@ pump_events() if (retval == -1) { perror("Read from targ failed"); + /* Go look for exceptions */ + continue; } else { retval = write(ofd, buf, retval); if (retval == -1) { @@ -248,8 +258,10 @@ handle_exception() exit(EX_SOFTWARE); } + printf("Saw exceptions %x\n", exceptions); if ((exceptions & TARG_EXCEPT_DEVICE_INVALID) != 0) { /* Device went away. Nothing more to do. */ + printf("Device went away\n"); exit(0); } |