Six officers shot gunman, ending massacre