Changeset: 3248cec1c6f0 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=3248cec1c6f0 Modified Files: common/utils/mutils.c common/utils/mutils.h Branch: default Log Message:
Merged from Apr2011 diffs (291 lines): diff --git a/common/utils/mutils.c b/common/utils/mutils.c --- a/common/utils/mutils.c +++ b/common/utils/mutils.c @@ -311,3 +311,39 @@ printf("back traces are not supported on this platform\n"); } #endif + +static char _bin_path[1024]; +char * +get_bin_path(void) +{ + /* getting the path to the executable's binary, isn't all that + * simple, unfortunately */ +#if defined(_MSC_VER) /* Windows */ + if (GetModuleFileName(NULL, _bin_path, + (DWORD) sizeof(_bin_path)) != 0) + return _bin_path; +#elif defined(HAVE__NSGETEXECUTABLEPATH) /* Darwin/OSX */ + uint32_t size = sizeof(_bin_path); + if (_NSGetExecutablePath(_bin_path, &size) == 0) + return _bin_path; +#elif defined(HAVE_SYS_SYSCTL_H) && defined(KERN_PROC_PATHNAME) /* BSD */ + int mib[4]; + size_t cb = sizeof(_bin_path); + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_PATHNAME; + mib[3] = -1; + if (sysctl(mib, 4, _bin_path, &cb, NULL, 0) == 0) + return _bin_path; +#elif defined(HAVE_GETEXECNAME) /* Solaris */ + const char *execn = getexecname(); + /* copy, such that the caller can actually modify this string */ + snprintf(_bin_path, sizeof(_bin_path), "%s", execn); +#else /* try Linux approach */ + if (readlink("/proc/self/exe", + _bin_path, sizeof(_bin_path)) != -1) + return _bin_path; +#endif + /* could use argv[0] (passed) to deduce location based on PATH */ + return NULL; +} diff --git a/common/utils/mutils.h b/common/utils/mutils.h --- a/common/utils/mutils.h +++ b/common/utils/mutils.h @@ -73,5 +73,6 @@ mutils_export int MT_lockf(char *filename, int mode, off_t off, off_t len); mutils_export void print_trace(void); +mutils_export char *get_bin_path(void); #endif /* _MUTILS_H_ */ diff --git a/tools/merovingian/daemon/argvcmds.c b/tools/merovingian/daemon/argvcmds.c --- a/tools/merovingian/daemon/argvcmds.c +++ b/tools/merovingian/daemon/argvcmds.c @@ -232,6 +232,9 @@ char *property; char *dbfarm = LOCALSTATEDIR "/monetdb5/dbfarm"; confkeyval *kv; + FILE *pfile = NULL; + char buf[8]; + pid_t meropid; if (argc < 2 || argc > 3) { command_help(2, &argv[-1]); @@ -277,6 +280,30 @@ fprintf(stderr, "set: no such property: %s\n", property); return(1); } + /* special trick to make it easy to use a different port with one + * command */ + if (strcmp(property, "port") == 0) { + int oport = kv->ival; + char *e; + if ((e = setConfVal(kv, p)) != NULL) { + fprintf(stderr, "set: failed to set property port: %s\n", e); + free(e); + return(1); + } + kv = findConfKey(ckv, "discoveryport"); + if (kv != NULL && kv->ival == oport && (e = setConfVal(kv, p)) != NULL) { + fprintf(stderr, "set: failed to set property discoveryport: %s\n", e); + free(e); + return(1); + } + kv = findConfKey(ckv, "controlport"); + if (kv != NULL && kv->ival == oport + 1) { + oport = atoi(p); + snprintf(buf, sizeof(buf), "%d", oport + 1); + property = "controlport"; + p = buf; + } + } if ((p = setConfVal(kv, p)) != NULL) { fprintf(stderr, "set: failed to set property %s: %s\n", property, p); free(p); @@ -288,6 +315,30 @@ return(1); } + property = getConfVal(ckv, "pidfile"); + + /* chdir to dbfarm so we can open relative files (like pidfile) */ + if (chdir(dbfarm) < 0) { + fprintf(stderr, "could not move to dbfarm '%s': %s\n", + dbfarm, strerror(errno)); + return(1); + } + + if ((pfile = fopen(property, "r")) != NULL && + fgets(buf, sizeof(buf), pfile) != NULL) + { + meropid = atoi(buf); + if (meropid != 0) { + if (kill(meropid, SIGHUP) == -1) { + fprintf(stderr, "sending SIGHUP to monetdbd[%d] failed: %s\n", + (int)meropid, strerror(errno)); + return(1); + } + } + } + if (pfile != NULL) + fclose(pfile); + return(0); } diff --git a/tools/merovingian/daemon/merovingian.c b/tools/merovingian/daemon/merovingian.c --- a/tools/merovingian/daemon/merovingian.c +++ b/tools/merovingian/daemon/merovingian.c @@ -413,7 +413,7 @@ err e; int argp; char *dbfarm = LOCALSTATEDIR "/monetdb5/dbfarm"; - char *pidfilename; + char *pidfilename = NULL; char *p; FILE *pidfile = NULL; char control_usock[1024]; @@ -529,8 +529,22 @@ srand(time(NULL)); /* figure out our hostname */ gethostname(_mero_hostname, 128); - /* where is the mserver5 binary we fork on demand? */ - _mero_mserver = BINDIR "/mserver5"; + /* where is the mserver5 binary we fork on demand? + * first try to locate it based on our binary location, fall-back to + * hardcoded bin-dir */ + _mero_mserver = get_bin_path(); + if (_mero_mserver != NULL) { + /* replace the trailing monetdbd by mserver5, fits nicely since + * they happen to be of same length */ + char *s = strrchr(_mero_mserver, '/'); + if (s != NULL && strcmp(s + 1, "monetdbd") == 0) { + s++; + *s++ = 'm'; *s++ = 's'; *s++ = 'e'; *s++ = 'r'; + *s++ = 'v'; *s++ = 'e'; *s++ = 'r'; *s++ = '5'; + if (stat(_mero_mserver, &sb) == -1) + _mero_mserver = NULL; + } + } /* setup default database properties, constants: unlike previous * versions, we do not want changing defaults any more */ _mero_db_props = getDefaultProps(); @@ -590,12 +604,24 @@ dbfarm, strerror(errno)); MERO_EXIT_CLEAN(1); } + /* absolutise dbfarm if it isn't yet (we're in it now) */ + if (*dbfarm != '/') { + dbfarm = alloca(1024); + if (getcwd(dbfarm, sizeof(1024)) == NULL) { + Mfprintf(stderr, "could not get dbfarm working directory: %s\n", + strerror(errno)); + MERO_EXIT(1); + } + } - /* exit early if this is not going to work well */ - if (stat(_mero_mserver, &sb) == -1) { - Mfprintf(stderr, "cannot stat %s executable: %s\n", - _mero_mserver, strerror(errno)); - MERO_EXIT_CLEAN(1); + if (_mero_mserver == NULL) { + _mero_mserver = BINDIR "/mserver5"; + if (stat(_mero_mserver, &sb) == -1) { + /* exit early if this is not going to work well */ + Mfprintf(stderr, "cannot stat %s executable: %s\n", + _mero_mserver, strerror(errno)); + MERO_EXIT_CLEAN(1); + } } /* read the merovingian properties from the dbfarm */ @@ -816,15 +842,7 @@ MERO_EXIT(1); } - { - char cwd[1024]; - if (getcwd(cwd, sizeof(cwd)) == NULL) { - Mfprintf(stderr, "could not get current working directory: %s\n", - strerror(errno)); - MERO_EXIT(1); - } - msab_init(cwd, NULL); - } + msab_init(dbfarm, NULL); unlink(control_usock); unlink(mapi_usock); diff --git a/tools/merovingian/daemon/monetdbd.1.in b/tools/merovingian/daemon/monetdbd.1.in --- a/tools/merovingian/daemon/monetdbd.1.in +++ b/tools/merovingian/daemon/monetdbd.1.in @@ -1,7 +1,7 @@ .\" Process this file with .\" groff -man -Tascii foo.1 .\" -.TH MONETDBD 1 "FEB 2011" MonetDB "MonetDB 5" +.TH MONETDBD 1 "APR 2011" MonetDB "MonetDB 5" .SH NAME monetdbd \- the MonetDB Database Server daemon .SH SYNOPSIS @@ -153,7 +153,10 @@ This property specifies which TCP port .B monetdbd should listen to for regular database connection requests. Defaults to -50000. +50000. When this value is changed, discoveryport and controlport are +changed also, when their values are port and port + 1 for discoveryport +and controlport respectively. This allows to easily make monetdbd run +on another port with a single command. .IP controlport For remote management of .BR monetdbd, diff --git a/tools/mserver/mserver5.c b/tools/mserver/mserver5.c --- a/tools/mserver/mserver5.c +++ b/tools/mserver/mserver5.c @@ -200,42 +200,6 @@ mal_exit(); } -static char _mserver_bin_path[1024]; -static char * -get_mserver_bin_path(void) -{ - /* getting the path to the executable's binary, isn't all that - * simple, unfortunately */ -#if defined(_MSC_VER) /* Windows */ - if (GetModuleFileName(NULL, _mserver_bin_path, - (DWORD) sizeof(_mserver_bin_path)) != 0) - return _mserver_bin_path; -#elif defined(HAVE__NSGETEXECUTABLEPATH) /* Darwin/OSX */ - uint32_t size = sizeof(_mserver_bin_path); - if (_NSGetExecutablePath(_mserver_bin_path, &size) == 0) - return _mserver_bin_path; -#elif defined(HAVE_SYS_SYSCTL_H) && defined(KERN_PROC_PATHNAME) /* BSD */ - int mib[4]; - size_t cb = sizeof(_mserver_bin_path); - mib[0] = CTL_KERN; - mib[1] = KERN_PROC; - mib[2] = KERN_PROC_PATHNAME; - mib[3] = -1; - if (sysctl(mib, 4, _mserver_bin_path, &cb, NULL, 0) == 0) - return _mserver_bin_path; -#elif defined(HAVE_GETEXECNAME) /* Solaris */ - const char *execn = getexecname(); - /* copy, such that the caller can actually modify this string */ - snprintf(_mserver_bin_path, sizeof(_mserver_bin_path), "%s", execn); -#else /* try Linux approach */ - if (readlink("/proc/self/exe", - _mserver_bin_path, sizeof(_mserver_bin_path)) != -1) - return _mserver_bin_path; -#endif - /* could use argv[0] (passed) to deduce location based on PATH */ - return NULL; -} - int main(int argc, char **av) { @@ -474,7 +438,7 @@ char *libdirs[] = { "lib", "lib64", "lib/64", "lib32", NULL }; size_t i; struct stat sb; - char *binpath = get_mserver_bin_path(); + char *binpath = get_bin_path(); if (binpath != NULL) { binpath = dirname(binpath); binpath = dirname(binpath); _______________________________________________ Checkin-list mailing list Checkin-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/checkin-list