diff options
author | wr61 <wr61@e10066b5-e1e2-0310-b819-94efdf66514b> | 2005-03-05 14:06:24 +0000 |
---|---|---|
committer | wr61 <wr61@e10066b5-e1e2-0310-b819-94efdf66514b> | 2005-03-05 14:06:24 +0000 |
commit | 21d78a218f69ab629be8358974fcb32b1ac71c21 (patch) | |
tree | f1f74643dc611d186328ad0cff82ddbf4b471354 | |
parent | 6a41628f4628c7cc989ea5409f30fcbd80392c0a (diff) | |
download | vdr-plugin-muggle-21d78a218f69ab629be8358974fcb32b1ac71c21.tar.gz vdr-plugin-muggle-21d78a218f69ab629be8358974fcb32b1ac71c21.tar.bz2 |
Option -d for embedded mysql datadir
git-svn-id: https://vdr-muggle.svn.sourceforge.net/svnroot/vdr-muggle/branches/0.1.3-wr@540 e10066b5-e1e2-0310-b819-94efdf66514b
-rw-r--r-- | mg_mysql.c | 31 | ||||
-rw-r--r-- | mg_mysql.h | 1 | ||||
-rw-r--r-- | mg_order.c | 1 | ||||
-rw-r--r-- | muggle.c | 23 | ||||
-rwxr-xr-x | mugglei.c | 19 |
5 files changed, 67 insertions, 8 deletions
@@ -25,16 +25,18 @@ class mysqlhandle_t { public: mysqlhandle_t(); ~mysqlhandle_t(); - private: - char *m_datadir; }; -char *server_args[] = +#ifndef HAVE_SERVER +static char *datadir; + +static char *server_args[] = { "muggle", + "--datadir=/tmp", // stupid default "--key_buffer_size=32M" }; -char *server_groups[] = +static char *server_groups[] = { "embedded", "server", @@ -42,6 +44,22 @@ char *server_groups[] = 0 }; +void +set_datadir(char *dir) +{ + mgDebug(1,"setting datadir to %s",dir); + struct stat stbuf; + datadir=strdup(dir); + asprintf(&server_args[1],"--datadir=%s",datadir); + if (stat(datadir,&stbuf)) + mkdir(datadir,0755); + if (stat(datadir,&stbuf)) + { + mgError("Cannot access datadir %s: errno=%d",datadir,errno); + } +} +#endif + mysqlhandle_t::mysqlhandle_t() { #ifndef HAVE_SERVER @@ -57,7 +75,6 @@ mysqlhandle_t::~mysqlhandle_t() #ifndef HAVE_SERVER mgDebug(3,"calling mysql_server_end"); mysql_server_end(); - free(m_datadir); #endif } @@ -491,9 +508,9 @@ mgmySql::Connect () } #else if (!mysql_real_connect(m_db, 0, 0, 0, 0, 0, 0, 0)) - mgWarning("Failed to connect to embedded data base:%s ",mysql_error(m_db)); + mgWarning("Failed to connect to embedded mysql in %s:%s ",datadir,mysql_error(m_db)); else - mgDebug(1,"Connected to embedded mysql"); + mgDebug(1,"Connected to embedded mysql in %s",datadir); #endif if (m_db) { @@ -17,6 +17,7 @@ using namespace std; void database_end(); // must be done explicitly +void set_datadir(char *datadir); /*! * \brief an abstract database class @@ -695,7 +695,6 @@ mgOrder::mgOrder(mgValmap& nv,char *prefix) unsigned int v = nv.getuint(idx); free(idx); if (v==0) break; - mgDebug(1,"found %s:%d",idx,v); setKey (mgKeyTypes(v) ); } if (size()>0) @@ -57,6 +57,12 @@ mgMuggle::mgMuggle (void) the_setup.DbPass = strdup (""); the_setup.GdCompatibility = false; the_setup.ToplevelDir = strdup ("/mnt/music/"); +#ifndef HAVE_SERVER + char *buf; + asprintf(&buf,"%s/.muggle",getenv("HOME")); + set_datadir(buf); + free(buf); +#endif } #if VDRVERSNUM >= 0321 @@ -86,6 +92,9 @@ mgMuggle::CommandLineHelp (void) " -u UUUU, --user=UUUU specify database user (default is )\n" " -w WWWW, --password=WWWW specify database password (default is empty)\n" " -t TTTT, --toplevel=TTTT specify toplevel directory for music (default is /mnt/music)\n" +#ifndef HAVE_SERVER + " -d DIRN, --datadir=DIRN specify directory for embedded sql data (default is $HOME/.muggle)\n" +#endif " -g, --giantdisc enable full Giantdisc compatibility mode\n" " -v, --verbose specify debug level. The higher the more. Default is 1\n"; } @@ -106,6 +115,9 @@ bool mgMuggle::ProcessArgs (int argc, char *argv[]) {"port", required_argument, NULL, 'p'}, {"user", required_argument, NULL, 'u'}, {"password", required_argument, NULL, 'w'}, +#ifndef HAVE_SERVER + {"datadir", required_argument, NULL, 'd'}, +#endif {"toplevel", required_argument, NULL, 't'}, {"giantdisc", no_argument, NULL, 'g'}, {NULL} @@ -115,7 +127,11 @@ bool mgMuggle::ProcessArgs (int argc, char *argv[]) c, option_index = 0; while ((c = +#ifndef HAVE_SERVER + getopt_long (argc, argv, "gh:s:n:p:t:u:w:d:v:", long_options, +#else getopt_long (argc, argv, "gh:s:n:p:t:u:w:v:", long_options, +#endif &option_index)) != -1) { switch (c) @@ -150,6 +166,13 @@ bool mgMuggle::ProcessArgs (int argc, char *argv[]) the_setup.DbPass = strcpyrealloc (the_setup.DbPass, optarg); } break; +#ifndef HAVE_SERVER + case 'd': + { + set_datadir(optarg); + } + break; +#endif case 'v': { mgSetDebugLevel (atol(optarg)); @@ -80,6 +80,9 @@ int main( int argc, char *argv[] ) std::cout << " -z - scan all database entries and delete entries for files not found" << std::endl; std::cout << " -z is not yet implemented" << std::endl; std::cout << " -c - delete the entire database and recreate a new empty one" << std::endl; +#ifndef HAVE_SERVER + std::cout << " -d - the data directory for the embedded mysql server. Defaults to ./.muggle" << std::endl; +#endif std::cout << " -v - the wanted log level, the higher the more. Default is 1" << std::endl; exit( 1 ); @@ -89,11 +92,21 @@ int main( int argc, char *argv[] ) import_assorted = false; delete_mode = false; create_mode = false; +#ifndef HAVE_SERVER + char *buf; + asprintf(&buf,"%s/.muggle",getenv("HOME")); + set_datadir(buf); + free(buf); +#endif // parse command line options while( 1 ) { +#ifndef HAVE_SERVER + int c = getopt(argc, argv, "h:s:n:u:p:t:zcv:d:"); +#else int c = getopt(argc, argv, "h:s:n:u:p:t:zcv:"); +#endif if (c == -1) break; @@ -140,6 +153,12 @@ int main( int argc, char *argv[] ) { mgSetDebugLevel(atol(optarg)); } break; +#ifndef HAVE_SERVER + case 'd': + { + set_datadir(optarg); + } break; +#endif } } mgSync *sync = new mgSync; // because we want to delete it before database_end |