util.c revision a5682f5243c3b36a55009c52d62edab683b28ccf
/*
* 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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* 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
* - check to see if a user is logged in to a graphical console
* - look up the zone name
*/
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <string.h>
#include <strings.h>
#include <stropts.h>
#include <syslog.h>
#include <spawn.h>
#include <wait.h>
#include <inetcfg.h>
#include <utmpx.h>
#include <pwd.h>
#include <limits.h>
#include <errno.h>
#include <zone.h>
#include "defines.h"
#include "structures.h"
#include "functions.h"
#include "variables.h"
extern char **environ;
void
{
char vbuf[1024];
if (debug) {
}
}
is_plugged_in(struct interface *i)
{
if (i->if_type == IF_WIRELESS)
return (B_TRUE);
}
{
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 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;
}
{
const char HOMESTR[] = "HOME=";
/*
* Check to see if our SMF property says popups are OK.
*/
return (B_FALSE);
/*
* Look for someone logged into the console from host ":0" (i.e.,
* the X display. Down the road, we should generalize this so
* ":0" is not hard-coded. Note that the entry we want is usually
* an ordinary user process but sometimes if a session leader has
* exited, it can come from a DEAD_PROCESS, as is known to happen
* when the user logs in via gdm(1m).
*/
setutxent();
break;
}
}
endutxent();
return (B_FALSE);
return (B_FALSE);
}
/*
* We shouldn't be dumping this into our environment or changing
* this display as this user. RFE to change this.
*/
(void) putenv("DISPLAY=:0.0");
}
void
{
return;
}