Mr. Legan’s home, on Gilroy’s South Side, also was searched, the chief said, adding that he had no further details.

California, by some yardsticks, is among the states with the strictest gun laws in the country. The authorities did not specify the type of weapon used in the attack or whether it is banned in California. But they said the gunman carried out the shooting with a semiautomatic rifle that he had purchased legally this month in Nevada, a scenario that experts said may highlight how restrictions in some jurisdictions can be undermined by neighboring states whose gun laws are more lax.

“That’s the problem with this patchwork of laws throughout the country,” said Adam Skaggs, the chief counsel of the Giffords Law Center to Prevent Gun Violence, which lobbies for tighter gun laws. “Some places are trying to move the needle at the state level, but it is like combating air pollution. Your state can be the strongest on regulating emissions, but if neighboring states have no pollution controls, then air pollution is going to come downwind.”

[Here is what we know and what we don’t know about the shooting.]

Gilroy’s garlic festival, founded in 1979, is an internationally known event, drawing roughly 100,000 visitors each year — and one that has special significance for locals. Thousands volunteer at the festival, which raises money for local organizations, including youth swim leagues, music groups and a mission trip to build houses in Mexico.