1 /*
2  * Copyright (c) 1998,1999,2000
3  *	Traakan, Inc., Los Altos, CA
4  *	All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice unmodified, this list of conditions, and the following
11  *    disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 /*
30  * Project:  NDMJOB
31  * Ident:    $Id: $
32  *
33  * Description:
34  *
35  */
36 
37 
38 #define GLOBAL
39 #include "ndmjob.h"
40 #include "debug.h"
41 #include "util.h"
42 #include "conffile.h"
43 
44 
45 int
main(int ac,char * av[])46 main (int ac, char *av[])
47 {
48 	int rc;
49 
50 	set_pname("ndmjob");
51 	dbopen(DBG_SUBDIR_CLIENT);
52 	config_init(0, NULL);
53 
54 	NDMOS_MACRO_ZEROFILL(&the_session);
55 	d_debug = -1;
56 
57 	/* ready the_param early so logging works during process_args() */
58 	NDMOS_MACRO_ZEROFILL (&the_param);
59 	the_param.log.deliver = ndmjob_log_deliver;
60 	the_param.log_level = 0;
61 	the_param.log_tag = "SESS";
62 
63 #ifndef NDMOS_OPTION_NO_CONTROL_AGENT
64 	b_bsize = 20;
65 	index_fp = stderr;
66 	o_tape_addr = -1;
67 	o_from_addr = -1;
68 	o_to_addr = -1;
69 	p_ndmp_port = NDMPPORT;
70 #endif /* !NDMOS_OPTION_NO_CONTROL_AGENT */
71 
72 	process_args (ac, av);
73 
74 	if (the_param.log_level < d_debug)
75 		the_param.log_level = d_debug;
76 	if (the_param.log_level < v_verbose)
77 		the_param.log_level = v_verbose;
78 	the_param.config_file_name = o_config_file;
79 
80 	if (the_mode == NDM_JOB_OP_DAEMON || the_mode == NDM_JOB_OP_TEST_DAEMON) {
81 		the_session.param = the_param;
82 
83 		if (n_noop) {
84 			dump_settings();
85 			return 0;
86 		}
87 
88 		ndma_daemon_session (&the_session, p_ndmp_port, the_mode == NDM_JOB_OP_TEST_DAEMON);
89 		return 0;
90 	}
91 
92 #ifndef NDMOS_OPTION_NO_CONTROL_AGENT
93 	the_session.control_acb.swap_connect = (o_swap_connect != 0);
94 
95 	build_job();		/* might not return */
96 
97 	the_session.param = the_param;
98 	the_session.control_acb.job = the_job;
99 
100 	if (n_noop) {
101 		dump_settings();
102 		return 0;
103 	}
104 
105 	start_index_file ();
106 
107 	rc = ndma_client_session (&the_session);
108 
109 	sort_index_file ();
110 
111 	if (rc == 0)
112 	    ndmjob_log (1, "Operation complete");
113 	else
114 	    ndmjob_log (1, "Operation complete but had problems.");
115 #endif /* !NDMOS_OPTION_NO_CONTROL_AGENT */
116 
117 	dbclose();
118 	return 0;
119 }
120 
121 
122