* configure.ac: Check if we can read the psinfo struct from

/proc (Solaris).
* config/procfs.m4: Add psinfo check
* config/config.psinfo.c: New file.
* Source/NSProcessInfo.m (+load): Read from psinfo if we can.
(Based on patch #4234 from Jeremy Bettis, with some modifications).


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@21634 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
fedor 2005-08-12 17:34:19 +00:00
parent 6979f0d2fe
commit 86c924bc0c
7 changed files with 670 additions and 150 deletions

View file

@ -1,3 +1,12 @@
2005-08-12 Adam Fedor <fedor@gnu.org>
* configure.ac: Check if we can read the psinfo struct from
/proc (Solaris).
* config/procfs.m4: Add psinfo check
* config/config.psinfo.c: New file.
* Source/NSProcessInfo.m (+load): Read from psinfo if we can.
(Based on patch #4234 from Jeremy Bettis, with some modifications).
2005-07-31 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GNUmakefile: Pass GNUSTEP_FLATTENED as preprocessor

View file

@ -169,6 +169,12 @@
/* Define if system supports the /proc filesystem */
#undef HAVE_PROCFS
/* Define to 1 if you have the <procfs.h> header file. */
#undef HAVE_PROCFS_H
/* Define if system supports reading psinfo from /proc */
#undef HAVE_PROCFS_PSINFO
/* Define if your Lib C defines program_invocation_name */
#undef HAVE_PROGRAM_INVOCATION_NAME
@ -415,9 +421,11 @@
first (like Motorola and SPARC, unlike Intel and VAX). */
#undef WORDS_BIGENDIAN
/* Define as `__inline' if that's what the C compiler calls it, or to nothing
if it is not supported. */
/* Define to `__inline__' or `__inline' if that's what the C compiler
calls it, or to nothing if 'inline' is not supported under any name. */
#ifndef __cplusplus
#undef inline
#endif
/* Define to `unsigned' if <sys/types.h> does not define. */
#undef size_t

View file

@ -78,6 +78,12 @@
#include <sys/sysctl.h>
#endif /* HAVE_KVM_ENV */
#if HAVE_PROCFS_H
#define id _procfs_avoid_id_collision
#include <procfs.h>
#undef id
#endif
#include "GSConfig.h"
#include "Foundation/NSString.h"
#include "Foundation/NSArray.h"
@ -337,7 +343,7 @@ _gnu_process_args(int argc, char *argv[], char *env[])
IF_NO_GC(RELEASE(arp));
}
#if !GS_FAKE_MAIN && ((defined(HAVE_PROCFS) || defined(HAVE_KVM_ENV)) && (defined(HAVE_LOAD_METHOD)))
#if !GS_FAKE_MAIN && ((defined(HAVE_PROCFS) || defined(HAVE_KVM_ENV) || defined(HAVE_PROCFS_PSINFO)) && (defined(HAVE_LOAD_METHOD)))
/*
* We have to save program arguments and environment before main () is
* executed, because main () could modify their values before we get a
@ -438,6 +444,74 @@ static char **_gnu_noobjc_env = NULL;
}
_gnu_noobjc_argv[i] = NULL;
return;
#elif defined(HAVE_PROCFS_PSINFO)
char *proc_file_name = NULL;
FILE *ifp;
psinfo_t pinfo;
char **vectors;
int i, count;
// Read commandline
proc_file_name = (char*)malloc(sizeof(char) * 2048);
sprintf(proc_file_name, "/proc/%d/psinfo", (int) getpid());
ifp = fopen(proc_file_name, "r");
if (ifp == NULL)
{
fprintf(stderr, "Error: Failed to open the process info file:%s\n",
proc_file_name);
abort();
}
fread(&pinfo, sizeof(pinfo), 1, ifp);
fclose(ifp);
vectors = (char **)pinfo.pr_envp;
if (!vectors)
{
fprintf(stderr, "Error: for some reason, environ == NULL "
"during GNUstep base initialization\n"
"Please check the linking process\n");
abort();
}
/* copy the environment strings */
for (count = 0; vectors[count]; count++)
;
_gnu_noobjc_env = (char**)malloc(sizeof(char*) * (count + 1));
if (!_gnu_noobjc_env)
goto malloc_error;
for (i = 0; i < count; i++)
{
_gnu_noobjc_env[i] = (char *)strdup(vectors[i]);
if (!_gnu_noobjc_env[i])
goto malloc_error;
}
_gnu_noobjc_env[i] = NULL;
/* get the argument vectors */
vectors = (char **)pinfo.pr_argv;
if (!vectors)
{
fprintf(stderr, "Error: psinfo does not return arguments for the current
process\n");
abort();
}
/* copy the argument strings */
for (_gnu_noobjc_argc = 0; vectors[_gnu_noobjc_argc]; _gnu_noobjc_argc++)
;
_gnu_noobjc_argv = (char**)malloc(sizeof(char*) * (_gnu_noobjc_argc + 1));
if (!_gnu_noobjc_argv)
goto malloc_error;
for (i = 0; i < _gnu_noobjc_argc; i++)
{
_gnu_noobjc_argv[i] = (char *)strdup(vectors[i]);
if (!_gnu_noobjc_argv[i])
goto malloc_error;
}
_gnu_noobjc_argv[i] = NULL;
return;
#else /* !HAVE_KVM_ENV (i.e. HAVE_PROCFS). */
/*

34
config/config.psinfo.c Normal file
View file

@ -0,0 +1,34 @@
/*
* Check to see if we can read the psinfo struct
*/
/*
Copyright (C) 2005 Free Software Foundation
Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.
*/
#include <stdio.h>
#include <procfs.h>
int main()
{
char *proc_file_name = NULL;
FILE *ifp;
psinfo_t pinfo;
char **vectors;
int i, count;
// Read commandline
proc_file_name = (char*)malloc(sizeof(char) * 2048);
sprintf(proc_file_name, "/proc/%d/psinfo", (int) getpid());
ifp = fopen(proc_file_name, "r");
if (ifp == NULL)
{
return 1;
}
fread(&pinfo, sizeof(pinfo), 1, ifp);
fclose(ifp);
return 0;
}

View file

@ -1,10 +1,12 @@
dnl AC_SYS_PROCFS
dnl This macro defines HAVE_PROCFS if either it finds a mounted /proc
dnl or the user explicitly enables it for cross-compiles.
dnl procfs macros
dnl Copyright (C) 2005 Free Software Foundation
dnl Copying and distribution of this file, with or without modification,
dnl are permitted in any medium without royalty provided the copyright
dnl notice and this notice are preserved.
dnl
dnl AC_SYS_PROCFS
dnl This macro defines HAVE_PROCFS if either it finds a mounted /proc
dnl or the user explicitly enables it for cross-compiles.
AC_DEFUN(AC_SYS_PROCFS,
[ AC_ARG_ENABLE(procfs,
[ --enable-procfs Use /proc filesystem (default)],
@ -39,3 +41,28 @@ AC_DEFUN(AC_SYS_PROCFS,
fi
]
)
dnl AC_SYS_PROCFS_PSINFO
dnl This macro defines HAVE_PROCFS_PSINFO if it can read the psinfo
dnl structure from the /proc/%pid% directory
AC_DEFUN(AC_SYS_PROCFS_PSINFO,
[ AC_ARG_ENABLE(procfs-psinfo,
[ --enable-procfs-psinfo Use /proc/%pid% to get info],
enable_procfs_psinfo="$enableval", if test "$cross_compiling" = yes; then enable_procfs_psinfo=cross; else enable_procfs_psinfo=yes; fi;)
AC_CACHE_CHECK([support for /proc psinfo struct], ac_cv_sys_procfs_psinfo,
[if test "$enable_procfs_psinfo" = yes; then
AC_TRY_RUN([#include "$srcdir/config/config.psinfo.c"],
ac_cv_sys_procfs_psinfo=yes, ac_cv_sys_procfs_psinfo=no,
ac_cv_sys_procfs_psinfo=yes)
elif test "$enable_procfs" = cross; then
AC_MSG_WARN(Pass --enable-procfs-psinfo argument to enable use of /proc psinfo information.)
else
ac_cv_sys_procfs_psinfo=no
fi])
if test $ac_cv_sys_procfs_psinfo = yes; then
AC_DEFINE(HAVE_PROCFS_PSINFO, 1, [Define if system supports reading psinfo from /proc])
fi
]
)

650
configure vendored

File diff suppressed because it is too large Load diff

View file

@ -439,6 +439,7 @@ fi
# to be used for constant strings by using the -fconstant-string-class
# option. If that is the case, we change it to NSConstantString.
#---------------------------------------------------------------------
strclass_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS -fconstant-string-class=FooConstantString"
AC_MSG_CHECKING(if the compiler supports -fconstant-string-class)
AC_CACHE_VAL(objc_compiler_supports_constant_string_class,
@ -456,6 +457,7 @@ else
NX_CONST_STRING_CLASS=NXConstantString
AC_MSG_RESULT(no)
fi
CPPFLAGS="$strclass_CPPFLAGS"
AC_SUBST(NX_CONST_STRING_OBJCFLAGS)
AC_SUBST(NX_CONST_STRING_CLASS)
@ -843,7 +845,9 @@ fi
# Defines HAVE_PROCFS if the kernel supports the /proc filesystem.
# Needed by NSProcessInfo.m
#--------------------------------------------------------------------
AC_CHECK_HEADERS(procfs.h)
AC_SYS_PROCFS
AC_SYS_PROCFS_PSINFO
AC_SYS_PROCFS_EXE_LINK
#--------------------------------------------------------------------
@ -927,7 +931,7 @@ GS_FAKE_MAIN=0
if test "$enable_fake_main" = "yes"; then
GS_FAKE_MAIN=1
elif test "$enable_pass_arguments" = "no"; then
if test "$objc_load_method_worked" = yes -a \( "$ac_cv_sys_procfs" = yes -o "$have_kvm_env" = 1 \); then
if test "$objc_load_method_worked" = yes -a \( "$ac_cv_sys_procfs" = yes -o "$have_kvm_env" = 1 -o "$ac_cv_sys_procfs_psinfo" = yes \); then
GS_FAKE_MAIN=0
else
GS_FAKE_MAIN=1