]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/ua_run.c
Turn off debug
[bacula/bacula] / bacula / src / dird / ua_run.c
index 4d32ffd45eb53a36ece4cfb91b36e07ac92d06be..7d5844cf8649e85813484a8d0411702bd551f300 100644 (file)
@@ -90,7 +90,7 @@ extern struct s_kw ReplaceOptions[];
  */
 int run_cmd(UAContext *ua, const char *cmd)
 {
-   JCR *jcr;
+   JCR *jcr = NULL;
    run_ctx rc;
    int i, opt;
 
@@ -102,14 +102,22 @@ int run_cmd(UAContext *ua, const char *cmd)
       return 0;
    }
 
+   if (find_arg(ua, NT_("fdcalled")) > 0) {
+      jcr->file_bsock = dup_bsock(ua->UA_sock);
+      ua->quit = true;
+   }
+
+try_again:
    /*
     * Create JCR to run job.  NOTE!!! after this point, free_jcr()
     *  before returning.
     */
-   jcr = new_jcr(sizeof(JCR), dird_free_jcr);
-   set_jcr_defaults(jcr, rc.job);
-   jcr->unlink_bsr = ua->jcr->unlink_bsr;    /* copy unlink flag from caller */
-   ua->jcr->unlink_bsr = false;
+   if (!jcr) {
+      jcr = new_jcr(sizeof(JCR), dird_free_jcr);
+      set_jcr_defaults(jcr, rc.job);
+      jcr->unlink_bsr = ua->jcr->unlink_bsr;    /* copy unlink flag from caller */
+      ua->jcr->unlink_bsr = false;
+   }
 
    jcr->verify_job = rc.verify_job;
    jcr->previous_job = rc.previous_job;
@@ -119,7 +127,7 @@ int run_cmd(UAContext *ua, const char *cmd)
    pm_strcpy(jcr->client_name, rc.client->name());
    jcr->fileset = rc.fileset;
    jcr->ExpectedFiles = rc.files;
-   if (rc.catalog != NULL) {
+   if (rc.catalog) {
       jcr->catalog = rc.catalog;
    }
    if (rc.where) {
@@ -127,6 +135,7 @@ int run_cmd(UAContext *ua, const char *cmd)
          free(jcr->where);
       }
       jcr->where = bstrdup(rc.where);
+      rc.where = NULL;
    }
 
    if (rc.regexwhere) {
@@ -134,6 +143,7 @@ int run_cmd(UAContext *ua, const char *cmd)
          free(jcr->RegexWhere);
       }
       jcr->RegexWhere = bstrdup(rc.regexwhere);       
+      rc.regexwhere = NULL;
    }
 
    if (rc.when) {
@@ -142,6 +152,7 @@ int run_cmd(UAContext *ua, const char *cmd)
          ua->send_msg(_("Invalid time, using current time.\n"));
          jcr->sched_time = time(NULL);
       }
+      rc.when = NULL;
    }
 
    if (rc.bootstrap) {
@@ -149,6 +160,7 @@ int run_cmd(UAContext *ua, const char *cmd)
          free(jcr->RestoreBootstrap);
       }
       jcr->RestoreBootstrap = bstrdup(rc.bootstrap);
+      rc.bootstrap = NULL;
    }
 
    if (rc.replace) {
@@ -167,9 +179,11 @@ int run_cmd(UAContext *ua, const char *cmd)
    } else {
       jcr->replace = REPLACE_ALWAYS;
    }
+   rc.replace = NULL;
 
    if (rc.Priority) {
       jcr->JobPriority = rc.Priority;
+      rc.Priority = 0;
    }
 
    if (rc.since) {
@@ -177,16 +191,15 @@ int run_cmd(UAContext *ua, const char *cmd)
          jcr->stime = get_pool_memory(PM_MESSAGE);
       }
       pm_strcpy(jcr->stime, rc.since);
+      rc.since = NULL;
    }
 
