Deleted Added
full compact
secondary.c (218214) secondary.c (218218)
1/*-
2 * Copyright (c) 2009-2010 The FreeBSD Foundation
3 * Copyright (c) 2010 Pawel Jakub Dawidek <pjd@FreeBSD.org>
4 * All rights reserved.
5 *
6 * This software was developed by Pawel Jakub Dawidek under sponsorship from
7 * the FreeBSD Foundation.
8 *

--- 15 unchanged lines hidden (view full) ---

24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2009-2010 The FreeBSD Foundation
3 * Copyright (c) 2010 Pawel Jakub Dawidek <pjd@FreeBSD.org>
4 * All rights reserved.
5 *
6 * This software was developed by Pawel Jakub Dawidek under sponsorship from
7 * the FreeBSD Foundation.
8 *

--- 15 unchanged lines hidden (view full) ---

24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: head/sbin/hastd/secondary.c 218214 2011-02-03 10:37:44Z pjd $");
32__FBSDID("$FreeBSD: head/sbin/hastd/secondary.c 218218 2011-02-03 11:39:49Z pjd $");
33
34#include <sys/param.h>
35#include <sys/time.h>
36#include <sys/bio.h>
37#include <sys/disk.h>
38#include <sys/stat.h>
39
40#include <err.h>

--- 318 unchanged lines hidden (view full) ---

359 /*
360 * Create communication channel between child and parent.
361 */
362 if (proto_client("socketpair://", &res->hr_event) < 0) {
363 KEEP_ERRNO((void)pidfile_remove(pfh));
364 pjdlog_exit(EX_OSERR,
365 "Unable to create event sockets between child and parent");
366 }
33
34#include <sys/param.h>
35#include <sys/time.h>
36#include <sys/bio.h>
37#include <sys/disk.h>
38#include <sys/stat.h>
39
40#include <err.h>

--- 318 unchanged lines hidden (view full) ---

359 /*
360 * Create communication channel between child and parent.
361 */
362 if (proto_client("socketpair://", &res->hr_event) < 0) {
363 KEEP_ERRNO((void)pidfile_remove(pfh));
364 pjdlog_exit(EX_OSERR,
365 "Unable to create event sockets between child and parent");
366 }
367 /*
368 * Create communication channel for sending connection requests from
369 * parent to child.
370 */
371 if (proto_client("socketpair://", &res->hr_conn) < 0) {
372 /* TODO: There's no need for this to be fatal error. */
373 KEEP_ERRNO((void)pidfile_remove(pfh));
374 pjdlog_exit(EX_OSERR,
375 "Unable to create connection sockets between parent and child");
376 }
367
368 pid = fork();
369 if (pid < 0) {
370 KEEP_ERRNO((void)pidfile_remove(pfh));
371 pjdlog_exit(EX_OSERR, "Unable to fork");
372 }
373
374 if (pid > 0) {
375 /* This is parent. */
376 proto_close(res->hr_remotein);
377 res->hr_remotein = NULL;
378 proto_close(res->hr_remoteout);
379 res->hr_remoteout = NULL;
380 /* Declare that we are receiver. */
381 proto_recv(res->hr_event, NULL, 0);
382 /* Declare that we are sender. */
383 proto_send(res->hr_ctrl, NULL, 0);
377
378 pid = fork();
379 if (pid < 0) {
380 KEEP_ERRNO((void)pidfile_remove(pfh));
381 pjdlog_exit(EX_OSERR, "Unable to fork");
382 }
383
384 if (pid > 0) {
385 /* This is parent. */
386 proto_close(res->hr_remotein);
387 res->hr_remotein = NULL;
388 proto_close(res->hr_remoteout);
389 res->hr_remoteout = NULL;
390 /* Declare that we are receiver. */
391 proto_recv(res->hr_event, NULL, 0);
392 /* Declare that we are sender. */
393 proto_send(res->hr_ctrl, NULL, 0);
394 proto_send(res->hr_conn, NULL, 0);
384 res->hr_workerpid = pid;
385 return;
386 }
387
388 gres = res;
389 mode = pjdlog_mode_get();
390
391 /* Declare that we are sender. */
392 proto_send(res->hr_event, NULL, 0);
393 /* Declare that we are receiver. */
394 proto_recv(res->hr_ctrl, NULL, 0);
395 res->hr_workerpid = pid;
396 return;
397 }
398
399 gres = res;
400 mode = pjdlog_mode_get();
401
402 /* Declare that we are sender. */
403 proto_send(res->hr_event, NULL, 0);
404 /* Declare that we are receiver. */
405 proto_recv(res->hr_ctrl, NULL, 0);
406 proto_recv(res->hr_conn, NULL, 0);
395 descriptors_cleanup(res);
396
397 descriptors_assert(res, mode);
398
399 pjdlog_init(mode);
400 pjdlog_prefix_set("[%s] (%s) ", res->hr_name, role2str(res->hr_role));
401 setproctitle("%s (secondary)", res->hr_name);
402

--- 367 unchanged lines hidden ---
407 descriptors_cleanup(res);
408
409 descriptors_assert(res, mode);
410
411 pjdlog_init(mode);
412 pjdlog_prefix_set("[%s] (%s) ", res->hr_name, role2str(res->hr_role));
413 setproctitle("%s (secondary)", res->hr_name);
414

--- 367 unchanged lines hidden ---