ctdb-daemon: Use correct tdb flags when enabling robust mutex support
[obnox/samba/samba-obnox.git] / ctdb / server / ctdb_lock_helper.c
index 2161a9a0c446a2ec8abb5e4da4e4ea01bf92d865..7a09ecf3c70edc9777c066384496f97db6407dd1 100644 (file)
@@ -36,9 +36,9 @@ static void send_result(int fd, char result)
 static void usage(void)
 {
        fprintf(stderr, "\n");
-       fprintf(stderr, "Usage: %s <log-fd> <ctdbd-pid> <output-fd> RECORD <db-path> <db-key>\n",
+       fprintf(stderr, "Usage: %s <log-fd> <ctdbd-pid> <output-fd> RECORD <db-path> <db-flags> <db-key>\n",
                progname);
-       fprintf(stderr, "       %s <log-fd> <ctdbd-pid> <output-fd> DB <db1-path> [<db2-path> ...]\n",
+       fprintf(stderr, "       %s <log-fd> <ctdbd-pid> <output-fd> DB <db1-path> <db1-flags> [<db2-path> <db2-flags>...]\n",
                progname);
 }
 
@@ -59,10 +59,14 @@ static uint8_t *hex_decode_talloc(TALLOC_CTX *mem_ctx,
        return buffer;
 }
 
-static int lock_record(const char *dbpath, const char *dbkey)
+static int lock_record(const char *dbpath, const char *dbflags, const char *dbkey)
 {
        TDB_DATA key;
        struct tdb_context *tdb;
+       int tdb_flags;
+
+       /* No error checking since CTDB always passes sane values */
+       tdb_flags = strtol(dbflags, NULL, 0);
 
        /* Convert hex key to key */
        if (strcmp(dbkey, "NULL") == 0) {
@@ -72,7 +76,7 @@ static int lock_record(const char *dbpath, const char *dbkey)
                key.dptr = hex_decode_talloc(NULL, dbkey, &key.dsize);
        }
 
-       tdb = tdb_open(dbpath, 0, TDB_DEFAULT, O_RDWR, 0600);
+       tdb = tdb_open(dbpath, 0, tdb_flags, O_RDWR, 0600);
        if (tdb == NULL) {
                fprintf(stderr, "%s: Error opening database %s\n", progname, dbpath);
                return 1;
@@ -89,11 +93,15 @@ static int lock_record(const char *dbpath, const char *dbkey)
 }
 
 
-static int lock_db(const char *dbpath)
+static int lock_db(const char *dbpath, const char *dbflags)
 {
        struct tdb_context *tdb;
+       int tdb_flags;
+
+       /* No error checking since CTDB always passes sane values */
+       tdb_flags = strtol(dbflags, NULL, 0);
 
-       tdb = tdb_open(dbpath, 0, TDB_DEFAULT, O_RDWR, 0600);
+       tdb = tdb_open(dbpath, 0, tdb_flags, O_RDWR, 0600);
        if (tdb == NULL) {
                fprintf(stderr, "%s: Error opening database %s\n", progname, dbpath);
                return 1;
@@ -140,21 +148,21 @@ int main(int argc, char *argv[])
        lock_type = argv[4];
 
        if (strcmp(lock_type, "RECORD") == 0) {
-               if (argc != 7) {
+               if (argc != 8) {
                        fprintf(stderr, "%s: Invalid number of arguments (%d)\n",
                                progname, argc);
                        usage();
                        exit(1);
                }
-               result = lock_record(argv[5], argv[6]);
+               result = lock_record(argv[5], argv[6], argv[7]);
 
        } else if (strcmp(lock_type, "DB") == 0) {
                int n;
 
                /* If there are no databases specified, no need for lock */
                if (argc > 5) {
-                       for (n=5; n<argc; n++) {
-                               result = lock_db(argv[n]);
+                       for (n=5; n+1<argc; n+=2) {
+                               result = lock_db(argv[n], argv[n+1]);
                                if (result != 0) {
                                        break;
                                }