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 
exit_program(void)41 int exit_program(void)
42 {
43   ndma_destroy_env_list(&E_environment);
44   ndma_destroy_env_list(&ji_environment);
45 
46   ndmjob_unregister_callbacks(&the_session, &the_param.log);
47 
48   exit(0);
49 }
50 
main(int ac,char * av[])51 int main(int ac, char* av[])
52 {
53   int rc;
54 
55   NDMOS_MACRO_ZEROFILL(&E_environment);
56   NDMOS_MACRO_ZEROFILL(&ji_environment);
57   NDMOS_MACRO_ZEROFILL(&m_media);
58   NDMOS_MACRO_ZEROFILL(&ji_media);
59 
60   NDMOS_MACRO_ZEROFILL(&the_session);
61   d_debug = -1;
62 
63   /* ready the_param early so logging works during process_args() */
64   NDMOS_MACRO_ZEROFILL(&the_param);
65   the_param.log.deliver = ndmjob_log_deliver;
66   the_param.log_level = 0;
67   the_param.log_tag = "SESS";
68 
69 #ifndef NDMOS_OPTION_NO_CONTROL_AGENT
70   b_bsize = 20;
71   index_fp = stderr;
72   o_tape_addr = -1;
73   o_from_addr = -1;
74   o_to_addr = -1;
75   p_ndmp_port = NDMPPORT;
76 #endif /* !NDMOS_OPTION_NO_CONTROL_AGENT */
77   log_fp = stderr;
78 
79   process_args(ac, av);
80 
81   if (the_param.log_level < d_debug) the_param.log_level = d_debug;
82   if (the_param.log_level < v_verbose) the_param.log_level = v_verbose;
83   the_param.config_file_name = o_config_file;
84 
85   ndmjob_register_callbacks(&the_session, &the_param.log);
86 
87   if (the_mode == NDM_JOB_OP_DAEMON) {
88     the_session.param = &the_param;
89 
90     if (n_noop) {
91       dump_settings();
92       exit_program();
93     }
94 
95     ndma_daemon_session(&the_session, p_ndmp_port);
96     exit_program();
97   }
98 
99 
100 #ifndef NDMOS_OPTION_NO_CONTROL_AGENT
101   build_job(); /* might not return */
102 
103   the_session.param = &the_param;
104 
105   if (n_noop) {
106     dump_settings();
107     exit_program();
108   }
109 
110   start_index_file();
111 
112   rc = ndma_client_session(&the_session, &the_job, (o_swap_connect != 0));
113 
114   sort_index_file();
115 
116   if (rc == 0)
117     ndmjob_log(1, "Operation complete");
118   else
119     ndmjob_log(1, "Operation complete but had problems.");
120 #endif /* !NDMOS_OPTION_NO_CONTROL_AGENT */
121 
122 
123   exit_program();
124 }
125