e9f76ce291ef0801defc1aadd03064ea95bface0 galt Wed Aug 5 23:19:00 2015 -0700 Added -profile=<profileName> option to hg/lib/sqlProg.c so now all of the hgsql-family of utils can login via ANY profile in their hg.conf. Seems to work quite well. Might be a lot easier in many cases to add a new profile to the existing ~/.hg.conf, instead of trying to use environment vars to point to some other hg.conf file. diff --git src/hg/lib/sqlProg.c src/hg/lib/sqlProg.c index a6ca8ed..b2644e8 100644 --- src/hg/lib/sqlProg.c +++ src/hg/lib/sqlProg.c @@ -195,46 +195,51 @@ * The program is execvp-ed, this function does not return. */ { int i, j = 0, nargc=cntArgv(progArgs)+userArgc+6, defaultFileNo, returnStatus; pid_t child_id; char **nargv, defaultFileName[256], defaultFileArg[256], *homeDir; // 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); defaultFileNo=sqlMakeDefaultsFile(defaultFileName, profile, "client"); 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]; nargv[j++] = NULL; // flush before forking so we can't accidentally get two copies of the output fflush(stdout); fflush(stderr); child_id = fork(); killChildPid = child_id; if (child_id == 0) { execvp(nargv[0], nargv); _exit(42); /* Why 42? Why not? Need something user defined that mysql isn't going to return */ } else