Update of /cvsroot/monetdb/sql/src/backends/monet5/merovingian
In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv363
Modified Files:
database.c database.h monetdb_lock.c
Log Message:
move monetdb lock code to database.c:db_lock
U monetdb_lock.c
Index: monetdb_lock.c
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet5/merovingian/monetdb_lock.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- monetdb_lock.c 19 Aug 2009 13:41:08 -0000 1.1
+++ monetdb_lock.c 10 Sep 2009 08:04:00 -0000 1.2
@@ -32,38 +32,14 @@
/* do for each listed database */
for (i = 1; i < argc; i++) {
- sabdb *stats;
- err e;
- char *dbname = argv[i];
-
- /* the argument is the database to take under maintenance, see
- * what Sabaoth can tell us about it */
- if ((e = SABAOTHgetStatus(&stats, dbname)) != MAL_SUCCEED) {
- fprintf(stderr, "lock: internal error: %s\n", e);
- GDKfree(e);
- exit(2);
- }
-
- if (stats != NULL) {
- char path[8096];
-
- if (stats->locked == 1) {
- fprintf(stderr, "lock: database '%s' already is
"
- "under maintenance\n", dbname);
- SABAOTHfreeStatus(&stats);
- hadwork = 1;
- state |= 1;
- continue;
- }
+ char *e;
- /* put this database in maintenance mode */
- snprintf(path, 8095, "%s/.maintenance", stats->path);
- fclose(fopen(path, "w"));
- printf("database %s is now under maintenance\n",
dbname);
- SABAOTHfreeStatus(&stats);
- } else {
- fprintf(stderr, "lock: no such database: %s\n", dbname);
+ if ((e = db_lock(argv[i])) != NULL) {
+ fprintf(stderr, "lock: %s\n", e);
+ free(e);
state |= 1;
+ } else {
+ printf("database '%s' is now under maintenance\n",
argv[i]);
}
hadwork = 1;
}
U database.c
Index: database.c
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet5/merovingian/database.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- database.c 9 Sep 2009 12:55:34 -0000 1.6
+++ database.c 10 Sep 2009 08:04:00 -0000 1.7
@@ -324,3 +324,43 @@
SABAOTHfreeStatus(&stats);
return(NULL);
}
+
+char* db_lock(char *dbname) {
+ char *e;
+ sabdb *stats;
+ char path[8096];
+ char buf[8096];
+ FILE *f;
+
+ /* the argument is the database to take under maintenance, see
+ * what Sabaoth can tell us about it */
+ if ((e = SABAOTHgetStatus(&stats, dbname)) != MAL_SUCCEED) {
+ snprintf(buf, sizeof(buf), "internal error: %s", e);
+ GDKfree(e);
+ return(strdup(buf));
+ }
+
+ if (stats == NULL) {
+ snprintf(buf, sizeof(buf), "no such database: %s", dbname);
+ return(strdup(buf));
+ }
+
+ if (stats->locked == 1) {
+ SABAOTHfreeStatus(&stats);
+ snprintf(buf, sizeof(buf), "database '%s' already is "
+ "under maintenance", dbname);
+ return(strdup(buf));
+ }
+
+ /* put this database in maintenance mode */
+ snprintf(path, sizeof(path), "%s/.maintenance", stats->path);
+ SABAOTHfreeStatus(&stats);
+ if ((f = fopen(path, "w")) == NULL) {
+ snprintf(buf, sizeof(buf), "could not create '%s' for '%s': %s",
+ path, dbname, strerror(errno));
+ return(strdup(buf));
+ }
+ fclose(f); /* no biggie if it fails, file is already there */
+
+ return(NULL);
+}
U database.h
Index: database.h
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet5/merovingian/database.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- database.h 9 Sep 2009 12:55:34 -0000 1.6
+++ database.h 10 Sep 2009 08:04:00 -0000 1.7
@@ -24,5 +24,6 @@
char* db_create(char* dbname);
char* db_destroy(char* dbname);
char* db_rename(char *olddb, char *newdb);
+char* db_lock(char *dbname);
#endif
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Monetdb-sql-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-sql-checkins