-   jcr->cloned = rc.cloned;
-
-   if (find_arg(ua, NT_("fdcalled")) > 0) {
-      jcr->file_bsock = dup_bsock(ua->UA_sock);
-      ua->quit = true;
+   if (rc.cloned) {
+      jcr->cloned = rc.cloned;
+      rc.cloned = false;
    }
 
-try_again:
+
    /* If pool changed, update migration write storage */
    if (jcr->JobType == JT_MIGRATE) {
       if (!set_migration_wstorage(jcr, rc.pool)) {
@@ -198,16 +211,19 @@ try_again:
       if (ReplaceOptions[i].token == jcr->replace) {
          rc.replace = ReplaceOptions[i].name;
       }
+      rc.replace = NULL;
    }
    if (rc.level_name) {
       if (!get_level_from_name(jcr, rc.level_name)) {
          ua->send_msg(_("Level %s not valid.\n"), rc.level_name);
          goto bail_out;
       }
+      rc.level_name = NULL;
    }
    if (rc.jid) {
       /* Note, this is also MigrateJobId */
       jcr->RestoreJobId = str_to_int64(rc.jid);
+      rc.jid = 0;
    }
 
    /* Run without prompting? */
@@ -228,7 +244,8 @@ try_again:
       goto bail_out;
    }
 
-   if (ua->cmd[0] == '.' && strncasecmp(ua->cmd, ".mod ", 5) == 0) {
+   if (strncasecmp(ua->cmd, ".mod ", 5) == 0 || 
+       (strncasecmp(ua->cmd, "mod ", 4) == 0 && strlen(ua->cmd) > 6)) {
       Dmsg1(000, "got: %s\n", ua->cmd);
       parse_ua_args(ua);
       rc.mod = true;
@@ -897,6 +914,17 @@ static bool scan_command_line_arguments(UAContext *ua, run_ctx &rc)
 
 #define YES_POS 14
 
+   rc.catalog_name = NULL;
+   rc.job_name = NULL;
+   rc.pool_name = NULL;
+   rc.store_name = NULL;
+   rc.client_name = NULL;
+   rc.restore_client_name = NULL;
+   rc.fileset_name = NULL;
+   rc.verify_job_name = NULL;
+   rc.previous_job_name = NULL;
+
+
    for (i=1; i<ua->argc; i++) {
       Dmsg2(800, "Doing arg %d = %s\n", i, ua->argk[i]);
       kw_ok = false;
@@ -906,12 +934,12 @@ static bool scan_command_line_arguments(UAContext *ua, run_ctx &rc)
             /* Note, yes and run have no value, so do not fail */
             if (!ua->argv[i] && j != YES_POS /*yes*/) {
                ua->send_msg(_("Value missing for keyword %s\n"), ua->argk[i]);
-               return 1;
+               return true;
             }
             Dmsg1(800, "Got keyword=%s\n", NPRT(kw[j]));
             switch (j) {
             case 0: /* job */
-               if (rc.job_name && !rc.mod) {
+               if (rc.job_name) {
                   ua->send_msg(_("Job name specified twice.\n"));
                   return false;
                }
@@ -928,7 +956,7 @@ static bool scan_command_line_arguments(UAContext *ua, run_ctx &rc)
                break;
             case 2: /* client */
             case 3: /* fd */
-               if (rc.client_name && !rc.mod) {
+               if (rc.client_name) {
                   ua->send_msg(_("Client specified twice.\n"));
                   return false;
                }
@@ -936,7 +964,7 @@ static bool scan_command_line_arguments(UAContext *ua, run_ctx &rc)
                kw_ok = true;
                break;
             case 4: /* fileset */
-               if (rc.fileset_name && !rc.mod) {
+               if (rc.fileset_name) {
                   ua->send_msg(_("FileSet specified twice.\n"));
                   return false;
                }
@@ -944,7 +972,7 @@ static bool scan_command_line_arguments(UAContext *ua, run_ctx &rc)
                kw_ok = true;
                break;
             case 5: /* level */
-               if (rc.level_name && !rc.mod) {
+               if (rc.level_name) {
                   ua->send_msg(_("Level specified twice.\n"));
                   return false;
                }
@@ -953,7 +981,7 @@ static bool scan_command_line_arguments(UAContext *ua, run_ctx &rc)
                break;
             case 6: /* storage */
             case 7: /* sd */
-               if (rc.store_name && !rc.mod) {
+               if (rc.store_name) {
                   ua->send_msg(_("Storage specified twice.\n"));
                   return false;
                }
@@ -1024,7 +1052,7 @@ static bool scan_command_line_arguments(UAContext *ua, run_ctx &rc)
                kw_ok = true;
                break;
             case 15: /* Verify Job */
-               if (rc.verify_job_name && !rc.mod) {
+               if (rc.verify_job_name) {
                   ua->send_msg(_("Verify Job specified twice.\n"));
                   return false;
                }
@@ -1056,7 +1084,7 @@ static bool scan_command_line_arguments(UAContext *ua, run_ctx &rc)
                kw_ok = true;
                break;
             case 21: /* Migration Job */
-               if (rc.previous_job_name && !rc.mod) {
+               if (rc.previous_job_name) {
                   ua->send_msg(_("Migration Job specified twice.\n"));
                   return false;
                }
@@ -1064,7 +1092,7 @@ static bool scan_command_line_arguments(UAContext *ua, run_ctx &rc)
                kw_ok = true;
                break;
             case 22: /* pool */
-               if (rc.pool_name && !rc.mod) {
+               if (rc.pool_name) {
                   ua->send_msg(_("Pool specified twice.\n"));
                   return false;
                }
@@ -1072,7 +1100,7 @@ static bool scan_command_line_arguments(UAContext *ua, run_ctx &rc)
                kw_ok = true;
                break;
             case 23: /* backupclient */
-               if (rc.client_name && !rc.mod) {
+               if (rc.client_name) {
                   ua->send_msg(_("Client specified twice.\n"));
                   return 0;
                }
@@ -1113,7 +1141,7 @@ static bool scan_command_line_arguments(UAContext *ua, run_ctx &rc)
              
    Dmsg0(800, "Done scan.\n");
 
-   if (rc.catalog_name != NULL) {
+   if (rc.catalog_name) {
        rc.catalog = GetCatalogResWithName(rc.catalog_name);
        if (rc.catalog == NULL) {
             ua->error_msg(_("Catalog \"%s\" not found\n"), rc.catalog_name);
@@ -1137,7 +1165,7 @@ static bool scan_command_line_arguments(UAContext *ua, run_ctx &rc)
       } else {
          Dmsg1(800, "Found job=%s\n", rc.job_name);
       }
-   } else {
+   } else if (!rc.job) {
       ua->send_msg(_("A job name must be specified.\n"));
       rc.job = select_job_resource(ua);
    }
@@ -1156,7 +1184,7 @@ static bool scan_command_line_arguments(UAContext *ua, run_ctx &rc)
          }
          rc.pool = select_pool_resource(ua);
       }
-   } else {
+   } else if (!rc.pool) {
       rc.pool = rc.job->pool;             /* use default */
    }
    if (!rc.pool) {
@@ -1177,7 +1205,7 @@ static bool scan_command_line_arguments(UAContext *ua, run_ctx &rc)
          rc.store->store = select_storage_resource(ua);
          pm_strcpy(rc.store->store_source, _("user selection"));
       }
-   } else {
+   } else if (!rc.store->store) {
       get_job_storage(rc.store, rc.job, NULL);      /* use default */
    }
    if (!rc.store->store) {
@@ -1198,7 +1226,7 @@ static bool scan_command_line_arguments(UAContext *ua, run_ctx &rc)
          }
          rc.client = select_client_resource(ua);
       }
-   } else {
+   } else if (!rc.client) {
       rc.client = rc.job->client;           /* use default */
    }
    if (!rc.client) {
@@ -1218,7 +1246,7 @@ static bool scan_command_line_arguments(UAContext *ua, run_ctx &rc)
          }
          rc.client = select_client_resource(ua);
       }
-   } else {
+   } else if (!rc.client) {
       rc.client = rc.job->client;           /* use default */
    }
    if (!rc.client) {
@@ -1237,7 +1265,7 @@ static bool scan_command_line_arguments(UAContext *ua, run_ctx &rc)
          ua->send_msg(_("FileSet \"%s\" not found.\n"), rc.fileset_name);
          rc.fileset = select_fileset_resource(ua);
       }
-   } else {
+   } else if (!rc.fileset) {
       rc.fileset = rc.job->fileset;           /* use default */
    }
    if (!rc.fileset) {
@@ -1254,7 +1282,7 @@ static bool scan_command_line_arguments(UAContext *ua, run_ctx &rc)
          ua->send_msg(_("Verify Job \"%s\" not found.\n"), rc.verify_job_name);
          rc.verify_job = select_job_resource(ua);
       }
-   } else {
+   } else if (!rc.verify_job) {
       rc.verify_job = rc.job->verify_job;
    }