08fb35f066888f31ecbfcb4a5a1517c58413c27c
galt
  Thu Nov 15 16:09:21 2018 -0800
fixing a problem with mysqldump and profile.db settings that messed it up. Now it comments out the database= setting, but only if it is mysqldump running.

diff --git src/hg/lib/sqlProg.c src/hg/lib/sqlProg.c
index 088e080..dbcda73 100644
--- src/hg/lib/sqlProg.c
+++ src/hg/lib/sqlProg.c
@@ -77,31 +77,31 @@
 {
 if (fileExists(path))
     {
     char *cnf = NULL;
     size_t cnfSize = 0;
     readInGulp(path, &cnf, &cnfSize);
     if (write (fileNo, cnf, cnfSize) == -1)
         {
         freeMem(cnf);
 	errAbort("Writing %s to file %s failed with errno %d", path, defaultFileName, errno);
         }
     freeMem(cnf);
     }
 }
 
-int sqlMakeDefaultsFile(char* defaultFileName, char* profile, char* group)
+int sqlMakeDefaultsFile(char* defaultFileName, char* profile, char* group, char *prog)
 /* Create a temporary file in the supplied directory to be passed to
  * mysql with --defaults-file.  Writes a mysql options set for
  * the mysql group [group] with the profile.host, profile.user, and
  * profile.password values returned from cfgVal().  If group is not
  * client or mysql, a --defaults-group-suffix=group must be passed to
  * mysql to actually invoke the settings.
  * passFileName cannot be static, and the last 6 characters must
  * be XXXXXX.  Those characters will be modified to form a unique suffix.
  * Returns a file descriptor for the file or dies with an error */
 {
 int fileNo;
 char paddedGroup [256]; /* string with brackets around the group name */
 char path[1024];
 
 if ((fileNo=mkstemp(defaultFileName)) == -1)
@@ -124,30 +124,34 @@
 
 safef(path, sizeof path, "%s/my.cnf", getenv("MYSQL_HOME"));
 copyCnfToDefaultsFile(path, defaultFileName, fileNo);
 
 safef(path, sizeof path, "%s/.my.cnf", getenv("HOME"));
 copyCnfToDefaultsFile(path, defaultFileName, fileNo);
 
 /* write out the group name, user, host, and password */
 safef(paddedGroup, sizeof(paddedGroup), "[%s]\n", group);
 if (write (fileNo, paddedGroup, strlen(paddedGroup)) == -1)
     errAbort("Writing group to temporary file %s failed with errno %d", defaultFileName, errno);
 
 char *settings = sqlProfileToMyCnf(profile);
 if (!settings)
     errAbort("profile %s not found in sqlProfileToMyCnf() -- failed for file %s failed with errno %d", profile, defaultFileName, errno);
+if (sameString(prog, "mysqldump"))
+    {  // need to suppress the database setting, it messes up mysqldump and is not needed. comment it out
+    settings = replaceChars(settings, "\ndatabase=", "\n#database=");
+    }
 if (write (fileNo, settings, strlen(settings)) == -1)
     errAbort("Writing profile %s settings=[%s] as my.cnf format failed for file %s failed with errno %d", profile, settings, defaultFileName, errno);
 
 
 return fileNo;
 }
 
 
 void sqlExecProg(char *prog, char **progArgs, int userArgc, char *userArgv[])
 /* Exec one of the sql programs using user and password from ~/.hg.conf.
  * progArgs is NULL-terminate array of program-specific arguments to add,
  * which maybe NULL. userArgv are arguments passed in from the command line.
  * The program is execvp-ed, this function does not return. */
 {
 sqlExecProgProfile(getDefaultProfileName(), prog, progArgs, userArgc, userArgv);
@@ -200,31 +204,31 @@
 // install cleanup signal handlers
 sqlProgInitSigHandlers();
 
 /* Assemble defaults file */
 if ((homeDir = getenv("HOME")) == NULL)
     errAbort("sqlExecProgProfile: HOME is not defined in environment; cannot create temporary password file");
 
 nukeOldCnfs(homeDir);
 // look for special parameter -profile=name
 for (i = 0; i < userArgc; i++)
     if (startsWith("-profile=", userArgv[i]))
 	profile=cloneString(userArgv[i]+strlen("-profile="));
 
 safef(defaultFileName, sizeof(defaultFileName), "%s/.hgsql.cnf-XXXXXX", homeDir);
 // discard returned fileNo
-(void) sqlMakeDefaultsFile(defaultFileName, profile, "client");
+(void) sqlMakeDefaultsFile(defaultFileName, profile, "client", prog);
 
 safef(defaultFileArg, sizeof(defaultFileArg), "--defaults-file=%s", defaultFileName);
 
 AllocArray(nargv, nargc);
 
 nargv[j++] = prog;
 nargv[j++] = defaultFileArg;   /* --defaults-file must come before other options */
 if (progArgs != NULL)
     {
     for (i = 0; progArgs[i] != NULL; i++)
         nargv[j++] = progArgs[i];
     }
 for (i = 0; i < userArgc; i++)
     if (!startsWith("-profile=", userArgv[i]))
 	nargv[j++] = userArgv[i];