bool MonitorItem::docmd(const char* command) { if (!doconnect()) { return false; } if (command[0] != 0) { writecmd(command); } emit clearText(get_name()); bool jobRunning = false; while (1) { int stat; if ((stat = bnet_recv(d->DSock)) >= 0) { strip_trailing_newline(d->DSock->msg); QString msg = QString::fromUtf8(d->DSock->msg); emit appendText(QString::fromUtf8(get_name()), msg); if (d->type == R_CLIENT) { if (msg.contains("Job started:")) jobRunning = true; } } else if (stat == BNET_SIGNAL) { if (d->DSock->msglen == BNET_EOD) { // qDebug() << "<< EOD >>"; if (d->type == R_CLIENT) emit jobIsRunning (jobRunning); return true; } else if (d->DSock->msglen == BNET_SUB_PROMPT) { // qDebug() << "<< PROMPT >>"; return false; } else if (d->DSock->msglen == BNET_HEARTBEAT) { bnet_sig(d->DSock, BNET_HB_RESPONSE); } else { qDebug() << bnet_sig_to_ascii(d->DSock); } } else { /* BNET_HARDEOF || BNET_ERROR */ d->DSock = NULL; d->state = MonitorItem::Error; emit statusChanged(get_name(), d->state); emit showStatusbarMessage("Error : BNET_HARDEOF or BNET_ERROR"); //fprintf(stderr, "<< ERROR >>\n")); return false; } /* if ((stat = bnet_recv(d->DSock)) >= 0) */ if (is_bnet_stop(d->DSock)) { d->DSock = NULL; d->state = MonitorItem::Error; emit statusChanged(get_name(), d->state); emit showStatusbarMessage("Error : Connection closed."); //fprintf(stderr, "<< STOP >>\n"); return false; /* error or term */ } /* if (is_bnet_stop(d->DSock) */ } /* while (1) */ }
/* * For a given file (path+filename), split into path and file, then * lookup the most recent backup in the catalog to get the JobId * and FileIndex, then insert them into the findex list. */ static bool insert_file_into_findex_list(UAContext *ua, RESTORE_CTX *rx, char *file, char *date) { strip_trailing_newline(file); split_path_and_filename(ua, rx, file); if (*rx->JobIds == 0) { Mmsg(rx->query, uar_jobid_fileindex, date, rx->path, rx->fname, rx->ClientName); } else { Mmsg(rx->query, uar_jobids_fileindex, rx->JobIds, date, rx->path, rx->fname, rx->ClientName); } rx->found = false; /* Find and insert jobid and File Index */ if (!db_sql_query(ua->db, rx->query, jobid_fileindex_handler, (void *)rx)) { ua->error_msg(_("Query failed: %s. ERR=%s\n"), rx->query, db_strerror(ua->db)); } if (!rx->found) { ua->error_msg(_("No database record found for: %s\n"), file); // ua->error_msg("Query=%s\n", rx->query); return true; } return true; }
void MonitorItem::get_list(const char *cmd, QStringList &lst) { doconnect(); writecmd(cmd); while (bnet_recv(d->DSock) >= 0) { strip_trailing_newline(d->DSock->msg); if (*(d->DSock->msg)) { lst << QString(d->DSock->msg); } } }
void restorePage::fileDoubleClicked(QTreeWidgetItem *item, int column) { char cmd[1000]; statusLine->setText(""); if (column == 0) { /* mark/unmark */ mainWin->waitEnter(); if (item->data(0, Qt::UserRole).toBool()) { bsnprintf(cmd, sizeof(cmd), "unmark \"%s\"", item->text(1).toUtf8().data()); item->setIcon(0, QIcon(QString::fromUtf8(":images/unchecked.png"))); item->setData(0, Qt::UserRole, false); } else { bsnprintf(cmd, sizeof(cmd), "mark \"%s\"", item->text(1).toUtf8().data()); item->setIcon(0, QIcon(QString::fromUtf8(":images/check.png"))); item->setData(0, Qt::UserRole, true); } m_console->write_dir(m_conn, cmd, false); if (m_console->read(m_conn) > 0) { strip_trailing_newline(m_console->msg(m_conn)); statusLine->setText(m_console->msg(m_conn)); } m_console->displayToPrompt(m_conn); mainWin->waitExit(); return; } /* * Double clicking other than column 0 means to decend into * the directory -- or nothing if it is not a directory. */ if (item->text(1).endsWith("/")) { QString fullpath = m_cwd + item->text(1); QTreeWidgetItem *item = m_dirPaths.value(fullpath); if (mainWin->m_miscDebug) { Pmsg1(dbglvl, "%s\n", fullpath.toUtf8().data()); } if (item) { directoryWidget->setCurrentItem(item); } else { QString msg = QString("DoubleClick else of item column %1 fullpath %2\n") .arg(column,10) .arg(fullpath); if (mainWin->m_miscDebug) Pmsg1(dbglvl, "%s\n", msg.toUtf8().data()); } } }
/* * Mark selected items */ void restorePage::markButtonPushed() { mainWin->waitEnter(); QList<QTreeWidgetItem *> treeItemList = fileWidget->selectedItems(); QTreeWidgetItem *item; char cmd[1000]; int count = 0; statusLine->setText(""); foreach (item, treeItemList) { count++; bsnprintf(cmd, sizeof(cmd), "mark \"%s\"", item->text(1).toUtf8().data()); item->setIcon(0, QIcon(QString::fromUtf8(":images/check.png"))); m_console->write_dir(m_conn, cmd, false); if (m_console->read(m_conn) > 0) { strip_trailing_newline(m_console->msg(m_conn)); statusLine->setText(m_console->msg(m_conn)); } Dmsg1(dbglvl, "cmd=%s\n", cmd); m_console->discardToPrompt(m_conn); }
static void *do_batch(void *jcr) { JCR *bjcr = (JCR *)jcr; char data[1024]; int lineno = 0; struct ATTR_DBR ar; memset(&ar, 0, sizeof(ar)); btime_t begin = get_current_btime(); char *datafile = bjcr->where; FILE *fd = fopen(datafile, "r"); if (!fd) { Emsg1(M_ERROR_TERM, 0, _("Error opening datafile %s\n"), datafile); } while (fgets(data, sizeof(data)-1, fd)) { strip_trailing_newline(data); lineno++; if (verbose && ((lineno % 5000) == 1)) { printf("\r%i", lineno); } fill_attr(&ar, data); if (!db_create_attributes_record(bjcr, bjcr->db, &ar)) { Emsg0(M_ERROR_TERM, 0, _("Error while inserting file\n")); } } fclose(fd); db_write_batch_file_records(bjcr); btime_t end = get_current_btime(); P(mutex); char ed1[200], ed2[200]; printf("\rbegin = %s, end = %s\n", edit_int64(begin, ed1),edit_int64(end, ed2)); printf("Insert time = %sms\n", edit_int64((end - begin) / 10000, ed1)); printf("Create %u files at %.2f/s\n", lineno, (lineno / ((float)((end - begin) / 1000000)))); nb--; V(mutex); pthread_exit(NULL); return NULL; }
int main(int argc, char *const *argv) { char *fname = NULL; int rc, ch; char data[1000]; char pat[500]; FILE *fd; bool match_only = true; int lineno; bool no_linenos = false; int ic = 0; setlocale(LC_ALL, ""); bindtextdomain("bacula", LOCALEDIR); textdomain("bacula"); while ((ch = getopt(argc, argv, "d:f:in?")) != -1) { switch (ch) { case 'd': /* set debug level */ debug_level = atoi(optarg); if (debug_level <= 0) { debug_level = 1; } break; case 'f': /* data */ fname = optarg; break; case 'i': /* ignore case */ ic = FNM_CASEFOLD; break; case 'l': no_linenos = true; break; case 'n': match_only = false; break; case '?': default: usage(); } } argc -= optind; argv += optind; if (!fname) { printf("A data file must be specified.\n"); usage(); } OSDependentInit(); for ( ;; ) { printf("Enter a wild-card: "); if (fgets(pat, sizeof(pat)-1, stdin) == NULL) { break; } strip_trailing_newline(pat); if (pat[0] == 0) { exit(0); } fd = fopen(fname, "r"); if (!fd) { printf(_("Could not open data file: %s\n"), fname); exit(1); } lineno = 0; while (fgets(data, sizeof(data)-1, fd)) { strip_trailing_newline(data); lineno++; rc = fnmatch(pat, data, ic); if ((match_only && rc == 0) || (!match_only && rc != 0)) { if (no_linenos) { printf("%s\n", data); } else { printf("%5d: %s\n", lineno, data); } } } fclose(fd); } exit(0); }
/* * Fill the fileWidget box with the contents of the current directory */ void restorePage::fillDirectory() { mainWin->waitEnter(); char modes[20], user[20], group[20], size[20], date[30]; char marked[10]; int pnl, fnl; POOLMEM *file = get_pool_memory(PM_FNAME); POOLMEM *path = get_pool_memory(PM_FNAME); fileWidget->clear(); m_console->write_dir(m_conn, "dir", false); QList<QTreeWidgetItem *> treeItemList; QStringList item; m_rx.setPattern("has no children\\.$"); bool first = true; while (m_console->read(m_conn) > 0) { char *p = m_console->msg(m_conn); char *l; strip_trailing_newline(p); if (*p == '$' || !*p) { continue; } if (first) { if (m_rx.indexIn(QString(p)) != -1) { continue; } first = false; } l = p; skip_nonspaces(&p); /* permissions */ *p++ = 0; bstrncpy(modes, l, sizeof(modes)); skip_spaces(&p); skip_nonspaces(&p); /* link count */ *p++ = 0; skip_spaces(&p); l = p; skip_nonspaces(&p); /* user */ *p++ = 0; skip_spaces(&p); bstrncpy(user, l, sizeof(user)); l = p; skip_nonspaces(&p); /* group */ *p++ = 0; bstrncpy(group, l, sizeof(group)); skip_spaces(&p); l = p; skip_nonspaces(&p); /* size */ *p++ = 0; bstrncpy(size, l, sizeof(size)); skip_spaces(&p); l = p; skip_nonspaces(&p); /* date/time */ skip_spaces(&p); skip_nonspaces(&p); *p++ = 0; bstrncpy(date, l, sizeof(date)); skip_spaces(&p); if (*p == '*') { bstrncpy(marked, "*", sizeof(marked)); p++; } else { bstrncpy(marked, " ", sizeof(marked)); } split_path_and_filename(p, path, &pnl, file, &fnl); item.clear(); item << "" << file << modes << user << group << size << date; if (item[1].endsWith("/")) { addDirectory(item[1]); } QTreeWidgetItem *ti = new QTreeWidgetItem((QTreeWidget *)0, item); ti->setTextAlignment(5, Qt::AlignRight); /* right align size */ if (strcmp(marked, "*") == 0) { ti->setIcon(0, QIcon(QString::fromUtf8(":images/check.png"))); ti->setData(0, Qt::UserRole, true); } else { ti->setIcon(0, QIcon(QString::fromUtf8(":images/unchecked.png"))); ti->setData(0, Qt::UserRole, false); } treeItemList.append(ti); } fileWidget->clear(); fileWidget->insertTopLevelItems(0, treeItemList); for (int i=0; i<7; i++) { fileWidget->resizeColumnToContents(i); } free_pool_memory(file); free_pool_memory(path); mainWin->waitExit(); }
int main(int argc, char *const *argv) { regex_t preg; char prbuf[500]; char *fname = NULL; int rc, ch; char data[1000]; char pat[500]; FILE *fd; bool match_only = true; int lineno; bool no_linenos = false; setlocale(LC_ALL, ""); bindtextdomain("bacula", LOCALEDIR); textdomain("bacula"); while ((ch = getopt(argc, argv, "d:f:n?")) != -1) { switch (ch) { case 'd': /* set debug level */ if (*optarg == 't') { dbg_timestamp = true; } else { debug_level = atoi(optarg); if (debug_level <= 0) { debug_level = 1; } } break; case 'f': /* data */ fname = optarg; break; case 'l': no_linenos = true; break; case 'n': match_only = false; break; case '?': default: usage(); } } argc -= optind; argv += optind; if (!fname) { printf("A data file must be specified.\n"); usage(); } OSDependentInit(); for ( ;; ) { printf("Enter regex pattern: "); if (fgets(pat, sizeof(pat)-1, stdin) == NULL) { break; } strip_trailing_newline(pat); if (pat[0] == 0) { exit(0); } rc = regcomp(&preg, pat, REG_EXTENDED); if (rc != 0) { regerror(rc, &preg, prbuf, sizeof(prbuf)); printf("Regex compile error: %s\n", prbuf); continue; } fd = fopen(fname, "r"); if (!fd) { printf(_("Could not open data file: %s\n"), fname); exit(1); } lineno = 0; while (fgets(data, sizeof(data)-1, fd)) { const int nmatch = 30; regmatch_t pmatch[nmatch]; strip_trailing_newline(data); lineno++; rc = regexec(&preg, data, nmatch, pmatch, 0); if ((match_only && rc == 0) || (!match_only && rc != 0)) { if (no_linenos) { printf("%s\n", data); } else { printf("%5d: %s\n", lineno, data); } } } fclose(fd); regfree(&preg); } exit(0); }
int main(int argc, char *const *argv) { char *fname = NULL; char *expr = NULL; int ch; bool sed=false; char data[1000]; FILE *fd; setlocale(LC_ALL, ""); bindtextdomain("bacula", LOCALEDIR); textdomain("bacula"); while ((ch = getopt(argc, argv, "sd:f:e:")) != -1) { switch (ch) { case 'd': /* set debug level */ if (*optarg == 't') { dbg_timestamp = true; } else { debug_level = atoi(optarg); if (debug_level <= 0) { debug_level = 1; } } break; case 'f': /* data */ fname = optarg; break; case 'e': expr = optarg; break; case 's': sed=true; break; case '?': default: usage(); } } argc -= optind; argv += optind; if (!fname) { printf("A data file must be specified.\n"); usage(); } if (!expr) { printf("An expression must be specified.\n"); usage(); } OSDependentInit(); alist *list; char *p; list = get_bregexps(expr); if (!list) { printf("Can't use %s as 'sed' expression\n", expr); exit (1); } fd = fopen(fname, "r"); if (!fd) { printf(_("Could not open data file: %s\n"), fname); exit(1); } while (fgets(data, sizeof(data)-1, fd)) { strip_trailing_newline(data); apply_bregexps(data, list, &p); if (sed) { printf("%s\n", p); } else { printf("%s => %s\n", data, p); } } fclose(fd); free_bregexps(list); delete list; exit(0); }
bool MonitorItem::get_job_defaults(struct JobDefaults &job_defs) { int stat; char *def; BSOCK *dircomm; bool rtn = false; QString scmd = QString(".defaults job=\"%1\"").arg(job_defs.job_name); if (job_defs.job_name == "") { return rtn; } if (!doconnect()) { return rtn; } dircomm = d->DSock; dircomm->fsend("%s", scmd.toUtf8().data()); while ((stat = dircomm->recv()) > 0) { def = strchr(dircomm->msg, '='); if (!def) { continue; } /* Pointer to default value */ *def++ = 0; strip_trailing_newline(def); if (strcmp(dircomm->msg, "job") == 0) { if (strcmp(def, job_defs.job_name.toUtf8().data()) != 0) { goto bail_out; } continue; } if (strcmp(dircomm->msg, "pool") == 0) { job_defs.pool_name = def; continue; } if (strcmp(dircomm->msg, "messages") == 0) { job_defs.messages_name = def; continue; } if (strcmp(dircomm->msg, "client") == 0) { job_defs.client_name = def; continue; } if (strcmp(dircomm->msg, "storage") == 0) { job_defs.store_name = def; continue; } if (strcmp(dircomm->msg, "where") == 0) { job_defs.where = def; continue; } if (strcmp(dircomm->msg, "level") == 0) { job_defs.level = def; continue; } if (strcmp(dircomm->msg, "type") == 0) { job_defs.type = def; continue; } if (strcmp(dircomm->msg, "fileset") == 0) { job_defs.fileset_name = def; continue; } if (strcmp(dircomm->msg, "catalog") == 0) { job_defs.catalog_name = def; continue; } if (strcmp(dircomm->msg, "enabled") == 0) { job_defs.enabled = *def == '1' ? true : false; continue; } } rtn = true; /* Fall through wanted */ bail_out: return rtn; }