util.c revision b00044a2eb43864b8718585d21949611a2ee59ef
/*
* 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 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* util.c contains a set of miscellaneous utility functions which:
* - syslog(LOG_DEBUG, ...) if debugging is enabled
* - check for an IP interface being marked running
* - look up all flags for an IP interface
* - start a child process
* - schedule a timer
* - look up the zone name
*/
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <string.h>
#include <stropts.h>
#include <syslog.h>
#include <spawn.h>
#include <wait.h>
#include <inetcfg.h>
#include <errno.h>
#include <zone.h>
#include "defines.h"
#include "structures.h"
#include "functions.h"
#include "variables.h"
extern char **environ;
/* PRINTFLIKE1 */
void
{
char vbuf[1024];
if (debug) {
}
}
{
return (0);
/*
* Interfaces can be ripped out from underneath us (for example
* by DHCP). We don't want to spam the console for those.
*/
dprintf("get_ifflags: icfg_get_flags failed for '%s'",
name);
else
/* just to be sure... */
flags = 0;
}
icfg_close(h);
return (flags);
}
/* This is just a work-around for CR 6745448: clear out a toxic interface */
void
zero_out_v4addr(const char *name)
{
struct sockaddr_in sinv;
int pfxlen;
return;
B_FALSE) == ICFG_SUCCESS &&
dprintf("bug workaround: clear out address %s on %s",
}
icfg_close(h);
}
/*
*
* This starts a child process determined by command. If command contains a
* slash then it is assumed to be a full path; otherwise the path is searched
* for an executable file with the name command. Command is also used as
* argv[0] of the new process. The rest of the arguments of the function
* up to the first NULL make up pointers to arguments of the new process.
*
* This function returns child exit status on success and -1 on failure.
*
* NOTE: original_sigmask must be set before this function is called.
*/
int
{
char vbuf[1024];
vbuf[0] = 0;
n = sizeof (vbuf);
}
return (-1);
}
(void) sigfillset(&fullset);
return (-1);
}
return (-1);
}
POSIX_SPAWN_SETSIGDEF|POSIX_SPAWN_SETSIGMASK)) != 0) {
return (-1);
}
environ)) > 0) {
return (-1);
}
return (-1);
}
strsignal(i));
return (-2);
} else {
return (WEXITSTATUS(status));
}
}
int
start_child(const char *command, ...)
{
int argv_len = 0;
int i = 1, rc;
do {
if (i >= argv_len) {
void *p;
if (p != NULL) {
argv = p;
} else {
return (-1);
}
}
return (rc);
}
/*
* Schedules a SIGALRM in delay seconds, unless one is already
* scheduled sooner. If one is already scheduled later than
* delay seconds from now, that one will be replaced.
*/
void
{
return;
}
void
{
return;
}