2 * File Server Shadow-Copy Daemon
4 * Copyright (C) David Disseldorp 2012-2015
7 * Copyright (c) 2011 Andreas Schneider <asn@samba.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, see <http://www.gnu.org/licenses/>.
29 #include "librpc/rpc/dcerpc_ep.h"
30 #include "../librpc/gen_ndr/srv_fsrvp.h"
31 #include "rpc_server/rpc_server.h"
32 #include "rpc_server/rpc_sock_helper.h"
33 #include "rpc_server/fss/srv_fss_agent.h"
35 #define DAEMON_NAME "fssd"
37 void start_fssd(struct tevent_context
*ev_ctx
,
38 struct messaging_context
*msg_ctx
);
40 static void fssd_reopen_logs(void)
42 char *lfile
= lp_logfile(NULL
);
45 if (lfile
== NULL
|| lfile
[0] == '\0') {
46 rc
= asprintf(&lfile
, "%s/log.%s", get_dyn_LOGFILEBASE(), DAEMON_NAME
);
48 lp_set_logfile(lfile
);
52 if (strstr(lfile
, DAEMON_NAME
) == NULL
) {
53 rc
= asprintf(&lfile
, "%s.%s", lp_logfile(NULL
), DAEMON_NAME
);
55 lp_set_logfile(lfile
);
64 static void fssd_smb_conf_updated(struct messaging_context
*msg
,
67 struct server_id server_id
,
70 DEBUG(10, ("Got message saying smb.conf was updated. Reloading.\n"));
71 change_to_root_user();
75 static void fssd_sig_term_handler(struct tevent_context
*ev
,
76 struct tevent_signal
*se
,
82 rpc_FileServerVssAgent_shutdown();
84 exit_server_cleanly("termination signal");
87 static void fssd_setup_sig_term_handler(struct tevent_context
*ev_ctx
)
89 struct tevent_signal
*se
;
91 se
= tevent_add_signal(ev_ctx
,
94 fssd_sig_term_handler
,
97 exit_server("failed to setup SIGTERM handler");
101 static void fssd_sig_hup_handler(struct tevent_context
*ev
,
102 struct tevent_signal
*se
,
108 change_to_root_user();
110 DEBUG(1,("reopening logs after SIGHUP\n"));
114 static void fssd_setup_sig_hup_handler(struct tevent_context
*ev_ctx
,
115 struct messaging_context
*msg_ctx
)
117 struct tevent_signal
*se
;
119 se
= tevent_add_signal(ev_ctx
,
122 fssd_sig_hup_handler
,
125 exit_server("failed to setup SIGHUP handler");
129 static bool fss_shutdown_cb(void *ptr
)
135 static bool fss_init_cb(void *ptr
)
138 status
= srv_fssa_start();
139 return NT_STATUS_IS_OK(status
);
142 void start_fssd(struct tevent_context
*ev_ctx
,
143 struct messaging_context
*msg_ctx
)
145 struct rpc_srv_callbacks fss_cb
;
151 fss_cb
.init
= fss_init_cb
;
152 fss_cb
.shutdown
= fss_shutdown_cb
;
153 fss_cb
.private_data
= NULL
;
155 DEBUG(1, ("Forking File Server Shadow-copy Daemon\n"));
160 DEBUG(0, ("failed to fork file server shadow-copy daemon [%s], "
161 "aborting ...\n", strerror(errno
)));
171 status
= reinit_after_fork(msg_ctx
,
174 if (!NT_STATUS_IS_OK(status
)) {
175 DEBUG(0,("reinit_after_fork() failed\n"));
176 smb_panic("reinit_after_fork() failed");
181 fssd_setup_sig_term_handler(ev_ctx
);
182 fssd_setup_sig_hup_handler(ev_ctx
, msg_ctx
);
184 ok
= serverid_register(procid_self(),
186 FLAG_MSG_PRINT_GENERAL
);
188 DEBUG(0, ("Failed to register serverid in fssd!\n"));
192 messaging_register(msg_ctx
,
194 MSG_SMB_CONF_UPDATED
,
195 fssd_smb_conf_updated
);
197 status
= rpc_FileServerVssAgent_init(&fss_cb
);
198 if (!NT_STATUS_IS_OK(status
)) {
199 DEBUG(0, ("Failed to register fssd rpc inteface! (%s)\n",
204 /* case is normalized by smbd on connection */
205 ok
= setup_named_pipe_socket("fssagentrpc", ev_ctx
, msg_ctx
);
207 DEBUG(0, ("Failed to open fssd named pipe!\n"));
211 DEBUG(1, ("File Server Shadow-copy Daemon Started (%d)\n", getpid()));
214 rc
= tevent_loop_wait(ev_ctx
);
216 /* should not be reached */
217 DEBUG(0,("tevent_loop_wait() exited with %d - %s\n",
218 rc
, (rc
== 0) ? "out of events" : strerror(errno
)));