/*
 * 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;
}
Beispiel #2
0
/*
 * 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;
}
Beispiel #3
0
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;
    }
}
Beispiel #4
0
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;
}
Beispiel #5
0
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());
}
Beispiel #6
0
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;
}
Beispiel #7
0
//' 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);
}
Beispiel #8
0
//' 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;
}
Beispiel #9
0
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;
}
Beispiel #10
0
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;
}
Beispiel #11
0
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;
}
Beispiel #12
0
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;

}
Beispiel #13
0
/*
 * 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";
}
Beispiel #14
0
/*
 * 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
}
Beispiel #15
0
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;
}
Beispiel #16
0
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;
}
Beispiel #17
0
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;
}
/**
 * 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;
}
Beispiel #19
0
/*
 * 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;
}
Beispiel #20
0
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);
}
Beispiel #21
0
size_t
__confstr_chk (int name, char *buf, size_t len, size_t buflen)
{
  if (__builtin_expect (buflen < len, 0))
    __chk_fail ();

  return confstr (name, buf, len);
}
Beispiel #22
0
size_t
__confstr_chk (int name, char *buf, size_t len, size_t buflen)
{
    if (__glibc_unlikely (buflen < len))
        __chk_fail ();

    return confstr (name, buf, len);
}
Beispiel #23
0
static int print_confstr(const struct conf_variable *cp, const char *pathname)
{
	size_t len;
	char *val;

	errno = 0;
	if ((len = confstr((int)cp->value, NULL, 0)) == 0) goto error;
	if ((val = malloc(len)) == NULL) err(EXIT_FAILURE, "Can't allocate %zu bytes", len);
	errno = 0;
	if (confstr((int)cp->value, val, len) == 0) goto error;
	print_string(cp->name, val);
	free(val);
	return 0;
error:
	if (errno != EINVAL) err(EXIT_FAILURE, "confstr(%ld)", cp->value);
	return -1;
}
Beispiel #24
0
int
main(int argc, char *argv[])
{
	char *pathbuf; size_t sz;

	printf("configuration test\n");

	sz = confstr(_CS_PATH,NULL,(size_t)0);
	if ((pathbuf = malloc(sz)) == NULL) {
		printf("no mem\n");
		exit(1);
	}
	confstr(_CS_PATH, pathbuf, sz);
	printf("_CS_PATH=%s\n", pathbuf);

	exit(0);
}
Beispiel #25
0
// Setup the data directory and output file
char * initPaths(const char *name) {
	int fd;
	size_t dirLen, fileLen;
	char *datadir, *outfile;
	struct stat statbuf;

	// Construct the data directory and output file paths
	dirLen = confstr(_CS_DARWIN_USER_TEMP_DIR, NULL, (size_t) 0);
	dirLen += sizeof(DATA_DIR);
	fileLen = dirLen + strnlen(name, MAX_STR_LEN);
	datadir = malloc(dirLen);
	outfile = malloc(fileLen);
	if (datadir == NULL || outfile == NULL) {
		fprintf(stderr, "Out of memory\n");
		exit(1);
	}
	confstr(_CS_DARWIN_USER_TEMP_DIR, datadir, dirLen);
	strlcat(datadir, DATA_DIR, dirLen);
	strlcpy(outfile, datadir, fileLen);
	strlcat(outfile, name, fileLen);

	// Create the datadir as needed
	stat(datadir, &statbuf);
	if (!S_ISDIR(statbuf.st_mode)) {
		fprintf(stderr, "Creating data directory: %s\n", datadir);
		if (mkdir(datadir, S_IRUSR | S_IWUSR | S_IXUSR) != 0) {
			fprintf(stderr, "Error creating data directory (%s): %s\n", strerror(errno), datadir);
			exit(1);
		}
	}

	// Create the output file as needed
	stat(outfile, &statbuf);
	if(!S_ISREG(statbuf.st_mode)) {
		fprintf(stderr, "Creating output file: %s\n", outfile);
		fd = open(outfile, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
		if (fd <= 0 || close(fd) != 0) {
			fprintf(stderr, "Error creating output file (%s): %s\n", strerror(errno), outfile);
			exit(1);
		}
	}

	// Return the output file path
	return outfile;
}
Beispiel #26
0
CString ThreadsVersion()
{
	char buf[1024] = "(error)";
	int ret = confstr( _CS_GNU_LIBPTHREAD_VERSION, buf, sizeof(buf) );
	if( ret == -1 )
		return "(unknown)";

	return buf;
}
static CString LibcVersion()
{	
	char buf[1024] = "(error)";
	int ret = confstr( _CS_GNU_LIBC_VERSION, buf, sizeof(buf) );
	if( ret == -1 )
		return "(unknown)";

	return buf;
}
Beispiel #28
0
/*
 * Returns system configuration variable using confstr().
 *
 * _name_ should be a constant under <code>Etc</code> which begins with <code>CS_</code>.
 *
 * The return value is a string or nil.
 * nil means no configuration-defined value.  (confstr() returns 0 but errno is not set.)
 *
 *   Etc.confstr(Etc::CS_PATH) #=> "/bin:/usr/bin"
 *
 *   # GNU/Linux
 *   Etc.confstr(Etc::CS_GNU_LIBC_VERSION) #=> "glibc 2.18"
 *   Etc.confstr(Etc::CS_GNU_LIBPTHREAD_VERSION) #=> "NPTL 2.18"
 *
 */
static VALUE
etc_confstr(VALUE obj, VALUE arg)
{
    int name;
    char localbuf[128], *buf = localbuf;
    size_t bufsize = sizeof(localbuf), ret;
    VALUE tmp;

    name = NUM2INT(arg);

    errno = 0;
    ret = confstr(name, buf, bufsize);
    if (bufsize < ret) {
        bufsize = ret;
        buf = ALLOCV_N(char, tmp, bufsize);
        errno = 0;
        ret = confstr(name, buf, bufsize);
    }
Beispiel #29
0
/* Crash-conditions-safe: */
bool UsingNPTL()
{
	char buf[1024] = "";
	int ret = confstr( _CS_GNU_LIBPTHREAD_VERSION, buf, sizeof(buf) );
	if( ret == -1 )
		return false;

	return !strncmp( buf, "NPTL", 4 );
}
Beispiel #30
0
void testValues() {
    f = 2;
    size_t result;
    
    char buf[10];
    confstr(anyint(), buf, 10);
    
    //@ assert f == 2;
    //@ assert vacuous: \false;
}