Get attachment script state before taking sp.AttachmentsSyncLock() to avoid race conditions between closing agents and scripts that may be doing attachment manipulation.

This is in an effort to resolve http://opensimulator.org/mantis/view.php?id=6557
Merge branch 'master' of ssh://opensimulator.org/var/git/opensim