]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
pluginlib: A better handling of STAT:/... command in metaplugin.
authorRadosław Korzeniewski <radoslaw@korzeniewski.net>
Tue, 30 Nov 2021 16:48:18 +0000 (17:48 +0100)
committerEric Bollengier <eric@baculasystems.com>
Thu, 14 Sep 2023 11:56:56 +0000 (13:56 +0200)
bacula/src/plugins/fd/pluginlib/metaplugin.cpp
bacula/src/plugins/fd/pluginlib/metaplugin_attributes.cpp
bacula/src/plugins/fd/pluginlib/test_metaplugin_backend.c

index 05ef0bb479f7959476b0c66e3ecb4cc349e83175..4c716cf88f16b7ede0a81b50b9cab5d661629943 100644 (file)
@@ -786,6 +786,7 @@ bRC METAPLUGIN::send_parameters(bpContext *ctx, char *command)
       "regress_error_restore_stderr",
       "regress_backup_plugin_objects",
       "regress_backup_other_file",
+      "regress_backup_external_stat",
       "regress_error_backup_abort",
       "regress_metadata_support",
       "regress_standard_error_backup",
@@ -2385,7 +2386,8 @@ bRC METAPLUGIN::startBackupFile(bpContext *ctx, struct save_pkt *sp)
             return bRC_Error;
 
          case metaplugin::attributes::Status_OK:
-            if (sp->type != FT_LNK) {
+            if (sp->type != FT_LNK)
+            {
                reqparams--;
             }
             continue;
index f69d1a88dec4f590f7f513f4e4ae73df913f9c1e..7ec7056fffc297f8a80507803d60c403b84ba09c 100644 (file)
@@ -71,8 +71,12 @@ namespace attributes
          if (rc < 0)
          {
             // error
-            DMSG1(ctx, DERROR, "Invalid path: %s\n", param.c_str());
-            return Invalid_Stat_Packet;
+            berrno be;
+            DMSG3(ctx, DERROR, "Invalid STAT path: %s Err=%s (%d)\n", param.c_str(), be.bstrerror(), be.code());
+            JMSG3(ctx, M_ERROR, "Invalid STAT path: %s Err=%s (%d)\n", param.c_str(), be.bstrerror(), be.code());
+            memset(&sp->statp, 0, sizeof(sp->statp));
+            sp->type = FT_REG;
+            return Status_Handled;
          }
          // stat is working as expected
          DMSG1(ctx, DDEBUG, "read_scan_stat_command():stat: %o\n", sp->statp.st_mode);
@@ -97,7 +101,9 @@ namespace attributes
                   // error reading link value
                   DMSG2(ctx, DERROR, "Error reading link value. Err=%s (%d)", be.bstrerror(), be.code());
                   JMSG3(ctx, M_ERROR, "Error reading link value: %s, Err=%s (%d)", param.c_str(), be.bstrerror(), be.code());
-                  return Status_Error;
+                  memset(&sp->statp, 0, sizeof(sp->statp));
+                  sp->type = FT_REG;
+                  return Status_Handled;
                }
                lname.c_str()[rc] = '\0';
                sp->link = lname.c_str();
index 7291fd921e8af15e9557fb6640e6b18230fa14fd..2ec429298d9e51306e48d5786e5ea46df4d1bf25 100644 (file)
@@ -73,6 +73,7 @@ bool regress_metadata_support = false;
 bool regress_standard_error_backup = false;
 bool regress_cancel_backup = false;
 bool regress_cancel_restore = false;
+bool regress_backup_external_stat = false;
 
 bool Job_Level_Incremental = false;
 
@@ -1211,6 +1212,19 @@ void perform_backup()
    signal_eod();
    signal_eod();
 
