From e8fcc3d7a69f44c84f6dc7a611594b876cbf9ed0 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Mon, 18 Jul 2016 14:30:30 +0900 Subject: [PATCH] repmgr: set default user for -R/--remote-user --- repmgr.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/repmgr.c b/repmgr.c index a23381ed..d71ff4d8 100644 --- a/repmgr.c +++ b/repmgr.c @@ -285,6 +285,20 @@ main(int argc, char **argv) PQconninfoFree(defs); + /* set default user for -R/--remote-user */ + + { + struct passwd *pw = NULL; + + pw = getpwuid(geteuid()); + if (pw == NULL) + { + fprintf(stderr, _("could not get current user name: %s\n"), strerror(errno)); + exit(ERR_BAD_CONFIG); + } + + strncpy(runtime_options.username, pw->pw_name, MAXLEN); + } /* * Though libpq will default to the username as dbname, PQconndefaults() @@ -4321,7 +4335,7 @@ do_help(void) printf(_(" -D, --data-dir=DIR local directory where the files will be\n" \ " copied to\n")); printf(_(" -f, --config-file=PATH path to the configuration file\n")); - printf(_(" -R, --remote-user=USERNAME database server username for rsync\n")); + printf(_(" -R, --remote-user=USERNAME database server username for rsync (default: \"%s\")\n"), runtime_options.username); printf(_(" -F, --force force potentially dangerous operations to happen\n")); printf(_(" --check-upstream-config verify upstream server configuration\n")); printf(_("\n"));