gen.c revision f3861e1a2ceec23a5b699c24d814b7775a9e0b52
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Support routines for library
*/
#include <errno.h>
#include <strings.h>
#include <fcntl.h>
#include <unistd.h>
#include <libscf.h>
#include <door.h>
#include <libxml/xmlreader.h>
#include "iscsitgt_impl.h"
#define WAIT_FOR_SERVICE 15
#define WAIT_FOR_DOOR 15
static char *bad_call_str = "<error><code>1</code>"
"<message>Can't call daemon</message></error>";
static Boolean_t check_and_online(int);
{
tgt_node_t *n = NULL;
door_arg_t d;
int s;
d.desc_num = 0;
d.rsize = 0;
if (((s = open(ISCSI_TARGET_MGMT_DOOR, 0)) < 0) ||
(door_call(s, &d) < 0)) {
if (s != -1)
(void) close(s);
d.rbuf = bad_call_str;
} else if ((s = open(ISCSI_TARGET_MGMT_DOOR, 0)) < 0) {
d.rbuf = bad_call_str;
} else if (door_call(s, &d) < 0)
d.rbuf = bad_call_str;
}
return (NULL);
while (xmlTextReaderRead(r) == 1)
if (tgt_node_process(r, &n) == False)
break;
if (d.rbuf != bad_call_str)
(void) close(s);
return (n);
}
static Boolean_t
is_online(void)
{
char *s;
if (strcmp(s, SCF_STATE_STRING_ONLINE) == 0)
free(s);
}
return (rval);
}
static Boolean_t
is_auto_enabled(void)
{
"auto_enable")) == NULL)
return (True);
return (rval);
}
static Boolean_t
{
int i,
fd;
if (!is_online()) {
if (!is_auto_enabled())
return (False);
return (False);
for (i = 0; i < WAIT_FOR_SERVICE; i++) {
break;
(void) sleep(1);
}
if (i == WAIT_FOR_SERVICE)
return (False);
}
for (i = 0; i < WAIT_FOR_DOOR; i++) {
return (True);
}
if (!is_online())
break;
(void) sleep(1);
}
return (False);
}