int jndex_tattle (void) { char buf[100]; int i; for (i = 0; i < n_ji_media; i++) { struct ndmmedia * me = &ji_media[i]; ndmmedia_to_str (me, buf); ndmjob_log (3, "ji me[%d] %s", i, buf); } for (i = 0; i < n_ji_environment; i++) { ndmp9_pval * pv = &ji_environment[i]; ndmjob_log (3, "ji env[%d] %s=%s", i, pv->name, pv->value); } for (i = 0; (i < n_file_arg) && (i < NDM_MAX_NLIST); i++) { if (nlist[i].fh_info.valid) { ndmjob_log (3, "ji fil[%d] fi=%lld %s", i, nlist[i].fh_info.value, file_arg[i]); } else { ndmjob_log (3, "ji fil[%d] not-found %s", i, file_arg[i]); } } return 0; }
int jndex_doit (void) { FILE * fp; int rc; fp = jndex_open(); if (!fp) { /* error messages already given */ return -1; } ndmjob_log (1, "Processing input index (-J%s)", J_index_file); if (n_file_arg > 0) { rc = ndmfhdb_add_fh_info_to_nlist (fp, nlist, n_file_arg); if (rc < 0) { /* toast one way or another */ } } jndex_fetch_post_backup_data_env(fp); jndex_fetch_post_backup_media(fp); jndex_tattle(); if (jndex_audit_not_found ()) { ndmjob_log (1, "Warning: Missing index entries, valid file name(s)?"); } jndex_merge_media (); return 0; }
int jndex_tattle (void) { char buf[100]; struct ndmmedia * me; struct ndm_env_entry * nev; int i; for (me = ji_media.head; me; me = me->next) { ndmmedia_to_str (me, buf); ndmjob_log (3, "ji me[%d] %s", i, buf); } for (nev = ji_environment.head; nev; nev = nev->next) { ndmjob_log (3, "ji env[%d] %s=%s", i, nev->pval.name, nev->pval.value); } for (i = 0; (i < n_file_arg) && (i < NDM_MAX_NLIST); i++) { if (nlist[i].fh_info.valid) { ndmjob_log (3, "ji fil[%d] fi=%lld %s", i, nlist[i].fh_info.value, file_arg[i]); } else { ndmjob_log (3, "ji fil[%d] not-found %s", i, file_arg[i]); } } return 0; }
int jndex_fetch_post_backup_data_env (FILE *fp) { int rc; char buf[512]; char * p; char * q; ndmp9_pval pv; rc = ndmbstf_first (fp, "DE ", buf, sizeof buf); if (rc <= 0) { return rc; /* error or not found */ } /* DE HIST=Yes */ while (buf[0] == 'D' && buf[1] == 'E' && buf[2] == ' ') { if (ji_environment.n_env >= NDM_MAX_ENV) { goto overflow; } p = &buf[2]; while (*p == ' ') p++; if (!strchr (p, '=')) { goto malformed; } q = strchr (p, '='); if (!q) { goto malformed; } *q++ = 0; pv.name = p; pv.value = q; ndma_store_env_list (&ji_environment, &pv); rc = ndmbstf_getline (fp, buf, sizeof buf); if (rc <= 0) { break; } continue; malformed: ndmjob_log (1, "Malformed in -J%s: %s", J_index_file, buf); continue; overflow: ndmjob_log (1, "Overflow in -J%s: %s", J_index_file, buf); } return 0; }
int jndex_fetch_post_backup_data_env (FILE *fp) { int rc; char buf[512]; char * p; char * q; rc = ndmbstf_first (fp, "DE ", buf, sizeof buf); if (rc <= 0) { return rc; /* error or not found */ } /* DE HIST=Yes */ while (buf[0] == 'D' && buf[1] == 'E' && buf[2] == ' ') { if (n_ji_environment >= NDM_MAX_ENV) { goto overflow; } p = &buf[2]; while (*p == ' ') p++; if (!strchr (p, '=')) { goto malformed; } p = NDMOS_API_STRDUP (p); q = strchr (p, '='); *q++ = 0; ji_environment[n_ji_environment].name = p; ji_environment[n_ji_environment].value = q; n_ji_environment++; rc = ndmbstf_getline (fp, buf, sizeof buf); if (rc <= 0) { break; } continue; malformed: ndmjob_log (1, "Malformed in -J%s: %s", J_index_file, buf); continue; overflow: ndmjob_log (1, "Overflow in -J%s: %s", J_index_file, buf); } return 0; }
FILE * jndex_open (void) { char buf[256]; FILE * fp; if (!J_index_file) { /* Hmmm. */ ndmjob_log (1, "Warning: No -J input index?"); return 0; } ndmjob_log (1, "Reading input index (-I%s)", J_index_file); fp = fopen(J_index_file, "r"); if (!fp) { perror (J_index_file); error_byebye ("Can not open -J%s input index", J_index_file); /* no return */ } if (fgets (buf, sizeof buf, fp) == NULL) { fclose (fp); error_byebye ("Failed read 1st line of -J%s", J_index_file); /* no return */ } if (strcmp (buf, "##ndmjob -I\n") != 0) { fclose (fp); error_byebye ("Bad 1st line in -J%s", J_index_file); /* no return */ } if (fgets (buf, sizeof buf, fp) == NULL) { fclose (fp); error_byebye ("Failed read 2nd line of -J%s", J_index_file); /* no return */ } if (strcmp (buf, "##ndmjob -J\n") != 0) { fclose (fp); error_byebye ("Bad 2nd line in -J%s", J_index_file); /* no return */ } ndmjob_log (2, "Opened index (-J%s)", J_index_file); return fp; }
int build_job (void) { struct ndm_job_param * job = &the_job; int i, rc, n_err; char errbuf[100]; NDMOS_MACRO_ZEROFILL(job); args_to_job (); ndma_job_auto_adjust (job); if (o_rules) apply_rules (job, o_rules); i = n_err = 0; do { rc = ndma_job_audit (job, errbuf, i); if (rc > n_err || rc < 0) { ndmjob_log (0, "error: %s", errbuf); } n_err = rc; } while (i++ < n_err); if (n_err) { error_byebye ("can't proceed"); /* no return */ } return 0; }
int jndex_merge_media (void) { struct ndmmedia * me; struct ndmmedia * jme; int i, j; for (j = 0; j < n_ji_media; j++) { jme = &ji_media[j]; if (! jme->valid_label) continue; /* can't match it up */ for (i = 0; i < n_m_media; i++) { me = &m_media[i]; if (! me->valid_label) continue; /* can't match it up */ if (strcmp (jme->label, me->label) != 0) continue; if (!jme->valid_slot && me->valid_slot) { jme->slot_addr = me->slot_addr; jme->valid_slot = 1; } } } for (i = 0; i < n_ji_media; i++) { m_media[i] = ji_media[i]; } n_m_media = i; ndmjob_log (3, "After merging input -J index with -m entries"); for (i = 0; i < n_m_media; i++) { char buf[40]; me = &m_media[i]; ndmmedia_to_str (me, buf); ndmjob_log (3, "%d: -m %s", i+1, buf); } return 0; }
int sort_index_file (void) { if (I_index_file && strcmp (I_index_file, "-") != 0 && atoi(I_index_file) == 0) { char cmd[512]; fprintf (index_fp, "##ndmjob -J\n"); /* sorts to 2nd line */ fclose (index_fp); index_fp = log_fp; /* in case anything else happens */ sprintf (cmd, "LC_ALL=C sort %s -o %s\n", I_index_file, I_index_file); ndmjob_log (3, "sort command: %s", cmd); ndmjob_log (1, "sorting index"); system (cmd); ndmjob_log (1, "sort index done"); } return 0; }
int jndex_fetch_post_backup_media (FILE *fp) { int rc; char buf[512]; rc = ndmbstf_first (fp, "CM ", buf, sizeof buf); if (rc <= 0) { return rc; /* error or not found */ } /* CM 01 T103/10850K */ while (buf[0] == 'C' && buf[1] == 'M' && buf[2] == ' ') { struct ndmmedia * me; if (n_ji_media >= NDM_MAX_MEDIA) { goto overflow; } me = &ji_media[n_ji_media]; if (ndmmedia_from_str (me, &buf[6])) { goto malformed; } n_ji_media++; rc = ndmbstf_getline (fp, buf, sizeof buf); if (rc <= 0) { break; } continue; malformed: ndmjob_log (1, "Malformed in -J%s: %s", J_index_file, buf); continue; overflow: ndmjob_log (1, "Overflow in -J%s: %s", J_index_file, buf); } return 0; }
int jndex_merge_media (void) { struct ndmmedia * me; struct ndmmedia * jme; int i; for (jme = ji_media.head; jme; jme = jme->next) { if (! jme->valid_label) continue; /* can't match it up */ for (me = m_media.head; me; me = me->next) { if (! me->valid_label) continue; /* can't match it up */ if (strcmp (jme->label, me->label) != 0) continue; if (!jme->valid_slot && me->valid_slot) { jme->slot_addr = me->slot_addr; jme->valid_slot = 1; } } } ndmca_destroy_media_table (&m_media); m_media = ji_media; ndmjob_log (3, "After merging input -J index with -m entries"); i = 0; for (me = m_media.head; me; me = me->next) { char buf[40]; ndmmedia_to_str (me, buf); ndmjob_log (3, "%d: -m %s", i + 1, buf); i++; } return 0; }
void error_byebye (char *fmt, ...) { va_list ap; char buf[4096]; va_start (ap, fmt); vsnprintf (buf, sizeof(buf), fmt, ap); va_end (ap); ndmjob_log (0, "FATAL: %s", buf); fprintf (stderr, "%s: %s\n", progname, buf); exit(1); }
int start_index_file (void) { if (I_index_file && strcmp (I_index_file, "-") != 0) { FILE * ifp; if (atoi(I_index_file) != 0) { ndmjob_log (1, "Writing index (-I%s)", I_index_file); ifp = fdopen(atoi(I_index_file), "w"); } else { ndmjob_log (1, "Writing index (-I%s)", I_index_file); ifp = fopen (I_index_file, "w"); } if (!ifp) { error_byebye ("can't open -I logfile"); } index_fp = ifp; fprintf (ifp, "##ndmjob -I\n"); } else { index_fp = stderr; } return 0; }
int jndex_audit_not_found (void) { int i; int not_found = 0; for (i = 0; (i < n_file_arg) && (i < NDM_MAX_NLIST); i++) { if (!nlist[i].fh_info.valid) { ndmjob_log (0, "No index entry for %s", file_arg[i]); not_found++; } } return not_found; }
int main (int ac, char *av[]) { int rc; set_pname("ndmjob"); dbopen(DBG_SUBDIR_CLIENT); config_init(0, NULL); NDMOS_MACRO_ZEROFILL(&the_session); d_debug = -1; /* ready the_param early so logging works during process_args() */ NDMOS_MACRO_ZEROFILL (&the_param); the_param.log.deliver = ndmjob_log_deliver; the_param.log_level = 0; the_param.log_tag = "SESS"; #ifndef NDMOS_OPTION_NO_CONTROL_AGENT b_bsize = 20; index_fp = stderr; o_tape_addr = -1; o_from_addr = -1; o_to_addr = -1; p_ndmp_port = NDMPPORT; #endif /* !NDMOS_OPTION_NO_CONTROL_AGENT */ process_args (ac, av); if (the_param.log_level < d_debug) the_param.log_level = d_debug; if (the_param.log_level < v_verbose) the_param.log_level = v_verbose; the_param.config_file_name = o_config_file; if (the_mode == NDM_JOB_OP_DAEMON || the_mode == NDM_JOB_OP_TEST_DAEMON) { the_session.param = the_param; if (n_noop) { dump_settings(); return 0; } ndma_daemon_session (&the_session, p_ndmp_port, the_mode == NDM_JOB_OP_TEST_DAEMON); return 0; } #ifndef NDMOS_OPTION_NO_CONTROL_AGENT the_session.control_acb.swap_connect = (o_swap_connect != 0); build_job(); /* might not return */ the_session.param = the_param; the_session.control_acb.job = the_job; if (n_noop) { dump_settings(); return 0; } start_index_file (); rc = ndma_client_session (&the_session); sort_index_file (); if (rc == 0) ndmjob_log (1, "Operation complete"); else ndmjob_log (1, "Operation complete but had problems."); #endif /* !NDMOS_OPTION_NO_CONTROL_AGENT */ dbclose(); return 0; }
int main (int ac, char *av[]) { int rc; NDMOS_MACRO_ZEROFILL (&E_environment); NDMOS_MACRO_ZEROFILL (&ji_environment); NDMOS_MACRO_ZEROFILL (&m_media); NDMOS_MACRO_ZEROFILL (&ji_media); NDMOS_MACRO_ZEROFILL (&the_session); d_debug = -1; /* ready the_param early so logging works during process_args() */ NDMOS_MACRO_ZEROFILL (&the_param); the_param.log.deliver = ndmjob_log_deliver; the_param.log_level = 0; the_param.log_tag = "SESS"; #ifndef NDMOS_OPTION_NO_CONTROL_AGENT b_bsize = 20; index_fp = stderr; o_tape_addr = -1; o_from_addr = -1; o_to_addr = -1; p_ndmp_port = NDMPPORT; #endif /* !NDMOS_OPTION_NO_CONTROL_AGENT */ log_fp = stderr; process_args (ac, av); if (the_param.log_level < d_debug) the_param.log_level = d_debug; if (the_param.log_level < v_verbose) the_param.log_level = v_verbose; the_param.config_file_name = o_config_file; if (the_mode == NDM_JOB_OP_DAEMON) { the_session.param = &the_param; if (n_noop) { dump_settings (); exit_program (); } ndma_daemon_session (&the_session, p_ndmp_port); exit_program (); } ndmjob_register_callbacks (&the_session, &the_param.log); #ifndef NDMOS_OPTION_NO_CONTROL_AGENT build_job(); /* might not return */ the_session.param = &the_param; if (n_noop) { dump_settings (); exit_program (); } start_index_file (); rc = ndma_client_session (&the_session, &the_job, (o_swap_connect != 0)); sort_index_file (); if (rc == 0) ndmjob_log (1, "Operation complete"); else ndmjob_log (1, "Operation complete but had problems."); #endif /* !NDMOS_OPTION_NO_CONTROL_AGENT */ exit_program (); }