src/filed/fd_snapshot.c
int do_command(const char *act, arg_parser *cmd) {
      int ret = 0, rcode;
      POOLMEM *command = get_pool_memory(PM_FNAME);
      POOLMEM *out = get_pool_memory(PM_FNAME);

      set_action(act);
      edit_snapshot_codes(&command, me->snapshot_command);
      edit_snapshot_env();

      Dmsg1(DT_SNAPSHOT|20, "Execute %s command\n", act);

      if (*command == 0) {
         Mmsg(errmsg, _("Error while creating command string %s.\n"), act);
         Dmsg1(DT_SNAPSHOT, "%s", errmsg);
         goto bail_out;
      }

      /* If the exit code is 1, we can expect to have a clear error
       * message in the output
       */
      if ((rcode = run_program_full_output(command, 600, out, env)) != 0) {
         if ((rcode & ~b_errno_exit) == 1) { /* exit 1, look the output */
            if (cmd->parse_cmd(out) == bRC_OK) {
               int i = cmd->find_arg_with_value("status");
               if (i >= 0) {
                  /* If we have a status, take it */
                  status = str_to_int64(cmd->argv[i]);
               } else {
                  status = 0;
               }
               i = cmd->find_arg_with_value("error");
               if (i >= 0) {
                  pm_strcpy(errmsg, cmd->argv[i]);
                  Dmsg1(DT_SNAPSHOT|20, "%s\n", errmsg);
                  goto bail_out;
               }
            }
         }
         berrno be;
         Mmsg(errmsg, _("Error while executing \"%s\" %s. %s %s\n"), 
              act, command, out, be.bstrerror());
         Dmsg1(DT_SNAPSHOT, "%s", errmsg);
         goto bail_out;
      }

      /* Need to decode the output of the script
       * TODO: some commands will have multiple lines
       */
      if (cmd->parse_cmd(out) != bRC_OK) {
         Dmsg2(DT_SNAPSHOT, "snapshot command %s output error: [%s]\n", act, out);
         Mmsg(errmsg, _("Unable to parse snapshot command output\n"));
         goto bail_out;
      }
      Dmsg1(DT_SNAPSHOT|50, "ret = %s\n", out);
      ret = 1;
   bail_out:
      free_pool_memory(command);
      free_pool_memory(out);
      return ret;
   }
/* TODO: Need to read stdout as well */
Need to read stdout as well
Need to read stdout as well
int do_command(const char *act, arg_parser *cmd) {
      int ret = 0, rcode;
      POOLMEM *command = get_pool_memory(PM_FNAME);
      POOLMEM *out = get_pool_memory(PM_FNAME);
      set_action(act);
      edit_snapshot_codes(&command, me->snapshot_command);
      edit_snapshot_env();
      Dmsg1(DT_SNAPSHOT|20, "Execute %s command\n", act);
      if (*command == 0) {
         Mmsg(errmsg, _("Error while creating command string %s.\n"), act);
         Dmsg1(DT_SNAPSHOT, "%s", errmsg);
         goto bail_out;
      }
      if ((rcode = run_program_full_output(command, 600, out, env)) != 0) {
         if ((rcode & ~b_errno_exit) == 1) { 
            if (cmd->parse_cmd(out) == bRC_OK) {
               int i = cmd->find_arg_with_value("status");
               if (i >= 0) {
                  status = str_to_int64(cmd->argv[i]);
               } else {
                  status = 0;
               }
               i = cmd->find_arg_with_value("error");
               if (i >= 0) {
                  pm_strcpy(errmsg, cmd->argv[i]);
                  Dmsg1(DT_SNAPSHOT|20, "%s\n", errmsg);
                  goto bail_out;
               }
            }
         }
         berrno be;
         Mmsg(errmsg, _("Error while executing \"%s\" %s. %s %s\n"), 
              act, command, out, be.bstrerror());
         Dmsg1(DT_SNAPSHOT, "%s", errmsg);
         goto bail_out;
      }
      if (cmd->parse_cmd(out) != bRC_OK) {
         Dmsg2(DT_SNAPSHOT, "snapshot command %s output error: [%s]\n", act, out);
         Mmsg(errmsg, _("Unable to parse snapshot command output\n"));
         goto bail_out;
      }
      Dmsg1(DT_SNAPSHOT|50, "ret = %s\n", out);
      ret = 1;
   bail_out:
      free_pool_memory(command);
      free_pool_memory(out);
      return ret;
   }
int do_command ( const char * act , arg_parser * cmd ) { int ret = 0 , rcode ; POOLMEM * command = get_pool_memory ( PM_FNAME ) ; POOLMEM * out = get_pool_memory ( PM_FNAME ) ; set_action ( act ) ; edit_snapshot_codes ( & command , me -> snapshot_command ) ; edit_snapshot_env ( ) ; Dmsg1 ( DT_SNAPSHOT | 20 , " \n " , act ) ; if ( * command == 0 ) { Mmsg ( errmsg , _ ( " \n " ) , act ) ; Dmsg1 ( DT_SNAPSHOT , " " , errmsg ) ; goto bail_out ; } if ( ( rcode = run_program_full_output ( command , 600 , out , env ) ) != 0 ) { if ( ( rcode & ~ b_errno_exit ) == 1 ) { if ( cmd -> parse_cmd ( out ) == bRC_OK ) { int i = cmd -> find_arg_with_value ( " " ) ; if ( i >= 0 ) { status = str_to_int64 ( cmd -> argv [ i ] ) ; } else { status = 0 ; } i = cmd -> find_arg_with_value ( " " ) ; if ( i >= 0 ) { pm_strcpy ( errmsg , cmd -> argv [ i ] ) ; Dmsg1 ( DT_SNAPSHOT | 20 , " \n " , errmsg ) ; goto bail_out ; } } } berrno be ; Mmsg ( errmsg , _ ( " \" \" \n " ) , act , command , out , be . bstrerror ( ) ) ; Dmsg1 ( DT_SNAPSHOT , " " , errmsg ) ; goto bail_out ; } if ( cmd -> parse_cmd ( out ) != bRC_OK ) { Dmsg2 ( DT_SNAPSHOT , " \n " , act , out ) ; Mmsg ( errmsg , _ ( " \n " ) ) ; goto bail_out ; } Dmsg1 ( DT_SNAPSHOT | 50 , " \n " , out ) ; ret = 1 ; bail_out : free_pool_memory ( command ) ; free_pool_memory ( out ) ; return ret ; }
TODO: Need to read stdout as well
TODO : Need to read stdout as well
/* If the exit code is 1, we can expect to have a clear error
       * message in the output
       */ /* exit 1, look the output */ /* If we have a status, take it */ /* Need to decode the output of the script
       * TODO: some commands will have multiple lines
       */