1 /* $NetBSD: iscsi-target.c,v 1.13 2007/11/12 23:25:41 agc Exp $ */
4 * Copyright (c) 2009 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Alistair Crooks (agc@netbsd.org)
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
51 main(int argc
, char **argv
)
59 iscsi_target_set_defaults(&tgt
);
60 while ((i
= getopt(argc
, argv
, "46b:Df:p:s:t:Vv:")) != -1) {
64 (void) snprintf(buf
, sizeof(buf
), "%d", i
);
65 iscsi_target_setvar(&tgt
, "address family", buf
);
68 iscsi_target_setvar(&tgt
, "blocklen", optarg
);
74 iscsi_target_setvar(&tgt
, "configfile", optarg
);
77 iscsi_target_setvar(&tgt
, "target port", optarg
);
80 if ((i
= atoi(optarg
)) > 0 && i
< 128) {
81 iscsi_target_setvar(&tgt
, "max sessions", optarg
);
85 iscsi_target_setvar(&tgt
, "iqn", optarg
);
88 (void) printf("\"%s\" %s\nPlease send all bug reports to %s\n", PACKAGE_NAME
, PACKAGE_VERSION
, PACKAGE_BUGREPORT
);
92 if (strcmp(optarg
, "net") == 0) {
93 iscsi_target_setvar(&tgt
, "debug", "net");
94 } else if (strcmp(optarg
, "iscsi") == 0) {
95 iscsi_target_setvar(&tgt
, "debug", "iscsi");
96 } else if (strcmp(optarg
, "scsi") == 0) {
97 iscsi_target_setvar(&tgt
, "debug", "scsi");
98 } else if (strcmp(optarg
, "all") == 0) {
99 iscsi_target_setvar(&tgt
, "debug", "all");
105 (void) signal(SIGPIPE
, SIG_IGN
);
107 /* Initialize target */
108 if (iscsi_target_start(&tgt
) != 0) {
109 (void) fprintf(stderr
, "iscsi_target_start() failed\n");
114 /* if we are supposed to be a daemon, detach from controlling tty */
115 if (detach_me_harder
&& daemon(0, 0) < 0) {
116 (void) fprintf(stderr
, "daemon() failed\n");
121 /* write pid to a file */
122 iscsi_target_write_pidfile(NULL
);
124 /* Wait for connections */
125 if (iscsi_target_listen(&tgt
) != 0) {
126 (void) fprintf(stderr
, "iscsi_target_listen() failed\n");