diff --git a/indra/newview/llpanellogin.cpp b/indra/newview/llpanellogin.cpp
index 142dea83e2d2b9cf45760151223a2eec1057653f..0b674301f0456e2069500093b479d99fcbbe973f 100644
--- a/indra/newview/llpanellogin.cpp
+++ b/indra/newview/llpanellogin.cpp
@@ -178,7 +178,7 @@ LLPanelLogin::LLPanelLogin(const LLRect &rect,
 
 	mPasswordModified = FALSE;
 
-	LLPanelLogin::sInstance = this;
+	sInstance = this;
 
 	LLView* login_holder = gViewerWindow->getLoginPanelHolder();
 	if (login_holder)
@@ -234,29 +234,44 @@ LLPanelLogin::LLPanelLogin(const LLRect &rect,
 	server_choice_combo->add(LLGridManager::getInstance()->getGridLabel(), 
 							 current_grid,
 							 ADD_TOP);	
-	server_choice_combo->selectFirstItem();		
+	server_choice_combo->selectFirstItem();
 
 	LLSLURL start_slurl(LLStartUp::getStartSLURL());
+	// The StartSLURL might have been set either by an explicit command-line
+	// argument (CmdLineLoginLocation) or by default.
+	// current_grid might have been set either by an explicit command-line
+	// argument (CmdLineGridChoice) or by default.
+	// If the grid specified by StartSLURL is the same as current_grid, the
+	// distinction is moot.
+	// If we have an explicit command-line SLURL, use that.
+	// If we DON'T have an explicit command-line SLURL but we DO have an
+	// explicit command-line grid, which is different from the default SLURL's
+	// -- do NOT override the explicit command-line grid with the grid from
+	// the default SLURL!
+	bool force_grid{ start_slurl.getGrid() != current_grid &&
+					 gSavedSettings.getString("CmdLineLoginLocation").empty() &&
+				   ! gSavedSettings.getString("CmdLineGridChoice").empty() };
 	if ( !start_slurl.isSpatial() ) // has a start been established by the command line or NextLoginLocation ? 
 	{
 		// no, so get the preference setting
 		std::string defaultStartLocation = gSavedSettings.getString("LoginLocation");
 		LL_INFOS("AppInit")<<"default LoginLocation '"<<defaultStartLocation<<"'"<<LL_ENDL;
 		LLSLURL defaultStart(defaultStartLocation);
-		if ( defaultStart.isSpatial() )
+		if ( defaultStart.isSpatial() && ! force_grid )
 		{
 			LLStartUp::setStartSLURL(defaultStart);
 		}
 		else
 		{
-			LL_INFOS("AppInit")<<"no valid LoginLocation, using home"<<LL_ENDL;
+			LL_INFOS("AppInit") << (force_grid? "--grid specified" : "no valid LoginLocation")
+								<< ", using home" << LL_ENDL;
 			LLSLURL homeStart(LLSLURL::SIM_LOCATION_HOME);
 			LLStartUp::setStartSLURL(homeStart);
 		}
 	}
-	else
+	else if (! force_grid)
 	{
-		LLPanelLogin::onUpdateStartSLURL(start_slurl); // updates grid if needed
+		onUpdateStartSLURL(start_slurl); // updates grid if needed
 	}
 	
 	childSetAction("connect_btn", onClickConnect, this);
@@ -380,7 +395,7 @@ void LLPanelLogin::setFocus(BOOL b)
 	{
 		if(b)
 		{
-			LLPanelLogin::giveFocus();
+			giveFocus();
 		}
 		else
 		{