Exemplo n.º 1
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;
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
int
apply_rules (struct ndm_job_param *job, char *rules)
{
	char			reason[100];
	int			rc = 0;

	strcpy (reason, "(no reason given)");

	if (NDMJR_NONE_RECOGNIZE(rules)) {
		rc = ndmjr_none_apply (job, reason);
		goto out;
	}


	error_byebye ("unknown rules: %s", rules);

  out:
	if (rc != 0) {
		error_byebye ("rules %s failed: %s", rules, reason);
	}

	return 0;
}
Exemplo n.º 4
0
int
start_log_file (void)
{
	if (L_log_file) {
		FILE *		lfp;

		lfp = fopen (L_log_file, "w");
		if (!lfp) {
			error_byebye ("can't open -L logfile");
		}
		log_fp = lfp;
	}

	return 0;
}
Exemplo n.º 5
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 = stderr;	/* 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");
		if (system (cmd) < 0)
		    error_byebye ("sort index failed");
		ndmjob_log (1, "sort index done");
	}

	return 0;
}
Exemplo n.º 6
0
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;
}