+   //
+   if (regress_backup_external_stat)
+   {
+      // the file with external stat(2) packet
+      snprintf(buf, BIGBUFLEN, "FNAME:%s/java/%d/stat.error\n", PLUGINPREFIX, mypid);
+      write_plugin('C', buf);
+      snprintf(buf, BIGBUFLEN, "STAT:%s\n", "/nonexistent.file");
+      write_plugin('C', buf);
+      write_plugin('I', "TEST18NEX");
+      signal_eod();
+      signal_eod();
+   }
+
    // this plugin object should be the latest item to backup
    if (regress_backup_plugin_objects)
    {
@@ -1669,67 +1683,88 @@ int main(int argc, char** argv) {
       // "regress_cancel_backup",
       // "regress_cancel_restore",
 
-      if (strcmp(buf, "regress_error_plugin_params=1\n") == 0) {
+      if (strcmp(buf, "regress_error_plugin_params=1\n") == 0)
+      {
          regress_error_plugin_params = true;
          continue;
       }
-      if (strcmp(buf, "regress_error_start_job=1\n") == 0) {
+      if (strcmp(buf, "regress_error_start_job=1\n") == 0)
+      {
          regress_error_start_job = true;
          continue;
       }
-      if (strcmp(buf, "regress_error_backup_no_files=1\n") == 0) {
+      if (strcmp(buf, "regress_error_backup_no_files=1\n") == 0)
+      {
          regress_error_backup_no_files = true;
          continue;
       }
-      if (strcmp(buf, "regress_error_backup_stderr=1\n") == 0) {
+      if (strcmp(buf, "regress_error_backup_stderr=1\n") == 0)
+      {
          regress_error_backup_stderr = true;
          continue;
       }
-      if (strcmp(buf, "regress_error_estimate_stderr=1\n") == 0) {
+      if (strcmp(buf, "regress_error_estimate_stderr=1\n") == 0)
+      {
          regress_error_estimate_stderr = true;
          continue;
       }
-      if (strcmp(buf, "regress_error_listing_stderr=1\n") == 0) {
+      if (strcmp(buf, "regress_error_listing_stderr=1\n") == 0)
+      {
          regress_error_listing_stderr = true;
          continue;
       }
-      if (strcmp(buf, "regress_error_restore_stderr=1\n") == 0) {
+      if (strcmp(buf, "regress_error_restore_stderr=1\n") == 0)
+      {
          regress_error_restore_stderr = true;
          continue;
       }
-      if (strcmp(buf, "regress_backup_plugin_objects=1\n") == 0) {
+      if (strcmp(buf, "regress_backup_plugin_objects=1\n") == 0)
+      {
          regress_backup_plugin_objects = true;
          continue;
       }
-      if (strcmp(buf, "regress_error_backup_abort=1\n") == 0) {
+      if (strcmp(buf, "regress_error_backup_abort=1\n") == 0)
+      {
          regress_error_backup_abort = true;
          continue;
       }
-      if (strcmp(buf, "regress_backup_other_file=1\n") == 0) {
+      if (strcmp(buf, "regress_backup_other_file=1\n") == 0)
+      {
          regress_backup_other_file = true;
          continue;
       }
-      if (strcmp(buf, "regress_metadata_support=1\n") == 0) {
+      if (strcmp(buf, "regress_backup_external_stat=1\n") == 0)
+      {
+         regress_backup_external_stat = true;
+         continue;
+      }
+      if (strcmp(buf, "regress_metadata_support=1\n") == 0)
+      {
          regress_metadata_support = true;
          continue;
       }
-      if (strcmp(buf, "regress_standard_error_backup=1\n") == 0) {
+      if (strcmp(buf, "regress_standard_error_backup=1\n") == 0)
+      {
          regress_standard_error_backup = true;
          continue;
       }
-      if (strcmp(buf, "regress_cancel_backup=1\n") == 0) {
+      if (strcmp(buf, "regress_cancel_backup=1\n") == 0)
+      {
          regress_cancel_backup = true;
          continue;
       }
-      if (strcmp(buf, "regress_cancel_restore=1\n") == 0) {
+      if (strcmp(buf, "regress_cancel_restore=1\n") == 0)
+      {
          regress_cancel_restore = true;
          continue;
       }
-      if (sscanf(buf, "listing=%s\n", buf) == 1){
+      if (sscanf(buf, "listing=%s\n", buf) == 1)
+      {
          strcpy(listing, buf);
          continue;
       }
-      if (sscanf(buf, "query=%s\n", buf) == 1){
+      if (sscanf(buf, "query=%s\n", buf) == 1)
+      {
          strcpy(query, buf);
          continue;
       }
@@ -1739,14 +1774,17 @@ int main(int argc, char** argv) {
          continue;
       }
    }
-   if (regress_cancel_restore || regress_cancel_backup) {
-      if (signal(SIGUSR1, catch_function) == SIG_ERR){
+   if (regress_cancel_restore || regress_cancel_backup)
+   {
+      if (signal(SIGUSR1, catch_function) == SIG_ERR)
+      {
          LOG("Cannot setup signal handler!");
          exit(EXIT_BACKEND_SIGNAL_HANDLER_ERROR);
       }
    }
    write_plugin('I', "TEST3");
-   if (!regress_error_plugin_params){
+   if (!regress_error_plugin_params)
+   {
       signal_eod();
    } else {
       write_plugin('E', "We do not accept your TEST3E! AsRequest.");
@@ -1756,7 +1794,8 @@ int main(int argc, char** argv) {
    len = read_plugin(buf);
    write_plugin('I', "TEST4");
 
-   if (regress_error_start_job){
+   if (regress_error_start_job)
+   {
       write_plugin('A', "We do not accept your TEST4E! AsRequest.");
       goto Term;
    }