本文整理汇总了C++中confstr函数的典型用法代码示例。如果您正苦于以下问题:C++ confstr函数的具体用法?C++ confstr怎么用?C++ confstr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了confstr函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: confstr
/*
* Class: sun_tools_attach_LinuxVirtualMachine
* Method: isLinuxThreads
* Signature: ()V
*/
JNIEXPORT jboolean JNICALL Java_sun_tools_attach_LinuxVirtualMachine_isLinuxThreads
(JNIEnv *env, jclass cls)
{
# ifndef _CS_GNU_LIBPTHREAD_VERSION
# define _CS_GNU_LIBPTHREAD_VERSION 3
# endif
size_t n;
char* s;
jboolean res;
n = confstr(_CS_GNU_LIBPTHREAD_VERSION, NULL, 0);
if (n <= 0) {
/* glibc before 2.3.2 only has LinuxThreads */
return JNI_TRUE;
}
s = (char *)malloc(n);
if (s == NULL) {
JNU_ThrowOutOfMemoryError(env, "malloc failed");
return JNI_TRUE;
}
confstr(_CS_GNU_LIBPTHREAD_VERSION, s, n);
/*
* If the LIBPTHREAD version include "NPTL" then we know we
* have the new threads library and not LinuxThreads
*/
res = (jboolean)(strstr(s, "NPTL") == NULL);
free(s);
return res;
}
开发者ID:AllenWeb,项目名称:openjdk-1,代码行数:36,代码来源:LinuxVirtualMachine.c
示例2: main
/*
* Test pthread creation at different thread priorities.
*/
int main(int argc, char *argv[])
{
char *pathbuf;
size_t n;
rt_init("h", parse_args, argc, argv);
n = confstr(_CS_GNU_LIBC_VERSION, NULL, (size_t) 0);
pathbuf = malloc(n);
if (!pathbuf)
abort();
confstr(_CS_GNU_LIBC_VERSION, pathbuf, n);
printf("LIBC_VERSION: %s\n", pathbuf);
free(pathbuf);
n = confstr(_CS_GNU_LIBPTHREAD_VERSION, NULL, (size_t) 0);
pathbuf = malloc(n);
if (!pathbuf)
abort();
confstr(_CS_GNU_LIBPTHREAD_VERSION, pathbuf, n);
printf("LIBPTHREAD_VERSION: %s\n", pathbuf);
free(pathbuf);
if (sysconf(_SC_THREAD_PRIO_INHERIT) == -1)
printf("No Prio inheritance support\n");
printf("Prio inheritance support present\n");
return 0;
}
开发者ID:1587,项目名称:ltp,代码行数:35,代码来源:testpi-0.c
示例3: printvar
static void
printvar (const struct conf_variable *cp, const char *pathname)
{
size_t slen;
char *sval;
long val;
switch (cp->type)
{
case CONSTANT:
print_longvar (cp->name, cp->value);
break;
case CONFSTR:
errno = 0;
slen = confstr ((int) cp->value, NULL, 0);
if (slen == 0)
{
if (errno == 0)
print_strvar (cp->name, "undefined");
return;
}
if ((sval = malloc (slen)) == NULL)
error (EXIT_FAILURE, 0, "Can't allocate %zu bytes", slen);
errno = 0;
if (confstr ((int) cp->value, sval, slen) == 0)
print_strvar (cp->name, "undefined");
else
print_strvar (cp->name, sval);
free (sval);
break;
case SYSCONF:
errno = 0;
if ((val = sysconf ((int) cp->value)) == -1)
{
if (a_flag && errno != 0)
return; /* Just skip invalid variables */
print_strvar (cp->name, "undefined");
}
else
print_longvar (cp->name, val);
break;
case PATHCONF:
errno = 0;
if ((val = pathconf (pathname, (int) cp->value)) == -1)
{
if (a_flag && errno != 0)
return; /* Just skip invalid variables */
print_strvar (cp->name, "undefined");
}
else
print_longvar (cp->name, val);
break;
}
}
开发者ID:ARMtools,项目名称:newlib-cygwin,代码行数:60,代码来源:getconf.c
示例4: uname
int uname(struct utsname *name) {
if( confstr(_CS_SYSNAME, name->sysname, sizeof name->sysname) == 0 ||
confstr(_CS_HOSTNAME, name->nodename, sizeof name->nodename) == 0 ||
confstr(_CS_RELEASE, name->release, sizeof name->release) == 0 ||
confstr(_CS_VERSION, name->version, sizeof name->version) == 0 ||
confstr(_CS_MACHINE, name->machine, sizeof name->machine) == 0) {
return -1;
}
return 0;
}
开发者ID:vocho,项目名称:openqnx,代码行数:10,代码来源:uname.c
示例5: citp_dump_config
static void citp_dump_config(void)
{
char buf[80];
confstr(_CS_GNU_LIBC_VERSION, buf, sizeof(buf));
log("GNU_LIBC_VERSION = %s", buf);
confstr(_CS_GNU_LIBPTHREAD_VERSION, buf, sizeof(buf));
log("GNU_LIBPTHREAD_VERSION = %s", buf);
log("ci_glibc_uses_nptl = %d", ci_glibc_uses_nptl());
log("ci_is_multithreaded = %d", ci_is_multithreaded());
}
开发者ID:arnetheduck,项目名称:openonload,代码行数:10,代码来源:startup.c
示例6: main
int main(int argc,char*argv[]) {
char*path;
size_t len;
len = confstr(_CS_PATH, (char *) NULL, 0);
if (!(path = malloc(1 + len)))
die("malloc...\n");
path[0] = ':';
confstr(_CS_PATH, path+1, len);
write(1,path,len);
return 0;
}
开发者ID:EmuxEvans,项目名称:CompositeFreeRTOS,代码行数:11,代码来源:confstr.c
示例7: getAll
//' Retrieve all configuration settings
//'
//' This functions returns all configuration settings which can be queried
//' in a data.frame object. The system-level functions \code{sysconf},
//' \code{pathconf} and \code{confstr} provide all the underlying information.
//'
//' @title Return all System Configuration Settings
//' @param path An optional character object specifying a path. Default is the
//' current directory.
//' @return A data.frame with three colums for key, value and (source) type.
//' Not all keys return a value; in those cases an empty string is returned.
//' Type is one of \code{path}, \code{sys} and \code{conf} and signals how the
//' value was obtained.
//' @author Dirk Eddelbuettel
//' @seealso \code{\link{getConfig}}
//' @examples
//' if (Sys.info()[["sysname"]] != "SunOS") {
//' head(getAll(), 30)
//' subset(getAll(), type=="path")
//' }
// [[Rcpp::export]]
Rcpp::DataFrame getAll(const std::string & path = ".") {
const struct conf *c;
size_t clen;
long int value;
char *cvalue;
std::vector<std::string> vname, vvalue, vtype;
char buf[256];
for (c = vars; c->name != NULL; ++c) {
//printf("%-35s", c->name);
vname.push_back(std::string(c->name).c_str());
snprintf(buf, 1, "%s", ""); // fallback
switch (c->calltype) {
case PATHCONF:
value = pathconf (path.c_str(), c->call_name);
if (value != -1) {
snprintf(buf, 255, "%ld", value);
}
vtype.push_back("path");
break;
case SYSCONF:
value = sysconf (c->call_name);
if (value == -1l) {
#if defined(_SC_UINT_MAX) && defined(_SC_ULONG_MAX)
if (c->call_name == _SC_UINT_MAX || c->call_name == _SC_ULONG_MAX)
snprintf(buf, 255, "%lu", value);
#endif
} else {
snprintf(buf, 255, "%ld", value);
}
vtype.push_back("sys");
break;
case CONFSTR:
clen = confstr (c->call_name, (char *) NULL, 0);
cvalue = R_alloc(clen, sizeof(char));
if (cvalue == NULL) {
Rcpp::stop("Memory allocation error");
}
if (confstr (c->call_name, cvalue, clen) != clen) {
Rcpp::stop("Confstr error");
}
snprintf(buf, 255, "%.*s", (int) clen, cvalue);
vtype.push_back("conf");
break;
}
vvalue.push_back(buf);
}
return Rcpp::DataFrame::create(Rcpp::Named("key") = vname,
Rcpp::Named("value") = vvalue,
Rcpp::Named("type") = vtype);
}
开发者ID:cran,项目名称:RcppGetconf,代码行数:74,代码来源:getconf.cpp
示例8: getConfig
//' Retrieve one configuration setting
//'
//' This functions returns the configuration setting for a given input.
//' in a data.frame object. The system-level functions \code{sysconf},
//' \code{pathconf} and \code{confstr} provide the underlying information.
//'
//' @title Return a System Configuration Setting
//' @param var An character object specifying a value for which configuration
//' is queried.
//' @param path An optional character object specifying a path. Default is the
//' current directory.
//' @return A result value corresponding to the requested setting. The return
//' type can be either integer for a numeric value, character for text or NULL
//' in case to value could be retrieved.
//' @author Dirk Eddelbuettel
//' @seealso \code{\link{getAll}}
//' @examples
//' if (Sys.info()[["sysname"]] != "SunOS") {
//' getConfig("_NPROCESSORS_CONF") # number of processor
//' getConfig("LEVEL1_ICACHE_SIZE") # leve1 cache size
//' getConfig("GNU_LIBC_VERSION") # libc version
//' }
// [[Rcpp::export]]
SEXP getConfig(const std::string & var,
const std::string & path = ".") {
const char *vararg = var.c_str();
const struct conf *c;
for (c = vars; c->name != NULL; ++c) {
if (strcmp (c->name, vararg) == 0 ||
(strncmp (c->name, "_POSIX_", 7) == 0 && strcmp (c->name + 7, vararg) == 0)) {
long int value;
size_t clen;
char *cvalue;
switch (c->calltype) {
case PATHCONF:
value = pathconf (path.c_str(), c->call_name);
if (value == -1) {
Rcpp::stop("Error with path arg: %s", path.c_str());
} else {
return Rcpp::wrap(value);
}
case SYSCONF:
value = sysconf (c->call_name);
if (value == -1l) {
#if defined(_SC_UINT_MAX) && defined(_SC_ULONG_MAX)
if (c->call_name == _SC_UINT_MAX || c->call_name == _SC_ULONG_MAX) {
return Rcpp::wrap(value);
} else {
#endif
Rcpp::stop("undefined");
#if defined(_SC_UINT_MAX) && defined(_SC_ULONG_MAX)
}
#endif
} else {
return Rcpp::wrap(value);
}
case CONFSTR:
clen = confstr (c->call_name, (char *) NULL, 0);
cvalue = R_alloc(clen, sizeof(char));
if (cvalue == NULL) {
Rcpp::stop("memory exhausted");
}
if (confstr(c->call_name, cvalue, clen) != clen) {
Rcpp::stop("Error with confstr");
}
return Rcpp::wrap(std::string(cvalue));
}
}
}
// fallback
return R_NilValue;
}
开发者ID:cran,项目名称:RcppGetconf,代码行数:76,代码来源:getconf.cpp
示例9: isnptl
int
isnptl (void)
{
size_t n = confstr (_CS_GNU_LIBPTHREAD_VERSION, NULL, 0);
if (n > 0) {
char *buf = alloca (n);
confstr (_CS_GNU_LIBPTHREAD_VERSION, buf, n);
if (strstr (buf, "NPTL")) {
return 1;
}
}
return 0;
}
开发者ID:angavrilov,项目名称:sbcl,代码行数:13,代码来源:linux-os.c
示例10: main
int main() {
int vals[] = {
_CS_PATH,
_CS_POSIX_V6_WIDTH_RESTRICTED_ENVS,
_CS_GNU_LIBC_VERSION,
_CS_GNU_LIBPTHREAD_VERSION,
_CS_POSIX_V6_ILP32_OFF32_LIBS,
_CS_POSIX_V6_ILP32_OFFBIG_LIBS,
_CS_POSIX_V6_LP64_OFF64_CFLAGS,
_CS_POSIX_V6_LP64_OFF64_LDFLAGS,
_CS_POSIX_V6_LP64_OFF64_LIBS,
_CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS,
_CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS,
_CS_POSIX_V6_LPBIG_OFFBIG_LIBS,
_CS_POSIX_V6_ILP32_OFF32_CFLAGS,
_CS_POSIX_V6_ILP32_OFF32_LDFLAGS,
_CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS,
_CS_POSIX_V6_ILP32_OFFBIG_CFLAGS
};
char* names[] = {
"_CS_PATH",
"_CS_POSIX_V6_WIDTH_RESTRICTED_ENVS",
"_CS_GNU_LIBC_VERSION",
"_CS_GNU_LIBPTHREAD_VERSION",
"_CS_POSIX_V6_ILP32_OFF32_LIBS",
"_CS_POSIX_V6_ILP32_OFFBIG_LIBS",
"_CS_POSIX_V6_LP64_OFF64_CFLAGS",
"_CS_POSIX_V6_LP64_OFF64_LDFLAGS",
"_CS_POSIX_V6_LP64_OFF64_LIBS",
"_CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS",
"_CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS",
"_CS_POSIX_V6_LPBIG_OFFBIG_LIBS",
"_CS_POSIX_V6_ILP32_OFF32_CFLAGS",
"_CS_POSIX_V6_ILP32_OFF32_LDFLAGS",
"_CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS",
"_CS_POSIX_V6_ILP32_OFFBIG_CFLAGS"
};
char buffer[256];
for (int i = 0; i < sizeof vals / sizeof vals[0]; i++) {
printf("ret: %d\n", confstr(vals[i], buffer, 256));
printf("%s: %s\n", names[i], buffer);
printf("errno: %d\n\n", errno);
errno = 0;
}
printf("(invalid) ret: %d\n", confstr(-123, buffer, 256));
printf("errno: %d\n", errno);
return 0;
}
开发者ID:AVert,项目名称:emscripten,代码行数:51,代码来源:confstr.c
示例11: findInPath
static const char* findInPath(const char* file)
{
static __thread char buffer[DARWIN_MAXPATHLEN];
if (*file == '/')
return file;
if (strchr(file, '/') != 0)
{
// No PATH resolution, only fix the case
strcpy(buffer, file);
translatePathCI(buffer);
return buffer;
}
const char* path = getenv("PATH");
if (!path)
{
// Get the default path.
size_t len = confstr(_CS_PATH, 0, 0);
char* buf = reinterpret_cast<char*>( alloca(len + 1) );
buf[0] = ':';
confstr(_CS_PATH, buf + 1, len);
path = buf;
}
const char* p = path;
do
{
const char* end = strchrnul(p, ':');
size_t len = end-p;
memcpy(buffer, p, len);
if (buffer[len-1] != '/')
buffer[len++] = '/';
strcpy(buffer+len, file);
translatePathCI(buffer);
if (::access(buffer, X_OK) == 0)
return buffer;
}
while (*p++);
return 0;
}
开发者ID:eccstartup,项目名称:darling,代码行数:48,代码来源:exec.cpp
示例12: main
int main() {
printf("Using gnu_get_lib_version(): The glibc version is: %s\n", gnu_get_libc_version());
char *p;
size_t max_size = 1024;
p = (char *)malloc(max_size);
confstr(_CS_GNU_LIBC_VERSION, p, (size_t)1024 );
printf("Using confstr(): The glibc version is: %s\n", p);
printf("Max size of 'p' is %ld", (long)max_size);
newline();
printf("OK, now for some error handling....\n");
error_handling();
newline();
printf("Gangsta! Now for some system data type printing!");
printing_system_data_types();
free(p);
return 0;
}
开发者ID:srazzaque,项目名称:kerrisk_tlpi,代码行数:25,代码来源:exercises.c
示例13: defined
/*
* This function returns the absolute path to the executable it is running in.
*
* The implementation follows http://stackoverflow.com/a/933996/712014
*
*/
const char *get_exe_path(const char *argv0) {
static char destpath[PATH_MAX];
char tmp[PATH_MAX];
#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
/* Linux and Debian/kFreeBSD provide /proc/self/exe */
#if defined(__linux__) || defined(__FreeBSD_kernel__)
const char *exepath = "/proc/self/exe";
#elif defined(__FreeBSD__)
const char *exepath = "/proc/curproc/file";
#endif
ssize_t linksize;
if ((linksize = readlink(exepath, destpath, sizeof(destpath) - 1)) != -1) {
/* readlink() does not NULL-terminate strings, so we have to. */
destpath[linksize] = '\0';
return destpath;
}
#endif
/* argv[0] is most likely a full path if it starts with a slash. */
if (argv0[0] == '/')
return argv0;
/* if argv[0] contains a /, prepend the working directory */
if (strchr(argv0, '/') != NULL &&
getcwd(tmp, sizeof(tmp)) != NULL) {
snprintf(destpath, sizeof(destpath), "%s/%s", tmp, argv0);
return destpath;
}
/* Fall back to searching $PATH (or _CS_PATH in absence of $PATH). */
char *path = getenv("PATH");
if (path == NULL) {
/* _CS_PATH is typically something like "/bin:/usr/bin" */
confstr(_CS_PATH, tmp, sizeof(tmp));
sasprintf(&path, ":%s", tmp);
} else {
path = strdup(path);
}
const char *component;
char *str = path;
while (1) {
if ((component = strtok(str, ":")) == NULL)
break;
str = NULL;
snprintf(destpath, sizeof(destpath), "%s/%s", component, argv0);
/* Of course this is not 100% equivalent to actually exec()ing the
* binary, but meh. */
if (access(destpath, X_OK) == 0) {
free(path);
return destpath;
}
}
free(path);
/* Last resort: maybe it’s in /usr/bin? */
return "/usr/bin/i3-nagbar";
}
开发者ID:DSMan195276,项目名称:i3,代码行数:66,代码来源:get_exe_path.c
示例14: fopen_ex
/*
* fopen_ex - open a file for variable architecture
* return: FILE *
* filename(in): path to the file to open
* type(in): open type
*/
FILE *
fopen_ex (const char *filename, const char *type)
{
#if defined(SOLARIS)
size_t r = 0;
char buf[1024];
extern size_t confstr (int, char *, size_t);
r = confstr (_CS_LFS_CFLAGS, buf, 1024);
if (r > 0)
return fopen64 (filename, type);
else
return fopen (filename, type);
#elif defined(HPUX)
#if _LFS64_LARGEFILE == 1
return fopen64 (filename, type);
#else
return fopen (filename, type);
#endif
#elif defined(AIX) || (defined(I386) && defined(LINUX))
return fopen64 (filename, type);
#else /* NT, ALPHA_OSF, and the others */
return fopen (filename, type);
#endif
}
开发者ID:dong1,项目名称:testsize,代码行数:32,代码来源:util_common.c
示例15: main
int main(void)
{
int confstr_len = confstr(_CS_GNU_LIBC_VERSION, NULL, 0);
char confstr_buf[confstr_len];
confstr(_CS_GNU_LIBC_VERSION, confstr_buf, confstr_len);
printf("At compile-time the version was %d.%d.\n",
__GLIBC__,
__GLIBC_MINOR__);
printf("At runtime the version is %s.\n",
gnu_get_libc_version());
printf("confstr reports %s.\n",
confstr_buf);
return 0;
}
开发者ID:mcpierce,项目名称:explorus,代码行数:16,代码来源:check_libc_version.c
示例16: setup_thread
int
setup_thread (struct database_dyn *db)
{
#ifdef __NR_set_tid_address
/* Only supported when NPTL is used. */
char buf[100];
if (confstr (_CS_GNU_LIBPTHREAD_VERSION, buf, sizeof (buf)) >= sizeof (buf)
|| strncmp (buf, "NPTL", 4) != 0)
return 0;
/* Do not try this at home, kids. We play with the SETTID address
even thought the process is multi-threaded. This can only work
since none of the threads ever terminates. */
INTERNAL_SYSCALL_DECL (err);
int r = INTERNAL_SYSCALL (set_tid_address, err, 1,
&db->head->nscd_certainly_running);
if (!INTERNAL_SYSCALL_ERROR_P (r, err))
/* We know the kernel can reset this field when nscd terminates.
So, set the field to a nonzero value which indicates that nscd
is certainly running and clients can skip the test. */
return db->head->nscd_certainly_running = 1;
#endif
return 0;
}
开发者ID:riscv,项目名称:riscv-glibc,代码行数:25,代码来源:nscd_setup_thread.c
示例17: confstr_cmd
static TACommandVerdict confstr_cmd(TAThread thread,TAInputStream stream)
{
int name;
size_t res;
char * buf;
size_t len;
/* Prepare */
name = readInt(&stream);
buf = (char*)readPointer(&stream);
len = readSize(&stream);
/* [ Set errno ] */
errno = readInt(&stream);
START_TARGET_OPERATION(thread);
/* Execute */
res = confstr(name,buf,len);
END_TARGET_OPERATION(thread);
/* Response */
writeSize(thread, res);
writeInt(thread, errno);
sendResponse(thread);
return taDefaultVerdict;
}
开发者ID:levenkov,项目名称:olver,代码行数:30,代码来源:sysconf_agent.c
示例18: rtProcPosixAdjustProfileEnvFromChild
/**
* Adjust the profile environment after forking the child process and changing
* the UID.
*
* @returns IRPT status code.
* @param hEnvToUse The environment we're going to use with execve.
* @param fFlags The process creation flags.
* @param hEnv The environment passed in by the user.
*/
static int rtProcPosixAdjustProfileEnvFromChild(RTENV hEnvToUse, uint32_t fFlags, RTENV hEnv)
{
int rc = VINF_SUCCESS;
#ifdef RT_OS_DARWIN
if ( RT_SUCCESS(rc)
&& (!(fFlags & RTPROC_FLAGS_ENV_CHANGE_RECORD) || RTEnvExistEx(hEnv, "TMPDIR")) )
{
char szValue[_4K];
size_t cbNeeded = confstr(_CS_DARWIN_USER_TEMP_DIR, szValue, sizeof(szValue));
if (cbNeeded > 0 && cbNeeded < sizeof(szValue))
{
char *pszTmp;
rc = RTStrCurrentCPToUtf8(&pszTmp, szValue);
if (RT_SUCCESS(rc))
{
rc = RTEnvSetEx(hEnvToUse, "TMPDIR", pszTmp);
RTStrFree(pszTmp);
}
}
else
rc = VERR_BUFFER_OVERFLOW;
}
#endif
return rc;
}
开发者ID:miguelinux,项目名称:vbox,代码行数:34,代码来源:process-creation-posix.cpp
示例19: etc_systmpdir
/*
* Returns system temporary directory; typically "/tmp".
*/
static VALUE
etc_systmpdir(void)
{
VALUE tmpdir;
#ifdef _WIN32
WCHAR path[_MAX_PATH];
UINT len = rb_w32_system_tmpdir(path, numberof(path));
if (!len) return Qnil;
tmpdir = rb_w32_conv_from_wchar(path, rb_filesystem_encoding());
#else
const char default_tmp[] = "/tmp";
const char *tmpstr = default_tmp;
size_t tmplen = strlen(default_tmp);
# if defined _CS_DARWIN_USER_TEMP_DIR
#ifndef MAXPATHLEN
#define MAXPATHLEN 1024
#endif
char path[MAXPATHLEN];
size_t len;
len = confstr(_CS_DARWIN_USER_TEMP_DIR, path, sizeof(path));
if (len > 0) {
tmpstr = path;
tmplen = len - 1;
}
# endif
tmpdir = rb_filesystem_str_new(tmpstr, tmplen);
#endif
FL_UNSET(tmpdir, FL_TAINT);
return tmpdir;
}
开发者ID:brightbox,项目名称:deb-ruby2.3,代码行数:33,代码来源:etc.c
示例20: system
int system(const char *cmd) {
int pid, status;
struct sigaction sa, savintr, savequit;
char *argv[4];
spawn_inheritance_type inherit;
char path[PATH_MAX + 1];
char buff[PATH_MAX + 1];
char *sh;
if(confstr(_CS_PATH, path, sizeof path) == 0 || !(sh = pathfind_r(path, "sh", "x", buff, sizeof buff))) {
sh = _PATH_BSHELL;
// If cmd is NULL we do an existance check on the shell.
if(!cmd) {
return eaccess(sh, X_OK) != -1;
}
}
// If cmd is NULL return existance of shell.
if(!cmd) {
return 1;
}
// Setup arguments for spawn.
argv[0] = "sh";
argv[1] = "-c";
argv[2] = (char *)cmd;
argv[3] = NULL;
// Ignore SIGINT,SIGQUIT and mask SIGCHLD on parent.
sa.sa_handler = SIG_IGN;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sigaction(SIGINT, &sa, &savintr);
sigaction(SIGQUIT, &sa, &savequit);
sigaddset(&sa.sa_mask, SIGCHLD);
sigprocmask(SIG_BLOCK, &sa.sa_mask, &inherit.sigmask);
// Inialize inheritance structure for spawn.
sigfillset(&inherit.sigdefault);
inherit.flags = SPAWN_SETSIGDEF | SPAWN_SETSIGMASK;
// POSIX 1003.1d implementation.
if((pid = spawn(sh, 0, NULL, &inherit, argv, environ)) == -1) {
status = -1;
} else while(waitpid(pid, &status, 0) == -1) {
if(errno != EINTR) {
status = -1;
break;
}
}
// restore SIGINT, SIGQUIT, SIGCHLD.
sigaction(SIGINT, &savintr, NULL);
sigaction(SIGQUIT, &savequit, NULL);
sigprocmask(SIG_SETMASK, &inherit.sigmask, NULL);
return(status);
}
开发者ID:vocho,项目名称:openqnx,代码行数:59,代码来源:system.c
注:本文中的confstr函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论