Fix the creation of ZPOOL_HIST_CMD pool history entries.

Move the libzfs_fini() after the zpool_log_history() call
so the ZPOOL_HIST_CMD entry can get written.

Re-work the management of the zfs_allow_log_key TSD.

Fixes #1998.