Imported Upstream version 3.3.1
[debian/amanda] / ndmp-src / amndmjob_main.c
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
46 main (int ac, char *av[])
47 {
48         int rc;
49
50         if (ac > 1 && av && av[1] && g_str_equal(av[1], "--version")) {
51                 printf("amndmjob-%s\n", VERSION);
52                 return (0);
53         }
54
55         set_pname("amndmjob");
56         dbopen(DBG_SUBDIR_CLIENT);
57         config_init(0, NULL);
58
59         NDMOS_MACRO_ZEROFILL(&the_session);
60         d_debug = -1;
61
62         /* ready the_param early so logging works during process_args() */
63         NDMOS_MACRO_ZEROFILL (&the_param);
64         the_param.log.deliver = ndmjob_log_deliver;
65         the_param.log_level = 0;
66         the_param.log_tag = "SESS";
67
68 #ifndef NDMOS_OPTION_NO_CONTROL_AGENT
69         b_bsize = 20;
70         index_fp = stderr;
71         o_tape_addr = -1;
72         o_from_addr = -1;
73         o_to_addr = -1;
74         p_ndmp_port = NDMPPORT;
75 #endif /* !NDMOS_OPTION_NO_CONTROL_AGENT */
76
77         process_args (ac, av);
78
79         if (the_param.log_level < d_debug)
80                 the_param.log_level = d_debug;
81         if (the_param.log_level < v_verbose)
82                 the_param.log_level = v_verbose;
83         the_param.config_file_name = o_config_file;
84
85         if (the_mode == NDM_JOB_OP_DAEMON || the_mode == NDM_JOB_OP_TEST_DAEMON) {
86                 the_session.param = the_param;
87
88                 if (n_noop) {
89                         dump_settings();
90                         return 0;
91                 }
92                 ndma_daemon_session (&the_session, p_ndmp_port, the_mode == NDM_JOB_OP_TEST_DAEMON);
93                 return 0;
94         }
95
96 #ifndef NDMOS_OPTION_NO_CONTROL_AGENT
97         the_session.control_acb.swap_connect = (o_swap_connect != 0);
98
99         build_job();            /* might not return */
100
101         the_session.param = the_param;
102         the_session.control_acb.job = the_job;
103
104         if (n_noop) {
105                 dump_settings();
106                 return 0;
107         }
108
109         start_index_file ();
110
111         rc = ndma_client_session (&the_session);
112
113         sort_index_file ();
114
115         if (rc == 0)
116             ndmjob_log (1, "Operation complete");
117         else
118             ndmjob_log (1, "Operation complete but had problems.");
119 #endif /* !NDMOS_OPTION_NO_CONTROL_AGENT */
120
121         dbclose();
122         return 0;
123 }
124
125