Compare commits
56 Commits
xemacs_20_
...
procps_1_2
Author | SHA1 | Date | |
---|---|---|---|
|
fe56feb875 | ||
|
5e9d34c91a | ||
|
0e086aef25 | ||
|
540385da7e | ||
|
540cd68691 | ||
|
c41d6e5a77 | ||
|
74ca45f795 | ||
|
5f4131f248 | ||
|
4bfef8c254 | ||
|
f77eba3d57 | ||
|
f18952a9d8 | ||
|
16cb163bb0 | ||
|
f8bdfa9a43 | ||
|
61f887fc67 | ||
|
9fd8936e93 | ||
|
ef693a93bc | ||
|
aa04293fc3 | ||
|
345a657d2c | ||
|
da7d7ff116 | ||
|
c5263a881e | ||
|
49adb94af0 | ||
|
b991ecaf9a | ||
|
2c8ae09776 | ||
|
8ecb7f296e | ||
|
3477d30dc5 | ||
|
f30dfecaf7 | ||
|
8a666eb5a4 | ||
|
61071132bf | ||
|
b177c3930d | ||
|
eb8d28b694 | ||
|
0b4f757b2b | ||
|
2aa20e2060 | ||
|
7d8ff8f72e | ||
|
576dde394a | ||
|
1d7491be0d | ||
|
15cc0113a9 | ||
|
9532dadc2e | ||
|
94715ef718 | ||
|
44bb75cf6e | ||
|
4d2072ce65 | ||
|
eb36f97c50 | ||
|
a76522a990 | ||
|
71187a5e51 | ||
|
b54a5d2dfd | ||
|
134ec106b3 | ||
|
1b90ed4fcc | ||
|
3fcc477b25 | ||
|
81c75477f4 | ||
|
8b025ff2c2 | ||
|
2de9ea5c7d | ||
|
d9e6288b7a | ||
|
8d78559597 | ||
|
2a281d0a53 | ||
|
28dfff5752 | ||
|
7d0d3db11c | ||
|
63c475d400 |
@@ -24,3 +24,4 @@ stamp-h
|
||||
sun4
|
||||
sun4sol2
|
||||
support
|
||||
i386-freebsd
|
||||
|
214
ChangeLog
214
ChangeLog
@@ -1,5 +1,219 @@
|
||||
1998-07-18 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* lib/{init, open}.c: Added `GLIBTOP_METHOD_PIPE' again.
|
||||
|
||||
* src/server/main.c: Removed gettext stuff.
|
||||
|
||||
1998-07-17 Martin Baulig <baulig@Stud.Informatik.uni-trier.de>
|
||||
|
||||
* sysdeps/common/sysdeps.c (glibtop_get_sysdeps_r): Using
|
||||
library functions with '_l' prefix instead of directly calling
|
||||
sysdeps code with '_r' prefix. This is necessary for client/server
|
||||
mode.
|
||||
|
||||
* lib/lib.awk (glibtop_get_*): Now correctly using
|
||||
`(1 << GLIBTOP_SYSDEPS_*)' instead of `GLIBTOP_SYSDEPS_*'.
|
||||
|
||||
* sysdeps/sun4/proclist.c (glibtop_get_proclist_p): Added
|
||||
implementation of that feature.
|
||||
|
||||
* sysdeps/sun4/proc_{uid, state}.c: Now working quite well.
|
||||
|
||||
* sysdeps/sun4/proc_{mem, time, signal, kernel, segment}.c: Added
|
||||
some basic implementation; this isn't really working yet.
|
||||
|
||||
* sysdeps/linux/sem_limits.c: Applied patch from Albert K T Hui
|
||||
<avatar@deva.net> for glibc 2.1.
|
||||
|
||||
1998-07-15 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* sysdeps/sun4/loadavg.h: New file. Imported from top 3.4.
|
||||
|
||||
* sysdeps/sun4/uptime.c (glibtop_get_uptime_p): Added
|
||||
implementation of that function using glibtop_get_cpu ().
|
||||
|
||||
* sysdeps/sun4/loadavg.c (glibtop_get_loadavg_p): Added
|
||||
implementation of that feature.
|
||||
|
||||
* sysdeps/sun4/{shm_limits.c, msg_limits.c, shm_limits.c}:
|
||||
Added implementation of this features.
|
||||
|
||||
1998-07-14 Martin Baulig <baulig@Stud.Informatik.uni-trier.de>
|
||||
|
||||
* src/daemon/server_config.h.in: Added some comments.
|
||||
|
||||
* src/daemon/server_config.pl: New file. This is a script you can use
|
||||
to create `server_config.h'. It will query you for some configuration
|
||||
options.
|
||||
|
||||
* configure.in (AC_PROG_AWK): Replaced this test with explicit test
|
||||
for `gawk' and `awk' since `mawk' doesn't work.
|
||||
|
||||
1998-07-14 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* src/daemon/gnuserv.c: Doing correct server initialization
|
||||
using `glibtop_set_parameter_l' and `glibtop_init_r'.
|
||||
|
||||
* src/daemon/main.c: Removed call to `glibtop_init_r'.
|
||||
|
||||
* lib/open.c (glibtop_open_l): We now call the open function
|
||||
of the sysdeps directory (glibtop_open_r) for server method
|
||||
`GLIBTOP_METHOD_DIRECT'.
|
||||
|
||||
* sysdeps/{linux, sun4, stub}/open.c: No longer `memset'
|
||||
server to zero.
|
||||
|
||||
* src/daemon/slave.c: New file.
|
||||
|
||||
* src/daemon/*.c: Done some more work on the daemon.
|
||||
|
||||
* sysdeps/common/gnuslib.c: Removed IPC stuff.
|
||||
|
||||
* include/glibtop/gnuserv.h: Removed IPC stuff.
|
||||
|
||||
* include/glibtop/command.h (glibtop_response_unit): Added
|
||||
typedef for `struct _glibtop_response_unit'.
|
||||
|
||||
* lib/Makefile.am: Using `$(top_srcdir)/features.def'
|
||||
instead of `$(top_builddir)/features.def'.
|
||||
|
||||
* sysdeps/guile/Makefile.am: Using `$(top_srcdir)/features.def'
|
||||
instead of `$(top_builddir)/features.def'.
|
||||
|
||||
* sysdeps/guile/names/Makefile.am: Dito.
|
||||
|
||||
* sysdeps/stub/*.c: changed suffix of all functions
|
||||
from '_s' to '_r'; see also ChangeLog entry from Jun 6.
|
||||
|
||||
1998-07-13 Martin Baulig <baulig@merkur.uni-trier.de>
|
||||
|
||||
* src/daemon/server_config.h: Removed from CVS.
|
||||
This is a config file which needs to be edited.
|
||||
|
||||
* src/daemon/server_config.h.in: Added. This is just
|
||||
an example for `server_config.h'.
|
||||
|
||||
1998-07-13 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* glibtop.h: Fixed invocation of `glibtop_close_r'.
|
||||
|
||||
* sysdeps/linux/procstate.c: Added missing `fclose'.
|
||||
|
||||
* include/glibtop/gnuserv.h (UNIX_DOMAIN_SOCKETS): Defining.
|
||||
|
||||
* include/glibtop/open.h (GLIBTOP_METHOD_UNIX): Added.
|
||||
|
||||
* lib/init.c: Added new method `GLIBTOP_METHOD_UNIX'.
|
||||
|
||||
* lib/open.c: Added support for Unix Domain Sockets.
|
||||
|
||||
* lib/close.c: Now closing inet and unix connections.
|
||||
|
||||
* lib/parameter.c (glibtop_set_parameter_l): You can now
|
||||
set the `method' and `features' fields.
|
||||
|
||||
* src/daemon/server_config.h: New file.
|
||||
|
||||
* src/daemon/{gnuserv.c, main.c}: More work on the server.
|
||||
|
||||
1998-07-10 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* src/Makefile.am (SUBDIRS): Removed `proxy'. This directory
|
||||
is considered obsolete and will be removed soon.
|
||||
|
||||
1998-07-06 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* sysdeps/common/mountlist.c: using functions from `xmalloc.c'.
|
||||
|
||||
* sysdeps/common/error.c: all functions now accept NULL as
|
||||
`server' argument.
|
||||
|
||||
* acconfig.h (AFS, MOUNTED_FREAD, MOUNTED_FREAD_FSTYP,
|
||||
MOUNTED_GETFSSTAT, MOUNTED_GETMNT, MOUNTED_GETMNTENT1,
|
||||
MOUNTED_GETMNTENT2, MOUNTED_GETMNTINFO, MOUNTED_LISTMNTENT,
|
||||
MOUNTED_VMOUNT, STAT_STATFS3_OSF1, STAT_READ_FILSYS,
|
||||
STAT_STATFS2_BSIZE, STAT_STATFS2_FSIZE, STAT_STATFS2_FS_DATA,
|
||||
STAT_STATFS4, STAT_STATVFS, STATFS_TRUNCATES_BLOCK_COUNTS):
|
||||
New macros.
|
||||
|
||||
* configure.in: added GNOME_FILEUTILS_CHECKS.
|
||||
|
||||
* sysdeps/common/{fsusage, mountlist}.[ch]:
|
||||
Imported from GNU Fileutils 3.16.
|
||||
|
||||
* sysdeps/common/mountlist.c: using g_malloc, g_realloc and g_strdup.
|
||||
|
||||
1998-07-03 Martin baulig <martin@home-of-linux.org>
|
||||
|
||||
* macros/gnome-libgtop-sysdeps.m4: No longer use
|
||||
`glibtop_machine.h' for Linux.
|
||||
|
||||
* sysdeps/linux/glibtop_machine.h: Removed.
|
||||
|
||||
* sysdeps/guile/guile.awk: Using `scm_append'
|
||||
instead of `gh_append'.
|
||||
|
||||
* sysdeps/guile/names/guile-names.awk: dito.
|
||||
|
||||
* sysdeps/linux/*.c: Using code from stable branch again.
|
||||
|
||||
* include/glibtop/parameter.h: New file.
|
||||
|
||||
* lib/parameter.c: New file.
|
||||
|
||||
* lib/{open, init}.c: Done some more work on server
|
||||
initialization
|
||||
|
||||
1998-06-21 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* perl/*: Added perl interface.
|
||||
|
||||
* sysdeps/linux/cpu.c: Bug fix.
|
||||
|
||||
* include/glibtop/global.h: Only including guile header files
|
||||
within libgtop.
|
||||
|
||||
* configure.in (LIGBTOP_LIBS): Added `-lgtop'.
|
||||
|
||||
* Makefile.am: Creating `perl/Makefile.PL' from `perl/Makefile.PL.in'
|
||||
and `perl/Libgtop.xs' using `perl/perl.awk'.
|
||||
|
||||
1998-06-18 Martin Baulig <baulig@taurus.uni-trier.de>
|
||||
|
||||
* sysdeps/linux/*.c: Reverted some stuff from 06-07-1998
|
||||
since it was too buggy.
|
||||
|
||||
* glibtop.h (_glibtop): New field `server_port'.
|
||||
|
||||
* lib/xmalloc.c (glibtop_strdup_r): New function.
|
||||
|
||||
* lib/gnuclient.c: Removed.
|
||||
|
||||
* lib/{command, write, read}.c: Changed client <-> server
|
||||
interface to make less system calls.
|
||||
|
||||
* src/daemon/main.c: Changed server side of interface.
|
||||
|
||||
* include/glibtop/command.h (struct _glibtop_response): New
|
||||
structure to return data from the server to the client.
|
||||
|
||||
1998-06-14 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* glibtop.h (struct _glibtop): Added `socket' field.
|
||||
|
||||
* include/glibtop/gnuserv.h: New file. Imported from xemacs 20.3.
|
||||
|
||||
* sysdeps/common/gnuslib.c: New file. Imported from xemacs 20.3
|
||||
|
||||
* lib/gnuclient.c: New file. Imported from xemacs 20.3
|
||||
|
||||
* sysdeps/daemon/gnuserv.c: New file. Imported from xemacs 20.3
|
||||
|
||||
* sysdeps/daemon: New directory.
|
||||
|
||||
* configure.in (LIBGTOP_LIBS, LIBGTOP_GUILE_LIBS): Added
|
||||
`$X_LIBS -lXau' when we have xauth.
|
||||
|
||||
* acconfig.h (HAVE_XAUTH): New tag.
|
||||
|
||||
* configure.in: Added check for `HAVE_XAUTH'.
|
||||
|
27
Makefile.am
27
Makefile.am
@@ -22,6 +22,9 @@ release:
|
||||
confexecdir=$(libdir)
|
||||
confexec_DATA = $(top_builddir)/libgtopConf.sh
|
||||
|
||||
noinst_DATA = $(top_builddir)/perl/Makefile.PL \
|
||||
$(top_builddir)/perl/Libgtop.xs
|
||||
|
||||
## to automatically rebuild aclocal.m4 if any of the macros in
|
||||
## `macros/' change
|
||||
@MAINT@include macros/macros.dep
|
||||
@@ -51,3 +54,27 @@ libgtopConf.sh: libgtopConf.sh.in Makefile
|
||||
-e 's,\@libgtop_want_examples\@,$(libgtop_want_examples),g' \
|
||||
< $(srcdir)/libgtopConf.sh.in > libgtopConf.tmp \
|
||||
&& mv libgtopConf.tmp libgtopConf.sh
|
||||
|
||||
perl/Makefile.PL: perl/Makefile.PL.in Makefile
|
||||
## Use sed and then mv to avoid problems if the user interrupts.
|
||||
sed -e 's,\@LIBGTOP_LIBDIR\@,$(libdir),g' \
|
||||
-e 's,\@LIBGTOP_INCLUDEDIR\@,$(includedir),g' \
|
||||
-e 's,\@LIBGTOP_LIBS\@,$(LIBGTOP_LIBS),g' \
|
||||
-e 's,\@LIBGTOP_INCS\@,$(LIBGTOP_INCS),g' \
|
||||
-e 's,\@LIBGTOP_GUILE_LIBS\@,$(LIBGTOP_GUILE_LIBS),g' \
|
||||
-e 's,\@LIBGTOP_GUILE_INCS\@,$(LIBGTOP_GUILE_INCS),g' \
|
||||
-e 's,\@LIBGTOP_BINDIR\@,$(LIBGTOP_BINDIR),g' \
|
||||
-e 's,\@LIBGTOP_SERVER\@,$(LIBGTOP_SERVER),g' \
|
||||
-e 's,\@libgtop_sysdeps_dir\@,$(libgtop_sysdeps_dir),g' \
|
||||
-e 's,\@libgtop_need_server\@,$(libgtop_need_server),g' \
|
||||
-e 's,\@libgtop_use_machine_h\@,$(libgtop_use_machine_h),g' \
|
||||
-e 's,\@libgtop_guile_found\@,$(libgtop_guile_found),g' \
|
||||
-e 's,\@libgtop_want_names\@,$(libgtop_want_names),g' \
|
||||
-e 's,\@libgtop_want_guile_names\@,$(libgtop_want_guile_names),g' \
|
||||
-e 's,\@libgtop_want_examples\@,$(libgtop_want_examples),g' \
|
||||
< $(srcdir)/perl/Makefile.PL.in > perl/Makefile.tmp \
|
||||
&& mv perl/Makefile.tmp perl/Makefile.PL
|
||||
|
||||
perl/Libgtop.xs: perl/perl.awk $(top_builddir)/config.h $(top_srcdir)/features.def
|
||||
$(AWK) -f $(top_srcdir)/perl/perl.awk < $(top_srcdir)/features.def > perl/lgt-t
|
||||
mv perl/lgt-t perl/Libgtop.xs
|
||||
|
79
acconfig.h
79
acconfig.h
@@ -12,6 +12,85 @@
|
||||
|
||||
/* Do not remove this comments and the empty lines; they are needed */
|
||||
#undef HAVE_PROGRAM_INVOCATION_SHORT_NAME
|
||||
/* Define if you have the Andrew File System. */
|
||||
#undef AFS
|
||||
|
||||
/* Define one of the following to indicate how a program can
|
||||
get a list of mounted filesystems. */
|
||||
|
||||
/* Define if there is no specific function for reading the list of
|
||||
mounted filesystems. fread will be used to read /etc/mnttab. [SVR2] */
|
||||
#undef MOUNTED_FREAD
|
||||
|
||||
/* Define if (like SVR2) there is no specific function for reading the
|
||||
list of mounted filesystems, and your system has these header files:
|
||||
<sys/fstyp.h> and <sys/statfs.h>. [SVR3] */
|
||||
#undef MOUNTED_FREAD_FSTYP
|
||||
|
||||
/* Define if there is a function named getfsstat for reading the list
|
||||
of mounted filesystems. [DEC Alpha running OSF/1] */
|
||||
#undef MOUNTED_GETFSSTAT
|
||||
|
||||
/* Define if there is a function named getmnt for reading the list of
|
||||
mounted filesystems. [Ultrix] */
|
||||
#undef MOUNTED_GETMNT
|
||||
|
||||
/* Define if there is a function named getmntent for reading the list
|
||||
of mounted filesystems, and that function takes a single argument.
|
||||
[4.3BSD, SunOS, HP-UX, Dynix, Irix] */
|
||||
#undef MOUNTED_GETMNTENT1
|
||||
|
||||
/* Define if there is a function named getmntent for reading the list of
|
||||
mounted filesystems, and that function takes two arguments. [SVR4] */
|
||||
#undef MOUNTED_GETMNTENT2
|
||||
|
||||
/* Define if there is a function named getmntinfo for reading the list
|
||||
of mounted filesystems. [4.4BSD] */
|
||||
#undef MOUNTED_GETMNTINFO
|
||||
|
||||
/* Define if there is a function named listmntent that can be used to
|
||||
list all mounted filesystems. [UNICOS] */
|
||||
#undef MOUNTED_LISTMNTENT
|
||||
|
||||
/* Define if there is a function named mntctl that can be used to read
|
||||
the list of mounted filesystems, and there is a system header file
|
||||
that declares `struct vmount.' [AIX] */
|
||||
#undef MOUNTED_VMOUNT
|
||||
|
||||
/* Define one of the following to indicate how a program can obtain
|
||||
filesystems usage information. */
|
||||
|
||||
/* Define if statfs takes 3 args. [DEC Alpha running OSF/1] */
|
||||
#undef STAT_STATFS3_OSF1
|
||||
|
||||
/* Define if there is no specific function for reading filesystems usage
|
||||
information and you have the <sys/filsys.h> header file. [SVR2] */
|
||||
#undef STAT_READ_FILSYS
|
||||
|
||||
/* Define if statfs takes 2 args and struct statfs has a field named f_bsize.
|
||||
[4.3BSD, SunOS 4, HP-UX, AIX PS/2] */
|
||||
#undef STAT_STATFS2_BSIZE
|
||||
|
||||
/* Define if statfs takes 2 args and struct statfs has a field named f_fsize.
|
||||
[4.4BSD, NetBSD] */
|
||||
#undef STAT_STATFS2_FSIZE
|
||||
|
||||
/* Define if statfs takes 2 args and the second argument has
|
||||
type struct fs_data. [Ultrix] */
|
||||
#undef STAT_STATFS2_FS_DATA
|
||||
|
||||
/* Define if statfs takes 4 args. [SVR3, Dynix, Irix, Dolphin] */
|
||||
#undef STAT_STATFS4
|
||||
|
||||
/* Define if there is a function named statvfs. [SVR4] */
|
||||
#undef STAT_STATVFS
|
||||
|
||||
/* Define if the block counts reported by statfs may be truncated to 2GB
|
||||
and the correct values may be stored in the f_spare array.
|
||||
[SunOS 4.1.2, 4.1.3, and 4.1.3_U1 are reported to have this problem.
|
||||
SunOS 4.1.1 seems not to be affected.] */
|
||||
#undef STATFS_TRUNCATES_BLOCK_COUNTS
|
||||
|
||||
|
||||
/* to fix a bug in autoheader on DEC OSF1. */
|
||||
#undef HAVE_PROGRAM_INVOCATION_NAME
|
||||
|
20
configure.in
20
configure.in
@@ -6,6 +6,8 @@ AC_INIT(copyright.txt)
|
||||
AM_CONFIG_HEADER(config.h)
|
||||
AC_CANONICAL_SYSTEM
|
||||
|
||||
AM_INIT_AUTOMAKE(libgtop, 0.01)
|
||||
|
||||
AM_ACLOCAL_INCLUDE(macros)
|
||||
|
||||
AC_ISC_POSIX
|
||||
@@ -13,7 +15,10 @@ AC_PROG_CC
|
||||
AC_STDC_HEADERS
|
||||
AC_ARG_PROGRAM
|
||||
|
||||
AC_PROG_AWK
|
||||
dnl We don't use `AC_PROG_AWK' since it checks for mawk first which
|
||||
dnl does not work for libgtop.
|
||||
AC_CHECK_PROGS(AWK, gawk awk, )
|
||||
test -z "$AWK" && AC_MSG_ERROR([Sorry, you need a working awk interpreter.])
|
||||
|
||||
AC_CHECK_TOOL(CC,gcc)
|
||||
AC_CHECK_TOOL(RANLIB,ranlib)
|
||||
@@ -32,8 +37,6 @@ export cross_compiling
|
||||
|
||||
AM_PROG_LIBTOOL
|
||||
|
||||
AM_INIT_AUTOMAKE(libgtop, 0.01)
|
||||
|
||||
dnl If you want to use libgtop without gnome, comment the following line out.
|
||||
GNOME_INIT_HOOK(gnome_found=yes)
|
||||
|
||||
@@ -121,10 +124,12 @@ test -z "$with_xauth" && { AC_CHECK_LIB(Xau, XauGetAuthByAddr,[:],with_xauth=no,
|
||||
test -z "$with_xauth" && with_xauth=yes
|
||||
if test "$with_xauth" = "yes"; then
|
||||
AC_DEFINE(HAVE_XAUTH)
|
||||
XE_SPACE(libs_xauth, $X_EXTRA_LIBS -lXau $libs_x $X_PRE_LIBS)
|
||||
XE_SPACE(libs_xauth, $X_LIBS -lXau)
|
||||
fi
|
||||
AC_SUBST(libs_xauth)
|
||||
|
||||
dnl For diskusage stuff
|
||||
GNOME_FILEUTILS_CHECKS
|
||||
|
||||
CFLAGS="$CFLAGS -D_IN_LIBGTOP"
|
||||
|
||||
@@ -154,7 +159,7 @@ AC_SUBST(LIBSUPPORT)
|
||||
AC_SUBST(SUPPORTINCS)
|
||||
|
||||
dnl These definitions are expanded in make.
|
||||
LIBGTOP_LIBS='-L$(libdir)'
|
||||
LIBGTOP_LIBS='-L$(libdir) -lgtop'
|
||||
LIBGTOP_INCS='-I$(includedir)'
|
||||
LIBGTOP_GUILE_LIBS="$LIBGTOP_LIBS"
|
||||
LIBGTOP_GUILE_INCS="$LIBGTOP_INCS"
|
||||
@@ -186,8 +191,8 @@ fi
|
||||
|
||||
AC_SUBST(libgtop_want_guile_names)
|
||||
|
||||
LIBGTOP_LIBS="$LIBGTOP_LIBS -lgtop_common"
|
||||
LIBGTOP_GUILE_LIBS="$LIBGTOP_GUILE_LIBS -lgtop_common"
|
||||
LIBGTOP_LIBS="$LIBGTOP_LIBS -lgtop_common $libs_xauth"
|
||||
LIBGTOP_GUILE_LIBS="$LIBGTOP_GUILE_LIBS -lgtop_common $libs_xauth"
|
||||
|
||||
if test "x$need_server" = "xyes" ; then
|
||||
LIBGTOP_LIBS="$LIBGTOP_LIBS -lgtop"
|
||||
@@ -248,5 +253,6 @@ src/proxy/Makefile
|
||||
src/daemon/Makefile
|
||||
lib/Makefile
|
||||
examples/Makefile
|
||||
perl/Makefile.PL
|
||||
support/Makefile
|
||||
macros/Makefile],[sed -e "/POTFILES =/r po/POTFILES" po/Makefile.in > po/Makefile])
|
||||
|
@@ -16,20 +16,20 @@ bin_PROGRAMS = first first_static second second_static \
|
||||
EXTRA_PROGRAMS = third third_static
|
||||
|
||||
first_SOURCES = first.c
|
||||
first_LDADD = $(top_builddir)/sysdeps/common/libgtop_common.la \
|
||||
$(top_builddir)/lib/libgtop.la \
|
||||
first_LDADD = $(top_builddir)/lib/libgtop.la \
|
||||
$(top_builddir)/sysdeps/common/libgtop_common.la \
|
||||
$(top_builddir)/sysdeps/@sysdeps_dir@/libgtop_sysdeps.la \
|
||||
@INTLLIBS@ @LIBSUPPORT@
|
||||
@INTLLIBS@ @LIBSUPPORT@ @libs_xauth@
|
||||
|
||||
first_static_SOURCES = $(first_SOURCES)
|
||||
first_static_LDADD = $(first_LDADD)
|
||||
first_static_LDFLAGS = -static
|
||||
|
||||
second_SOURCES = second.c
|
||||
second_LDADD = $(top_builddir)/sysdeps/common/libgtop_common.la \
|
||||
$(top_builddir)/lib/libgtop.la \
|
||||
second_LDADD = $(top_builddir)/lib/libgtop.la \
|
||||
$(top_builddir)/sysdeps/common/libgtop_common.la \
|
||||
$(top_builddir)/sysdeps/@sysdeps_dir@/libgtop_sysdeps.la \
|
||||
@INTLLIBS@ @LIBSUPPORT@
|
||||
@INTLLIBS@ @LIBSUPPORT@ @libs_xauth@
|
||||
|
||||
second_static_SOURCES = $(second_SOURCES)
|
||||
second_static_LDADD = $(second_LDADD)
|
||||
@@ -46,7 +46,7 @@ third_LDADD = $(top_builddir)/sysdeps/guile/libgtop_guile.la \
|
||||
$(top_builddir)/lib/libgtop.la \
|
||||
$(top_builddir)/sysdeps/common/libgtop_common.la \
|
||||
$(top_builddir)/sysdeps/@sysdeps_dir@/libgtop_sysdeps.la \
|
||||
@GUILE_LIBS@ @INTLLIBS@ @LIBSUPPORT@
|
||||
@GUILE_LIBS@ @INTLLIBS@ @LIBSUPPORT@ @libs_xauth@
|
||||
|
||||
third_static_SOURCES = $(third_SOURCES)
|
||||
third_static_LDADD = $(third_LDADD)
|
||||
|
161
examples/first.c
161
examples/first.c
@@ -26,6 +26,8 @@
|
||||
#include <glibtop/close.h>
|
||||
#include <glibtop/xmalloc.h>
|
||||
|
||||
#include <glibtop/parameter.h>
|
||||
|
||||
#include <glibtop/union.h>
|
||||
#include <glibtop/sysdeps.h>
|
||||
|
||||
@@ -38,7 +40,8 @@ main (int argc, char *argv [])
|
||||
{
|
||||
glibtop_union data;
|
||||
glibtop_sysdeps sysdeps;
|
||||
unsigned c, count, i, *ptr;
|
||||
unsigned c, method, count, port, i, *ptr;
|
||||
char buffer [BUFSIZ];
|
||||
pid_t pid, ppid;
|
||||
|
||||
count = PROFILE_COUNT;
|
||||
@@ -47,63 +50,79 @@ main (int argc, char *argv [])
|
||||
bindtextdomain (PACKAGE, GTOPLOCALEDIR);
|
||||
textdomain (PACKAGE);
|
||||
|
||||
glibtop_init ();
|
||||
glibtop_init_r (&glibtop_global_server, 0, GLIBTOP_INIT_NO_OPEN);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
glibtop_get_parameter (GLIBTOP_PARAM_METHOD, &method, sizeof (method));
|
||||
|
||||
printf ("Method = %d\n", method);
|
||||
|
||||
count = glibtop_get_parameter (GLIBTOP_PARAM_COMMAND, buffer, BUFSIZ);
|
||||
buffer [count] = 0;
|
||||
|
||||
printf ("Command = '%s'\n", buffer);
|
||||
|
||||
count = glibtop_get_parameter (GLIBTOP_PARAM_HOST, buffer, BUFSIZ);
|
||||
buffer [count] = 0;
|
||||
|
||||
glibtop_get_parameter (GLIBTOP_PARAM_PORT, &port, sizeof (port));
|
||||
|
||||
printf ("Host = '%s' - %u\n\n", buffer, port);
|
||||
|
||||
for (c = 0; c < PROFILE_COUNT; c++)
|
||||
glibtop_get_cpu (&data.cpu);
|
||||
|
||||
fprintf (stderr, "CPU (0x%08lx): %lu, %lu, %lu, %lu, %lu, %lu\n",
|
||||
printf ("CPU (0x%08lx): %lu, %lu, %lu, %lu, %lu, %lu\n",
|
||||
data.cpu.flags, data.cpu.total, data.cpu.user, data.cpu.nice,
|
||||
data.cpu.sys, data.cpu.idle, data.cpu.frequency);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
for (c = 0; c < PROFILE_COUNT; c++)
|
||||
glibtop_get_mem (&data.mem);
|
||||
|
||||
fprintf (stderr, "Memory (0x%08lx): %lu, %lu, %lu, %lu, %lu, %lu, %lu, %lu\n",
|
||||
printf ("Memory (0x%08lx): %lu, %lu, %lu, %lu, %lu, %lu, %lu, %lu\n",
|
||||
data.mem.flags, data.mem.total, data.mem.used, data.mem.free,
|
||||
data.mem.shared, data.mem.buffer, data.mem.cached,
|
||||
data.mem.user, data.mem.locked);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
for (c = 0; c < PROFILE_COUNT; c++)
|
||||
glibtop_get_swap (&data.swap);
|
||||
|
||||
fprintf (stderr, "Swap (0x%08lx): %lu, %lu, %lu\n", data.swap.flags,
|
||||
printf ("Swap (0x%08lx): %lu, %lu, %lu\n", data.swap.flags,
|
||||
data.swap.total, data.swap.used, data.swap.free);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
for (c = 0; c < PROFILE_COUNT; c++)
|
||||
glibtop_get_uptime (&data.uptime);
|
||||
|
||||
fprintf (stderr, "Uptime (0x%08lx): %f, %f\n", data.uptime.flags,
|
||||
printf ("Uptime (0x%08lx): %f, %f\n", data.uptime.flags,
|
||||
data.uptime.uptime, data.uptime.idletime);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
for (c = 0; c < PROFILE_COUNT; c++)
|
||||
glibtop_get_loadavg (&data.loadavg);
|
||||
|
||||
fprintf (stderr, "Loadavg (0x%08lx): %f, %f, %f\n", data.loadavg.flags,
|
||||
printf ("Loadavg (0x%08lx): %f, %f, %f\n", data.loadavg.flags,
|
||||
data.loadavg.loadavg [0], data.loadavg.loadavg [1],
|
||||
data.loadavg.loadavg [2]);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
for (c = 0; c < PROFILE_COUNT; c++)
|
||||
glibtop_get_shm_limits (&data.shm_limits);
|
||||
|
||||
fprintf (stderr, "Shm Limits (0x%08lx): %ld, %ld, %ld, %ld, %ld\n",
|
||||
printf ("Shm Limits (0x%08lx): %ld, %ld, %ld, %ld, %ld\n",
|
||||
data.shm_limits.flags, data.shm_limits.shmmax,
|
||||
data.shm_limits.shmmin, data.shm_limits.shmmni,
|
||||
data.shm_limits.shmseg, data.shm_limits.shmall);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
for (c = 0; c < PROFILE_COUNT; c++)
|
||||
glibtop_get_msg_limits (&data.msg_limits);
|
||||
|
||||
fprintf (stderr, "Msg Limits (0x%08lx): %ld, %ld, %ld, %ld, %ld, %ld, %ld\n",
|
||||
printf ("Msg Limits (0x%08lx): %ld, %ld, %ld, %ld, %ld, %ld, %ld\n",
|
||||
data.msg_limits.flags, data.msg_limits.msgpool,
|
||||
data.msg_limits.msgmap, data.msg_limits.msgmax,
|
||||
data.msg_limits.msgmnb, data.msg_limits.msgmni,
|
||||
data.msg_limits.msgssz, data.msg_limits.msgtql);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
for (c = 0; c < PROFILE_COUNT; c++)
|
||||
glibtop_get_sem_limits (&data.sem_limits);
|
||||
|
||||
fprintf (stderr, "Sem Limits (0x%08lx): "
|
||||
printf ("Sem Limits (0x%08lx): "
|
||||
"%ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld\n",
|
||||
data.sem_limits.flags, data.sem_limits.semmap,
|
||||
data.sem_limits.semmni, data.sem_limits.semmns,
|
||||
@@ -112,11 +131,11 @@ main (int argc, char *argv [])
|
||||
data.sem_limits.semusz, data.sem_limits.semvmx,
|
||||
data.sem_limits.semaem);
|
||||
|
||||
fprintf (stderr, "\n");
|
||||
printf ("\n");
|
||||
|
||||
glibtop_get_sysdeps (&sysdeps);
|
||||
|
||||
fprintf (stderr, "Sysdeps (0x%08lx): %lu, %lu, %lu, %lu, %lu, "
|
||||
printf ("Sysdeps (0x%08lx): %lu, %lu, %lu, %lu, %lu, "
|
||||
"%lu, %lu, %lu, %lu, %lu, %lu, %lu, %lu, %lu, %lu, %lu\n",
|
||||
sysdeps.flags, sysdeps.cpu, sysdeps.mem, sysdeps.swap,
|
||||
sysdeps.uptime, sysdeps.loadavg, sysdeps.shm_limits,
|
||||
@@ -126,19 +145,19 @@ main (int argc, char *argv [])
|
||||
sysdeps.proc_time, sysdeps.proc_signal,
|
||||
sysdeps.proc_kernel, sysdeps.proc_segment);
|
||||
|
||||
fprintf (stderr, "\n");
|
||||
printf ("\n");
|
||||
|
||||
ptr = glibtop_get_proclist (&data.proclist);
|
||||
|
||||
fprintf (stderr, "Proclist (0x%08lx): %ld, %ld, %ld\n",
|
||||
printf ("Proclist (0x%08lx): %ld, %ld, %ld\n",
|
||||
data.proclist.flags, data.proclist.number,
|
||||
data.proclist.size, data.proclist.total);
|
||||
|
||||
if (ptr) {
|
||||
fprintf (stderr, "\nProcess: ");
|
||||
printf ("\nProcess: ");
|
||||
for (i = 0; i < data.proclist.number; i++)
|
||||
fprintf (stderr, "%s%u", i ? ", " : "", ptr [i]);
|
||||
fprintf (stderr, "\n");
|
||||
printf ("%s%u", i ? ", " : "", ptr [i]);
|
||||
printf ("\n");
|
||||
}
|
||||
|
||||
glibtop_free (ptr);
|
||||
@@ -146,20 +165,20 @@ main (int argc, char *argv [])
|
||||
pid = getpid ();
|
||||
ppid = getppid ();
|
||||
|
||||
fprintf (stderr, "\n");
|
||||
printf ("\n");
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
for (c = 0; c < PROFILE_COUNT; c++)
|
||||
glibtop_get_proc_state (&data.proc_state, pid);
|
||||
|
||||
fprintf (stderr, "Proc_State PID %5u (0x%08lx): '%s', %c, %u, %u\n",
|
||||
printf ("Proc_State PID %5u (0x%08lx): '%s', %c, %u, %u\n",
|
||||
pid, data.proc_state.flags, data.proc_state.cmd,
|
||||
data.proc_state.state, data.proc_state.uid,
|
||||
data.proc_state.gid);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
for (c = 0; c < PROFILE_COUNT; c++)
|
||||
glibtop_get_proc_uid (&data.proc_uid, pid);
|
||||
|
||||
fprintf (stderr, "Proc_Uid PID %5u (0x%08lx): "
|
||||
printf ("Proc_Uid PID %5u (0x%08lx): "
|
||||
"%d %d %d %d %d %d %d %d %d %d %d %d\n",
|
||||
pid, data.proc_uid.flags, data.proc_uid.uid,
|
||||
data.proc_uid.euid, data.proc_uid.gid,
|
||||
@@ -169,37 +188,37 @@ main (int argc, char *argv [])
|
||||
data.proc_uid.tpgid, data.proc_uid.priority,
|
||||
data.proc_uid.nice);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
for (c = 0; c < PROFILE_COUNT; c++)
|
||||
glibtop_get_proc_mem (&data.proc_mem, pid);
|
||||
|
||||
fprintf (stderr, "Proc_Mem PID %5u (0x%08lx): "
|
||||
printf ("Proc_Mem PID %5u (0x%08lx): "
|
||||
"%ld %ld %ld %ld %ld %ld\n", pid, data.proc_mem.flags,
|
||||
data.proc_mem.size, data.proc_mem.vsize,
|
||||
data.proc_mem.resident, data.proc_mem.share,
|
||||
data.proc_mem.rss, data.proc_mem.rss_rlim);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
for (c = 0; c < PROFILE_COUNT; c++)
|
||||
glibtop_get_proc_time (&data.proc_time, pid);
|
||||
|
||||
fprintf (stderr, "Proc_Time PID %5u (0x%08lx): "
|
||||
printf ("Proc_Time PID %5u (0x%08lx): "
|
||||
"%ld %ld %ld %ld %ld %ld %ld\n", pid, data.proc_time.flags,
|
||||
data.proc_time.start_time, data.proc_time.utime,
|
||||
data.proc_time.stime, data.proc_time.cutime,
|
||||
data.proc_time.cstime, data.proc_time.timeout,
|
||||
data.proc_time.it_real_value);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
for (c = 0; c < PROFILE_COUNT; c++)
|
||||
glibtop_get_proc_signal (&data.proc_signal, pid);
|
||||
|
||||
fprintf (stderr, "Proc_Signal PID %5u (0x%08lx): "
|
||||
printf ("Proc_Signal PID %5u (0x%08lx): "
|
||||
"%d %d %d %d\n", pid, data.proc_signal.flags,
|
||||
data.proc_signal.signal, data.proc_signal.blocked,
|
||||
data.proc_signal.sigignore, data.proc_signal.sigcatch);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
for (c = 0; c < PROFILE_COUNT; c++)
|
||||
glibtop_get_proc_kernel (&data.proc_kernel, pid);
|
||||
|
||||
fprintf (stderr, "Proc_Kernel PID %5u (0x%08lx): "
|
||||
printf ("Proc_Kernel PID %5u (0x%08lx): "
|
||||
"%lu %lu %lu %lu %lu %lu %lu %lu\n", pid,
|
||||
data.proc_kernel.flags, data.proc_kernel.k_flags,
|
||||
data.proc_kernel.min_flt, data.proc_kernel.maj_flt,
|
||||
@@ -207,30 +226,30 @@ main (int argc, char *argv [])
|
||||
data.proc_kernel.kstk_esp, data.proc_kernel.kstk_eip,
|
||||
data.proc_kernel.wchan);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
for (c = 0; c < PROFILE_COUNT; c++)
|
||||
glibtop_get_proc_segment (&data.proc_segment, pid);
|
||||
|
||||
fprintf (stderr, "Proc_Segment PID %5u (0x%08lx): "
|
||||
printf ("Proc_Segment PID %5u (0x%08lx): "
|
||||
"%ld %ld %ld %ld %lu %lu %lu\n", pid, data.proc_segment.flags,
|
||||
data.proc_segment.trs, data.proc_segment.lrs,
|
||||
data.proc_segment.drs, data.proc_segment.dt,
|
||||
data.proc_segment.start_code, data.proc_segment.end_code,
|
||||
data.proc_segment.start_stack);
|
||||
|
||||
fprintf (stderr, "\n");
|
||||
printf ("\n");
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
for (c = 0; c < PROFILE_COUNT; c++)
|
||||
glibtop_get_proc_state (&data.proc_state, ppid);
|
||||
|
||||
fprintf (stderr, "Proc_State PPID %5u (0x%08lx): '%s', %c, %u, %u\n",
|
||||
printf ("Proc_State PPID %5u (0x%08lx): '%s', %c, %u, %u\n",
|
||||
ppid, data.proc_state.flags, data.proc_state.cmd,
|
||||
data.proc_state.state, data.proc_state.uid,
|
||||
data.proc_state.gid);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
for (c = 0; c < PROFILE_COUNT; c++)
|
||||
glibtop_get_proc_uid (&data.proc_uid, ppid);
|
||||
|
||||
fprintf (stderr, "Proc_Uid PPID %5u (0x%08lx): "
|
||||
printf ("Proc_Uid PPID %5u (0x%08lx): "
|
||||
"%d %d %d %d %d %d %d %d %d %d %d %d\n",
|
||||
ppid, data.proc_uid.flags, data.proc_uid.uid,
|
||||
data.proc_uid.euid, data.proc_uid.gid,
|
||||
@@ -240,37 +259,37 @@ main (int argc, char *argv [])
|
||||
data.proc_uid.tpgid, data.proc_uid.priority,
|
||||
data.proc_uid.nice);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
for (c = 0; c < PROFILE_COUNT; c++)
|
||||
glibtop_get_proc_mem (&data.proc_mem, ppid);
|
||||
|
||||
fprintf (stderr, "Proc_Mem PPID %5u (0x%08lx): "
|
||||
printf ("Proc_Mem PPID %5u (0x%08lx): "
|
||||
"%ld %ld %ld %ld %ld %ld\n", ppid, data.proc_mem.flags,
|
||||
data.proc_mem.size, data.proc_mem.vsize,
|
||||
data.proc_mem.resident, data.proc_mem.share,
|
||||
data.proc_mem.rss, data.proc_mem.rss_rlim);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
for (c = 0; c < PROFILE_COUNT; c++)
|
||||
glibtop_get_proc_time (&data.proc_time, ppid);
|
||||
|
||||
fprintf (stderr, "Proc_Time PPID %5u (0x%08lx): "
|
||||
printf ("Proc_Time PPID %5u (0x%08lx): "
|
||||
"%ld %ld %ld %ld %ld %ld %ld\n", ppid, data.proc_time.flags,
|
||||
data.proc_time.start_time, data.proc_time.utime,
|
||||
data.proc_time.stime, data.proc_time.cutime,
|
||||
data.proc_time.cstime, data.proc_time.timeout,
|
||||
data.proc_time.it_real_value);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
for (c = 0; c < PROFILE_COUNT; c++)
|
||||
glibtop_get_proc_signal (&data.proc_signal, ppid);
|
||||
|
||||
fprintf (stderr, "Proc_Signal PPID %5u (0x%08lx): "
|
||||
printf ("Proc_Signal PPID %5u (0x%08lx): "
|
||||
"%d %d %d %d\n", ppid, data.proc_signal.flags,
|
||||
data.proc_signal.signal, data.proc_signal.blocked,
|
||||
data.proc_signal.sigignore, data.proc_signal.sigcatch);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
for (c = 0; c < PROFILE_COUNT; c++)
|
||||
glibtop_get_proc_kernel (&data.proc_kernel, ppid);
|
||||
|
||||
fprintf (stderr, "Proc_Kernel PPID %5u (0x%08lx): "
|
||||
printf ("Proc_Kernel PPID %5u (0x%08lx): "
|
||||
"%lu %lu %lu %lu %lu %lu %lu %lu\n", ppid,
|
||||
data.proc_kernel.flags, data.proc_kernel.k_flags,
|
||||
data.proc_kernel.min_flt, data.proc_kernel.maj_flt,
|
||||
@@ -278,30 +297,30 @@ main (int argc, char *argv [])
|
||||
data.proc_kernel.kstk_esp, data.proc_kernel.kstk_eip,
|
||||
data.proc_kernel.wchan);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
for (c = 0; c < PROFILE_COUNT; c++)
|
||||
glibtop_get_proc_segment (&data.proc_segment, ppid);
|
||||
|
||||
fprintf (stderr, "Proc_Segment PPID %5u (0x%08lx): "
|
||||
printf ("Proc_Segment PPID %5u (0x%08lx): "
|
||||
"%ld %ld %ld %ld %lu %lu %lu\n", ppid, data.proc_segment.flags,
|
||||
data.proc_segment.trs, data.proc_segment.lrs,
|
||||
data.proc_segment.drs, data.proc_segment.dt,
|
||||
data.proc_segment.start_code, data.proc_segment.end_code,
|
||||
data.proc_segment.start_stack);
|
||||
|
||||
fprintf (stderr, "\n");
|
||||
printf ("\n");
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
for (c = 0; c < PROFILE_COUNT; c++)
|
||||
glibtop_get_proc_state (&data.proc_state, 1);
|
||||
|
||||
fprintf (stderr, "Proc_State INIT %5u (0x%08lx): '%s', %c, %u, %u\n",
|
||||
printf ("Proc_State INIT %5u (0x%08lx): '%s', %c, %u, %u\n",
|
||||
1, data.proc_state.flags, data.proc_state.cmd,
|
||||
data.proc_state.state, data.proc_state.uid,
|
||||
data.proc_state.gid);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
for (c = 0; c < PROFILE_COUNT; c++)
|
||||
glibtop_get_proc_uid (&data.proc_uid, 1);
|
||||
|
||||
fprintf (stderr, "Proc_Uid INIT %5u (0x%08lx): "
|
||||
printf ("Proc_Uid INIT %5u (0x%08lx): "
|
||||
"%d %d %d %d %d %d %d %d %d %d %d %d\n",
|
||||
1, data.proc_uid.flags, data.proc_uid.uid,
|
||||
data.proc_uid.euid, data.proc_uid.gid,
|
||||
@@ -311,37 +330,37 @@ main (int argc, char *argv [])
|
||||
data.proc_uid.tpgid, data.proc_uid.priority,
|
||||
data.proc_uid.nice);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
for (c = 0; c < PROFILE_COUNT; c++)
|
||||
glibtop_get_proc_mem (&data.proc_mem, 1);
|
||||
|
||||
fprintf (stderr, "Proc_Mem INIT %5u (0x%08lx): "
|
||||
printf ("Proc_Mem INIT %5u (0x%08lx): "
|
||||
"%ld %ld %ld %ld %ld %ld\n", 1, data.proc_mem.flags,
|
||||
data.proc_mem.size, data.proc_mem.vsize,
|
||||
data.proc_mem.resident, data.proc_mem.share,
|
||||
data.proc_mem.rss, data.proc_mem.rss_rlim);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
for (c = 0; c < PROFILE_COUNT; c++)
|
||||
glibtop_get_proc_time (&data.proc_time, 1);
|
||||
|
||||
fprintf (stderr, "Proc_Time INIT %5u (0x%08lx): "
|
||||
printf ("Proc_Time INIT %5u (0x%08lx): "
|
||||
"%ld %ld %ld %ld %ld %ld %ld\n", 1, data.proc_time.flags,
|
||||
data.proc_time.start_time, data.proc_time.utime,
|
||||
data.proc_time.stime, data.proc_time.cutime,
|
||||
data.proc_time.cstime, data.proc_time.timeout,
|
||||
data.proc_time.it_real_value);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
for (c = 0; c < PROFILE_COUNT; c++)
|
||||
glibtop_get_proc_signal (&data.proc_signal, 1);
|
||||
|
||||
fprintf (stderr, "Proc_Signal INIT %5u (0x%08lx): "
|
||||
printf ("Proc_Signal INIT %5u (0x%08lx): "
|
||||
"%d %d %d %d\n", 1, data.proc_signal.flags,
|
||||
data.proc_signal.signal, data.proc_signal.blocked,
|
||||
data.proc_signal.sigignore, data.proc_signal.sigcatch);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
for (c = 0; c < PROFILE_COUNT; c++)
|
||||
glibtop_get_proc_kernel (&data.proc_kernel, 1);
|
||||
|
||||
fprintf (stderr, "Proc_Kernel INIT %5u (0x%08lx): "
|
||||
printf ("Proc_Kernel INIT %5u (0x%08lx): "
|
||||
"%lu %lu %lu %lu %lu %lu %lu %lu\n", 1,
|
||||
data.proc_kernel.flags, data.proc_kernel.k_flags,
|
||||
data.proc_kernel.min_flt, data.proc_kernel.maj_flt,
|
||||
@@ -349,15 +368,17 @@ main (int argc, char *argv [])
|
||||
data.proc_kernel.kstk_esp, data.proc_kernel.kstk_eip,
|
||||
data.proc_kernel.wchan);
|
||||
|
||||
for (c = 0; c < count; c++)
|
||||
for (c = 0; c < PROFILE_COUNT; c++)
|
||||
glibtop_get_proc_segment (&data.proc_segment, 1);
|
||||
|
||||
fprintf (stderr, "Proc_Segment INIT %5u (0x%08lx): "
|
||||
printf ("Proc_Segment INIT %5u (0x%08lx): "
|
||||
"%ld %ld %ld %ld %lu %lu %lu\n", 1, data.proc_segment.flags,
|
||||
data.proc_segment.trs, data.proc_segment.lrs,
|
||||
data.proc_segment.drs, data.proc_segment.dt,
|
||||
data.proc_segment.start_code, data.proc_segment.end_code,
|
||||
data.proc_segment.start_stack);
|
||||
|
||||
glibtop_close ();
|
||||
|
||||
exit (0);
|
||||
}
|
||||
|
@@ -35,12 +35,14 @@ typedef struct _glibtop glibtop;
|
||||
|
||||
struct _glibtop
|
||||
{
|
||||
int fd; /* Server file descriptor */
|
||||
unsigned flags;
|
||||
unsigned method; /* Server Method */
|
||||
#ifdef HAVE_GLIBTOP_MACHINE_H
|
||||
glibtop_machine machine; /* Machine dependent data */
|
||||
#endif
|
||||
int input [2]; /* Pipe client <- server */
|
||||
int output [2]; /* Pipe client -> server */
|
||||
int socket; /* Accepted connection of a socket */
|
||||
unsigned long os_version_code; /* Version code of the operating system */
|
||||
const char *name; /* Program name for error messages */
|
||||
const char *server_command; /* Command used to invoke server */
|
||||
@@ -48,6 +50,7 @@ struct _glibtop
|
||||
const char *server_user; /* Name of the user on the target host */
|
||||
const char *server_rsh; /* Command used to connect to the target host */
|
||||
unsigned long features; /* Server is required for this features */
|
||||
unsigned long server_port; /* Port on which daemon is listening */
|
||||
pid_t pid; /* PID of the server */
|
||||
};
|
||||
|
||||
@@ -57,7 +60,7 @@ extern const unsigned long glibtop_server_features;
|
||||
|
||||
#define glibtop_init() glibtop_init_r(&glibtop_global_server, 0, 0);
|
||||
|
||||
#define glibtop_close() glibtop_close_r(&glibtop_global_server);
|
||||
#define glibtop_close() glibtop_close_r(glibtop_global_server);
|
||||
|
||||
extern glibtop *glibtop_init_r __P((glibtop **, const unsigned long, const unsigned));
|
||||
|
||||
|
@@ -5,4 +5,5 @@ glibtop_HEADERS = close.h loadavg.h prockernel.h procstate.h \
|
||||
proctime.h shm_limits.h version.h cpu.h msg_limits.h \
|
||||
procmem.h procuid.h swap.h write.h error.h open.h \
|
||||
procsegment.h read.h sysdeps.h xmalloc.h global.h \
|
||||
output.h procsignal.h read_data.h union.h
|
||||
output.h procsignal.h read_data.h union.h types.h \
|
||||
parameter.h
|
||||
|
@@ -50,13 +50,32 @@ __BEGIN_DECLS
|
||||
|
||||
#define GLIBTOP_MAX_CMND 18
|
||||
|
||||
#define _GLIBTOP_PARAM_SIZE 16
|
||||
|
||||
typedef struct _glibtop_command glibtop_command;
|
||||
|
||||
typedef struct _glibtop_response glibtop_response;
|
||||
typedef union _glibtop_response_union glibtop_response_union;
|
||||
|
||||
struct _glibtop_command
|
||||
{
|
||||
glibtop server;
|
||||
unsigned command;
|
||||
size_t size;
|
||||
size_t size, data_size;
|
||||
char parameter [_GLIBTOP_PARAM_SIZE];
|
||||
};
|
||||
|
||||
union _glibtop_response_union
|
||||
{
|
||||
glibtop_union data;
|
||||
glibtop_sysdeps sysdeps;
|
||||
};
|
||||
|
||||
struct _glibtop_response
|
||||
{
|
||||
off_t offset;
|
||||
size_t size, data_size;
|
||||
glibtop_response_union u;
|
||||
};
|
||||
|
||||
#define glibtop_call(p1, p2, p3, p4) glibtop_call_r(glibtop_global_server, p1, p2, p3, p4)
|
||||
|
@@ -62,6 +62,11 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef WITHOUT_GUILE
|
||||
#undef HAVE_GUILE
|
||||
#undef GLIBTOP_GUILE_NAMES
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_GUILE
|
||||
#include <guile/gh.h>
|
||||
#endif
|
||||
|
@@ -54,10 +54,8 @@ static char header_rcsid [] = "!Header: gnuserv.h,v 2.4 95/02/16 11:58:11 arup a
|
||||
* sockets with sysv ipc
|
||||
*/
|
||||
|
||||
|
||||
#define INTERNET_DOMAIN_SOCKETS
|
||||
#define UNIX_DOMAIN_SOCKETS
|
||||
/* #define SYSV_IPC */
|
||||
|
||||
/*
|
||||
* Define additional authentication protocols to be used. These methods will
|
||||
@@ -77,7 +75,7 @@ static char header_rcsid [] = "!Header: gnuserv.h,v 2.4 95/02/16 11:58:11 arup a
|
||||
* stuff related to supporting MIT-MAGIC-COOKIE-1
|
||||
*/
|
||||
|
||||
#define MCOOKIE_SCREEN "999" /* screen # to use as the gnuserv cookie */
|
||||
#define MCOOKIE_SCREEN "42980" /* screen # to use as the gnuserv cookie */
|
||||
#define MCOOKIE_NAME "MAGIC-1" /* authentication protocol name */
|
||||
#define MCOOKIE_X_NAME "MIT-MAGIC-COOKIE-1" /* as needed by X */
|
||||
|
||||
@@ -91,15 +89,13 @@ static char header_rcsid [] = "!Header: gnuserv.h,v 2.4 95/02/16 11:58:11 arup a
|
||||
* Pick a default communication scheme, if none was specified.
|
||||
*/
|
||||
|
||||
#if !defined(SYSV_IPC) && !defined(UNIX_DOMAIN_SOCKETS) && !defined(INTERNET_DOMAIN_SOCKETS)
|
||||
#if !defined(UNIX_DOMAIN_SOCKETS) && !defined(INTERNET_DOMAIN_SOCKETS)
|
||||
|
||||
#ifdef HAVE_SYSVIPC
|
||||
#define SYSV_IPC /* SYSV systems use SYSV IPC by default */
|
||||
#endif /* HAVE_SYSVIPC */
|
||||
/* BSD systems use Unix Domain sockets by default */
|
||||
|
||||
#ifdef BSD
|
||||
#define UNIX_DOMAIN_SOCKETS /* BSD systems use Unix Domain sockets by default */
|
||||
#endif /* BSD */
|
||||
#define UNIX_DOMAIN_SOCKETS
|
||||
#endif
|
||||
|
||||
#endif /* No communication method pre-defined */
|
||||
|
||||
@@ -111,24 +107,6 @@ static char header_rcsid [] = "!Header: gnuserv.h,v 2.4 95/02/16 11:58:11 arup a
|
||||
* what you want.
|
||||
*/
|
||||
|
||||
# define GSERV_BUFSZ BUFSIZ
|
||||
|
||||
|
||||
#ifdef SYSV_IPC
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/msg.h>
|
||||
|
||||
#define send_string(s,str) \
|
||||
if (strlen(msgp->mtext) + strlen(str) < GSERV_BUFSZ) \
|
||||
strcat(msgp->mtext,str); \
|
||||
else \
|
||||
{ \
|
||||
fprintf(stderr,"%s: not enough message buffer space\n",progname); \
|
||||
exit(1); \
|
||||
} \
|
||||
|
||||
#endif /* SYSV_IPC */
|
||||
|
||||
#if defined(INTERNET_DOMAIN_SOCKETS) || defined(UNIX_DOMAIN_SOCKETS)
|
||||
#include <sys/socket.h>
|
||||
#endif /* INTERNET_DOMAIN_SOCKETS || UNIX_DOMAIN_SOCKETS */
|
||||
@@ -155,10 +133,6 @@ static char header_rcsid [] = "!Header: gnuserv.h,v 2.4 95/02/16 11:58:11 arup a
|
||||
#undef TRUE
|
||||
#define TRUE 1
|
||||
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
extern char *progname;
|
||||
|
||||
/* The casts shut Sun's compiler up and are safe in the context these
|
||||
are actually used. */
|
||||
#define max2(x,y) (((int) (x) > (int) (y)) ? (x) : (y))
|
||||
@@ -177,15 +151,8 @@ extern char *progname;
|
||||
#define CONN_IPC 2
|
||||
|
||||
/* function declarations */
|
||||
int make_connection (char *hostarg, int portarg, int *s);
|
||||
#ifdef SYSV_IPC
|
||||
void disconnect_from_ipc_server();
|
||||
#endif
|
||||
#if defined(INTERNET_DOMAIN_SOCKETS) || defined(UNIX_DOMAIN_SOCKETS)
|
||||
void send_string (int s, const char *msg);
|
||||
void disconnect_from_server (int s, int echo);
|
||||
int read_line (int s, char *dest);
|
||||
#endif
|
||||
extern int glibtop_make_connection __P((const char *, int, int *));
|
||||
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
int internet_addr (char *host);
|
||||
extern long glibtop_internet_addr __P((const char *));
|
||||
#endif
|
||||
|
@@ -26,8 +26,20 @@
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#define _GLIBTOP_INIT_STATE_INIT 0x10000
|
||||
#define _GLIBTOP_INIT_STATE_OPEN 0x20000
|
||||
#define _GLIBTOP_INIT_STATE_SERVER 0x40000
|
||||
|
||||
#define GLIBTOP_INIT_NO_OPEN 1
|
||||
#define GLIBTOP_INIT_NO_INIT 2
|
||||
|
||||
#define GLIBTOP_OPEN_NO_OVERRIDE 1
|
||||
|
||||
#define GLIBTOP_METHOD_DIRECT 1
|
||||
#define GLIBTOP_METHOD_PIPE 2
|
||||
#define GLIBTOP_METHOD_INET 3
|
||||
#define GLIBTOP_METHOD_UNIX 4
|
||||
|
||||
extern void glibtop_open_l __P((glibtop *, const char *, const unsigned long, const unsigned));
|
||||
|
||||
extern void glibtop_open_r __P((glibtop *, const char *, const unsigned long, const unsigned));
|
||||
|
42
include/glibtop/parameter.h
Normal file
42
include/glibtop/parameter.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the Gnome Top Library.
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
The Gnome Top Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The Gnome Top Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#ifndef __GLIBTOP_PARAMETER_H__
|
||||
#define __GLIBTOP_PARAMETER_H__
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/open.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#define GLIBTOP_PARAM_METHOD 1
|
||||
#define GLIBTOP_PARAM_FEATURES 2
|
||||
#define GLIBTOP_PARAM_COMMAND 3
|
||||
#define GLIBTOP_PARAM_HOST 4
|
||||
#define GLIBTOP_PARAM_PORT 5
|
||||
|
||||
#define glibtop_get_parameter(p1,p2,p3) glibtop_get_parameter_l(glibtop_global_server,p1,p2,p3)
|
||||
#define glibtop_set_parameter(p1,p2,p3) glibtop_set_parameter_l(glibtop_global_server,p1,p2,p3)
|
||||
|
||||
extern size_t glibtop_get_parameter_l __P((glibtop *, const unsigned, void *, size_t));
|
||||
extern void glibtop_set_parameter_l __P((glibtop *, const unsigned, const void *, size_t));
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
@@ -30,11 +30,13 @@ __BEGIN_DECLS
|
||||
#define glibtop_malloc(p1) glibtop_malloc_r(glibtop_global_server, p1)
|
||||
#define glibtop_calloc(p1, p2) glibtop_calloc_r(glibtop_global_server, p1, p2)
|
||||
#define glibtop_realloc(p1, p2) glibtop_realloc_r(glibtop_global_server, p1, p2)
|
||||
#define glibtop_strdup(p2) glibtop_strdup_r(glibtop_global_server, p1)
|
||||
#define glibtop_free(p1) glibtop_free_r(glibtop_global_server, p1)
|
||||
|
||||
extern void *glibtop_malloc_r __P((glibtop *, size_t));
|
||||
extern void *glibtop_calloc_r __P((glibtop *, size_t, size_t));
|
||||
extern void *glibtop_realloc_r __P((glibtop *, void *, size_t));
|
||||
extern char *glibtop_strdup_r __P((glibtop *, const char *));
|
||||
extern void glibtop_free_r __P((glibtop *, void *));
|
||||
|
||||
__END_DECLS
|
||||
|
@@ -8,14 +8,16 @@ CFLAGS = -Wall -W @CFLAGS@ -DGTOP_SERVER=\""@LIBGTOP_SERVER@"\"
|
||||
|
||||
lib_LTLIBRARIES = libgtop.la
|
||||
|
||||
libgtop_la_SOURCES = init.c open.c close.c command.c read.c read_data.c write.c lib.c
|
||||
libgtop_la_SOURCES = init.c open.c close.c command.c read.c read_data.c \
|
||||
write.c lib.c parameter.c
|
||||
|
||||
BUILT_SOURCES = lib.c
|
||||
|
||||
lib.c: lib.awk $(top_builddir)/config.h $(top_builddir)/features.def
|
||||
$(AWK) -f $(srcdir)/lib.awk < $(top_builddir)/features.def > lib-t
|
||||
lib.c: lib.awk $(top_builddir)/config.h $(top_srcdir)/features.def
|
||||
$(AWK) -f $(srcdir)/lib.awk < $(top_srcdir)/features.def > lib-t
|
||||
mv lib-t lib.c
|
||||
|
||||
EXTRA_DIST = lib.awk
|
||||
|
||||
CLEANFILES = lib.c
|
||||
|
||||
|
18
lib/close.c
18
lib/close.c
@@ -19,14 +19,30 @@
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/open.h>
|
||||
#include <glibtop/close.h>
|
||||
#include <glibtop/command.h>
|
||||
|
||||
/* Closes pipe to gtop server. */
|
||||
/* Closes server. */
|
||||
|
||||
void
|
||||
glibtop_close_r (glibtop *server)
|
||||
{
|
||||
switch (server->method) {
|
||||
case GLIBTOP_METHOD_UNIX:
|
||||
case GLIBTOP_METHOD_INET:
|
||||
glibtop_call_l (server, GLIBTOP_CMND_QUIT,
|
||||
0, NULL, 0, NULL);
|
||||
|
||||
if (close (server->socket))
|
||||
glibtop_warn_io ("close");
|
||||
|
||||
break;
|
||||
case GLIBTOP_METHOD_PIPE:
|
||||
kill (server->pid, SIGKILL);
|
||||
close (server->input [0]);
|
||||
close (server->output [1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -27,28 +27,51 @@
|
||||
#include <glibtop/xmalloc.h>
|
||||
|
||||
void *
|
||||
glibtop_call_l (glibtop *server, unsigned command, size_t send_size, void *send_buf,
|
||||
size_t recv_size, void *recv_buf)
|
||||
glibtop_call_l (glibtop *server, unsigned command, size_t send_size,
|
||||
void *send_buf, size_t recv_size, void *recv_buf)
|
||||
{
|
||||
glibtop_command *cmnd;
|
||||
void *ptr;
|
||||
glibtop_command cmnd;
|
||||
glibtop_response response;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
cmnd = glibtop_calloc_r (server, 1, sizeof (glibtop_command));
|
||||
memset (&cmnd, 0, sizeof (glibtop_command));
|
||||
|
||||
memcpy (&cmnd->server, server, sizeof (glibtop));
|
||||
memcpy (&cmnd.server, server, sizeof (glibtop));
|
||||
|
||||
cmnd->command = command;
|
||||
cmnd->size = send_size;
|
||||
cmnd.command = command;
|
||||
|
||||
glibtop_write_l (server, sizeof (glibtop_command), cmnd);
|
||||
glibtop_write_l (server, send_size, send_buf);
|
||||
glibtop_read_l (server, recv_size, recv_buf);
|
||||
/* If send_size is less than _GLIBTOP_PARAM_SIZE (normally 16 Bytes), we
|
||||
* send it together with command, so we only need one system call instead
|
||||
* of two. */
|
||||
|
||||
ptr = glibtop_read_data_l (server);
|
||||
if (send_size <= _GLIBTOP_PARAM_SIZE) {
|
||||
memcpy (cmnd.parameter, send_buf, send_size);
|
||||
cmnd.size = send_size;
|
||||
} else {
|
||||
cmnd.data_size = send_size;
|
||||
}
|
||||
|
||||
glibtop_free_r (server, cmnd);
|
||||
glibtop_write_l (server, sizeof (glibtop_command), &cmnd);
|
||||
|
||||
glibtop_read_l (server, sizeof (glibtop_response), &response);
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "RESPONSE: %lu - %d\n",
|
||||
response.offset, response.data_size);
|
||||
#endif
|
||||
|
||||
if (recv_buf)
|
||||
memcpy (recv_buf, ((char *) &response) + response.offset,
|
||||
recv_size);
|
||||
|
||||
if (response.data_size) {
|
||||
void *ptr = glibtop_malloc_r (server, response.data_size);
|
||||
|
||||
glibtop_read_l (server, response.data_size, ptr);
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
620
lib/gnuclient.c
620
lib/gnuclient.c
@@ -1,620 +0,0 @@
|
||||
/* -*-C-*-
|
||||
Client code to allow local and remote editing of files by XEmacs.
|
||||
Copyright (C) 1989 Free Software Foundation, Inc.
|
||||
Copyright (C) 1995 Sun Microsystems, Inc.
|
||||
Copyright (C) 1997 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of XEmacs.
|
||||
|
||||
XEmacs is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2, or (at your option) any
|
||||
later version.
|
||||
|
||||
XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with XEmacs; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
|
||||
Author: Andy Norman (ange@hplb.hpl.hp.com), based on
|
||||
'etc/emacsclient.c' from the GNU Emacs 18.52 distribution.
|
||||
|
||||
Please mail bugs and suggestions to the author at the above address.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file incorporates new features added by Bob Weiner <weiner@mot.com>,
|
||||
* Darrell Kindred <dkindred@cmu.edu> and Arup Mukherjee <arup@cmu.edu>.
|
||||
* GNUATTACH support added by Ben Wing <wing@xemacs.org>.
|
||||
* Please see the note at the end of the README file for details.
|
||||
*
|
||||
* (If gnuserv came bundled with your emacs, the README file is probably
|
||||
* ../etc/gnuserv.README relative to the directory containing this file)
|
||||
*/
|
||||
|
||||
#if 0
|
||||
/* Hand-munged RCS header */
|
||||
static char rcsid [] = "!Header: gnuclient.c,v 2.2 95/12/12 01:39:21 wing nene !";
|
||||
#endif
|
||||
|
||||
#include "gnuserv.h"
|
||||
#include "getopt.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif /* HAVE_STRING_H */
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif /* HAVE_UNISTD_H */
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#if !defined(SYSV_IPC) && !defined(UNIX_DOMAIN_SOCKETS) && \
|
||||
!defined(INTERNET_DOMAIN_SOCKETS)
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
fprintf (stderr, "Sorry, the Emacs server is only "
|
||||
"supported on systems that have\n");
|
||||
fprintf (stderr, "Unix Domain sockets, Internet Domain "
|
||||
"sockets or System V IPC.\n");
|
||||
exit (1);
|
||||
} /* main */
|
||||
#else /* SYSV_IPC || UNIX_DOMAIN_SOCKETS || INTERNET_DOMAIN_SOCKETS */
|
||||
|
||||
static char cwd[MAXPATHLEN+2]; /* current working directory when calculated */
|
||||
static char *cp = NULL; /* ptr into valid bit of cwd above */
|
||||
|
||||
static pid_t emacs_pid; /* Process id for emacs process */
|
||||
|
||||
void initialize_signals (void);
|
||||
|
||||
static void
|
||||
tell_emacs_to_resume (int sig)
|
||||
{
|
||||
char buffer[GSERV_BUFSZ+1];
|
||||
int s; /* socket / msqid to server */
|
||||
int connect_type; /* CONN_UNIX, CONN_INTERNET, or
|
||||
ONN_IPC */
|
||||
|
||||
/* Why is SYSV so retarded? */
|
||||
/* We want emacs to realize that we are resuming */
|
||||
signal(SIGCONT, tell_emacs_to_resume);
|
||||
|
||||
connect_type = make_connection (NULL, (u_short) 0, &s);
|
||||
|
||||
sprintf(buffer,"(gnuserv-eval '(resume-pid-console %d))", (int)getpid());
|
||||
send_string(s, buffer);
|
||||
|
||||
#ifdef SYSV_IPC
|
||||
if (connect_type == (int) CONN_IPC)
|
||||
disconnect_from_ipc_server (s, msgp, FALSE);
|
||||
#else /* !SYSV_IPC */
|
||||
if (connect_type != (int) CONN_IPC)
|
||||
disconnect_from_server (s, FALSE);
|
||||
#endif /* !SYSV_IPC */
|
||||
}
|
||||
|
||||
static void
|
||||
pass_signal_to_emacs (int sig)
|
||||
{
|
||||
if (kill (emacs_pid, sig) == -1)
|
||||
{
|
||||
fprintf (stderr, "gnuattach: Could not pass signal to emacs process\n");
|
||||
exit (1);
|
||||
}
|
||||
initialize_signals ();
|
||||
}
|
||||
|
||||
void
|
||||
initialize_signals ()
|
||||
{
|
||||
/* Set up signal handler to pass relevant signals to emacs process.
|
||||
We used to send SIGSEGV, SIGBUS, SIGPIPE, SIGILL and others to
|
||||
Emacs, but I think it's better not to. I can see no reason why
|
||||
Emacs should SIGSEGV whenever gnuclient SIGSEGV-s, etc. */
|
||||
signal (SIGHUP, pass_signal_to_emacs);
|
||||
signal (SIGQUIT, pass_signal_to_emacs);
|
||||
signal (SIGINT, pass_signal_to_emacs);
|
||||
#ifdef SIGWINCH
|
||||
signal (SIGWINCH, pass_signal_to_emacs);
|
||||
#endif
|
||||
|
||||
/* We want emacs to realize that we are resuming */
|
||||
signal (SIGCONT, tell_emacs_to_resume);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
get_current_working_directory -- return the cwd.
|
||||
*/
|
||||
static char *
|
||||
get_current_working_directory (void)
|
||||
{
|
||||
if (cp == NULL)
|
||||
{ /* haven't calculated it yet */
|
||||
#ifdef BSD
|
||||
if (getwd (cwd) == 0)
|
||||
#else /* !BSD */
|
||||
if (getcwd (cwd,MAXPATHLEN) == NULL)
|
||||
#endif /* !BSD */
|
||||
{
|
||||
perror (progname);
|
||||
fprintf (stderr, "%s: unable to get current working directory\n",
|
||||
progname);
|
||||
exit (1);
|
||||
} /* if */
|
||||
|
||||
/* on some systems, cwd can look like '@machine/' ... */
|
||||
/* ignore everything before the first '/' */
|
||||
for (cp = cwd; *cp && *cp != '/'; ++cp)
|
||||
;
|
||||
|
||||
} /* if */
|
||||
|
||||
return cp;
|
||||
|
||||
} /* get_current_working_directory */
|
||||
|
||||
|
||||
/*
|
||||
filename_expand -- try to convert the given filename into a fully-qualified
|
||||
pathname.
|
||||
*/
|
||||
static void
|
||||
filename_expand (char *fullpath, char *filename)
|
||||
/* fullpath - returned full pathname */
|
||||
/* filename - filename to expand */
|
||||
{
|
||||
int len;
|
||||
|
||||
fullpath[0] = '\0';
|
||||
|
||||
if (filename[0] && filename[0] != '/')
|
||||
{ /* relative filename */
|
||||
strcat (fullpath, get_current_working_directory ());
|
||||
len = strlen (fullpath);
|
||||
|
||||
if (len > 0 && fullpath[len-1] == '/') /* trailing slash already? */
|
||||
; /* yep */
|
||||
else
|
||||
strcat (fullpath, "/"); /* nope, append trailing slash */
|
||||
} /* if */
|
||||
|
||||
strcat (fullpath,filename);
|
||||
|
||||
} /* filename_expand */
|
||||
|
||||
/* Encase the string in quotes, escape all the backslashes and quotes
|
||||
in string. */
|
||||
static char *
|
||||
clean_string (CONST char *s)
|
||||
{
|
||||
int i = 0;
|
||||
char *p, *res;
|
||||
|
||||
for (p = s; *p; p++, i++)
|
||||
{
|
||||
if (*p == '\\' || *p == '\"')
|
||||
++i;
|
||||
else if (*p == '\004')
|
||||
i += 3;
|
||||
}
|
||||
p = res = (char *)malloc (i + 2 + 1);
|
||||
*p++ = '\"';
|
||||
for (; *s; p++, s++)
|
||||
{
|
||||
switch (*s)
|
||||
{
|
||||
case '\\':
|
||||
*p++ = '\\';
|
||||
*p = '\\';
|
||||
break;
|
||||
case '\"':
|
||||
*p++ = '\\';
|
||||
*p = '\"';
|
||||
break;
|
||||
case '\004':
|
||||
*p++ = '\\';
|
||||
*p++ = 'C';
|
||||
*p++ = '-';
|
||||
*p = 'd';
|
||||
break;
|
||||
default:
|
||||
*p = *s;
|
||||
}
|
||||
}
|
||||
*p++ = '\"';
|
||||
*p = '\0';
|
||||
return res;
|
||||
}
|
||||
|
||||
#define GET_ARGUMENT(var, desc) do { \
|
||||
if (*(p + 1)) (var) = p + 1; \
|
||||
else \
|
||||
{ \
|
||||
if (!argv[++i]) \
|
||||
{ \
|
||||
fprintf (stderr, "%s: `%s' must be followed by an argument\n", \
|
||||
progname, desc); \
|
||||
exit (1); \
|
||||
} \
|
||||
(var) = argv[i]; \
|
||||
} \
|
||||
over = 1; \
|
||||
} while (0)
|
||||
|
||||
/* A strdup immitation. */
|
||||
static char *
|
||||
my_strdup (CONST char *s)
|
||||
{
|
||||
char *new = malloc (strlen (s) + 1);
|
||||
if (new)
|
||||
strcpy (new, s);
|
||||
return new;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
int starting_line = 1; /* line to start editing at */
|
||||
char command[MAXPATHLEN+50]; /* emacs command buffer */
|
||||
char fullpath[MAXPATHLEN+1]; /* full pathname to file */
|
||||
char *eval_form = NULL; /* form to evaluate with `-eval' */
|
||||
char *eval_function = NULL; /* function to evaluate with `-f' */
|
||||
char *load_library = NULL; /* library to load */
|
||||
int quick = 0; /* quick edit, don't wait for user to
|
||||
finish */
|
||||
int batch = 0; /* batch mode */
|
||||
int view = 0; /* view only. */
|
||||
int nofiles = 0;
|
||||
int errflg = 0; /* option error */
|
||||
int s; /* socket / msqid to server */
|
||||
int connect_type; /* CONN_UNIX, CONN_INTERNET, or
|
||||
* CONN_IPC */
|
||||
int suppress_windows_system = 0;
|
||||
char *display = NULL;
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
char *hostarg = NULL; /* remote hostname */
|
||||
char *remotearg;
|
||||
char thishost[HOSTNAMSZ]; /* this hostname */
|
||||
char remotepath[MAXPATHLEN+1]; /* remote pathname */
|
||||
char *path;
|
||||
int rflg = 0; /* pathname given on cmdline */
|
||||
char *portarg;
|
||||
u_short port = 0; /* port to server */
|
||||
#endif /* INTERNET_DOMAIN_SOCKETS */
|
||||
#ifdef SYSV_IPC
|
||||
struct msgbuf *msgp; /* message */
|
||||
#endif /* SYSV_IPC */
|
||||
char *tty = NULL;
|
||||
char buffer[GSERV_BUFSZ + 1]; /* buffer to read pid */
|
||||
char result[GSERV_BUFSZ + 1];
|
||||
int i;
|
||||
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
memset (remotepath, 0, sizeof (remotepath));
|
||||
#endif /* INTERNET_DOMAIN_SOCKETS */
|
||||
|
||||
progname = strrchr (argv[0], '/');
|
||||
if (progname)
|
||||
++progname;
|
||||
else
|
||||
progname = argv[0];
|
||||
|
||||
display = getenv ("DISPLAY");
|
||||
if (!display)
|
||||
suppress_windows_system = 1;
|
||||
else
|
||||
display = my_strdup (display);
|
||||
|
||||
for (i = 1; argv[i] && !errflg; i++)
|
||||
{
|
||||
if (*argv[i] != '-')
|
||||
break;
|
||||
else if (*argv[i] == '-'
|
||||
&& (*(argv[i] + 1) == '\0'
|
||||
|| (*(argv[i] + 1) == '-' && *(argv[i] + 2) == '\0')))
|
||||
{
|
||||
/* `-' or `--' */
|
||||
++i;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!strcmp (argv[i], "-batch") || !strcmp (argv[i], "--batch"))
|
||||
batch = 1;
|
||||
else if (!strcmp (argv[i], "-eval") || !strcmp (argv[i], "--eval"))
|
||||
{
|
||||
if (!argv[++i])
|
||||
{
|
||||
fprintf (stderr, "%s: `-eval' must be followed by an argument\n",
|
||||
progname);
|
||||
exit (1);
|
||||
}
|
||||
eval_form = argv[i];
|
||||
}
|
||||
else if (!strcmp (argv[i], "-display") || !strcmp (argv[i], "--display"))
|
||||
{
|
||||
suppress_windows_system = 0;
|
||||
if (!argv[++i])
|
||||
{
|
||||
fprintf (stderr,
|
||||
"%s: `-display' must be followed by an argument\n",
|
||||
progname);
|
||||
exit (1);
|
||||
}
|
||||
if (display)
|
||||
free (display);
|
||||
/* no need to strdup. */
|
||||
display = argv[i];
|
||||
}
|
||||
else if (!strcmp (argv[i], "-nw"))
|
||||
suppress_windows_system = 1;
|
||||
else
|
||||
{
|
||||
/* Iterate over one-letter options. */
|
||||
char *p;
|
||||
int over = 0;
|
||||
for (p = argv[i] + 1; *p && !over; p++)
|
||||
{
|
||||
switch (*p)
|
||||
{
|
||||
case 'q':
|
||||
quick = 1;
|
||||
break;
|
||||
case 'v':
|
||||
view = 1;
|
||||
break;
|
||||
case 'f':
|
||||
GET_ARGUMENT (eval_function, "-f");
|
||||
break;
|
||||
case 'l':
|
||||
GET_ARGUMENT (load_library, "-l");
|
||||
break;
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
case 'h':
|
||||
GET_ARGUMENT (hostarg, "-h");
|
||||
break;
|
||||
case 'p':
|
||||
GET_ARGUMENT (portarg, "-p");
|
||||
port = atoi (portarg);
|
||||
break;
|
||||
case 'r':
|
||||
GET_ARGUMENT (remotearg, "-r");
|
||||
strcpy (remotepath, remotearg);
|
||||
rflg = 1;
|
||||
break;
|
||||
#endif /* INTERNET_DOMAIN_SOCKETS */
|
||||
default:
|
||||
errflg = 1;
|
||||
}
|
||||
} /* for */
|
||||
} /* else */
|
||||
} /* for */
|
||||
|
||||
if (errflg)
|
||||
{
|
||||
fprintf (stderr,
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
"usage: %s [-nw] [-display display] [-q] [-v] [-l library]\n"
|
||||
" [-batch] [-f function] [-eval form]\n"
|
||||
" [-h host] [-p port] [-r remote-path] [[+line] file] ...\n",
|
||||
#else /* !INTERNET_DOMAIN_SOCKETS */
|
||||
"usage: %s [-nw] [-q] [-v] [-l library] [-f function] [-eval form] "
|
||||
"[[+line] path] ...\n",
|
||||
#endif /* !INTERNET_DOMAIN_SOCKETS */
|
||||
progname);
|
||||
exit (1);
|
||||
}
|
||||
if (batch && argv[i])
|
||||
{
|
||||
fprintf (stderr, "%s: Cannot specify `-batch' with file names\n",
|
||||
progname);
|
||||
exit (1);
|
||||
}
|
||||
if (suppress_windows_system && hostarg)
|
||||
{
|
||||
fprintf (stderr, "%s: Remote editing is available only on X\n",
|
||||
progname);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
*result = '\0';
|
||||
if (eval_function || eval_form || load_library)
|
||||
{
|
||||
#if defined(INTERNET_DOMAIN_SOCKETS)
|
||||
connect_type = make_connection (hostarg, port, &s);
|
||||
#else
|
||||
connect_type = make_connection (NULL, (u_short) 0, &s);
|
||||
#endif
|
||||
sprintf (command, "(gnuserv-eval%s '(progn ", quick ? "-quickly" : "");
|
||||
send_string (s, command);
|
||||
if (load_library)
|
||||
{
|
||||
sprintf (command, " (load-library %s)", clean_string (load_library));
|
||||
send_string (s, command);
|
||||
}
|
||||
if (eval_form)
|
||||
{
|
||||
sprintf (command, " %s", eval_form);
|
||||
send_string (s, command);
|
||||
}
|
||||
if (eval_function)
|
||||
{
|
||||
sprintf (command, " (%s)", eval_function);
|
||||
send_string (s, command);
|
||||
}
|
||||
send_string (s, "))");
|
||||
send_string (s, EOT_STR);
|
||||
if (read_line (s, result) == 0)
|
||||
{
|
||||
fprintf (stderr, "%s: Could not read\n", progname);
|
||||
exit (1);
|
||||
}
|
||||
} /* eval_function || eval_form || load_library */
|
||||
else if (batch)
|
||||
{
|
||||
fprintf (stderr, "%s: `-batch' requires an evaluation\n",
|
||||
progname);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if (!batch)
|
||||
{
|
||||
if (suppress_windows_system)
|
||||
{
|
||||
tty = ttyname (0);
|
||||
if (!tty)
|
||||
{
|
||||
fprintf (stderr, "%s: Not connected to a tty", progname);
|
||||
exit (1);
|
||||
}
|
||||
#if defined(INTERNET_DOMAIN_SOCKETS)
|
||||
connect_type = make_connection (hostarg, port, &s);
|
||||
#else
|
||||
connect_type = make_connection (NULL, (u_short) 0, &s);
|
||||
#endif
|
||||
send_string (s, "(gnuserv-eval '(emacs-pid))");
|
||||
send_string (s, EOT_STR);
|
||||
|
||||
if (read_line (s, buffer) == 0)
|
||||
{
|
||||
fprintf (stderr, "%s: Could not establish Emacs procces id\n",
|
||||
progname);
|
||||
exit (1);
|
||||
}
|
||||
/* Don't do disconnect_from_server becasue we have already read
|
||||
data, and disconnect doesn't do anything else. */
|
||||
#ifndef INTERNET_DOMAIN_SOCKETS
|
||||
if (connect_type == (int) CONN_IPC)
|
||||
disconnect_from_ipc_server (s, msgp, FALSE);
|
||||
#endif /* !SYSV_IPC */
|
||||
|
||||
emacs_pid = (pid_t)atol(buffer);
|
||||
initialize_signals();
|
||||
} /* suppress_windows_system */
|
||||
|
||||
#if defined(INTERNET_DOMAIN_SOCKETS)
|
||||
connect_type = make_connection (hostarg, port, &s);
|
||||
#else
|
||||
connect_type = make_connection (NULL, (u_short) 0, &s);
|
||||
#endif
|
||||
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
if (connect_type == (int) CONN_INTERNET)
|
||||
{
|
||||
char *ptr;
|
||||
gethostname (thishost, HOSTNAMSZ);
|
||||
if (!rflg)
|
||||
{ /* attempt to generate a path
|
||||
* to this machine */
|
||||
if ((ptr = getenv ("GNU_NODE")) != NULL)
|
||||
/* user specified a path */
|
||||
strcpy (remotepath, ptr);
|
||||
}
|
||||
#if 0 /* This is really bogus... re-enable it if you must have it! */
|
||||
#if defined (hp9000s300) || defined (hp9000s800)
|
||||
else if (strcmp (thishost,hostarg))
|
||||
{ /* try /net/thishost */
|
||||
strcpy (remotepath, "/net/"); /* (this fails using internet
|
||||
addresses) */
|
||||
strcat (remotepath, thishost);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{ /* same machines, no need for path */
|
||||
remotepath[0] = '\0'; /* default is the empty path */
|
||||
}
|
||||
#endif /* INTERNET_DOMAIN_SOCKETS */
|
||||
|
||||
#ifdef SYSV_IPC
|
||||
if ((msgp = (struct msgbuf *)
|
||||
malloc (sizeof *msgp + GSERV_BUFSZ)) == NULL)
|
||||
{
|
||||
fprintf (stderr, "%s: not enough memory for message buffer\n", progname);
|
||||
exit (1);
|
||||
} /* if */
|
||||
|
||||
msgp->mtext[0] = '\0'; /* ready for later strcats */
|
||||
#endif /* SYSV_IPC */
|
||||
|
||||
if (suppress_windows_system)
|
||||
{
|
||||
char *term = getenv ("TERM");
|
||||
if (!term)
|
||||
{
|
||||
fprintf (stderr, "%s: unknown terminal type\n", progname);
|
||||
exit (1);
|
||||
}
|
||||
sprintf (command, "(gnuserv-edit-files '(tty %s %s %d) '(",
|
||||
clean_string (tty), clean_string (term), (int)getpid ());
|
||||
}
|
||||
else /* !suppress_windows_system */
|
||||
{
|
||||
sprintf (command, "(gnuserv-edit-files '(x %s) '(",
|
||||
clean_string (display));
|
||||
} /* !suppress_windows_system */
|
||||
send_string (s, command);
|
||||
|
||||
if (!argv[i])
|
||||
nofiles = 1;
|
||||
|
||||
for (; argv[i]; i++)
|
||||
{
|
||||
if (i < argc - 1 && *argv[i] == '+')
|
||||
starting_line = atoi (argv[i++]);
|
||||
else
|
||||
starting_line = 1;
|
||||
/* If the last argument is +something, treat it as a file. */
|
||||
if (i == argc)
|
||||
{
|
||||
starting_line = 1;
|
||||
--i;
|
||||
}
|
||||
filename_expand (fullpath, argv[i]);
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
path = malloc (strlen (remotepath) + strlen (fullpath) + 1);
|
||||
sprintf (path, "%s%s", remotepath, fullpath);
|
||||
#else
|
||||
path = my_strdup (fullpath);
|
||||
#endif
|
||||
sprintf (command, "(%d . %s)", starting_line, clean_string (path));
|
||||
send_string (s, command);
|
||||
free (path);
|
||||
} /* for */
|
||||
|
||||
sprintf (command, ")%s%s",
|
||||
(quick || (nofiles && !suppress_windows_system)) ? " 'quick" : "",
|
||||
view ? " 'view" : "");
|
||||
send_string (s, command);
|
||||
send_string (s, ")");
|
||||
|
||||
#ifdef SYSV_IPC
|
||||
if (connect_type == (int) CONN_IPC)
|
||||
disconnect_from_ipc_server (s, msgp, FALSE);
|
||||
#else /* !SYSV_IPC */
|
||||
if (connect_type != (int) CONN_IPC)
|
||||
disconnect_from_server (s, FALSE);
|
||||
#endif /* !SYSV_IPC */
|
||||
} /* not batch */
|
||||
|
||||
if (batch && !quick)
|
||||
printf ("%s\n", result);
|
||||
|
||||
return 0;
|
||||
|
||||
} /* main */
|
||||
|
||||
#endif /* SYSV_IPC || UNIX_DOMAIN_SOCKETS || INTERNET_DOMAIN_SOCKETS */
|
175
lib/init.c
175
lib/init.c
@@ -20,23 +20,174 @@
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/open.h>
|
||||
#include <glibtop/xmalloc.h>
|
||||
#include <glibtop/parameter.h>
|
||||
|
||||
#ifndef DEFAULT_PORT
|
||||
#define DEFAULT_PORT 42800
|
||||
#endif
|
||||
|
||||
static glibtop _glibtop_global_server;
|
||||
glibtop *glibtop_global_server = NULL;
|
||||
glibtop *glibtop_global_server = &_glibtop_global_server;
|
||||
|
||||
glibtop *
|
||||
glibtop_init_r (glibtop **server, const unsigned long features,
|
||||
const unsigned flags)
|
||||
|
||||
void
|
||||
_init_server (glibtop *server, const unsigned features)
|
||||
{
|
||||
if (*server != NULL)
|
||||
return *server;
|
||||
char *command, *temp;
|
||||
|
||||
if (glibtop_global_server == NULL) {
|
||||
glibtop_global_server = &_glibtop_global_server;
|
||||
glibtop_open_l (glibtop_global_server, "glibtop",
|
||||
features, flags);
|
||||
/* Try to get server command, but don't override if already
|
||||
* set via glibtop_set_parameter () */
|
||||
|
||||
if (server->server_command == NULL) {
|
||||
const char *temp = getenv ("LIBGTOP_SERVER") ?
|
||||
getenv ("LIBGTOP_SERVER") : GTOP_SERVER;
|
||||
|
||||
server->server_command = glibtop_strdup_r (server, temp);
|
||||
}
|
||||
|
||||
return *server = glibtop_global_server;
|
||||
if (server->server_rsh == NULL) {
|
||||
const char *temp = getenv ("LIBGTOP_RSH") ?
|
||||
getenv ("LIBGTOP_RSH") : "/usr/bin/ssh";
|
||||
|
||||
server->server_rsh = glibtop_strdup_r (server, temp);
|
||||
}
|
||||
|
||||
/* Try to get server method, but don't override if already
|
||||
* set via glibtop_set_parameter () */
|
||||
|
||||
if (server->method) return;
|
||||
|
||||
/* If server->command doesn't start with a colon, then it is
|
||||
* the full pathname of the server executable. */
|
||||
|
||||
if (server->server_command [0] != ':') {
|
||||
if (features & glibtop_server_features) {
|
||||
/* We really need the server. */
|
||||
server->method = GLIBTOP_METHOD_PIPE;
|
||||
} else {
|
||||
/* Fine. No server is needed, so we call the
|
||||
* sysdeps functions directly. */
|
||||
server->method = GLIBTOP_METHOD_DIRECT;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* If the first character of 'server_command' is a colon,
|
||||
* the first field is the method to connect to the server. */
|
||||
|
||||
/* Everything up to the next colon is the method. */
|
||||
|
||||
command = glibtop_strdup_r (server, server->server_command+1);
|
||||
temp = strstr (command, ":");
|
||||
if (temp) *temp = 0;
|
||||
|
||||
/* Dispatch method. */
|
||||
|
||||
if (!strcmp (command, "direct")) {
|
||||
/* Use sysdeps dir instead of connecting to server
|
||||
* even if using the server would be required on
|
||||
* the current system. */
|
||||
server->method = GLIBTOP_METHOD_DIRECT;
|
||||
|
||||
} else if (!strcmp (command, "inet")) {
|
||||
|
||||
server->method = GLIBTOP_METHOD_INET;
|
||||
|
||||
/* Connect to internet server. */
|
||||
|
||||
if (temp == NULL) {
|
||||
/* If no value was set, we use 'localhost'. */
|
||||
if (server->server_host == NULL)
|
||||
server->server_host = glibtop_strdup_r
|
||||
(server, "localhost");
|
||||
} else {
|
||||
char *temp2 = strstr (temp+1, ":");
|
||||
if (temp2) *temp2 = 0;
|
||||
|
||||
/* Override default. */
|
||||
if (server->server_host)
|
||||
glibtop_free_r (server, (char *) server->server_host);
|
||||
|
||||
server->server_host = glibtop_strdup_r
|
||||
(server, temp+1);
|
||||
|
||||
temp = temp2;
|
||||
}
|
||||
|
||||
if (temp == NULL) {
|
||||
/* If no value was set, we use DEFAULT_PORT. */
|
||||
if (server->server_port == 0)
|
||||
server->server_port = DEFAULT_PORT;
|
||||
} else {
|
||||
char *temp2 = strstr (temp+1, ":");
|
||||
if (temp2) *temp2 = 0;
|
||||
|
||||
if (sscanf (temp+1, "%ld", &server->server_port) != 1)
|
||||
server->server_port = DEFAULT_PORT;
|
||||
|
||||
temp = temp2 ? temp2 + 1 : temp2;
|
||||
}
|
||||
|
||||
} else if (!strcmp (command, "unix")) {
|
||||
|
||||
/* Connect to unix domain socket. */
|
||||
server->method = GLIBTOP_METHOD_UNIX;
|
||||
|
||||
} else if (!strcmp (command, "pipe")) {
|
||||
|
||||
/* Open pipe to server. */
|
||||
server->method = GLIBTOP_METHOD_PIPE;
|
||||
|
||||
} else {
|
||||
|
||||
glibtop_error_r (server, "Unknown server method '%s'",
|
||||
server->server_command+1);
|
||||
|
||||
}
|
||||
|
||||
glibtop_free_r (server, command);
|
||||
}
|
||||
|
||||
glibtop *
|
||||
glibtop_init_r (glibtop **server_ptr, const unsigned long features,
|
||||
const unsigned flags)
|
||||
{
|
||||
glibtop *server;
|
||||
|
||||
if (server_ptr == NULL)
|
||||
return NULL;
|
||||
|
||||
if (*server_ptr == NULL)
|
||||
*server_ptr = glibtop_global_server;
|
||||
|
||||
server = *server_ptr;
|
||||
|
||||
/* Should we do the initialization? */
|
||||
|
||||
if (flags & GLIBTOP_INIT_NO_INIT)
|
||||
return server;
|
||||
|
||||
/* Do the initialization, but only if not already initialized. */
|
||||
|
||||
if ((server->flags & _GLIBTOP_INIT_STATE_INIT) == 0) {
|
||||
_init_server (server, features);
|
||||
|
||||
server->flags |= _GLIBTOP_INIT_STATE_INIT;
|
||||
}
|
||||
|
||||
/* Should we open the server? */
|
||||
|
||||
if (flags & GLIBTOP_INIT_NO_OPEN)
|
||||
return server;
|
||||
|
||||
/* Open server, but only if not already opened. */
|
||||
|
||||
if ((server->flags & _GLIBTOP_INIT_STATE_OPEN) == 0)
|
||||
glibtop_open_l (glibtop_global_server, "glibtop",
|
||||
features, flags);
|
||||
|
||||
return server;
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ BEGIN {
|
||||
print "";
|
||||
|
||||
print "#include <glibtop.h>";
|
||||
print "#include <glibtop/open.h>";
|
||||
print "#include <glibtop/sysdeps.h>";
|
||||
print "#include <glibtop/command.h>";
|
||||
|
||||
@@ -29,7 +30,9 @@ function output(feature) {
|
||||
print "{";
|
||||
print "\tglibtop_init_r (&server, GLIBTOP_SYSDEPS_"toupper(feature)", 0);";
|
||||
print "";
|
||||
print "\tif (server->features & GLIBTOP_SYSDEPS_"toupper(feature)") {";
|
||||
print "\tif ((server->flags & _GLIBTOP_INIT_STATE_SERVER) &&";
|
||||
print "\t (server->features & (1 << GLIBTOP_SYSDEPS_"toupper(feature)")))";
|
||||
print "\t{";
|
||||
|
||||
if (feature ~ /^proc_/) {
|
||||
print "\t\t"prefix"glibtop_call_l (server, GLIBTOP_CMND_"toupper(feature)", sizeof (pid_t),";
|
||||
|
141
lib/open.c
141
lib/open.c
@@ -25,6 +25,8 @@
|
||||
#include <glibtop/command.h>
|
||||
#include <glibtop/xmalloc.h>
|
||||
|
||||
#include <glibtop/gnuserv.h>
|
||||
|
||||
/* Opens pipe to gtop server. Returns 0 on success and -1 on error. */
|
||||
|
||||
void
|
||||
@@ -32,125 +34,108 @@ glibtop_open_l (glibtop *server, const char *program_name,
|
||||
const unsigned long features, const unsigned flags)
|
||||
{
|
||||
char version [BUFSIZ], buffer [BUFSIZ];
|
||||
char *server_command, *server_rsh, *temp;
|
||||
char *server_host, *server_user;
|
||||
glibtop_sysdeps sysdeps;
|
||||
|
||||
memset (server, 0, sizeof (glibtop));
|
||||
int connect_type;
|
||||
unsigned nbytes;
|
||||
|
||||
server->name = program_name;
|
||||
|
||||
/* Is the user allowed to override the server ? */
|
||||
/* It is important to set _GLIBTOP_INIT_STATE_OPEN here when we
|
||||
* do recursive calls to glibtop_init_r (). */
|
||||
|
||||
if ((flags & GLIBTOP_OPEN_NO_OVERRIDE) == 0) {
|
||||
server->flags |= _GLIBTOP_INIT_STATE_OPEN;
|
||||
|
||||
/* Try to get data from environment. */
|
||||
switch (server->method) {
|
||||
case GLIBTOP_METHOD_DIRECT:
|
||||
fprintf (stderr, "Calling sysdeps open function.\n");
|
||||
|
||||
temp = getenv ("LIBGTOP_SERVER") ?
|
||||
getenv ("LIBGTOP_SERVER") : GTOP_SERVER;
|
||||
glibtop_open_r (server, program_name, features, flags);
|
||||
|
||||
server_command = glibtop_malloc_r (server, strlen (temp) + 1);
|
||||
break;
|
||||
case GLIBTOP_METHOD_INET:
|
||||
fprintf (stderr, "Connecting to '%s' port %ld.\n",
|
||||
server->server_host, server->server_port);
|
||||
|
||||
strcpy (server_command, temp);
|
||||
connect_type = glibtop_make_connection
|
||||
(server->server_host, server->server_port,
|
||||
&server->socket);
|
||||
|
||||
temp = getenv ("LIBGTOP_RSH") ?
|
||||
getenv ("LIBGTOP_RSH") : "rsh";
|
||||
fprintf (stderr, "Connect Type is %d.\n", connect_type);
|
||||
|
||||
server_rsh = glibtop_malloc_r (server, strlen (temp) + 1);
|
||||
server->flags |= _GLIBTOP_INIT_STATE_SERVER;
|
||||
|
||||
strcpy (server_rsh, temp);
|
||||
server->features = -1;
|
||||
break;
|
||||
case GLIBTOP_METHOD_UNIX:
|
||||
fprintf (stderr, "Connecting to Unix Domain Socket.\n");
|
||||
|
||||
/* Extract host and user information. */
|
||||
connect_type = glibtop_make_connection
|
||||
("unix", 0, &server->socket);
|
||||
|
||||
temp = strstr (server_command, ":");
|
||||
fprintf (stderr, "Connect Type is %d.\n", connect_type);
|
||||
|
||||
if (temp) {
|
||||
*temp = 0;
|
||||
server_host = server_command;
|
||||
server_command = temp+1;
|
||||
server->flags |= _GLIBTOP_INIT_STATE_SERVER;
|
||||
|
||||
temp = strstr (server_host, "@");
|
||||
server->features = -1;
|
||||
break;
|
||||
case GLIBTOP_METHOD_PIPE:
|
||||
fprintf (stderr, "Opening pipe to server (%s).\n",
|
||||
GTOP_SERVER);
|
||||
|
||||
if (temp) {
|
||||
*temp = 0;
|
||||
server_user = server_host;
|
||||
server_host = temp+1;
|
||||
} else {
|
||||
server_user = NULL;
|
||||
}
|
||||
} else {
|
||||
server_host = NULL;
|
||||
server_user = NULL;
|
||||
}
|
||||
#if 0
|
||||
if (socketpair (AF_UNIX, SOCK_STREAM, 0, server->input))
|
||||
glibtop_error_io_r (server, "socketpair");
|
||||
|
||||
/* Store everything in `server'. */
|
||||
|
||||
server->server_command = server_command;
|
||||
server->server_host = server_host;
|
||||
server->server_user = server_user;
|
||||
server->server_rsh = server_rsh;
|
||||
}
|
||||
|
||||
/* Get server features. */
|
||||
|
||||
if (server->server_host == NULL) {
|
||||
server->features = glibtop_server_features;
|
||||
|
||||
if (server->features == 0)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Fork and exec server. */
|
||||
if (socketpair (AF_UNIX, SOCK_STREAM, 0, server->output))
|
||||
glibtop_error_io_r (server, "socketpair");
|
||||
#endif
|
||||
|
||||
if (pipe (server->input) || pipe (server->output))
|
||||
glibtop_error_r (server, _("cannot make a pipe: %s\n"),
|
||||
strerror (errno));
|
||||
glibtop_error_io_r (server, "cannot make a pipe");
|
||||
|
||||
server->pid = fork ();
|
||||
|
||||
if (server->pid < 0) {
|
||||
glibtop_error_r (server, _("%s: fork failed: %s\n"),
|
||||
strerror (errno));
|
||||
glibtop_error_io_r (server, "fork failed");
|
||||
} else if (server->pid == 0) {
|
||||
close (0); close (1); /* close (2); */
|
||||
close (0); close (1);
|
||||
close (server->input [0]); close (server->output [1]);
|
||||
dup2 (server->input [1], 1); /* dup2 (server->input [1], 2); */
|
||||
dup2 (server->input [1], 1);
|
||||
dup2 (server->output [0], 0);
|
||||
|
||||
if (server_host) {
|
||||
if (server_user) {
|
||||
execl (server->server_rsh, "-l",
|
||||
server->server_user, server->server_host,
|
||||
server->server_command, NULL);
|
||||
} else {
|
||||
execl (server->server_rsh,
|
||||
server->server_host, server_command, NULL);
|
||||
}
|
||||
} else {
|
||||
execl (server->server_command, NULL);
|
||||
}
|
||||
|
||||
execl (GTOP_SERVER, NULL);
|
||||
glibtop_error_io_r (server, "execl %s", GTOP_SERVER);
|
||||
_exit (2);
|
||||
}
|
||||
|
||||
fprintf (stderr, "PID: %d\n", server->pid);
|
||||
|
||||
close (server->input [1]);
|
||||
close (server->output [0]);
|
||||
|
||||
sprintf (version, "%s server %s ready.\n", PACKAGE, VERSION);
|
||||
|
||||
glibtop_read_l (server, strlen (version), buffer);
|
||||
glibtop_read_l (server, sizeof (nbytes), &nbytes);
|
||||
|
||||
if (nbytes != strlen (version))
|
||||
glibtop_error_r (server, "Requested %u bytes but got %u",
|
||||
strlen (version), nbytes);
|
||||
|
||||
glibtop_read_l (server, nbytes, buffer);
|
||||
|
||||
if (memcmp (version, buffer, strlen (version)))
|
||||
glibtop_error_r (server, _("server version is not %s"), VERSION);
|
||||
glibtop_error_r (server, "server version is not %s",
|
||||
VERSION);
|
||||
break;
|
||||
}
|
||||
|
||||
fprintf (stderr, "Calling GLITOP_CMND_SYSDEPS ...\n");
|
||||
/* If the server has been started, ask it for its features. */
|
||||
|
||||
if (server->flags & _GLIBTOP_INIT_STATE_SERVER) {
|
||||
glibtop_sysdeps sysdeps;
|
||||
|
||||
glibtop_call_l (server, GLIBTOP_CMND_SYSDEPS, 0, NULL,
|
||||
sizeof (glibtop_sysdeps), &sysdeps);
|
||||
|
||||
server->features = sysdeps.features;
|
||||
|
||||
fprintf (stderr, "Features: %lu\n", server->features);
|
||||
fprintf (stderr, "Server features are %lu.\n",
|
||||
server->features);
|
||||
}
|
||||
}
|
||||
|
80
lib/parameter.c
Normal file
80
lib/parameter.c
Normal file
@@ -0,0 +1,80 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the Gnome Top Library.
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
The Gnome Top Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The Gnome Top Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/parameter.h>
|
||||
|
||||
#define _write_data(ptr,size) \
|
||||
if ((data_ptr == NULL) || (data_size < size)) return -size; \
|
||||
if (ptr == NULL) { strcpy (data_ptr, ""); return 1; } \
|
||||
memcpy (data_ptr, ptr, size); \
|
||||
return size;
|
||||
|
||||
#define _check_data(size) \
|
||||
if ((data_ptr == NULL) || (data_size != size)) { \
|
||||
glibtop_error_r (server, "glibtop_set_parameter (%d): " \
|
||||
"Expected %lu bytes but got %lu.", \
|
||||
parameter, size, data_size); \
|
||||
return; \
|
||||
}
|
||||
|
||||
#define _strlen(ptr) (ptr ? strlen (ptr) : 0)
|
||||
|
||||
size_t
|
||||
glibtop_get_parameter_l (glibtop *server, const unsigned parameter,
|
||||
void *data_ptr, size_t data_size)
|
||||
{
|
||||
switch (parameter) {
|
||||
case GLIBTOP_PARAM_METHOD:
|
||||
_write_data (&server->method,
|
||||
sizeof (server->method));
|
||||
case GLIBTOP_PARAM_FEATURES:
|
||||
_write_data (&server->features,
|
||||
sizeof (server->features));
|
||||
case GLIBTOP_PARAM_COMMAND:
|
||||
_write_data (server->server_command,
|
||||
_strlen(server->server_command));
|
||||
case GLIBTOP_PARAM_HOST:
|
||||
_write_data (server->server_host,
|
||||
_strlen(server->server_host));
|
||||
case GLIBTOP_PARAM_PORT:
|
||||
_write_data (&server->server_port,
|
||||
sizeof (server->server_port));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
glibtop_set_parameter_l (glibtop *server, const unsigned parameter,
|
||||
const void *data_ptr, size_t data_size)
|
||||
{
|
||||
switch (parameter) {
|
||||
case GLIBTOP_PARAM_METHOD:
|
||||
_check_data (sizeof (server->method));
|
||||
memcpy (&server->method, data_ptr, data_size);
|
||||
break;
|
||||
case GLIBTOP_PARAM_FEATURES:
|
||||
_check_data (sizeof (server->features));
|
||||
memcpy (&server->features, data_ptr, data_size);
|
||||
break;
|
||||
}
|
||||
}
|
43
lib/read.c
43
lib/read.c
@@ -23,19 +23,48 @@
|
||||
|
||||
/* Reads some data from server. */
|
||||
|
||||
static void
|
||||
do_read (int s, void *ptr, size_t total_size)
|
||||
{
|
||||
int nread;
|
||||
size_t already_read = 0, remaining = total_size;
|
||||
|
||||
while (already_read < total_size) {
|
||||
nread = recv (s, ptr, remaining, 0);
|
||||
|
||||
if (nread == 0) {
|
||||
close (s);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (nread <= 0) {
|
||||
glibtop_error_io ("recv");
|
||||
return;
|
||||
}
|
||||
|
||||
already_read += nread;
|
||||
remaining -= nread;
|
||||
(char *) ptr += nread;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
glibtop_read_l (glibtop *server, size_t size, void *buf)
|
||||
{
|
||||
size_t ssize;
|
||||
int ret = 0;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
if (read (server->input [0], &ssize, sizeof (size_t)) < 0)
|
||||
glibtop_error_r (server, _("read size: %s"), strerror (errno));
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "LIBRARY: really reading %d bytes.\n", size);
|
||||
#endif
|
||||
|
||||
if (size != ssize)
|
||||
glibtop_error_r (server, _("got %d bytes but requested %d"), ssize, size);
|
||||
if (server->socket) {
|
||||
do_read (server->socket, buf, size);
|
||||
} else {
|
||||
ret = read (server->input [0], buf, size);
|
||||
}
|
||||
|
||||
if (read (server->input [0], buf, size) < 0)
|
||||
glibtop_error_r (server, _("read %d bytes: %s"), size, strerror (errno));
|
||||
if (ret < 0)
|
||||
glibtop_error_io_r (server, _("read %d bytes"), size);
|
||||
}
|
||||
|
@@ -29,20 +29,39 @@ glibtop_read_data_l (glibtop *server)
|
||||
{
|
||||
size_t size;
|
||||
void *ptr;
|
||||
int ret;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
if (read (server->input [0], &size, sizeof (size_t)) < 0)
|
||||
glibtop_error_r (server, _("read data size: %s"),
|
||||
strerror (errno));
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "LIBRARY: reading %d data bytes.\n", sizeof (size_t));
|
||||
#endif
|
||||
|
||||
if (server->socket) {
|
||||
ret = recv (server->socket, &size, sizeof (size_t), 0);
|
||||
} else {
|
||||
ret = read (server->input [0], &size, sizeof (size_t));
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
glibtop_error_io_r (server, _("read data size"));
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "LIBRARY: really reading %d data bytes (ret = %d).\n", size, ret);
|
||||
#endif
|
||||
|
||||
if (!size) return NULL;
|
||||
|
||||
ptr = glibtop_malloc_r (server, size);
|
||||
|
||||
if (read (server->input [0], ptr, size) < 0)
|
||||
glibtop_error_r (server, _("read data %d bytes: %s"),
|
||||
size, strerror (errno));
|
||||
if (server->socket) {
|
||||
ret = recv (server->socket, ptr, size, 0);
|
||||
} else {
|
||||
ret = read (server->input [0], ptr, size);
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
glibtop_error_io_r (server, _("read data %d bytes"));
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
19
lib/write.c
19
lib/write.c
@@ -26,13 +26,22 @@
|
||||
void
|
||||
glibtop_write_l (glibtop *server, size_t size, void *buf)
|
||||
{
|
||||
int ret;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
if (write (server->output [1], &size, sizeof (size_t)) < 0)
|
||||
glibtop_error_r (server, _("write size: %s"), strerror (errno));
|
||||
if (size == 0) return;
|
||||
|
||||
if (!size) return;
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "LIBRARY: really writing %d bytes.\n", size);
|
||||
#endif
|
||||
|
||||
if (write (server->output [1], buf, size) < 0)
|
||||
glibtop_error_r (server, _("write %d bytes: %s"), size, strerror (errno));
|
||||
if (server->socket) {
|
||||
ret = send (server->socket, buf, size, 0);
|
||||
} else {
|
||||
ret = write (server->output [1], buf, size);
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
glibtop_error_io_r (server, _("write %d bytes"), size);
|
||||
}
|
||||
|
111
libproc/Makefile
Normal file
111
libproc/Makefile
Normal file
@@ -0,0 +1,111 @@
|
||||
# Auto-adaptive C library Makefile adapted for libproc, Chuck Blake.
|
||||
# Assumptions are basically that all the .c files in the CWD are modules
|
||||
# for the library and that all .h files are the interface to the library.
|
||||
|
||||
# PROJECT SPECIFIC MACROS
|
||||
NAME = proc
|
||||
|
||||
# INSTALLATION OPTIONS
|
||||
TOPDIR = /usr
|
||||
HDRDIR = $(TOPDIR)/include/$(NAME)# where to put .h files
|
||||
LIBDIR = $(TOPDIR)/lib# where to put library files
|
||||
SHLIBDIR = /lib# where to put shared library files
|
||||
HDROWN = -o root -g root # owner of header files
|
||||
LIBOWN = -o root -g root # owner of library files
|
||||
INSTALL = install
|
||||
|
||||
# COMPILATION OPTIONS
|
||||
CC = gcc -O2 -D_GNU_SOURCE #-ggdb # easy to command-line override
|
||||
CFLAGS = -I.. -Wall
|
||||
|
||||
# ----------------------------------------------------------------#
|
||||
# The rest is the auto-magic section -- highly GNU make dependent #
|
||||
# You should never need to edit this. #
|
||||
# ----------------------------------------------------------------#
|
||||
|
||||
VC_SUF = ,v
|
||||
VC_PFX = RCS/
|
||||
RCSFILES = $(patsubst $(VC_PFX)%$(VC_SUF),%,$(wildcard $(VC_PFX)*$(VC_SUF)))
|
||||
|
||||
# We take the union of RCS files and other files in CWD so that new files do
|
||||
# not need to alter this makefile. 'sort' removes duplicates. This allows the
|
||||
# convenience of compiling and testing new files before the initial check-in.
|
||||
|
||||
SRC = $(sort $(wildcard *.c) $(filter %.c,$(RCSFILES)))
|
||||
HDR = $(sort $(wildcard *.h) $(filter %.h,$(RCSFILES)))
|
||||
|
||||
OBJ = $(SRC:.c=.o)
|
||||
SONAME = lib$(NAME).so.$(LIBVERSION)
|
||||
|
||||
ifeq ($(SHARED),1)
|
||||
CFLAGS += -fpic
|
||||
all: lib$(NAME).a $(SONAME)
|
||||
else
|
||||
all: lib$(NAME).a
|
||||
endif
|
||||
|
||||
lib$(NAME).a: $(OBJ)
|
||||
$(AR) rcs $@ $^
|
||||
|
||||
$(SONAME): $(OBJ)
|
||||
gcc -Wl,-shared -Wl,-soname,$(SONAME) -o $@ $^ -lc
|
||||
ln -sf $(SONAME) lib$(NAME).so
|
||||
|
||||
# AUTOMATIC DEPENDENCY GENERATION -- GCC AND GNUMAKE DEPENDENT
|
||||
|
||||
.depend:
|
||||
$(strip $(CC) $(CFLAGS) -MM -MG $(SRC) > .depend)
|
||||
include .depend
|
||||
|
||||
# INSTALLATION
|
||||
|
||||
install: all
|
||||
if ! [ -d $(HDRDIR) ] ; then mkdir $(HDRDIR) ; fi
|
||||
$(INSTALL) $(HDROWN) $(HDR) $(TOPDIR)/include/$(NAME)
|
||||
$(INSTALL) $(LIBOWN) lib$(NAME).a $(LIBDIR)
|
||||
ifeq ($(SHARED),1)
|
||||
$(INSTALL) $(LIBOWN) $(SONAME) $(SHLIBDIR)
|
||||
ln -sf $(SHLIBDIR)/$(SONAME) $(SHLIBDIR)/lib$(NAME).so
|
||||
ldconfig
|
||||
endif
|
||||
|
||||
# VARIOUS SHORT CUT TARGETS
|
||||
.PHONY: all install dep clean distclean checkout checkclean
|
||||
|
||||
dep: .depend
|
||||
|
||||
clean:
|
||||
$(RM) lib$(NAME).* *.o
|
||||
|
||||
distclean: clean
|
||||
$(RM) .depend signames.h
|
||||
|
||||
checkout:
|
||||
$(CO) $(RCSFILES)
|
||||
|
||||
checkclean:
|
||||
$(RM) $(RCSFILES)
|
||||
|
||||
# CUSTOM c -> o rule so that command-line has minimal whitespace
|
||||
|
||||
%.o : %.c
|
||||
$(strip $(CC) $(CFLAGS) -c $<)
|
||||
|
||||
# PROJECT SPECIFIC DEPENDENCIES/BUILD RULES
|
||||
|
||||
|
||||
version.o: version.c version.h
|
||||
ifdef MINORVERSION
|
||||
$(strip $(CC) $(CFLAGS) -DVERSION=\"$(VERSION)\" -DSUBVERSION=\"$(SUBVERSION)\" -DMINORVERSION=\"$(MINORVERSION)\" -c version.c)
|
||||
else
|
||||
$(strip $(CC) $(CFLAGS) -DVERSION=\"$(VERSION)\" -DSUBVERSION=\"$(SUBVERSION)\" -c version.c)
|
||||
endif
|
||||
|
||||
signals.o : signames.h
|
||||
|
||||
signames.h ../proc/signames.h : /usr/include/signal.h
|
||||
/lib/cpp -dM </usr/include/signal.h | \
|
||||
tr -s '\t ' ' ' | sort -n +2 | sed \
|
||||
's:#define SIG\([A-Z]\+[0-9]*\) \([0-9]\+\) *\(\|/\*.*\)$$:{\
|
||||
\2,"\1" },:p;d' > signames.h
|
||||
|
49
libproc/alloc.c
Normal file
49
libproc/alloc.c
Normal file
@@ -0,0 +1,49 @@
|
||||
/***********************************************************************\
|
||||
* Copyright (C) 1992 by Michael K. Johnson, johnsonm@sunsite.unc.edu *
|
||||
* *
|
||||
* This file is placed under the conditions of the GNU public *
|
||||
* license, version 2, or any later version. See file COPYING *
|
||||
* for information on distribution conditions. *
|
||||
\***********************************************************************/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void *xcalloc(void *pointer, int size) {
|
||||
void * ret;
|
||||
if (pointer)
|
||||
free(pointer);
|
||||
if (!(ret = calloc(1, size))) {
|
||||
fprintf(stderr, "xcalloc: allocation error, size = %d\n", size);
|
||||
exit(1);
|
||||
} else {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
void *xmalloc(unsigned int size) {
|
||||
void *p;
|
||||
|
||||
if (size == 0)
|
||||
++size;
|
||||
p = malloc(size);
|
||||
if (!p) {
|
||||
fprintf(stderr, "xmalloc: malloc(%d) failed", size);
|
||||
perror(NULL);
|
||||
exit(1);
|
||||
}
|
||||
return(p);
|
||||
}
|
||||
|
||||
void *xrealloc(void *oldp, unsigned int size) {
|
||||
void *p;
|
||||
|
||||
if (size == 0)
|
||||
++size;
|
||||
p = realloc(oldp, size);
|
||||
if (!p) {
|
||||
fprintf(stderr, "xrealloc: realloc(%d) failed", size);
|
||||
perror(NULL);
|
||||
exit(1);
|
||||
}
|
||||
return(p);
|
||||
}
|
307
libproc/compare.c
Normal file
307
libproc/compare.c
Normal file
@@ -0,0 +1,307 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 1994 Charles Blake and Michael K. Johnson
|
||||
* This file is a part of procps, which is distributable
|
||||
* under the conditions of the GNU Public License. See the
|
||||
* file COPYING for details.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <string.h> /* for strcmp */
|
||||
#include <stdio.h> /* for parse error output */
|
||||
#include "proc/readproc.h" /* for proc_t */
|
||||
#include "proc/tree.h" /* for struct tree_node */
|
||||
|
||||
/*
|
||||
This module was written by Charles Blake for procps.
|
||||
|
||||
mult_lvl_cmp:
|
||||
slick general purpose multi-level compare function I invented.
|
||||
sort_depth:
|
||||
the number of levels of functions *to use*. This means many more levels
|
||||
can be defined than mult_lvl_cmp tres out. If this is 1 then mult_lvl_cmp
|
||||
is just a trivial wrapper around (*sort_function[0]).
|
||||
sort_direction:
|
||||
multiplicative factor for the output of cmp_whatever.
|
||||
1 ==> default order, -1 ==> reverse order, 0 ==> forced equality
|
||||
The 0 bit is the neat part. Since a value of zero is the code for equality
|
||||
multiplying the output of cmp_foo(a,b) forces a==b to be true. This is a
|
||||
convenient way to turn sorting off in middle levels of a multi-level sort.
|
||||
If time is a problem, reforming the whole sort_function array to not include
|
||||
these unsorted middle levels will be faster since then cmp_foo won't even
|
||||
be called. It might simplify some code depending upon how you organize it.
|
||||
sort_function[]:
|
||||
array of function pointers that points to our family of comparison functions
|
||||
(I have named them cmp_* but mult_lvl_cmp doesn't care what they're named).
|
||||
This may be declared and initialized like so:
|
||||
int (*sort_function[])(void* a, void* b)={&cmp_foo, &cmp_bar, &cmp_hiho};
|
||||
You could also use my command line '-O' parser below.
|
||||
|
||||
Note that we only descend levels until the order is determined. If we descend
|
||||
all levels, that means that the items are equal at all levels, so we return 0.
|
||||
Otherwise we return whatever the level's cmp_foo function would have returned.
|
||||
This allows whatever default behavior you want for cmp_foo. sort_direction[]
|
||||
reverses this default behavior, but mult_lvl_cmp doesn't decide that ascending
|
||||
or descending is the default. That is the job of your cmp_foo's.
|
||||
*/
|
||||
|
||||
/* the only reason these are global is because qsort(3) likes it that way.
|
||||
It's also a little more efficient if mult_lvl_cmp() is called many times.
|
||||
*/
|
||||
|
||||
typedef int (*cmp_t)(void*,void*); /* for function pointer casts */
|
||||
|
||||
int sort_depth = 0;
|
||||
int sort_direction[10]; /* storage for 10 levels, but 4 would be plenty!*/
|
||||
int (*sort_function[10])(void* a, void* b);
|
||||
|
||||
int mult_lvl_cmp(void* a, void* b) {
|
||||
int i, cmp_val;
|
||||
for(i = 0; i < sort_depth; i++) {
|
||||
cmp_val = sort_direction[i] * (*sort_function[i])(a,b);
|
||||
if (cmp_val != 0)
|
||||
return cmp_val;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int node_mult_lvl_cmp(void* a, void* b) {
|
||||
int i, cmp_val;
|
||||
for(i = 0; i < sort_depth; i++) {
|
||||
cmp_val = sort_direction[i] * (*sort_function[i])(&(((struct tree_node *)a)->proc),&(((struct tree_node *)b)->proc));
|
||||
if (cmp_val != 0)
|
||||
return cmp_val;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* qsort(3) compliant comparison functions for all members of the ps_proc
|
||||
structure (in the same order in which they appear in the proc_t declaration)
|
||||
return is {-1,0,1} as {a<b, a==b, a>b}
|
||||
default ordering is ascending for all members. (flip 1,-1 to reverse)
|
||||
*/
|
||||
/* pre-processor macros to cut down on source size (and typing!)
|
||||
Note the use of the string concatenation operator ##
|
||||
*/
|
||||
#define CMP_STR(NAME) \
|
||||
int cmp_ ## NAME(proc_t** P, proc_t** Q) { \
|
||||
return strcmp((*P)-> ## NAME, (*Q)-> ## NAME); \
|
||||
}
|
||||
|
||||
#define CMP_INT(NAME) \
|
||||
int cmp_ ## NAME (proc_t** P, proc_t** Q) { \
|
||||
if ((*P)-> ## NAME < (*Q)-> ## NAME) return -1; \
|
||||
if ((*P)-> ## NAME > (*Q)-> ## NAME) return 1; \
|
||||
return 0; \
|
||||
}
|
||||
|
||||
/* Define the (46!) cmp_ functions with the above macros for every element
|
||||
of proc_t. If the binary gets too big, we could nuke inessentials.
|
||||
*/
|
||||
|
||||
/* CMP_STR(cmdline) */
|
||||
CMP_STR(user)
|
||||
CMP_STR(cmd)
|
||||
/* CMP_INT(state) */
|
||||
/* CMP_STR(ttyc) */
|
||||
CMP_INT(uid)
|
||||
CMP_INT(pid)
|
||||
CMP_INT(ppid)
|
||||
CMP_INT(pgrp)
|
||||
CMP_INT(session)
|
||||
CMP_INT(tty)
|
||||
CMP_INT(tpgid)
|
||||
CMP_INT(utime)
|
||||
CMP_INT(stime)
|
||||
CMP_INT(cutime)
|
||||
CMP_INT(cstime)
|
||||
/* CMP_INT(priority) */
|
||||
CMP_INT(nice)
|
||||
CMP_INT(start_time)
|
||||
/* CMP_INT(signal) */
|
||||
/* CMP_INT(blocked) */
|
||||
/* CMP_INT(sigignore) */
|
||||
/* CMP_INT(sigcatch) */
|
||||
CMP_INT(flags)
|
||||
CMP_INT(min_flt)
|
||||
CMP_INT(cmin_flt)
|
||||
CMP_INT(maj_flt)
|
||||
CMP_INT(cmaj_flt)
|
||||
/* CMP_INT(timeout) */
|
||||
CMP_INT(vsize)
|
||||
CMP_INT(rss)
|
||||
/* CMP_INT(rss_rlim) */
|
||||
/* CMP_INT(start_code) */
|
||||
/* CMP_INT(end_code) */
|
||||
/* CMP_INT(start_stack) */
|
||||
/* CMP_INT(kstk_esp) */
|
||||
/* CMP_INT(kstk_eip) */
|
||||
/* CMP_INT(wchan) */
|
||||
CMP_INT(pcpu)
|
||||
CMP_INT(size)
|
||||
CMP_INT(resident)
|
||||
CMP_INT(share)
|
||||
/* CMP_INT(trs) */
|
||||
/* CMP_INT(lrs) */
|
||||
/* CMP_INT(drs) */
|
||||
/* CMP_INT(dt) */
|
||||
|
||||
/* define user interface to sort keys. Fairly self-explanatory. */
|
||||
|
||||
struct cmp_fun_struct {
|
||||
char letter; /* single option-letter for key */
|
||||
char name[15]; /* long option name for key */
|
||||
int (*fun)(proc_t**, proc_t**); /* pointer to cmp_key */
|
||||
} cmp[] = {
|
||||
/* { '?', "cmdline", &cmp_cmdline }, */
|
||||
{ 'u', "user", &cmp_user },
|
||||
{ 'c', "cmd", &cmp_cmd },
|
||||
/* { '?', "state", &cmp_state }, */
|
||||
/* { '?', "ttyc", &cmp_ttyc }, */
|
||||
{ 'U', "uid", &cmp_uid },
|
||||
{ 'p', "pid", &cmp_pid },
|
||||
{ 'P', "ppid", &cmp_ppid },
|
||||
{ 'g', "pgrp", &cmp_pgrp },
|
||||
{ 'o', "session", &cmp_session },
|
||||
{ 't', "tty", &cmp_tty },
|
||||
{ 'G', "tpgid", &cmp_tpgid },
|
||||
{ 'k', "utime", &cmp_utime },
|
||||
{ 'K', "stime", &cmp_stime },
|
||||
{ 'j', "cutime", &cmp_cutime },
|
||||
{ 'J', "cstime", &cmp_cstime },
|
||||
/* { '?', "counter", &cmp_counter }, */
|
||||
{ 'y', "priority", &cmp_nice },
|
||||
{ 'T', "start_time", &cmp_start_time },
|
||||
/* { '?', "signal", &cmp_signal }, */
|
||||
/* { '?', "blocked", &cmp_blocked }, */
|
||||
/* { '?', "sigignore", &cmp_sigignore }, */
|
||||
/* { '?', "sigcatch", &cmp_sigcatch }, */
|
||||
{ 'f', "flags", &cmp_flags },
|
||||
{ 'm', "min_flt", &cmp_min_flt },
|
||||
{ 'n', "cmin_flt", &cmp_cmin_flt },
|
||||
{ 'M', "maj_flt", &cmp_maj_flt },
|
||||
{ 'N', "cmaj_flt", &cmp_cmaj_flt },
|
||||
/* { 'C', "timeout", &cmp_timeout }, */
|
||||
{ 'v', "vsize", &cmp_vsize },
|
||||
{ 'r', "rss", &cmp_rss },
|
||||
/* { '?', "rss_rlim", &cmp_rss_rlim }, */
|
||||
/* { '?', "start_code", &cmp_start_code }, */
|
||||
/* { '?', "end_code", &cmp_end_code }, */
|
||||
/* { '?', "start_stack", &cmp_start_stack }, */
|
||||
/* { '?', "kstk_esp", &cmp_kstk_esp }, */
|
||||
/* { '?', "kstk_eip", &cmp_kstk_eip }, */
|
||||
/* { '?', "wchan", &cmp_wchan }, */
|
||||
{ 'C', "pcpu", &cmp_pcpu },
|
||||
{ 's', "size", &cmp_size },
|
||||
{ 'R', "resident", &cmp_resident },
|
||||
{ 'S', "share", &cmp_share },
|
||||
/* { '?', "trs", &cmp_trs }, */
|
||||
/* { '?', "lrs", &cmp_lrs }, */
|
||||
/* { '?', "drs", &cmp_drs }, */
|
||||
/* { '?', "dt", &cmp_dt }, */
|
||||
{ '\0',"terminator", NULL }
|
||||
};
|
||||
|
||||
void dump_keys(void) {
|
||||
int i;
|
||||
for(i=0; cmp[i].letter; i++)
|
||||
fprintf(stderr, "%s-O%c , --sort:%-15.15s%s",
|
||||
i%2?"":" ",
|
||||
cmp[i].letter, cmp[i].name,
|
||||
i%2?"\n":"");
|
||||
if (i%2)
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
/* command line option parsing. Assign sort_{depth,direction[],function[]}
|
||||
based upon a string of the form:
|
||||
[+-]a[+-]b[+-]c...
|
||||
with a,b,c,... being letter flags corresponding to a particular sort
|
||||
key and the optional '-' specifying a reverse sort on that key. + doesn't
|
||||
mean anything, but it keeps things looking balanced...
|
||||
*/
|
||||
int parse_sort_opt(char* opt) {
|
||||
int i, next_dir=1;
|
||||
for(; *opt ; ++opt) {
|
||||
if (*opt == '-' || *opt == '+') {
|
||||
if (*opt == '-')
|
||||
next_dir = -1;
|
||||
opt++;
|
||||
continue;
|
||||
}
|
||||
for (i = 0; cmp[i].letter; i++)
|
||||
if (*opt == cmp[i].letter)
|
||||
break;
|
||||
if (!cmp[i].letter) {
|
||||
fprintf(stderr,
|
||||
"ps: no such sort key -- %c. Possibilities are:\n", *opt);
|
||||
dump_keys();
|
||||
return -1;
|
||||
} else {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,
|
||||
"sort level %d: key %s, direction % d\n",
|
||||
sort_depth, cmp[i].name, next_dir);
|
||||
#endif
|
||||
sort_function[sort_depth] = (cmp_t)cmp[i].fun;
|
||||
sort_direction[sort_depth++] = next_dir;
|
||||
next_dir = 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int parse_long_sort(char* opt) {
|
||||
char* comma;
|
||||
int i, more_keys, next_dir=1;
|
||||
do {
|
||||
if (*opt == '-' || *opt == '+') {
|
||||
if (*opt == '-')
|
||||
next_dir = -1;
|
||||
more_keys = 1;
|
||||
opt++;
|
||||
continue;
|
||||
}
|
||||
more_keys = ((comma=index(opt,',')) != NULL);
|
||||
/* keys are ',' delimited */
|
||||
if (more_keys)
|
||||
*comma='\0'; /* terminate for strcmp() */
|
||||
for(i = 0; cmp[i].letter; ++i)
|
||||
if (strcmp(opt, cmp[i].name) == 0)
|
||||
break;
|
||||
if (!cmp[i].letter) {
|
||||
fprintf(stderr,
|
||||
"ps: no such sort key -- %s. Possibilities are:\n", opt);
|
||||
dump_keys();
|
||||
return -1;
|
||||
} else {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,
|
||||
"sort level %d: key %s, direction % d\n",
|
||||
sort_depth, cmp[i].name, next_dir);
|
||||
#endif
|
||||
sort_function[sort_depth] = (cmp_t)cmp[i].fun;
|
||||
sort_direction[sort_depth++] = next_dir;
|
||||
next_dir = 1;
|
||||
}
|
||||
opt = comma + 1; /* do next loop on next key, if more keys, else done*/
|
||||
} while (more_keys);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void reset_sort_options (void)
|
||||
{
|
||||
int i;
|
||||
|
||||
sort_depth=0;
|
||||
for (i=0;i<10;i++){
|
||||
sort_direction[i]=0;
|
||||
sort_function[i]=(cmp_t)NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void register_sort_function (int dir, cmp_t func)
|
||||
{
|
||||
sort_function[sort_depth] = func;
|
||||
sort_direction[sort_depth++] = dir;
|
||||
}
|
269
libproc/devname.c
Normal file
269
libproc/devname.c
Normal file
@@ -0,0 +1,269 @@
|
||||
/* device name <-> number map system optimized for rapid, constant time lookup.
|
||||
Copyright Charles Blake, 1996, see COPYING for details.
|
||||
*/
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mman.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#define __KERNEL__
|
||||
#include <linux/kdev_t.h>
|
||||
#undef __KERNEL__
|
||||
|
||||
#define DEVDIR "/dev"
|
||||
#define DEVTAB "psdevtab"
|
||||
static char *devtab_paths[] = {
|
||||
"/etc/" DEVTAB,
|
||||
"%s/." DEVTAB,
|
||||
NULL
|
||||
};
|
||||
#define DEVINITIALMODE 0664
|
||||
#define DEV_MAX_PATH (5+256)
|
||||
#define DEV_NAME_MAX 8
|
||||
|
||||
static dev_t major[] = { 2, 3, 4, 5, 19, 20, 22, 23, 24, 25, 32, 33,
|
||||
46, 47, 48, 49 };
|
||||
#define Nminor 256
|
||||
#define Nmajor (sizeof(major)/sizeof(dev_t))
|
||||
#define Ndev (Nmajor*Nminor)
|
||||
#define Ndevtab (Ndev*DEV_NAME_MAX)
|
||||
|
||||
static char* devtab; /* the memory buffer holding all the name strings */
|
||||
|
||||
/* This macro evaluates to the address into the table of the string of
|
||||
DEV_NAME_MAX chars for the device with major m, minor n. */
|
||||
#define TAB(m,n) (devtab + (m)*(Nminor*DEV_NAME_MAX) + (n)*DEV_NAME_MAX)
|
||||
|
||||
static int devtab_initialized = 0;
|
||||
|
||||
static char* name_to_path(char* name); /* forward declarations */
|
||||
static int init_devtab (void);
|
||||
|
||||
/* Device Name -> Number Map
|
||||
many-to-one: -1 on failed match.
|
||||
*/
|
||||
dev_t name_to_dev(char* name) {
|
||||
static struct stat sbuf;
|
||||
return (stat(name_to_path(name), &sbuf) < 0) ? -1 : sbuf.st_rdev;
|
||||
}
|
||||
|
||||
/* find m in a[] assuming a is sorted into ascending order */
|
||||
/* in-line linear search placeholder until more majors warrant binary search */
|
||||
static __inline__ int lookup(dev_t m, dev_t* a, int n) {
|
||||
int k;
|
||||
for(k=0; k < n && a[k] != m; k++)
|
||||
;
|
||||
return (k < n) ? k : -1;
|
||||
}
|
||||
|
||||
/* Device Number -> Name Map
|
||||
one-to-many: first directory order match in DEVDIR, "" on failed match.
|
||||
*/
|
||||
char* dev_to_name(dev_t num) {
|
||||
static char rval[DEV_NAME_MAX+1];
|
||||
dev_t m = MAJOR(num), n = MINOR(num), tmp;
|
||||
if (!devtab_initialized && !init_devtab())
|
||||
return "";
|
||||
if ((tmp = lookup(m, major, Nmajor)) == (dev_t)-1)
|
||||
return "";
|
||||
strncpy(rval, TAB(tmp,n), DEV_NAME_MAX);
|
||||
rval[DEV_NAME_MAX] = '\0';
|
||||
return rval;
|
||||
}
|
||||
|
||||
static int dev_to_devtab(int);
|
||||
|
||||
static int init_devtab(void) {
|
||||
static struct stat sbuf, lbuf;
|
||||
static int fd;
|
||||
char **fmt, path[64], *HOME = getenv("HOME") ? getenv("HOME") : "";
|
||||
for (fmt = devtab_paths; *fmt; fmt++) {
|
||||
snprintf(path, sizeof path, *fmt, HOME);
|
||||
lbuf.st_ino = 0; /* initialize for test later */
|
||||
if (lstat(path, &lbuf) >= 0 && S_ISLNK(lbuf.st_mode))
|
||||
/* don't follow symlinks */
|
||||
continue;
|
||||
if ( (fd = open(path, O_RDONLY)) < 0 /* open DEVTAB file */
|
||||
|| fstat(fd, &sbuf) < 0 /* fstat it */
|
||||
|| (lbuf.st_ino && (sbuf.st_ino != lbuf.st_ino)) /* race */
|
||||
|| sbuf.st_nlink > 1 /* hardlink attack */
|
||||
|| sbuf.st_size != Ndevtab /* make sure it's the right size */
|
||||
|| (devtab = mmap(0, Ndevtab, PROT_READ, MAP_SHARED, fd, 0)) == (caddr_t) -1
|
||||
|| close(fd) == -1)
|
||||
{ /* could not open for read, attempt to fix/create */
|
||||
int oumsk = umask(0);
|
||||
if (devtab)
|
||||
munmap(devtab, Ndevtab);
|
||||
if (((fd = open(path, O_RDWR|O_TRUNC|O_CREAT, DEVINITIALMODE)) == -1 &&
|
||||
(unlink(path), fd = open(path, O_RDWR|O_TRUNC|O_CREAT, DEVINITIALMODE)) == -1)
|
||||
|| !dev_to_devtab(fd)) {
|
||||
close(fd); /* either both opens failed or the constructor failed */
|
||||
unlink(path); /* in case we created but could not fill a file */
|
||||
umask(oumsk);
|
||||
continue;
|
||||
} else {
|
||||
devtab_initialized = 1;
|
||||
close(fd);
|
||||
umask(oumsk);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
return devtab_initialized = 1;
|
||||
}
|
||||
return devtab_initialized;
|
||||
}
|
||||
|
||||
/* stat every file in DEVDIR saving its basename in devtab[] if it has
|
||||
a MAJOR(st_rdev) in our list of majors. return 0 on error otherwise 1. */
|
||||
static int dev_to_devtab(int fd) {
|
||||
static struct stat sbuf;
|
||||
int i;
|
||||
dev_t m;
|
||||
struct dirent* ent;
|
||||
DIR* dev;
|
||||
|
||||
if (!(dev = opendir(DEVDIR))) {
|
||||
fprintf(stderr, "%s: %s\nCannot generate device number -> name mapping.\n",
|
||||
DEVDIR, sys_errlist[errno]);
|
||||
return 0;
|
||||
}
|
||||
if (!(devtab = malloc(Ndevtab))) {
|
||||
fprintf(stderr, "%s: could not allocate memory\n", sys_errlist[errno]);
|
||||
return 0;
|
||||
}
|
||||
memset((void*)devtab, 0, Ndevtab);
|
||||
while ((ent = readdir(dev))) { /* loop over all dirents in DEVDIR */
|
||||
if (lstat(name_to_path(ent->d_name), &sbuf) < 0
|
||||
|| !S_ISCHR(sbuf.st_mode)) /* only look for char special devs */
|
||||
continue; /* due to overloading of majors */
|
||||
m = MAJOR(sbuf.st_rdev); /* copy name to appropriate spot */
|
||||
if ((i = lookup(m, major, Nmajor)) != -1)
|
||||
strncpy(TAB(i,MINOR(sbuf.st_rdev)), ent->d_name, DEV_NAME_MAX);
|
||||
}
|
||||
closedir(dev);
|
||||
if (write(fd, devtab, Ndevtab) != Ndevtab) /* probably no disk space */
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static char path[DEV_MAX_PATH];
|
||||
|
||||
static char* name_to_path(char* name) {
|
||||
static char* Path;
|
||||
if (!Path) {
|
||||
strcpy(path, DEVDIR); /* copy DEVDIR */
|
||||
path[sizeof(DEVDIR) - 1] = '/'; /* change NUL to '/' */
|
||||
Path = path + sizeof(DEVDIR); /* put Path at start of basename */
|
||||
}
|
||||
strncpy(Path, name, DEV_MAX_PATH - sizeof(DEVDIR));
|
||||
return path;
|
||||
}
|
||||
|
||||
#ifdef TEST_DEVNAME
|
||||
int main(int argc, char** argv) { /* usage: cmd [<major> <minor>|<name>] */
|
||||
dev_t tmp;
|
||||
if (argc < 2) {
|
||||
printf("%s: [ maj min... | name ... ]\n", argv[0]);
|
||||
return 0;
|
||||
}
|
||||
if (argv[1][0] >= '0' && argv[1][0] <= '9')
|
||||
for(argv++ ; argv[0] && argv[1] ; argv+=2)
|
||||
printf("%s\n", dev_to_name(MKDEV( atoi(argv[0]), atoi(argv[1]) )));
|
||||
else
|
||||
for(argv++ ; *argv ; argv++) {
|
||||
tmp = name_to_dev(*argv);
|
||||
printf("%d, %d\n", MAJOR(tmp), MINOR(tmp));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
Using this program on over 700 files in /dev to perform number->name resolution
|
||||
took well under 300 microsecs per device number pair on a Pentium 90. It is
|
||||
somewhat tough to time because once the 3 pages have been mapped in, the time is
|
||||
almost zero. For things like top, this method may even be faster in the long
|
||||
run. Those interested can gprof it for me. This system has the virtue of being
|
||||
nearly perfectly adaptable to individual systems, self updating when /dev
|
||||
changes and pretty darn fast when it hasn't. It will be slow for users without
|
||||
perms to change the psdevtab file, though. So this is what I decided was
|
||||
reasonable. If the process does not have perms to create or update
|
||||
/etc/psdevtab and it is out of date, we try /tmp/psdevtab. If /tmp/psdevtab is
|
||||
either out of date or unreadable (malicious user creates it and chmods it),
|
||||
$HOME/.psdevtab is used. This secondarily allows for per-user naming of ttys,
|
||||
but is really so that at most one user sees only a single delay per /dev
|
||||
modification.
|
||||
|
||||
To do the timings I did something like this with zsh:
|
||||
a=(`ls -l *(%^@/) | awk '{print $5 $6}' | sed 's/,/ /'`);
|
||||
time ./test $a
|
||||
|
||||
Finally, for lack of a better file for these to be in, I have collected the
|
||||
old algorithmic device number <-> device name mappings.
|
||||
Let m = major device number and n = minor device number satisfy:
|
||||
devno = m<<8 + n , m = devno>>8 , n = devno && 0x00FF, and let
|
||||
char L[32]="pqrstuvwxyzABCDEFGHIJKLMNOPQRSTU", H[16]="01234567890abcdef";
|
||||
DEVICE NUMBERS SPECIAL FILE NAMES
|
||||
OLD SYSTEM (64 pseudoterminal devices):
|
||||
m=4:
|
||||
n=0..63: tty + itoa_dec(n+1)
|
||||
n=128..191: pty + L[(n-128)/16] + H[(n-128)%16]
|
||||
n=192..255: tty + L[(n-192)/16] + H[(n-192)%16]
|
||||
NEW SYSTEM (256/512 pseudoterminal devices):
|
||||
m=2, n: pty + L[n/16] + H[n%16]
|
||||
m=3, n: tty + L[n/16] + H[n%16]
|
||||
m=4, n: tty + itoa_dec(n+1)
|
||||
m=49, n: pty + L[16+n/16] + H[n%16]
|
||||
m=50, n: tty + L[16+n/16] + H[n%16]
|
||||
(THE SAME IN EITHER SYSTEM)
|
||||
CALL-UNIX AND CONTROLLING TERMINAL DEVICES
|
||||
m=5:
|
||||
n=0: tty
|
||||
n=64..128: cua + {'0' + (n-64)}
|
||||
CYCLADES MULTIPORT:
|
||||
m=19, n: ttyC + itoa_hex(n)
|
||||
m=20, n: cub + itoa_hex(n) */
|
||||
|
||||
/* Re-implementation of old interface with the new generic functions. */
|
||||
|
||||
/* This does exactly the same thing as name_to_dev only now a full "ttyXX"
|
||||
specification will work as well.
|
||||
*/
|
||||
int tty_to_dev(char *tty) {
|
||||
static char pref_name_1[32] = "tty", *pnam1 = pref_name_1 + 3,
|
||||
pref_name_2[32] = "cu", *pnam2 = pref_name_2 + 2;
|
||||
dev_t num;
|
||||
if ((num = name_to_dev(tty)) != (dev_t) -1) /* try tty straight up */
|
||||
return num;
|
||||
strncpy(pnam1, tty, 32 - 3); /* try with "tty" prepended */
|
||||
if ((num = name_to_dev(pref_name_1)) != (dev_t) -1)
|
||||
return num;
|
||||
strncpy(pnam2, tty, 32 - 2); /* try with "cu" prepended */
|
||||
if ((num = name_to_dev(pref_name_2)) != (dev_t) -1)
|
||||
return num;
|
||||
return -1; /* no match */
|
||||
}
|
||||
|
||||
/* new abstraction that can maybe be generalized a little better. */
|
||||
char* abbrev_of_tty(char *tty) {
|
||||
static char temp[32]; /* return buf: good only until next call */
|
||||
char *pos = strpbrk(tty, "yu"); /* end of (presumed) prefices: tty*, cu* */
|
||||
temp[0] = 0;
|
||||
if (tty && tty[0] && pos && pos[0] && pos[1])
|
||||
sprintf(temp, "%*.*s", 3, 3, pos + 1);
|
||||
else
|
||||
strncpy(temp, " ? ", 31);
|
||||
return temp;
|
||||
}
|
||||
|
||||
/* Do in-place modification of the 4-buffer `tty' based upon `dev' */
|
||||
void dev_to_tty(char *tty, int dev) {
|
||||
char* new = abbrev_of_tty(dev_to_name(dev));
|
||||
strncpy(tty, new, 4);
|
||||
}
|
10
libproc/devname.h
Normal file
10
libproc/devname.h
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
dev_t name_to_dev(char* name);
|
||||
char* dev_to_name(dev_t num);
|
||||
|
||||
dev_t tty_to_dev(char *tty);
|
||||
void dev_to_tty(char *tty, int dev);
|
||||
|
||||
char* abbrev_of_tty(char *tty);
|
252
libproc/ksym.c
Normal file
252
libproc/ksym.c
Normal file
@@ -0,0 +1,252 @@
|
||||
/* kernel address -> symbol with next lower address. Charles Blake, 1996.
|
||||
* Written to obviate the need for psdatabase initialization based upon kernel
|
||||
* binary formats, etc.
|
||||
*
|
||||
* The basic algorithm is an approximate (intervals split vaguely 50-50) binary
|
||||
* search taking advantage of the fact the System.map is already sorted in
|
||||
* ascending order by the kernel makefile. It needs to assume an average symbol
|
||||
* record length to avoid scanning the entire symbol table, but in practice the
|
||||
* search time does not seem to be especially sensitive to this choice.
|
||||
*
|
||||
* The search could be an exact binary search if the lines of System.map were
|
||||
* padded with blanks to the right. awk '{printf "%8s%2s %-21.21s\n",$1,$2,$3}'
|
||||
* would do the trick for this but either makes the file large or truncates
|
||||
* symbols. The approximate method seems to be plenty fast enough, costing
|
||||
* only about as much as one extra fstat() or so per process.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/utsname.h>
|
||||
#include "proc/psdata.h"
|
||||
#include "proc/ps.h"
|
||||
#include "proc/version.h"
|
||||
|
||||
#define MAX_ADDR_SZ 32
|
||||
static char *sysmap, *sysmap_last, sysmap_fmt[10];
|
||||
static int sysmap_len, sysmap_mean = 32, sysmap_addrsz;
|
||||
|
||||
/* scan backward in a string no further than address beg looking for c */
|
||||
static char *strchrrev(char *a, char *beg, char c) {
|
||||
if (a)
|
||||
while (--a > beg && *a != c) ;
|
||||
return a;
|
||||
}
|
||||
|
||||
/* return ptr to the beg of approximately the i-th record */
|
||||
static char *addr_str(int i) {
|
||||
char *guess = sysmap + sysmap_mean * i;
|
||||
if (!i) return sysmap;
|
||||
if (guess - sysmap > sysmap_len - 2) guess = sysmap + sysmap_len - 2;
|
||||
for ( ; *guess != '\n' && guess > sysmap; guess--)
|
||||
;
|
||||
return guess + 1;
|
||||
|
||||
}
|
||||
|
||||
/* return ptr to symbol string (\n terminated) given beg of record ptr */
|
||||
static char *sym_put(char *buf, int len, char *addrptr) {
|
||||
char *s;
|
||||
while (*addrptr++ != ' ') ;
|
||||
while (*addrptr++ != ' ') ;
|
||||
strncpy(buf, addrptr, len);
|
||||
for (s = buf; s < buf + len; s++)
|
||||
if (*s == '\n')
|
||||
*s = '\0';
|
||||
buf[len - 1] = '\0';
|
||||
return buf;
|
||||
}
|
||||
|
||||
/* Try to open and mmap a single symbol table file and initialize globals */
|
||||
int sysmap_mmap(char *path) {
|
||||
int fd;
|
||||
struct stat sbuf;
|
||||
char *p;
|
||||
if (sysmap) /* do nothing if already mapped */
|
||||
return 1;
|
||||
if ((fd = open(path, O_RDONLY)) < 0
|
||||
|| fstat(fd, &sbuf) < 0
|
||||
|| (sysmap = mmap(0, sbuf.st_size,
|
||||
PROT_READ, MAP_SHARED,
|
||||
fd, 0)) == (caddr_t) -1)
|
||||
{
|
||||
close(fd);
|
||||
sysmap = NULL;
|
||||
return 0;
|
||||
}
|
||||
sysmap_len = sbuf.st_size;
|
||||
sysmap_last = strchrrev(sysmap + sysmap_len - 2, sysmap, '\n') + 1;
|
||||
|
||||
/* Now check first line of sysmap for hex numbers in first column. Note:
|
||||
0x/0X prefixes are disallowed, but easily addable. Capitalization is
|
||||
irrelevant because strncasecmp(3) is used below instead of strncmp. */
|
||||
for (p = sysmap; *p != ' '
|
||||
&& ((*p >= '0' && *p <= '9') ||
|
||||
(*p >= 'A' && *p <= 'F') ||
|
||||
(*p >= 'a' && *p <= 'f'))
|
||||
&& p < sysmap + MAX_ADDR_SZ;
|
||||
p++) /* no-op */ ;
|
||||
if (*p != ' ') { /* uh-oh: cannot understand format */
|
||||
fprintf(stderr, "warning: %s not parseable as a System.map.\n", path);
|
||||
munmap(sysmap, sysmap_len);
|
||||
sysmap = NULL;
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
sysmap_addrsz = p - sysmap;
|
||||
snprintf(sysmap_fmt, sizeof sysmap_fmt, "%%0%dlx", sysmap_addrsz);
|
||||
close(fd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* kernel address -> name resolver.
|
||||
returned value is only good until the next call to the function.
|
||||
*/
|
||||
char *sysmap_symbol(unsigned long address) {
|
||||
static char rval[128], *pc, addr[MAX_ADDR_SZ];
|
||||
int i, p, n = sysmap_len / (double)sysmap_mean;
|
||||
|
||||
sprintf(addr, sysmap_fmt, address);
|
||||
p = 0; pc = sysmap;
|
||||
while (n) {
|
||||
i = p + (n >> 1);
|
||||
if (strncasecmp(addr, pc = addr_str(i), sysmap_addrsz) > 0)
|
||||
p = i + 1;
|
||||
n >>= 1;
|
||||
}
|
||||
if (pc == sysmap_last) /* scan forward but not past end */
|
||||
return sym_put(rval, sizeof rval, pc);
|
||||
while (strncasecmp(addr, pc, sysmap_addrsz) > 0)
|
||||
pc = strchr(pc, '\n') + 1;
|
||||
if (pc == sysmap) /* scan backward but not past beg */
|
||||
return sym_put(rval, sizeof rval, pc);
|
||||
while (strncasecmp(addr, pc, sysmap_addrsz) < 0)
|
||||
pc = strchrrev(pc - 1, sysmap, '\n') + 1;
|
||||
return sym_put(rval, sizeof rval, pc);
|
||||
}
|
||||
|
||||
/* extern struct nlist *namelist; */
|
||||
struct tbl_s vars, fncs;
|
||||
struct psdb_hdr db_hdr;
|
||||
int psdb = -1;
|
||||
|
||||
int open_psdb(void) {
|
||||
static char *sysmap_paths[] = {
|
||||
"/boot/System.map-%s",
|
||||
"/boot/System.map",
|
||||
"/lib/modules/%s/System.map",
|
||||
NULL
|
||||
};
|
||||
static char *psdb_paths[] = {
|
||||
"/etc/psdatabase",
|
||||
"/boot/psdatabase-%s",
|
||||
"/boot/psdatabase",
|
||||
"/lib/modules/%s/psdatabase",
|
||||
NULL
|
||||
};
|
||||
char **fmt, *env, path[64];
|
||||
struct utsname uts;
|
||||
uname(&uts);
|
||||
if ((env = getenv("PS_SYSMAP")) && sysmap_mmap(env))
|
||||
return 0;
|
||||
for (fmt = sysmap_paths; *fmt; fmt++) {
|
||||
snprintf(path, sizeof path, *fmt, uts.release);
|
||||
if (sysmap_mmap(path))
|
||||
return 0;
|
||||
}
|
||||
for (fmt = psdb_paths; *fmt; fmt++) {
|
||||
snprintf(path, sizeof path, *fmt, uts.release);
|
||||
if ((psdb = open(path, O_RDONLY)) != -1 &&
|
||||
read(psdb, (char*)&db_hdr, sizeof db_hdr) == sizeof db_hdr &&
|
||||
strncmp(db_hdr.magic, procps_version, sizeof(db_hdr.magic)) == 0)
|
||||
/* && version_cmp(kernel,psdatabase) */
|
||||
return 0;
|
||||
if (psdb != -1)
|
||||
fprintf(stderr,
|
||||
"psdatabase has magic no. %*s instead of %*s\n",
|
||||
(int) sizeof db_hdr.magic, db_hdr.magic,
|
||||
(int) sizeof db_hdr.magic, procps_version);
|
||||
close(psdb);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void close_psdb(void) {
|
||||
if (sysmap)
|
||||
munmap(sysmap, sysmap_len);
|
||||
else if (psdb != -1)
|
||||
close(psdb);
|
||||
psdb = -1;
|
||||
sysmap = NULL;
|
||||
}
|
||||
|
||||
int read_tbl(struct dbtbl_s *dbtbl, struct tbl_s *tbl) {
|
||||
lseek(psdb, dbtbl->off, SEEK_SET);
|
||||
tbl->tbl = (struct sym_s *) xmalloc(dbtbl->size);
|
||||
if (read(psdb, (char *) tbl->tbl, dbtbl->size) != dbtbl->size) {
|
||||
perror(PSDATABASE);
|
||||
exit(1);
|
||||
}
|
||||
tbl->nsym = dbtbl->nsym;
|
||||
tbl->strings = (char *) (tbl->tbl + tbl->nsym);
|
||||
return 0;
|
||||
}
|
||||
|
||||
char * find_func(unsigned long address) {
|
||||
int n;
|
||||
struct sym_s *p;
|
||||
char *s;
|
||||
|
||||
if (sysmap)
|
||||
return sysmap_symbol(address);
|
||||
if (psdb == -1)
|
||||
return "(no psdb)";
|
||||
if (fncs.tbl == NULL)
|
||||
read_tbl(&db_hdr.fncs, &fncs);
|
||||
p = fncs.tbl;
|
||||
n = fncs.nsym;
|
||||
while (n) {
|
||||
int i = n / 2;
|
||||
if (p[i].addr < address) {
|
||||
p = &p[i+1];
|
||||
if (p->addr > address) {
|
||||
--p;
|
||||
break;
|
||||
}
|
||||
--n;
|
||||
}
|
||||
n /= 2;
|
||||
}
|
||||
s = p->name + fncs.strings;
|
||||
return *s=='_' ? s+1 : s;
|
||||
}
|
||||
|
||||
char * wchan(unsigned long address) {
|
||||
static char zero = 0;
|
||||
char *p;
|
||||
|
||||
if (address) {
|
||||
p = find_func(address);
|
||||
if (strncmp(p, "sys_", 4) == 0)
|
||||
p += 4;
|
||||
while (*p == '_' && *p)
|
||||
++p;
|
||||
} else /* 0 address means not in kernel space */
|
||||
p = &zero;
|
||||
return p;
|
||||
}
|
||||
|
||||
#ifdef SYSMAP_TEST
|
||||
int main(int ac, char** av) {
|
||||
if (ac < 3) {printf("%s System.map lines hexaddr ...\n",av[0]); return 1;}
|
||||
if (!sysmap_mmap(av[1])) return 1;
|
||||
if ((sysmap_mean = atoi(av[2])) <= 0) return 1;
|
||||
for (av += 3; *av; av++)
|
||||
printf("%s %s\n", *av, sysmap_symbol(strtoul(*av, NULL, 16)));
|
||||
return 0;
|
||||
}
|
||||
#endif
|
52
libproc/output.c
Normal file
52
libproc/output.c
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
Some output conversion routines for libproc
|
||||
Copyright (C) 1996, Charles Blake. See COPYING for details.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
/* output a string, converting unprintables to octal as we go, and stopping after
|
||||
processing max chars of output (accounting for expansion due to octal rep).
|
||||
*/
|
||||
unsigned print_str(FILE* file, char *s, unsigned max) {
|
||||
int i;
|
||||
for (i=0; s[i] && i < max; i++)
|
||||
if (isprint(s[i]) || s[i] == ' ')
|
||||
fputc(s[i], file);
|
||||
else {
|
||||
if (max - i > 3) {
|
||||
fprintf(file, "\\%03o", s[i]);
|
||||
i += 3; /* 4 printed, but i counts one */
|
||||
} else
|
||||
return max - i;
|
||||
}
|
||||
return max - i;
|
||||
}
|
||||
|
||||
/* output an argv style NULL-terminated string list, converting unprintables
|
||||
to octal as we go, separating items of the list by 'sep' and stopping after
|
||||
processing max chars of output (accounting for expansion due to octal rep).
|
||||
*/
|
||||
unsigned print_strlist(FILE* file, char **strs, char* sep, unsigned max) {
|
||||
int i, n, seplen = strlen(sep);
|
||||
for (n=0; *strs && n < max; strs++) {
|
||||
for (i=0; strs[0][i] && n+i < max; i++)
|
||||
if (isprint(strs[0][i]) || strs[0][i] == ' ')
|
||||
fputc(strs[0][i], file);
|
||||
else {
|
||||
if (max-(n+i) > 3) {
|
||||
fprintf(file, "\\%03o", strs[0][i]);
|
||||
n += 3; /* 4 printed, but i counts one */
|
||||
} else
|
||||
return max - n;
|
||||
}
|
||||
n += i;
|
||||
if (n + seplen < max) {
|
||||
fputs(sep, file);
|
||||
n += seplen;
|
||||
} else
|
||||
return max - n;
|
||||
}
|
||||
return max - n;
|
||||
}
|
30
libproc/ps.h
Normal file
30
libproc/ps.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/* The shadow of the original with only common prototypes now. */
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
/* get definition of HZ */
|
||||
#include <asm/param.h>
|
||||
|
||||
/* get page info */
|
||||
#include <asm/page.h>
|
||||
|
||||
char *wchan(unsigned long);
|
||||
char *find_func(unsigned long address);
|
||||
void *xcalloc(void *pointer, int size);
|
||||
void *xmalloc(unsigned int size);
|
||||
void *xrealloc(void *oldp, unsigned int size);
|
||||
|
||||
int mult_lvl_cmp(void* a, void* b);
|
||||
int node_mult_lvl_cmp(void* a, void* b);
|
||||
void dump_keys(void);
|
||||
|
||||
char *user_from_uid(int uid);
|
||||
|
||||
int open_sysmap(void);
|
||||
int open_psdb(void);
|
||||
void close_psdb(void);
|
||||
void make_fnctbl(void);
|
||||
|
||||
unsigned print_str (FILE* file, char *s, unsigned max);
|
||||
unsigned print_strlist(FILE* file, char **strs, char* sep, unsigned max);
|
||||
unsigned snprint_strlist(char *buf, int max, char **strs, char *sep);
|
103
libproc/psdata.h
Normal file
103
libproc/psdata.h
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* psdata.h
|
||||
*
|
||||
* Jeffrey A. Uphoff <juphoff@nrao.edu>, 1995, 1996.
|
||||
* Michael K. Johnson.
|
||||
* Bruno Lankester.
|
||||
* (And others I'm sure...)
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Capabilities are for reading system images and producing maps for
|
||||
* WCHAN output.
|
||||
*
|
||||
* AOUT_CAPABLE and ELF_CAPABLE may have 32-bit word size limitations
|
||||
* and have only been tested by the maintainer on Intel systems. They
|
||||
* are retained in the source tree in case they are useful; they are
|
||||
* intended to be generally deprecated.
|
||||
*
|
||||
* BFD_CAPABLE should work on any system with BFD.
|
||||
*
|
||||
* Set the capabilities in the top-level Makefile.
|
||||
*/
|
||||
|
||||
#if defined(ELF_CAPABLE)
|
||||
# define ELF_OBJECT 1
|
||||
# define ELF_FUNC 2
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <linux/utsname.h>
|
||||
|
||||
#define PSDATABASE "/etc/psdatabase"
|
||||
|
||||
struct dbtbl_s {
|
||||
off_t off; /* offset in psdatabase */
|
||||
int nsym; /* # symbols */
|
||||
int size; /* size of array + strings */
|
||||
};
|
||||
|
||||
/*
|
||||
* header of psdatabase
|
||||
*/
|
||||
struct psdb_hdr {
|
||||
/* Current procps package version goes here. kmemps doesn't like this. */
|
||||
char magic[32];
|
||||
/*
|
||||
* These are not functional--they only reside in the database for
|
||||
* informational purposes (i.e. if you want to look at the raw
|
||||
* database and see what kernel it's for).
|
||||
*/
|
||||
char uts_release[__NEW_UTS_LEN];
|
||||
char uts_version[__NEW_UTS_LEN];
|
||||
/*
|
||||
* Again, this is not functional, it's just there for information: it
|
||||
* shows the path to the uncompressed kernel image that was used to
|
||||
* generate this database.
|
||||
*/
|
||||
char sys_path[128];
|
||||
/* List of all functions. */
|
||||
struct dbtbl_s fncs;
|
||||
/*
|
||||
* This is currently only used to look up system_utsname while
|
||||
* psupdate is building the database--it really should be phased out!
|
||||
*/
|
||||
/* List of all bss and data symbols. */
|
||||
struct dbtbl_s vars;
|
||||
/*
|
||||
* The list of tty names that kmemps likes/uses in no longer present
|
||||
* in the procps psdatabase--it was never being built by procps'
|
||||
* psupdate anyway, so I removed the entry from the database header.
|
||||
*/
|
||||
};
|
||||
|
||||
struct sym_s {
|
||||
unsigned long addr; /* core address in kernel */
|
||||
int name; /* offset from strings ptr */
|
||||
};
|
||||
|
||||
struct tbl_s {
|
||||
struct sym_s *tbl;
|
||||
int nsym;
|
||||
char *strings; /* ptr to start of strings */
|
||||
};
|
||||
|
||||
extern struct psdb_hdr db_hdr;
|
||||
extern struct tbl_s fncs, vars;
|
||||
|
||||
int read_tbl (struct dbtbl_s *, struct tbl_s *);
|
||||
void *xmalloc (unsigned int);
|
||||
void *xrealloc (void *, unsigned int);
|
||||
|
||||
#define MLSEEK(FD, WHERE, WHENCE, ERROR)\
|
||||
if (lseek ((FD), (WHERE), (WHENCE)) == -1) {\
|
||||
perror ((ERROR));\
|
||||
exit (errno);\
|
||||
}
|
||||
|
||||
#define MREAD(FD, WHAT, SIZE, ERROR)\
|
||||
if (read ((FD), (WHAT), (SIZE)) != (SIZE)) {\
|
||||
perror ((ERROR));\
|
||||
exit (errno);\
|
||||
}
|
37
libproc/pwcache.c
Normal file
37
libproc/pwcache.c
Normal file
@@ -0,0 +1,37 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <pwd.h>
|
||||
#include "proc/ps.h"
|
||||
|
||||
#define HASHSIZE 16 /* power of 2 */
|
||||
#define HASH(x) ((x) & (HASHSIZE - 1))
|
||||
|
||||
|
||||
static struct pwbuf {
|
||||
int uid;
|
||||
char name[12];
|
||||
struct pwbuf *next;
|
||||
} *pwhash[HASHSIZE];
|
||||
|
||||
char *user_from_uid(int uid)
|
||||
{
|
||||
struct pwbuf **p;
|
||||
struct passwd *pw;
|
||||
|
||||
p = &pwhash[HASH(uid)];
|
||||
while (*p) {
|
||||
if ((*p)->uid == uid)
|
||||
return((*p)->name);
|
||||
p = &(*p)->next;
|
||||
}
|
||||
*p = (struct pwbuf *) xmalloc(sizeof(struct pwbuf));
|
||||
(*p)->uid = uid;
|
||||
if ((pw = getpwuid(uid)) == NULL)
|
||||
sprintf((*p)->name, "#%d", uid);
|
||||
else
|
||||
sprintf((*p)->name, "%-.8s", pw->pw_name);
|
||||
(*p)->next = NULL;
|
||||
return((*p)->name);
|
||||
}
|
||||
|
||||
void bad_user_access_length() { }
|
395
libproc/readproc.c
Normal file
395
libproc/readproc.c
Normal file
@@ -0,0 +1,395 @@
|
||||
/*
|
||||
* New Interface to Process Table -- PROCTAB Stream (a la Directory streams)
|
||||
* Copyright(C) 1996. Charles L. Blake.
|
||||
*/
|
||||
#include "proc/version.h"
|
||||
#include "proc/readproc.h"
|
||||
#include "proc/devname.h"
|
||||
#include "proc/ps.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/dir.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#define Do(x) (flags & PROC_ ## x) /* convenient shorthand */
|
||||
|
||||
/* initiate a process table scan
|
||||
*/
|
||||
PROCTAB* openproc(int flags, ...) {
|
||||
va_list ap;
|
||||
PROCTAB* PT = xmalloc(sizeof(PROCTAB));
|
||||
|
||||
if (!Do(PID) && !(PT->procfs = opendir("/proc")))
|
||||
return NULL;
|
||||
PT->flags = flags;
|
||||
va_start(ap, flags); /* Init args list */
|
||||
if (Do(PID))
|
||||
PT->pids = va_arg(ap, pid_t*);
|
||||
else if (Do(TTY))
|
||||
PT->ttys = va_arg(ap, dev_t*);
|
||||
else if (Do(UID)) {
|
||||
PT->uids = va_arg(ap, uid_t*);
|
||||
PT->nuid = va_arg(ap, int);
|
||||
} else if (Do(STAT))
|
||||
PT->stats = va_arg(ap, char*);
|
||||
va_end(ap); /* Clean up args list */
|
||||
if (Do(ANYTTY) && Do(TTY))
|
||||
PT->flags = PT->flags & ~PROC_TTY; /* turn off TTY flag */
|
||||
return PT;
|
||||
}
|
||||
|
||||
/* terminate a process table scan
|
||||
*/
|
||||
void closeproc(PROCTAB* PT) {
|
||||
if (PT->procfs) closedir(PT->procfs);
|
||||
if (PT) free(PT);
|
||||
}
|
||||
|
||||
/* deallocate the space allocated by readproc if the passed rbuf was NULL
|
||||
*/
|
||||
void freeproc(proc_t* p) {
|
||||
if (!p) /* in case p is NULL */
|
||||
return;
|
||||
/* ptrs are after strings to avoid copying memory when building them. */
|
||||
/* so free is called on the address of the address of strvec[0]. */
|
||||
if (p->cmdline)
|
||||
free((void*)*p->cmdline);
|
||||
if (p->environ)
|
||||
free((void*)*p->environ);
|
||||
free(p);
|
||||
}
|
||||
|
||||
/* stat2proc() makes sure it can handle arbitrary executable file basenames
|
||||
for `cmd', i.e. those with embedded whitespace or embedded ')'s. Such names
|
||||
confuse %s (see scanf(3)), so the string is split and %39c is used instead.
|
||||
(except for embedded ')' "(%[^)]c)" would work.
|
||||
*/
|
||||
void stat2proc(char* S, proc_t* P) {
|
||||
char* tmp = strrchr(S, ')'); /* split into "PID (cmd" and "<rest>" */
|
||||
*tmp = '\0'; /* replace trailing ')' with NUL */
|
||||
/* parse these two strings separately, skipping the leading "(". */
|
||||
memset(P->cmd, 0, sizeof P->cmd); /* clear even though *P xcalloc'd ?! */
|
||||
sscanf(S, "%d (%39c", &P->pid, P->cmd);
|
||||
sscanf(tmp + 2, /* skip space after ')' too */
|
||||
"%c %d %d %d %d %d %lu %lu %lu %lu %lu %ld %ld %ld %ld %d "
|
||||
"%d %lu %lu %ld %lu %lu %lu %lu %lu %lu %lu %lu %LX %LX %LX %LX %lu",
|
||||
&P->state, &P->ppid, &P->pgrp, &P->session, &P->tty, &P->tpgid,
|
||||
&P->flags, &P->min_flt, &P->cmin_flt, &P->maj_flt, &P->cmaj_flt,
|
||||
&P->utime, &P->stime, &P->cutime, &P->cstime, &P->priority, &P->nice,
|
||||
&P->timeout, &P->it_real_value, &P->start_time, &P->vsize, &P->rss,
|
||||
&P->rss_rlim, &P->start_code, &P->end_code, &P->start_stack,
|
||||
&P->kstk_esp, &P->kstk_eip, &P->signal, &P->blocked, &P->sigignore,
|
||||
&P->sigcatch, &P->wchan);
|
||||
if (P->tty == 0)
|
||||
P->tty = -1; /* the old notty val, update elsewhere bef. moving to 0 */
|
||||
if (linux_version_code < LINUX_VERSION(1,3,39)) {
|
||||
P->priority = 2*15 - P->priority; /* map old meanings to new */
|
||||
P->nice = 15 - P->nice;
|
||||
}
|
||||
if (linux_version_code < LINUX_VERSION(1,1,30) && P->tty != -1)
|
||||
P->tty = 4*0x100 + P->tty; /* when tty wasn't full devno */
|
||||
}
|
||||
|
||||
void statm2proc(char* s, proc_t* P) {
|
||||
sscanf(s, "%ld %ld %ld %ld %ld %ld %ld",
|
||||
&P->size, &P->resident, &P->share,
|
||||
&P->trs, &P->lrs, &P->drs, &P->dt);
|
||||
}
|
||||
|
||||
void nulls2sep(char* str, int len, char sep) {
|
||||
int i;
|
||||
for (i = 0; i < len; i++)
|
||||
if (str[i] == 0)
|
||||
str[i] = sep;
|
||||
}
|
||||
|
||||
int file2str(char *directory, char *what, char *ret, int cap) {
|
||||
static char filename[80];
|
||||
int fd, num_read;
|
||||
|
||||
sprintf(filename, "%s/%s", directory, what);
|
||||
if ( (fd = open(filename, O_RDONLY, 0)) == -1 ) return -1;
|
||||
if ( (num_read = read(fd, ret, cap - 1)) <= 0 ) return -1;
|
||||
ret[num_read] = 0;
|
||||
close(fd);
|
||||
return num_read;
|
||||
}
|
||||
|
||||
char** file2strvec(char* directory, char* what) {
|
||||
char buf[2048]; /* read buf bytes at a time */
|
||||
char *p, *rbuf = 0, *endbuf, **q, **ret;
|
||||
int fd, tot = 0, n, c, end_of_file = 0;
|
||||
int align;
|
||||
|
||||
sprintf(buf, "%s/%s", directory, what);
|
||||
if ( (fd = open(buf, O_RDONLY, 0) ) == -1 ) return NULL;
|
||||
|
||||
/* read whole file into a memory buffer, allocating as we go */
|
||||
while ((n = read(fd, buf, sizeof buf - 1)) > 0) {
|
||||
if (n < sizeof buf - 1)
|
||||
end_of_file = 1;
|
||||
if (n == 0 && rbuf == 0)
|
||||
return NULL; /* process died between our open and read */
|
||||
if (n < 0) {
|
||||
if (rbuf)
|
||||
free(rbuf);
|
||||
return NULL; /* read error */
|
||||
}
|
||||
if (end_of_file && buf[n-1]) /* last read char not null */
|
||||
buf[n++] = '\0'; /* so append null-terminator */
|
||||
rbuf = xrealloc(rbuf, tot + n); /* allocate more memory */
|
||||
memcpy(rbuf + tot, buf, n); /* copy buffer into it */
|
||||
tot += n; /* increment total byte ctr */
|
||||
if (end_of_file)
|
||||
break;
|
||||
}
|
||||
close(fd);
|
||||
if (n <= 0 && !end_of_file) {
|
||||
if (rbuf) free(rbuf);
|
||||
return NULL; /* read error */
|
||||
}
|
||||
endbuf = rbuf + tot; /* count space for pointers */
|
||||
align = (sizeof(char*)-1) - ((tot + sizeof(char*)-1) & (sizeof(char*)-1));
|
||||
for (c = 0, p = rbuf; p < endbuf; p++)
|
||||
if (!*p)
|
||||
c += sizeof(char*);
|
||||
c += sizeof(char*); /* one extra for NULL term */
|
||||
|
||||
rbuf = xrealloc(rbuf, tot + c + align); /* make room for ptrs AT END */
|
||||
endbuf = rbuf + tot; /* addr just past data buf */
|
||||
q = ret = (char**) (endbuf+align); /* ==> free(*ret) to dealloc */
|
||||
*q++ = p = rbuf; /* point ptrs to the strings */
|
||||
endbuf--; /* do not traverse final NUL */
|
||||
while (++p < endbuf)
|
||||
if (!*p) /* NUL char implies that */
|
||||
*q++ = p+1; /* next string -> next char */
|
||||
|
||||
*q = 0; /* null ptr list terminator */
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* These are some nice GNU C expression subscope "inline" functions.
|
||||
The can be used with arbitrary types and evaluate their arguments
|
||||
exactly once.
|
||||
*/
|
||||
|
||||
/* Test if item X of type T is present in the 0 terminated list L */
|
||||
# define XinL(T, X, L) ( { \
|
||||
T x = (X), *l = (L); \
|
||||
while (*l && *l != x) l++; \
|
||||
*l == x; \
|
||||
} )
|
||||
|
||||
/* Test if item X of type T is present in the list L of length N */
|
||||
# define XinLN(T, X, L, N) ( { \
|
||||
T x = (X), *l = (L); \
|
||||
int i = 0, n = (N); \
|
||||
while (i < n && l[i] != x) i++; \
|
||||
i < n && l[i] == x; \
|
||||
} )
|
||||
|
||||
/* readproc: return a pointer to a proc_t filled with requested info about the
|
||||
* next process available matching the restriction set. If no more such
|
||||
* processes are available, return a null pointer (boolean false). Use the
|
||||
* passed buffer instead of allocating space if it is non-NULL. */
|
||||
|
||||
/* This is optimized so that if a PID list is given, only those files are
|
||||
* searched for in /proc. If other lists are given in addition to the PID list,
|
||||
* the same logic can follow through as for the no-PID list case. This is
|
||||
* fairly complex, but it does try to not to do any unnecessary work.
|
||||
* Unfortunately, the reverse filtering option in which any PID *except* the
|
||||
* ones listed is pursued.
|
||||
*/
|
||||
#define flags (PT->flags)
|
||||
proc_t* readproc(PROCTAB* PT, proc_t* rbuf) {
|
||||
static struct direct *ent; /* dirent handle */
|
||||
static struct stat sb; /* stat buffer */
|
||||
static char path[32], sbuf[256]; /* bufs for stat,statm */
|
||||
int allocated = 0, matched = 0; /* flags */
|
||||
proc_t *p = NULL;
|
||||
|
||||
/* loop until a proc matching restrictions is found or no more processes */
|
||||
/* I know this could be a while loop -- this way is easier to indent ;-) */
|
||||
next_proc: /* get next PID for consideration */
|
||||
if (Do(PID)) {
|
||||
if (!*PT->pids) /* set to next item in pids */
|
||||
return NULL;
|
||||
sprintf(path, "/proc/%d", *(PT->pids)++);
|
||||
matched = 1;
|
||||
} else { /* get next numeric /proc ent */
|
||||
while ((ent = readdir(PT->procfs)) &&
|
||||
(*ent->d_name < '0' || *ent->d_name > '9'))
|
||||
;
|
||||
if (!ent || !ent->d_name)
|
||||
return NULL;
|
||||
sprintf(path, "/proc/%s", ent->d_name);
|
||||
}
|
||||
if (stat(path, &sb) == -1) /* no such dirent (anymore) */
|
||||
goto next_proc;
|
||||
if (Do(UID) && !XinLN(uid_t, sb.st_uid, PT->uids, PT->nuid))
|
||||
goto next_proc; /* not one of the requested uids */
|
||||
|
||||
if (!allocated) { /* assign mem for return buf */
|
||||
p = rbuf ? rbuf : xcalloc(p, sizeof *p); /* passed buf or alloced mem */
|
||||
allocated = 1; /* remember space is set up */
|
||||
}
|
||||
p->uid = sb.st_uid; /* need a way to get real uid */
|
||||
|
||||
if ((file2str(path, "stat", sbuf, sizeof sbuf)) == -1)
|
||||
goto next_proc; /* error reading /proc/#/stat */
|
||||
stat2proc(sbuf, p); /* parse /proc/#/stat */
|
||||
|
||||
if (!matched && Do(TTY) && !XinL(dev_t, p->tty, PT->ttys))
|
||||
goto next_proc; /* not one of the requested ttys */
|
||||
|
||||
if (!matched && Do(ANYTTY) && p->tty == -1)
|
||||
goto next_proc; /* no controlling terminal */
|
||||
|
||||
if (!matched && Do(STAT) && !strchr(PT->stats,p->state))
|
||||
goto next_proc; /* not one of the requested states */
|
||||
|
||||
if (Do(FILLMEM)) { /* read, parse /proc/#/statm */
|
||||
if ((file2str(path, "statm", sbuf, sizeof sbuf)) != -1 )
|
||||
statm2proc(sbuf, p); /* ignore statm errors here */
|
||||
} /* statm fields just zero */
|
||||
|
||||
/* some number->text resolving which is time consuming */
|
||||
if (Do(FILLTTY))
|
||||
dev_to_tty(p->ttyc, p->tty);
|
||||
if (Do(FILLUSR))
|
||||
strncpy(p->user, user_from_uid(p->uid), sizeof p->user);
|
||||
|
||||
if (Do(FILLCMD)) /* read+parse /proc/#/cmdline */
|
||||
p->cmdline = file2strvec(path, "cmdline");
|
||||
if (Do(FILLENV)) /* read+parse /proc/#/environ */
|
||||
p->environ = file2strvec(path, "environ");
|
||||
|
||||
if (p->state == 'Z') /* fixup cmd for zombies */
|
||||
strncat(p->cmd," <zombie>", sizeof p->cmd);
|
||||
|
||||
return p;
|
||||
}
|
||||
#undef flags
|
||||
|
||||
/* Convenient wrapper around openproc and readproc to slurp in the whole process
|
||||
* tree subset satisfying the constraints of flags and the optional PID list.
|
||||
* Free allocated memory with freeproctree(). The tree structure is a classic
|
||||
* left-list children + right-list siblings. The algorithm is a two-pass of the
|
||||
* process table. Since most process trees will have children with strictly
|
||||
* increasing PIDs, most of the structure will be picked up in the first pass.
|
||||
* The second loop then cleans up any nodes which turn out to have preceeded
|
||||
* their parent in /proc order.
|
||||
*/
|
||||
|
||||
/* Traverse tree 't' breadth-first looking for a process with pid p */
|
||||
proc_t* LookupPID(proc_t* t, pid_t p) {
|
||||
proc_t* tmp = NULL;
|
||||
if (!t)
|
||||
return NULL;
|
||||
if (t->pid == p) /* look here/terminate recursion */
|
||||
return t;
|
||||
if ((tmp = LookupPID(t->l, p))) /* recurse over children */
|
||||
return tmp;
|
||||
for (; t; t=t->r) /* recurse over siblings */
|
||||
if ((tmp = LookupPID(tmp, p)))
|
||||
return tmp;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
proc_t* readproctree(int flags, ...) {
|
||||
static proc_t tree;
|
||||
PROCTAB* PT = NULL;
|
||||
proc_t *node, *tmp=NULL, *tmp2=NULL;
|
||||
va_list ap;
|
||||
|
||||
/* pass through apropriate arguments to openproc */
|
||||
va_start(ap, flags);
|
||||
if (Do(UID)) {
|
||||
/* temporary variables to ensure that va_arg() instances
|
||||
* are called in the right order
|
||||
*/
|
||||
uid_t* u;
|
||||
int i;
|
||||
|
||||
u = va_arg(ap, uid_t*);
|
||||
i = va_arg(ap, int);
|
||||
PT = openproc(flags, u, i);
|
||||
}
|
||||
else if (Do(PID) || Do(TTY) || Do(STAT))
|
||||
PT = openproc(flags, va_arg(ap, void*));
|
||||
else
|
||||
PT = openproc(flags);
|
||||
va_end(ap);
|
||||
|
||||
/* first pass: build tree, putting orphans on the first level */
|
||||
tree.l = tree.r = NULL;
|
||||
while ((node = readproc(PT,0)))
|
||||
if ((tmp = LookupPID(&tree, node->ppid))) {
|
||||
node->r = tmp->l->r; /* node --> left list of parent */
|
||||
tmp->l->r = node;
|
||||
} else {
|
||||
node->r = tree.r; /* node --> right list of 'tree' */
|
||||
tree.r = node;
|
||||
}
|
||||
/* second pass: scan tree for PPIDs of level-1 nodes moving links as necessary */
|
||||
for (node = &tree; node; node = node->r)
|
||||
if ((tmp = LookupPID(&tree, node->r->ppid))) {
|
||||
tmp2 = node->r; /* unlink from right list of 'tree' */
|
||||
node->r = node->r->r;
|
||||
tmp2->r = tmp->l->r; /* insert as child of found node */
|
||||
tmp->l->r = node;
|
||||
}
|
||||
closeproc(PT);
|
||||
return &tree;
|
||||
}
|
||||
|
||||
/* Convenient wrapper around openproc and readproc to slurp in the whole process
|
||||
* table subset satisfying the constraints of flags and the optional PID list.
|
||||
* Free allocated memory with freeproctab(). Access via tab[N]->member. The
|
||||
* pointer list is NULL terminated.
|
||||
*/
|
||||
proc_t** readproctab(int flags, ...) {
|
||||
PROCTAB* PT = NULL;
|
||||
proc_t** tab = NULL;
|
||||
int n = 0;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, flags); /* pass through args to openproc */
|
||||
if (Do(UID)) {
|
||||
/* temporary variables to ensure that va_arg() instances
|
||||
* are called in the right order
|
||||
*/
|
||||
uid_t* u;
|
||||
int i;
|
||||
|
||||
u = va_arg(ap, uid_t*);
|
||||
i = va_arg(ap, int);
|
||||
PT = openproc(flags, u, i);
|
||||
}
|
||||
else if (Do(PID) || Do(TTY) || Do(STAT))
|
||||
PT = openproc(flags, va_arg(ap, void*)); /* assume ptr sizes same */
|
||||
else
|
||||
PT = openproc(flags);
|
||||
va_end(ap);
|
||||
do { /* read table: */
|
||||
tab = xrealloc(tab, (n+1)*sizeof(proc_t*));/* realloc as we go, using */
|
||||
tab[n] = readproc(PT, NULL); /* final null to terminate */
|
||||
} while (tab[n++]); /* stop when NULL reached */
|
||||
closeproc(PT);
|
||||
return tab;
|
||||
}
|
||||
|
||||
/* deallocate a table of pointers to proc structures
|
||||
*/
|
||||
void freeproctab(proc_t** tab) {
|
||||
proc_t** p;
|
||||
for(p = tab; *p; p++)
|
||||
freeproc(*p);
|
||||
free(tab);
|
||||
}
|
168
libproc/readproc.h
Normal file
168
libproc/readproc.h
Normal file
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* New Interface to Process Table -- PROCTAB Stream (a la Directory streams)
|
||||
* Copyright(C) 1996. Charles L. Blake.
|
||||
*/
|
||||
|
||||
/* Basic data structure which holds all information we can get about a process.
|
||||
* (unless otherwise specified, fields are read from /proc/#/stat)
|
||||
*/
|
||||
typedef struct proc_s {
|
||||
char
|
||||
user[10], /* user name corresponding to owner of process */
|
||||
cmd[40], /* basename of executable file in call to exec(2) */
|
||||
state, /* single-char code for process state (S=sleeping) */
|
||||
ttyc[5], /* string representation of controlling tty device */
|
||||
**environ, /* environment string vector (/proc/#/environ) */
|
||||
**cmdline; /* command line string vector (/proc/#/cmdline) */
|
||||
int
|
||||
uid, /* user id */
|
||||
pid, /* process id */
|
||||
ppid, /* pid of parent process */
|
||||
pgrp, /* process group id */
|
||||
session, /* session id */
|
||||
tty, /* full device number of controlling terminal */
|
||||
tpgid, /* terminal process group id */
|
||||
priority, /* kernel scheduling priority */
|
||||
nice; /* standard unix nice level of process */
|
||||
long long
|
||||
signal, /* mask of pending signals */
|
||||
blocked, /* mask of blocked signals */
|
||||
sigignore, /* mask of ignored signals */
|
||||
sigcatch; /* mask of caught signals */
|
||||
long
|
||||
start_time, /* start time of process -- seconds since 1-1-70 */
|
||||
utime, /* user-mode CPU time accumulated by process */
|
||||
stime, /* kernel-mode CPU time accumulated by process */
|
||||
cutime, /* cumulative utime of process and reaped children */
|
||||
cstime, /* cumulative stime of process and reaped children */
|
||||
/* the next 7 members come from /proc/#/statm */
|
||||
size, /* total # of pages of memory */
|
||||
resident, /* number of resident set (non-swapped) pages (4k) */
|
||||
share, /* number of pages of shared (mmap'd) memory */
|
||||
trs, /* text resident set size */
|
||||
lrs, /* shared-lib resident set size */
|
||||
drs, /* data resident set size */
|
||||
dt; /* dirty pages */
|
||||
unsigned
|
||||
pcpu; /* %CPU usage (is not filled in by readproc!!!) */
|
||||
unsigned long
|
||||
vsize, /* number of pages of virtual memory ... */
|
||||
rss, /* resident set size from /proc/#/stat */
|
||||
rss_rlim, /* resident set size ... ? */
|
||||
timeout, /* ? */
|
||||
it_real_value, /* ? */
|
||||
flags, /* kernel flags for the process */
|
||||
min_flt, /* number of minor page faults since process start */
|
||||
maj_flt, /* number of major page faults since process start */
|
||||
cmin_flt, /* cumulative min_flt of process and child processes */
|
||||
cmaj_flt, /* cumulative maj_flt of process and child processes */
|
||||
start_code, /* address of beginning of code segment */
|
||||
end_code, /* address of end of code segment */
|
||||
start_stack, /* address of the bottom of stack for the process */
|
||||
kstk_esp, /* kernel stack pointer */
|
||||
kstk_eip, /* kernel stack pointer */
|
||||
wchan; /* address of kernel wait channel proc is sleeping in */
|
||||
struct proc_s *l, /* ptrs for building arbitrary linked structs */
|
||||
*r; /* (i.e. singly/doubly-linked lists and trees */
|
||||
} proc_t;
|
||||
|
||||
/* PROCTAB: data structure holding the persistent information readproc needs
|
||||
* from openproc(). The setup is intentionally similar to the dirent interface
|
||||
* and other system table interfaces (utmp+wtmp come to mind).
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
typedef struct {
|
||||
DIR* procfs;
|
||||
int flags;
|
||||
pid_t* pids; /* pids of the procs */
|
||||
dev_t* ttys; /* devnos of the cttys */
|
||||
uid_t* uids; /* uids of procs */
|
||||
int nuid; /* cannot really sentinel-terminate unsigned short[] */
|
||||
char* stats; /* status chars (actually output into /proc//stat) */
|
||||
} PROCTAB;
|
||||
|
||||
/* initialize a PROCTAB structure holding needed call-to-call persistent data
|
||||
*/
|
||||
PROCTAB* openproc(int flags, ... /* pid_t*|uid_t*|dev_t*|char* [, int n] */ );
|
||||
|
||||
/* Convenient wrapper around openproc and readproc to slurp in the whole process
|
||||
* table subset satisfying the constraints of flags and the optional PID list.
|
||||
* Free allocated memory with freeproctab(). Access via tab[N]->member. The
|
||||
* pointer list is NULL terminated.
|
||||
*/
|
||||
proc_t** readproctab(int flags, ... /* same as openproc */ );
|
||||
|
||||
/* Convenient wrapper around openproc and readproc to slurp in the whole process
|
||||
* tree subset satisfying the constraints of flags and the optional PID list.
|
||||
*/
|
||||
proc_t* readproctree(int flags, ... /* same as openproc */ );
|
||||
|
||||
/* clean-up open files, etc from the openproc()
|
||||
*/
|
||||
void closeproc(PROCTAB* PT);
|
||||
|
||||
/* retrieve the next process matching the criteria set by the openproc()
|
||||
*/
|
||||
proc_t* readproc(PROCTAB* PT, proc_t* return_buf);
|
||||
|
||||
/* deallocate space allocated by readproc
|
||||
*/
|
||||
void freeproc(proc_t* p);
|
||||
|
||||
/* deallocate space allocated by readproctab
|
||||
*/
|
||||
void freeproctab(proc_t** p);
|
||||
|
||||
/* openproc/readproctab:
|
||||
*
|
||||
* Return PROCTAB* / *proc_t[] or NULL on error ((probably) "/proc" cannot be
|
||||
* opened.) By default readproc will consider all processes as valid to parse
|
||||
* and return, but not actually fill in the cmdline, environ, and /proc/#/statm
|
||||
* derived memory fields.
|
||||
*
|
||||
* `flags' (a bitwise-or of PROC_* below) modifies the default behavior. The
|
||||
* "fill" options will cause more of the proc_t to be filled in. The "filter"
|
||||
* options all use the second argument as the pointer to a list of objects:
|
||||
* process status', process id's, user id's, and tty device numbers. The third
|
||||
* argument is the length of the list (currently only used for lists of user
|
||||
* id's since unsigned short[] supports no convenient termination sentinel.)
|
||||
*/
|
||||
#define PROC_FILLMEM 0x1 /* read statm into the appropriate proc_t entries */
|
||||
#define PROC_FILLCMD 0x2 /* alloc and fill in `cmdline' part of proc_t */
|
||||
#define PROC_FILLENV 0x4 /* alloc and fill in `environ' part of proc_t */
|
||||
#define PROC_FILLTTY 0x8 /* resolve device number -> tty name via psdevtab */
|
||||
#define PROC_FILLUSR 0x10 /* resolve user id number -> user name via passwd */
|
||||
/* consider only processes with one of the passed: */
|
||||
#define PROC_PID 0x100 /* process id numbers ( 0 terminated) */
|
||||
#define PROC_TTY 0x200 /* ctty device nos. ( 0 terminated) */
|
||||
#define PROC_UID 0x400 /* user id numbers ( length needed ) */
|
||||
#define PROC_STAT 0x800 /* status fields ('\0' terminated) */
|
||||
#define PROC_ANYTTY 0x1000 /* proc must have a controlling terminal */
|
||||
|
||||
/* utility functions which may be of general interest: */
|
||||
|
||||
/* slurp /proc/DIR/FILE into a single large string into the passed
|
||||
buffer. return the number of bytes actually used. used for stat,statm
|
||||
*/
|
||||
int file2str(char *dir, char *file, char *buf, int buf_size);
|
||||
|
||||
/* convert a file of null terminated strings into an argv-style string vector
|
||||
* which may be de-allocated with a single free() on a dereference of the return
|
||||
* value, e.g. free(*ret). used for cmdline, environ.
|
||||
*/
|
||||
char** file2strvec(char* directory, char* what);
|
||||
|
||||
/* parse /proc/#/stat entries in string s into a proc_t
|
||||
*/
|
||||
void stat2proc(char* S, proc_t*);
|
||||
|
||||
/* parse /proc/#/statm entries in string s into a proc_t
|
||||
*/
|
||||
void statm2proc(char* s, proc_t*);
|
||||
|
||||
/* convert a memory buffer with nulls into a single string,
|
||||
replacing the nulls with sep. No longer used.
|
||||
*/
|
||||
void nulls2sep(char* str, int len, char sep);
|
65
libproc/signals.c
Normal file
65
libproc/signals.c
Normal file
@@ -0,0 +1,65 @@
|
||||
/* signals.c - signal name handling */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include "proc/signals.h"
|
||||
|
||||
|
||||
typedef struct {
|
||||
int number;
|
||||
char *name;
|
||||
} SIGNAME;
|
||||
|
||||
|
||||
static SIGNAME signals[] = {
|
||||
#include "signames.h" /* should be in same dir as this file */
|
||||
{ 0,NULL }};
|
||||
|
||||
|
||||
void list_signals(void)
|
||||
{
|
||||
SIGNAME *walk;
|
||||
int col;
|
||||
|
||||
col = 0;
|
||||
for (walk = signals; walk->name; walk++) {
|
||||
if (col+strlen(walk->name)+1 > 80) {
|
||||
putchar('\n');
|
||||
col = 0;
|
||||
}
|
||||
printf("%s%s",col ? " " : "",walk->name);
|
||||
col += strlen(walk->name)+1;
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
|
||||
int get_signal(char *name,char *cmd)
|
||||
{
|
||||
SIGNAME *walk;
|
||||
|
||||
if (isdigit(*name))
|
||||
return atoi(name);
|
||||
for (walk = signals; walk->name; walk++)
|
||||
if (!strcmp(walk->name,name)) break;
|
||||
if (walk->name) return walk->number;
|
||||
fprintf(stderr,"%s: unknown signal; %s -l lists signals.\n",name,cmd);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* get_signal2 is by Michael Shields. 1994/04/25. */
|
||||
int get_signal2(char *name)
|
||||
{
|
||||
SIGNAME *walk;
|
||||
|
||||
if (!name)
|
||||
return(-1);
|
||||
if (isdigit(*name))
|
||||
return atoi(name);
|
||||
for (walk = signals; walk->name; walk++)
|
||||
if (!strcmp(walk->name,name))
|
||||
return(walk->number);
|
||||
return(-1);
|
||||
}
|
12
libproc/signals.h
Normal file
12
libproc/signals.h
Normal file
@@ -0,0 +1,12 @@
|
||||
/* signals.h - signal name handling */
|
||||
|
||||
void list_signals(void);
|
||||
|
||||
/* Lists all known signal names on standard output. */
|
||||
|
||||
int get_signal(char *name,char *cmd);
|
||||
int get_signal2(char *name);
|
||||
|
||||
/* Returns the signal number of NAME. If no such signal exists, an error
|
||||
message is displayed and the program is terminated. CMD is the name of the
|
||||
application. */
|
32
libproc/signames.h
Normal file
32
libproc/signames.h
Normal file
@@ -0,0 +1,32 @@
|
||||
{ 1,"HUP" },
|
||||
{ 2,"INT" },
|
||||
{ 3,"QUIT" },
|
||||
{ 4,"ILL" },
|
||||
{ 5,"TRAP" },
|
||||
{ 6,"ABRT" },
|
||||
{ 6,"IOT" },
|
||||
{ 7,"BUS" },
|
||||
{ 8,"FPE" },
|
||||
{ 9,"KILL" },
|
||||
{ 10,"USR1" },
|
||||
{ 11,"SEGV" },
|
||||
{ 12,"USR2" },
|
||||
{ 13,"PIPE" },
|
||||
{ 14,"ALRM" },
|
||||
{ 15,"TERM" },
|
||||
{ 16,"STKFLT" },
|
||||
{ 17,"CHLD" },
|
||||
{ 18,"CONT" },
|
||||
{ 19,"STOP" },
|
||||
{ 20,"TSTP" },
|
||||
{ 21,"TTIN" },
|
||||
{ 22,"TTOU" },
|
||||
{ 23,"URG" },
|
||||
{ 24,"XCPU" },
|
||||
{ 25,"XFSZ" },
|
||||
{ 26,"VTALRM" },
|
||||
{ 27,"PROF" },
|
||||
{ 28,"WINCH" },
|
||||
{ 29,"IO" },
|
||||
{ 30,"PWR" },
|
||||
{ 31,"UNUSED" },
|
20
libproc/status.c
Normal file
20
libproc/status.c
Normal file
@@ -0,0 +1,20 @@
|
||||
#include "proc/ps.h"
|
||||
#include "proc/readproc.h"
|
||||
|
||||
char * status(proc_t* task) {
|
||||
static char buf[4] = " ";
|
||||
|
||||
buf[0] = task->state;
|
||||
if (task->rss == 0 && task->state != 'Z')
|
||||
buf[1] = 'W';
|
||||
else
|
||||
buf[1] = ' ';
|
||||
if (task->nice < 0)
|
||||
buf[2] = '<';
|
||||
else if (task->nice > 0)
|
||||
buf[2] = 'N';
|
||||
else
|
||||
buf[2] = ' ';
|
||||
|
||||
return(buf);
|
||||
}
|
176
libproc/sysinfo.c
Normal file
176
libproc/sysinfo.c
Normal file
@@ -0,0 +1,176 @@
|
||||
/* File for parsing top-level /proc entities. */
|
||||
#include "proc/sysinfo.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include "proc/version.h"
|
||||
|
||||
#define BAD_OPEN_MESSAGE \
|
||||
"Error: /proc must be mounted\n" \
|
||||
" To mount /proc at boot you need an /etc/fstab line like:\n" \
|
||||
" /proc /proc proc defaults\n" \
|
||||
" In the meantime, mount /proc /proc -t proc\n"
|
||||
|
||||
#define UPTIME_FILE "/proc/uptime"
|
||||
#define LOADAVG_FILE "/proc/loadavg"
|
||||
#define MEMINFO_FILE "/proc/meminfo"
|
||||
|
||||
static char buf[1024];
|
||||
|
||||
/* This macro opens FILE only if necessary and seeks to 0 so that successive
|
||||
calls to the functions are more efficient. It also reads the current
|
||||
contents of the file into the global buf.
|
||||
*/
|
||||
#define FILE_TO_BUF(FILE) { \
|
||||
static int n, fd = -1; \
|
||||
if (fd == -1 && (fd = open(FILE, O_RDONLY)) == -1) { \
|
||||
fprintf(stderr, BAD_OPEN_MESSAGE); \
|
||||
close(fd); \
|
||||
return 0; \
|
||||
} \
|
||||
lseek(fd, 0L, SEEK_SET); \
|
||||
if ((n = read(fd, buf, sizeof buf - 1)) < 0) { \
|
||||
perror(FILE); \
|
||||
close(fd); \
|
||||
fd = -1; \
|
||||
return 0; \
|
||||
} \
|
||||
buf[n] = '\0'; \
|
||||
}
|
||||
|
||||
#define SET_IF_DESIRED(x,y) if (x) *(x) = (y) /* evals 'x' twice */
|
||||
|
||||
int uptime(double *uptime_secs, double *idle_secs) {
|
||||
double up=0, idle=0;
|
||||
|
||||
FILE_TO_BUF(UPTIME_FILE)
|
||||
if (sscanf(buf, "%lf %lf", &up, &idle) < 2) {
|
||||
fprintf(stderr, "bad data in " UPTIME_FILE "\n");
|
||||
return 0;
|
||||
}
|
||||
SET_IF_DESIRED(uptime_secs, up);
|
||||
SET_IF_DESIRED(idle_secs, idle);
|
||||
return up; /* assume never be zero seconds in practice */
|
||||
}
|
||||
|
||||
int loadavg(double *av1, double *av5, double *av15) {
|
||||
double avg_1=0, avg_5=0, avg_15=0;
|
||||
|
||||
FILE_TO_BUF(LOADAVG_FILE)
|
||||
if (sscanf(buf, "%lf %lf %lf", &avg_1, &avg_5, &avg_15) < 3) {
|
||||
fprintf(stderr, "bad data in " LOADAVG_FILE "\n");
|
||||
exit(1);
|
||||
}
|
||||
SET_IF_DESIRED(av1, avg_1);
|
||||
SET_IF_DESIRED(av5, avg_5);
|
||||
SET_IF_DESIRED(av15, avg_15);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* The following /proc/meminfo parsing routine assumes the following format:
|
||||
[ <label> ... ] # header lines
|
||||
[ <label> ] <num> [ <num> ... ] # table rows
|
||||
[ repeats of above line ]
|
||||
|
||||
Any lines with fewer <num>s than <label>s get trailing <num>s set to zero.
|
||||
The return value is a NULL terminated unsigned** which is the table of
|
||||
numbers without labels. Convenient enumeration constants for the major and
|
||||
minor dimensions are available in the header file. Note that this version
|
||||
requires that labels do not contain digits. It is readily extensible to
|
||||
labels which do not *begin* with digits, though.
|
||||
*/
|
||||
|
||||
#define MAX_ROW 3 /* these are a little liberal for flexibility */
|
||||
#define MAX_COL 7
|
||||
|
||||
unsigned** meminfo(void) {
|
||||
static unsigned *row[MAX_ROW + 1]; /* row pointers */
|
||||
static unsigned num[MAX_ROW * MAX_COL]; /* number storage */
|
||||
char *p;
|
||||
char fieldbuf[12]; /* bigger than any field name or size in kb */
|
||||
int i, j, k, l;
|
||||
|
||||
set_linux_version();
|
||||
FILE_TO_BUF(MEMINFO_FILE)
|
||||
if (!row[0]) /* init ptrs 1st time through */
|
||||
for (i=0; i < MAX_ROW; i++) /* std column major order: */
|
||||
row[i] = num + MAX_COL*i; /* A[i][j] = A + COLS*i + j */
|
||||
p = buf;
|
||||
for (i=0; i < MAX_ROW; i++) /* zero unassigned fields */
|
||||
for (j=0; j < MAX_COL; j++)
|
||||
row[i][j] = 0;
|
||||
if (linux_version_code < LINUX_VERSION(2,0,0)) {
|
||||
for (i=0; i < MAX_ROW && *p; i++) { /* loop over rows */
|
||||
while(*p && !isdigit(*p)) p++; /* skip chars until a digit */
|
||||
for (j=0; j < MAX_COL && *p; j++) { /* scanf column-by-column */
|
||||
l = sscanf(p, "%u%n", row[i] + j, &k);
|
||||
p += k; /* step over used buffer */
|
||||
if (*p == '\n' || l < 1) /* end of line/buffer */
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
while(*p) {
|
||||
sscanf(p,"%11s%n",fieldbuf,&k);
|
||||
if(!strcmp(fieldbuf,"MemTotal:")) {
|
||||
p+=k;
|
||||
sscanf(p," %d",&(row[meminfo_main][meminfo_total]));
|
||||
row[meminfo_main][meminfo_total]<<=10;
|
||||
while(*p++ != '\n');
|
||||
}
|
||||
else if(!strcmp(fieldbuf,"MemFree:")) {
|
||||
p+=k;
|
||||
sscanf(p," %d",&(row[meminfo_main][meminfo_free]));
|
||||
row[meminfo_main][meminfo_free]<<=10;
|
||||
while(*p++ != '\n');
|
||||
}
|
||||
else if(!strcmp(fieldbuf,"MemShared:")) {
|
||||
p+=k;
|
||||
sscanf(p," %d",&(row[meminfo_main][meminfo_shared]));
|
||||
row[meminfo_main][meminfo_shared]<<=10;
|
||||
while(*p++ != '\n');
|
||||
}
|
||||
else if(!strcmp(fieldbuf,"Buffers:")) {
|
||||
p+=k;
|
||||
sscanf(p," %d",&(row[meminfo_main][meminfo_buffers]));
|
||||
row[meminfo_main][meminfo_buffers]<<=10;
|
||||
while(*p++ != '\n');
|
||||
}
|
||||
else if(!strcmp(fieldbuf,"Cached:")) {
|
||||
p+=k;
|
||||
sscanf(p," %d",&(row[meminfo_main][meminfo_cached]));
|
||||
row[meminfo_main][meminfo_cached]<<=10;
|
||||
while(*p++ != '\n');
|
||||
}
|
||||
else if(!strcmp(fieldbuf,"SwapTotal:")) {
|
||||
p+=k;
|
||||
sscanf(p," %d",&(row[meminfo_swap][meminfo_total]));
|
||||
row[meminfo_swap][meminfo_total]<<=10;
|
||||
while(*p++ != '\n');
|
||||
}
|
||||
else if(!strcmp(fieldbuf,"SwapFree:")) {
|
||||
p+=k;
|
||||
sscanf(p," %d",&(row[meminfo_swap][meminfo_free]));
|
||||
row[meminfo_swap][meminfo_free]<<=10;
|
||||
while(*p++ != '\n');
|
||||
}
|
||||
else
|
||||
while(*p++ != '\n'); /* ignore lines we don't understand */
|
||||
}
|
||||
row[meminfo_swap][meminfo_used]=row[meminfo_swap][meminfo_total]-row[meminfo_swap][meminfo_free];
|
||||
row[meminfo_main][meminfo_used]=row[meminfo_main][meminfo_total]-row[meminfo_main][meminfo_free];
|
||||
}
|
||||
return row; /* NULL return ==> error */
|
||||
}
|
||||
|
||||
/* shorthand for read_table("/proc/meminfo")[meminfo_main][meminfo_total] */
|
||||
unsigned read_total_main(void) {
|
||||
unsigned** mem;
|
||||
return (mem = meminfo()) ? mem[meminfo_main][meminfo_total] : -1;
|
||||
}
|
17
libproc/sysinfo.h
Normal file
17
libproc/sysinfo.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef SYSINFO_H
|
||||
#define SYSINFO_H
|
||||
|
||||
int loadavg(double *av1, double *av5, double *av15);
|
||||
int uptime (double *uptime_secs, double *idle_secs);
|
||||
unsigned** meminfo(void);
|
||||
|
||||
enum meminfo_row { meminfo_main = 0,
|
||||
meminfo_swap };
|
||||
|
||||
enum meminfo_col { meminfo_total = 0, meminfo_used, meminfo_free,
|
||||
meminfo_shared, meminfo_buffers, meminfo_cached
|
||||
};
|
||||
|
||||
unsigned read_total_main(void);
|
||||
|
||||
#endif /* SYSINFO_H */
|
14
libproc/tree.h
Normal file
14
libproc/tree.h
Normal file
@@ -0,0 +1,14 @@
|
||||
struct tree_node {
|
||||
proc_t *proc;
|
||||
pid_t pid;
|
||||
pid_t ppid;
|
||||
char *line;
|
||||
char *cmd;
|
||||
char **cmdline;
|
||||
char **environ;
|
||||
int children;
|
||||
int maxchildren;
|
||||
int *child;
|
||||
int have_parent;
|
||||
};
|
||||
|
39
libproc/version.c
Normal file
39
libproc/version.c
Normal file
@@ -0,0 +1,39 @@
|
||||
/* Suite version information for procps utilities
|
||||
* Copyright (c) 1995 Martin Schulze <joey@infodrom.north.de>
|
||||
* Ammended by cblake to only export the function symbol.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef MINORVERSION
|
||||
char procps_version[] = "procps version " VERSION "." SUBVERSION "." MINORVERSION;
|
||||
#else
|
||||
char procps_version[] = "procps version " VERSION "." SUBVERSION;
|
||||
#endif
|
||||
|
||||
void display_version(void) {
|
||||
fprintf(stdout, "%s\n", procps_version);
|
||||
}
|
||||
|
||||
/* Linux kernel version information for procps utilities
|
||||
* Copyright (c) 1996 Charles Blake <cblake@bbn.com>
|
||||
*/
|
||||
#include <sys/utsname.h>
|
||||
|
||||
#define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z)
|
||||
|
||||
int linux_version_code = 0;
|
||||
|
||||
void set_linux_version(void) {
|
||||
static struct utsname uts;
|
||||
int x = 0, y = 0, z = 0; /* cleared in case sscanf() < 3 */
|
||||
|
||||
if (linux_version_code) return;
|
||||
if (uname(&uts) == -1) /* failure most likely implies impending death */
|
||||
exit(1);
|
||||
if (sscanf(uts.release, "%d.%d.%d", &x, &y, &z) < 3)
|
||||
fprintf(stderr, /* *very* unlikely to happen by accident */
|
||||
"Non-standard uts for running kernel:\n"
|
||||
"release %s=%d.%d.%d gives version code %d\n",
|
||||
uts.release, x, y, z, LINUX_VERSION(x,y,z));
|
||||
linux_version_code = LINUX_VERSION(x, y, z);
|
||||
}
|
24
libproc/version.h
Normal file
24
libproc/version.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef PROC_VERSION_H
|
||||
#define PROC_VERSION_H
|
||||
|
||||
/* Suite version information for procps utilities
|
||||
* Copyright (c) 1995 Martin Schulze <joey@infodrom.north.de>
|
||||
* Linux kernel version information for procps utilities
|
||||
* Copyright (c) 1996 Charles Blake <cblake@bbn.com>
|
||||
*/
|
||||
|
||||
extern void display_version(void); /* display suite version */
|
||||
extern char procps_version[]; /* global buf for suite version */
|
||||
|
||||
extern int linux_version_code; /* runtime version of LINUX_VERSION_CODE
|
||||
in /usr/include/linux/version.h */
|
||||
extern void set_linux_version(void); /* set linux_version_code */
|
||||
|
||||
|
||||
/* Convenience macros for composing/decomposing version codes */
|
||||
#define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z)
|
||||
#define LINUX_VERSION_MAJOR(x) ((x) & 0xFF0000) /* Dare we hope for a */
|
||||
#define LINUX_VERSION_MINOR(x) ((x) & 0x00FF00) /* Linux 256.0.0? ;-) */
|
||||
#define LINUX_VERSION_PATCH(x) ((x) & 0x0000FF)
|
||||
|
||||
#endif /* PROC_VERSION_H */
|
89
libproc/whattime.c
Normal file
89
libproc/whattime.c
Normal file
@@ -0,0 +1,89 @@
|
||||
/* This is a trivial uptime program. I hereby release this program
|
||||
* into the public domain. I disclaim any responsibility for this
|
||||
* program --- use it at your own risk. (as if there were any.. ;-)
|
||||
* -michaelkjohnson (johnsonm@sunsite.unc.edu)
|
||||
*
|
||||
* Modified by Larry Greenfield to give a more traditional output,
|
||||
* count users, etc. (greenfie@gauss.rutgers.edu)
|
||||
*
|
||||
* Modified by mkj again to fix a few tiny buglies.
|
||||
*
|
||||
* Modified by J. Cowley to add printing the uptime message to a
|
||||
* string (for top) and to optimize file handling. 19 Mar 1993.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <utmp.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include "proc/whattime.h"
|
||||
#include "proc/sysinfo.h"
|
||||
|
||||
static char buf[128];
|
||||
double av[3];
|
||||
|
||||
char *sprint_uptime(void) {
|
||||
struct utmp *utmpstruct;
|
||||
int upminutes, uphours, updays;
|
||||
int pos;
|
||||
struct tm *realtime;
|
||||
time_t realseconds;
|
||||
int numuser;
|
||||
double uptime_secs, idle_secs;
|
||||
|
||||
/* first get the current time */
|
||||
|
||||
time(&realseconds);
|
||||
realtime = localtime(&realseconds);
|
||||
pos = sprintf(buf, " %2d:%02d%s ",
|
||||
realtime->tm_hour%12 ? realtime->tm_hour%12 : 12,
|
||||
realtime->tm_min, realtime->tm_hour > 11 ? "pm" : "am");
|
||||
|
||||
/* read and calculate the amount of uptime */
|
||||
|
||||
uptime(&uptime_secs, &idle_secs);
|
||||
|
||||
updays = (int) uptime_secs / (60*60*24);
|
||||
strcat (buf, "up ");
|
||||
pos += 3;
|
||||
if (updays)
|
||||
pos += sprintf(buf + pos, "%d day%s, ", updays, (updays != 1) ? "s" : "");
|
||||
upminutes = (int) uptime_secs / 60;
|
||||
uphours = upminutes / 60;
|
||||
uphours = uphours % 24;
|
||||
upminutes = upminutes % 60;
|
||||
if(uphours)
|
||||
pos += sprintf(buf + pos, "%2d:%02d, ", uphours, upminutes);
|
||||
else
|
||||
pos += sprintf(buf + pos, "%d min, ", upminutes);
|
||||
|
||||
/* count the number of users */
|
||||
|
||||
numuser = 0;
|
||||
setutent();
|
||||
while ((utmpstruct = getutent())) {
|
||||
if ((utmpstruct->ut_type == USER_PROCESS) &&
|
||||
(utmpstruct->ut_name[0] != '\0'))
|
||||
numuser++;
|
||||
}
|
||||
endutent();
|
||||
|
||||
pos += sprintf(buf + pos, "%2d user%s, ", numuser, numuser == 1 ? "" : "s");
|
||||
|
||||
loadavg(&av[0], &av[1], &av[2]);
|
||||
|
||||
pos += sprintf(buf + pos, " load average: %.2f, %.2f, %.2f",
|
||||
av[0], av[1], av[2]);
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
void print_uptime(void)
|
||||
{
|
||||
printf("%s\n", sprint_uptime());
|
||||
}
|
9
libproc/whattime.h
Normal file
9
libproc/whattime.h
Normal file
@@ -0,0 +1,9 @@
|
||||
/* whattime.h --- see whattime.c for explanation */
|
||||
|
||||
#ifndef __WHATTIME_H
|
||||
#define __WHATTIME_H
|
||||
|
||||
void print_uptime(void);
|
||||
char *sprint_uptime(void);
|
||||
|
||||
#endif
|
1
perl/.cvsignore
Normal file
1
perl/.cvsignore
Normal file
@@ -0,0 +1 @@
|
||||
Libgtop.xs Makefile blib pm_to_blib Libgtop.c Libgtop.bs Makefile.PL
|
5
perl/Changes
Normal file
5
perl/Changes
Normal file
@@ -0,0 +1,5 @@
|
||||
Revision history for Perl extension Libgtop.
|
||||
|
||||
0.01 Sun Jun 21 21:00:59 1998
|
||||
- original version; created by h2xs 1.18
|
||||
|
26
perl/Libgtop.pm
Normal file
26
perl/Libgtop.pm
Normal file
@@ -0,0 +1,26 @@
|
||||
package Libgtop;
|
||||
|
||||
use strict;
|
||||
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
|
||||
|
||||
require Exporter;
|
||||
require DynaLoader;
|
||||
require AutoLoader;
|
||||
|
||||
@ISA = qw(Exporter DynaLoader);
|
||||
# Items to export into callers namespace by default. Note: do not export
|
||||
# names by default without a very good reason. Use EXPORT_OK instead.
|
||||
# Do not simply export all your public functions/methods/constants.
|
||||
@EXPORT = qw(
|
||||
|
||||
);
|
||||
$VERSION = '0.01';
|
||||
|
||||
bootstrap Libgtop $VERSION;
|
||||
|
||||
# Preloaded methods go here.
|
||||
|
||||
# Autoload methods go after __END__, and are processed by the autosplit program.
|
||||
|
||||
1;
|
||||
__END__
|
8
perl/MANIFEST
Normal file
8
perl/MANIFEST
Normal file
@@ -0,0 +1,8 @@
|
||||
.cvsignore
|
||||
Changes
|
||||
Libgtop.pm
|
||||
MANIFEST
|
||||
Makefile.PL.in
|
||||
new.pl
|
||||
perl.awk
|
||||
test.pl
|
10
perl/Makefile.PL.in
Normal file
10
perl/Makefile.PL.in
Normal file
@@ -0,0 +1,10 @@
|
||||
# -*-cperl-*-
|
||||
use ExtUtils::MakeMaker;
|
||||
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
|
||||
# the contents of the Makefile that is written.
|
||||
WriteMakefile('NAME' => 'Libgtop',
|
||||
'VERSION_FROM' => 'Libgtop.pm',
|
||||
'LIBS' => ['@LIBGTOP_GUILE_LIBS@'],
|
||||
'DEFINE' => '',
|
||||
'INC' => '@LIBGTOP_GUILE_INCS@',
|
||||
);
|
13
perl/new.pl
Executable file
13
perl/new.pl
Executable file
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/perl -w
|
||||
|
||||
require 5.004;
|
||||
|
||||
use blib;
|
||||
use strict;
|
||||
use Libgtop;
|
||||
|
||||
print "CPU Usage: ".join (':', Libgtop::cpu)."\n";
|
||||
print "Memory Usage: ".join (':', Libgtop::mem)."\n";
|
||||
print "Swap Usage: ".join (':', Libgtop::swap)."\n";
|
||||
|
||||
|
86
perl/perl.awk
Normal file
86
perl/perl.awk
Normal file
@@ -0,0 +1,86 @@
|
||||
BEGIN {
|
||||
print "/* Libgtop.xs */";
|
||||
print "/* This is a generated file. Please modify `perl.awk' */";
|
||||
print "";
|
||||
|
||||
print "#ifdef __cplusplus";
|
||||
print "extern \"C\" {";
|
||||
print "#endif";
|
||||
print "#include \"EXTERN.h\"";
|
||||
print "#include \"perl.h\"";
|
||||
print "#include \"XSUB.h\"";
|
||||
print "#ifdef __cplusplus";
|
||||
print "}";
|
||||
print "#endif";
|
||||
print "";
|
||||
print "#undef PACKAGE";
|
||||
print "";
|
||||
print "#include <glibtop.h>";
|
||||
print "#include <glibtop/union.h>";
|
||||
print "";
|
||||
print "MODULE = Libgtop\t\tPACKAGE = Libgtop";
|
||||
print "";
|
||||
|
||||
convert["long"] = "newSViv";
|
||||
convert["ulong"] = "newSViv";
|
||||
convert["double"] = "newSVnv";
|
||||
}
|
||||
|
||||
/^(\w+)/ {
|
||||
feature = $1;
|
||||
|
||||
print "void";
|
||||
if (feature ~ /^proc_/) {
|
||||
print feature"(pid)";
|
||||
print "\tunsigned\tpid;";
|
||||
} else {
|
||||
print feature"()";
|
||||
}
|
||||
|
||||
print "PREINIT:";
|
||||
print "\tglibtop_"feature" "feature";";
|
||||
|
||||
if (feature ~ /^proclist/) {
|
||||
print "\tunsigned i, *ptr;";
|
||||
print "PPCODE:";
|
||||
print "\tptr = glibtop_get_proclist (&proclist);";
|
||||
print "";
|
||||
print "\tif (ptr) {";
|
||||
print "\t\tfor (i = 0; i < proclist.number; i++)";
|
||||
print "\t\t\tXPUSHs (sv_2mortal (newSViv (ptr [i])));";
|
||||
print "\t}";
|
||||
print "";
|
||||
print "\tglibtop_free (ptr);";
|
||||
} else {
|
||||
print "PPCODE:";
|
||||
if (feature ~ /^proc_/) {
|
||||
print "\tglibtop_get_"feature" (&"feature", pid);";
|
||||
} else {
|
||||
print "\tglibtop_get_"feature" (&"feature");";
|
||||
}
|
||||
print "";
|
||||
|
||||
nr_elements = split ($2, elements, /:/);
|
||||
for (element = 1; element <= nr_elements; element++) {
|
||||
list = elements[element];
|
||||
type = elements[element];
|
||||
sub(/\(.*/, "", type);
|
||||
sub(/^\w+\(/, "", list); sub(/\)$/, "", list);
|
||||
count = split (list, fields, /,/);
|
||||
for (field = 1; field <= count; field++) {
|
||||
if (type ~ /^str$/) {
|
||||
print "\tXPUSHs (sv_2mortal (newSVpv ("$1"."fields[field]", 0)));";
|
||||
} else {
|
||||
if (type ~ /^char$/) {
|
||||
print "\tXPUSHs (sv_2mortal (newSVpv (&"$1"."fields[field]", 1)));";
|
||||
} else {
|
||||
print "\tXPUSHs (sv_2mortal ("convert[type]" ("$1"."fields[field]")));";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
print "";
|
||||
}
|
||||
|
20
perl/test.pl
Normal file
20
perl/test.pl
Normal file
@@ -0,0 +1,20 @@
|
||||
# Before `make install' is performed this script should be runnable with
|
||||
# `make test'. After `make install' it should work as `perl test.pl'
|
||||
|
||||
######################### We start with some black magic to print on failure.
|
||||
|
||||
# Change 1..1 below to 1..last_test_to_print .
|
||||
# (It may become useful if the test is moved to ./t subdirectory.)
|
||||
|
||||
BEGIN { $| = 1; print "1..1\n"; }
|
||||
END {print "not ok 1\n" unless $loaded;}
|
||||
use Libgtop;
|
||||
$loaded = 1;
|
||||
print "ok 1\n";
|
||||
|
||||
######################### End of black magic.
|
||||
|
||||
# Insert your test code below (better if it prints "ok 13"
|
||||
# (correspondingly "not ok 13") depending on the success of chunk 13
|
||||
# of the test code):
|
||||
|
124
po/fr.po
124
po/fr.po
@@ -6,7 +6,7 @@
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: libgtop VERSION\n"
|
||||
"POT-Creation-Date: 1998-05-31 22:31+0200\n"
|
||||
"POT-Creation-Date: 1998-06-20 15:28+0200\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: Vincent Renardias <vincent@waw.com>\n"
|
||||
"Language-Team: Vincent Renardias <vincent@waw.com>\n"
|
||||
@@ -17,67 +17,67 @@ msgstr ""
|
||||
#: lib/open.c:36
|
||||
#, c-format
|
||||
msgid "cannot make a pipe: %s\n"
|
||||
msgstr ""
|
||||
msgstr "impossible de cr<63><72>r un tube: %s\n"
|
||||
|
||||
#: lib/open.c:41
|
||||
#, c-format
|
||||
msgid "%s: fork failed: %s\n"
|
||||
msgstr ""
|
||||
msgstr "%s: duplication <20>chou<6F>e: %s\n"
|
||||
|
||||
#: lib/open.c:59
|
||||
#, c-format
|
||||
msgid "server version is not %s"
|
||||
msgstr ""
|
||||
msgstr "la version du serveur n'est pas %s"
|
||||
|
||||
#: lib/read.c:34
|
||||
#, c-format
|
||||
msgid "read size: %s"
|
||||
msgstr ""
|
||||
msgstr "taille lue: %s"
|
||||
|
||||
#: lib/read.c:37
|
||||
#, c-format
|
||||
msgid "got %d bytes but requested %d"
|
||||
msgstr ""
|
||||
msgstr "obtenu %d octets, mais %d <20>taient demand<6E>s"
|
||||
|
||||
#: lib/read.c:40
|
||||
#, c-format
|
||||
msgid "read %d bytes: %s"
|
||||
msgstr ""
|
||||
msgstr "lecture de %d octets: %s"
|
||||
|
||||
#: lib/write.c:32
|
||||
#, c-format
|
||||
msgid "write size: %s"
|
||||
msgstr ""
|
||||
msgstr "taille <20>crite: %s"
|
||||
|
||||
#: lib/write.c:37
|
||||
#, c-format
|
||||
msgid "write %d bytes: %s"
|
||||
msgstr ""
|
||||
msgstr "<EFBFBD>crit %d octets: %s"
|
||||
|
||||
#: lib/read_data.c:36
|
||||
#, c-format
|
||||
msgid "read data size: %s"
|
||||
msgstr ""
|
||||
msgstr "taille de la lecture: %s"
|
||||
|
||||
#: lib/read_data.c:46
|
||||
#, c-format
|
||||
msgid "read data %d bytes: %s"
|
||||
msgstr ""
|
||||
msgstr "lecture de %d octets de donn<6E>es: %s"
|
||||
|
||||
#: sysdeps/common/xmalloc.c:32
|
||||
#, c-format
|
||||
msgid "malloc %d bytes: %s"
|
||||
msgstr ""
|
||||
msgstr "malloc de %d octets: %s"
|
||||
|
||||
#: sysdeps/common/xmalloc.c:44
|
||||
#, c-format
|
||||
msgid "calloc %d block (%d bytes each): %s"
|
||||
msgstr ""
|
||||
msgstr "calloc de %d blocks (%d octets chacuns): %s"
|
||||
|
||||
#: sysdeps/common/xmalloc.c:56
|
||||
#, c-format
|
||||
msgid "realloc %d bytes: %s"
|
||||
msgstr ""
|
||||
msgstr "realloc de %d octets: %s"
|
||||
|
||||
#: sysdeps/names/sysdeps.c:42 sysdeps/names/sysdeps.c:62
|
||||
msgid "CPU Usage"
|
||||
@@ -93,7 +93,7 @@ msgstr "Utilisation du Swap"
|
||||
|
||||
#: sysdeps/names/sysdeps.c:45 sysdeps/names/sysdeps.c:65
|
||||
msgid "System Uptime"
|
||||
msgstr ""
|
||||
msgstr "Uptime du syst<73>me"
|
||||
|
||||
#: sysdeps/names/sysdeps.c:46 sysdeps/names/sysdeps.c:66
|
||||
msgid "Load Averange"
|
||||
@@ -117,31 +117,31 @@ msgstr "Liste des taches en cours d'
|
||||
|
||||
#: sysdeps/names/sysdeps.c:51 sysdeps/names/sysdeps.c:71
|
||||
msgid "Process Status information"
|
||||
msgstr ""
|
||||
msgstr "Information sur l'<27>tat du processus"
|
||||
|
||||
#: sysdeps/names/sysdeps.c:52 sysdeps/names/sysdeps.c:72
|
||||
msgid "Process UID and TTY information"
|
||||
msgstr ""
|
||||
msgstr "Information UID et TTY du processus"
|
||||
|
||||
#: sysdeps/names/sysdeps.c:53 sysdeps/names/sysdeps.c:73
|
||||
msgid "Process Memory information"
|
||||
msgstr ""
|
||||
msgstr "Information M<>moire du Processus"
|
||||
|
||||
#: sysdeps/names/sysdeps.c:54 sysdeps/names/sysdeps.c:74
|
||||
msgid "Process Time information"
|
||||
msgstr ""
|
||||
msgstr "Information Temporelle sur le processus"
|
||||
|
||||
#: sysdeps/names/sysdeps.c:55 sysdeps/names/sysdeps.c:75
|
||||
msgid "Process Signal information"
|
||||
msgstr ""
|
||||
msgstr "Information sur les signaux du processus"
|
||||
|
||||
#: sysdeps/names/sysdeps.c:56 sysdeps/names/sysdeps.c:76
|
||||
msgid "Process Kernel Data information"
|
||||
msgstr ""
|
||||
msgstr "Information sur les donn<6E>es noyau du processus"
|
||||
|
||||
#: sysdeps/names/sysdeps.c:57 sysdeps/names/sysdeps.c:77
|
||||
msgid "Process Segment information"
|
||||
msgstr ""
|
||||
msgstr "Information sur la segmentation du processus"
|
||||
|
||||
#: sysdeps/names/cpu.c:37
|
||||
msgid "Total CPU Time"
|
||||
@@ -153,7 +153,7 @@ msgstr "Temps CPU en mode utilisateur"
|
||||
|
||||
#: sysdeps/names/cpu.c:39
|
||||
msgid "CPU Time in User Mode (nice)"
|
||||
msgstr ""
|
||||
msgstr "Temps CPU en mode utilisateur (nice)"
|
||||
|
||||
#: sysdeps/names/cpu.c:40
|
||||
msgid "CPU Time in System Mode"
|
||||
@@ -165,7 +165,7 @@ msgstr "Temps CPU pour la tache inactive"
|
||||
|
||||
#: sysdeps/names/cpu.c:42
|
||||
msgid "Tick Frequency"
|
||||
msgstr ""
|
||||
msgstr "Fr<EFBFBD>quence des ticks"
|
||||
|
||||
#: sysdeps/names/cpu.c:47
|
||||
msgid "The number of jiffies (1/100ths of a second) since system boot"
|
||||
@@ -175,31 +175,31 @@ msgstr "Nombre de jiffies (1/100e de seconde) depuis le boot du syst
|
||||
msgid ""
|
||||
"The number of jiffies (1/100ths of a second) that the system spent in user "
|
||||
"mode"
|
||||
msgstr ""
|
||||
msgstr "Le nombre de jiffies (1/100<30>me de seconde) que le systme a pass<73> en mode utilisateur"
|
||||
|
||||
#: sysdeps/names/cpu.c:51
|
||||
msgid ""
|
||||
"The number of jiffies (1/100ths of a second) that the system spent in user "
|
||||
"mode with low priority (nice)"
|
||||
msgstr ""
|
||||
msgstr "Le nombre de jiffies (1/100<30>me de seconde) que le syst<73>me a pass<73> en mode utilisateur en priorit<69> basse (nice)"
|
||||
|
||||
#: sysdeps/names/cpu.c:53
|
||||
msgid ""
|
||||
"The number of jiffies (1/100ths of a second) that the system spent in system "
|
||||
"mode"
|
||||
msgstr ""
|
||||
msgstr "Le nombre de jiffies (1/100<30>me de seconde) que le syst<73>me a pass<73> en mode syst<73>me"
|
||||
|
||||
#: sysdeps/names/cpu.c:55
|
||||
msgid ""
|
||||
"The number of jiffies (1/100ths of a second) that the system spend in the "
|
||||
"idle task"
|
||||
msgstr ""
|
||||
msgstr "Le nombre de jiffies (1/100<30>me de seconde) que le systme a pass<73> dans le processus inactif (idle task)"
|
||||
|
||||
#: sysdeps/names/cpu.c:57
|
||||
msgid ""
|
||||
"All of the above values are in jiffies (1/100ths of a second) unless "
|
||||
"otherwise stated in this field (i.e. 'frequency != 100')"
|
||||
msgstr ""
|
||||
msgstr "Toutes les valeurs ci-dessus sont exprim<69>es en jiffies (1/100<30>me de seconde) sauf pr<70>cision contraire (i.e.: fr<66>quence != 100)"
|
||||
|
||||
#: sysdeps/names/loadavg.c:36
|
||||
msgid "Load Average"
|
||||
@@ -207,7 +207,7 @@ msgstr "Charge Moyenne"
|
||||
|
||||
#: sysdeps/names/loadavg.c:41
|
||||
msgid "Number of jobs running simultaneously averaged over 1, 5 and 15 minutes"
|
||||
msgstr ""
|
||||
msgstr "Nombre de processus tournant simultannement en moyenne sur 1, 5 et 15 minutes"
|
||||
|
||||
#: sysdeps/names/mem.c:39
|
||||
msgid "Total Memory"
|
||||
@@ -231,7 +231,7 @@ msgstr "Tampons"
|
||||
|
||||
#: sysdeps/names/mem.c:44
|
||||
msgid "Cached"
|
||||
msgstr ""
|
||||
msgstr "Dans le cache"
|
||||
|
||||
#: sysdeps/names/mem.c:45
|
||||
msgid "User"
|
||||
@@ -247,83 +247,83 @@ msgstr "M
|
||||
|
||||
#: sysdeps/names/mem.c:52
|
||||
msgid "Used memory size in kB"
|
||||
msgstr ""
|
||||
msgstr "M<EFBFBD>moire utilis<69>e en Ko"
|
||||
|
||||
#: sysdeps/names/mem.c:53
|
||||
msgid "Free memory size in kB"
|
||||
msgstr ""
|
||||
msgstr "M<EFBFBD>moire libre en Ko"
|
||||
|
||||
#: sysdeps/names/mem.c:54
|
||||
msgid "Shared memory size in kB"
|
||||
msgstr ""
|
||||
msgstr "M<EFBFBD>moire partag<61>e en Ko"
|
||||
|
||||
#: sysdeps/names/mem.c:55
|
||||
msgid "Size of buffers kB"
|
||||
msgstr ""
|
||||
msgstr "Taille des tampons en Ko"
|
||||
|
||||
#: sysdeps/names/mem.c:56
|
||||
msgid "Size of cached memory in kB"
|
||||
msgstr ""
|
||||
msgstr "Taille de la m<>moire dans le cache en Ko"
|
||||
|
||||
#: sysdeps/names/mem.c:57
|
||||
msgid "Memory used from user processes in kB"
|
||||
msgstr ""
|
||||
msgstr "M<EFBFBD>moire utilis<69>e par les processus utilisateurs en Ko"
|
||||
|
||||
#: sysdeps/names/mem.c:58
|
||||
msgid "Memory in locked pages in kB"
|
||||
msgstr ""
|
||||
msgstr "M<EFBFBD>moire dans les pages v<>rouill<6C>es en Ko"
|
||||
|
||||
#: sysdeps/names/swap.c:36 sysdeps/names/swap.c:43
|
||||
msgid "Total Swap Space"
|
||||
msgstr ""
|
||||
msgstr "Taille totalle de la zone d'<27>change"
|
||||
|
||||
#: sysdeps/names/swap.c:37 sysdeps/names/swap.c:44
|
||||
msgid "Used Swap Space"
|
||||
msgstr ""
|
||||
msgstr "Taille utilis<69>e de la zone d'<27>change"
|
||||
|
||||
#: sysdeps/names/swap.c:38 sysdeps/names/swap.c:45
|
||||
msgid "Free Swap Space"
|
||||
msgstr ""
|
||||
msgstr "Espace libre de la zone d'<27>change"
|
||||
|
||||
#: sysdeps/names/uptime.c:36
|
||||
msgid "Uptime"
|
||||
msgstr ""
|
||||
msgstr "Uptime"
|
||||
|
||||
#: sysdeps/names/uptime.c:37
|
||||
msgid "Idletime"
|
||||
msgstr ""
|
||||
msgstr "Idletime"
|
||||
|
||||
#: sysdeps/names/uptime.c:42
|
||||
msgid "Time in seconds since system boot"
|
||||
msgstr ""
|
||||
msgstr "Temps en secondes depuis le d<>marrage du syst<73>me"
|
||||
|
||||
#: sysdeps/names/uptime.c:43
|
||||
msgid "Time in seconds the system spent in the idle task since system boot"
|
||||
msgstr ""
|
||||
msgstr "Temps en secondes pass<73> dans le processus inactif depuis le d<>marrage du syst<73>me"
|
||||
|
||||
#: sysdeps/names/shm_limits.c:37 sysdeps/names/shm_limits.c:46
|
||||
msgid "Max segment size"
|
||||
msgstr ""
|
||||
msgstr "Taille maximum des segments"
|
||||
|
||||
#: sysdeps/names/shm_limits.c:38 sysdeps/names/shm_limits.c:47
|
||||
msgid "Min segment size"
|
||||
msgstr ""
|
||||
msgstr "Taille minimum des segments"
|
||||
|
||||
#: sysdeps/names/shm_limits.c:39 sysdeps/names/shm_limits.c:48
|
||||
msgid "Max number of segments"
|
||||
msgstr ""
|
||||
msgstr "Nombre maximum des segments"
|
||||
|
||||
#: sysdeps/names/shm_limits.c:40 sysdeps/names/shm_limits.c:49
|
||||
msgid "Max shared segments per process"
|
||||
msgstr ""
|
||||
msgstr "Nombre maximum de segments partag<61>s par processus"
|
||||
|
||||
#: sysdeps/names/shm_limits.c:41 sysdeps/names/shm_limits.c:50
|
||||
msgid "Max total shared memory"
|
||||
msgstr ""
|
||||
msgstr "Taille totalle de la m<>moire partag<61>e"
|
||||
|
||||
#: sysdeps/names/msg_limits.c:37 sysdeps/names/msg_limits.c:48
|
||||
msgid "Size in kilobytes of message pool"
|
||||
msgstr ""
|
||||
msgstr "Taille en kilo-octets du pool de messages"
|
||||
|
||||
#: sysdeps/names/msg_limits.c:38 sysdeps/names/msg_limits.c:49
|
||||
msgid "Number of entries in message map"
|
||||
@@ -331,23 +331,23 @@ msgstr ""
|
||||
|
||||
#: sysdeps/names/msg_limits.c:39 sysdeps/names/msg_limits.c:50
|
||||
msgid "Max size of message"
|
||||
msgstr ""
|
||||
msgstr "Taille maximum des messages"
|
||||
|
||||
#: sysdeps/names/msg_limits.c:40 sysdeps/names/msg_limits.c:51
|
||||
msgid "Default max size of queue"
|
||||
msgstr ""
|
||||
msgstr "Taille maximum par d<>faut de la queue"
|
||||
|
||||
#: sysdeps/names/msg_limits.c:41 sysdeps/names/msg_limits.c:52
|
||||
msgid "Max queues system wide"
|
||||
msgstr ""
|
||||
msgstr "Nombre maximum de queues dans le syst<73>me"
|
||||
|
||||
#: sysdeps/names/msg_limits.c:42 sysdeps/names/msg_limits.c:53
|
||||
msgid "Message segment size"
|
||||
msgstr ""
|
||||
msgstr "Taille des segments de messages"
|
||||
|
||||
#: sysdeps/names/msg_limits.c:43 sysdeps/names/msg_limits.c:54
|
||||
msgid "Number of system message headers"
|
||||
msgstr ""
|
||||
msgstr "Nombre d'entetes de messages syst<73>me"
|
||||
|
||||
#: sysdeps/names/sem_limits.c:39 sysdeps/names/sem_limits.c:53
|
||||
msgid "Number of entries in semaphore map"
|
||||
@@ -355,19 +355,19 @@ msgstr ""
|
||||
|
||||
#: sysdeps/names/sem_limits.c:40 sysdeps/names/sem_limits.c:54
|
||||
msgid "Max number of arrays"
|
||||
msgstr ""
|
||||
msgstr "Nombre maximum de tables"
|
||||
|
||||
#: sysdeps/names/sem_limits.c:41 sysdeps/names/sem_limits.c:55
|
||||
msgid "Max semaphores system wide"
|
||||
msgstr ""
|
||||
msgstr "Nombre maximum de s<>maphores dans le syst<73>me"
|
||||
|
||||
#: sysdeps/names/sem_limits.c:42 sysdeps/names/sem_limits.c:56
|
||||
msgid "Number of undo structures system wide"
|
||||
msgstr ""
|
||||
msgstr "Nombre de structures 'undo' dans le syst<73>me"
|
||||
|
||||
#: sysdeps/names/sem_limits.c:43 sysdeps/names/sem_limits.c:57
|
||||
msgid "Max semaphores per array"
|
||||
msgstr ""
|
||||
msgstr "Nombre maximum de s<>maphores par table"
|
||||
|
||||
#: sysdeps/names/sem_limits.c:44 sysdeps/names/sem_limits.c:58
|
||||
msgid "Max ops per semop call"
|
||||
@@ -379,11 +379,11 @@ msgstr ""
|
||||
|
||||
#: sysdeps/names/sem_limits.c:46 sysdeps/names/sem_limits.c:60
|
||||
msgid "sizeof struct sem_undo"
|
||||
msgstr ""
|
||||
msgstr "sizeof struct sem_undo"
|
||||
|
||||
#: sysdeps/names/sem_limits.c:47 sysdeps/names/sem_limits.c:61
|
||||
msgid "Semaphore max value"
|
||||
msgstr ""
|
||||
msgstr "Valeur maximum d'un s<>maphore"
|
||||
|
||||
#: sysdeps/names/sem_limits.c:48 sysdeps/names/sem_limits.c:62
|
||||
msgid "Adjust on exit max value"
|
||||
|
@@ -1 +1 @@
|
||||
SUBDIRS = server proxy
|
||||
SUBDIRS = server daemon
|
||||
|
4
src/daemon/.cvsignore
Normal file
4
src/daemon/.cvsignore
Normal file
@@ -0,0 +1,4 @@
|
||||
Makefile.in
|
||||
Makefile
|
||||
gnuserv
|
||||
server_config.h
|
25
src/daemon/Makefile.am
Normal file
25
src/daemon/Makefile.am
Normal file
@@ -0,0 +1,25 @@
|
||||
LINK = $(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -o $@
|
||||
|
||||
INCLUDES = -I$(top_builddir) -I$(top_srcdir) @machine_incs@ \
|
||||
-I$(top_srcdir)/include -I$(top_srcdir)/intl @GUILE_INCS@ \
|
||||
-DGTOPLOCALEDIR=\"$(datadir)/locale\" -D_GNU_SOURCE
|
||||
|
||||
CFLAGS = -Wall -W @CFLAGS@ -DGTOP_SERVER=\""@LIBGTOP_SERVER@"\" -DDEBUG -DREAL_DEBUG
|
||||
|
||||
bin_PROGRAMS = gnuserv
|
||||
|
||||
EXTRA_PROGRAMS = gtop_daemon
|
||||
|
||||
gnuserv_SOURCES = gnuserv.c main.c slave.c
|
||||
gnuserv_LDADD = $(top_builddir)/lib/libgtop.la \
|
||||
$(top_builddir)/sysdeps/common/libgtop_common.la \
|
||||
$(top_builddir)/sysdeps/@sysdeps_dir@/libgtop_sysdeps.la \
|
||||
@INTLLIBS@ @LIBSUPPORT@ @X_LIBS@ -lXau
|
||||
gnuserv_LDFLAGS = -static
|
||||
|
||||
gtop_daemon_SOURCES = main.c inet.c loop.c output.c version.c
|
||||
gtop_daemon_LDADD = $(top_builddir)/lib/libgtop.la \
|
||||
$(top_builddir)/sysdeps/common/libgtop_common.la \
|
||||
$(top_builddir)/sysdeps/@sysdeps_dir@/libgtop_sysdeps.la \
|
||||
@INTLLIBS@ @LIBSUPPORT@
|
||||
gtop_daemon_LDFLAGS = -static
|
@@ -1,620 +0,0 @@
|
||||
/* -*-C-*-
|
||||
Client code to allow local and remote editing of files by XEmacs.
|
||||
Copyright (C) 1989 Free Software Foundation, Inc.
|
||||
Copyright (C) 1995 Sun Microsystems, Inc.
|
||||
Copyright (C) 1997 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of XEmacs.
|
||||
|
||||
XEmacs is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2, or (at your option) any
|
||||
later version.
|
||||
|
||||
XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with XEmacs; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
|
||||
Author: Andy Norman (ange@hplb.hpl.hp.com), based on
|
||||
'etc/emacsclient.c' from the GNU Emacs 18.52 distribution.
|
||||
|
||||
Please mail bugs and suggestions to the author at the above address.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file incorporates new features added by Bob Weiner <weiner@mot.com>,
|
||||
* Darrell Kindred <dkindred@cmu.edu> and Arup Mukherjee <arup@cmu.edu>.
|
||||
* GNUATTACH support added by Ben Wing <wing@xemacs.org>.
|
||||
* Please see the note at the end of the README file for details.
|
||||
*
|
||||
* (If gnuserv came bundled with your emacs, the README file is probably
|
||||
* ../etc/gnuserv.README relative to the directory containing this file)
|
||||
*/
|
||||
|
||||
#if 0
|
||||
/* Hand-munged RCS header */
|
||||
static char rcsid [] = "!Header: gnuclient.c,v 2.2 95/12/12 01:39:21 wing nene !";
|
||||
#endif
|
||||
|
||||
#include "gnuserv.h"
|
||||
#include "getopt.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif /* HAVE_STRING_H */
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif /* HAVE_UNISTD_H */
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#if !defined(SYSV_IPC) && !defined(UNIX_DOMAIN_SOCKETS) && \
|
||||
!defined(INTERNET_DOMAIN_SOCKETS)
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
fprintf (stderr, "Sorry, the Emacs server is only "
|
||||
"supported on systems that have\n");
|
||||
fprintf (stderr, "Unix Domain sockets, Internet Domain "
|
||||
"sockets or System V IPC.\n");
|
||||
exit (1);
|
||||
} /* main */
|
||||
#else /* SYSV_IPC || UNIX_DOMAIN_SOCKETS || INTERNET_DOMAIN_SOCKETS */
|
||||
|
||||
static char cwd[MAXPATHLEN+2]; /* current working directory when calculated */
|
||||
static char *cp = NULL; /* ptr into valid bit of cwd above */
|
||||
|
||||
static pid_t emacs_pid; /* Process id for emacs process */
|
||||
|
||||
void initialize_signals (void);
|
||||
|
||||
static void
|
||||
tell_emacs_to_resume (int sig)
|
||||
{
|
||||
char buffer[GSERV_BUFSZ+1];
|
||||
int s; /* socket / msqid to server */
|
||||
int connect_type; /* CONN_UNIX, CONN_INTERNET, or
|
||||
ONN_IPC */
|
||||
|
||||
/* Why is SYSV so retarded? */
|
||||
/* We want emacs to realize that we are resuming */
|
||||
signal(SIGCONT, tell_emacs_to_resume);
|
||||
|
||||
connect_type = make_connection (NULL, (u_short) 0, &s);
|
||||
|
||||
sprintf(buffer,"(gnuserv-eval '(resume-pid-console %d))", (int)getpid());
|
||||
send_string(s, buffer);
|
||||
|
||||
#ifdef SYSV_IPC
|
||||
if (connect_type == (int) CONN_IPC)
|
||||
disconnect_from_ipc_server (s, msgp, FALSE);
|
||||
#else /* !SYSV_IPC */
|
||||
if (connect_type != (int) CONN_IPC)
|
||||
disconnect_from_server (s, FALSE);
|
||||
#endif /* !SYSV_IPC */
|
||||
}
|
||||
|
||||
static void
|
||||
pass_signal_to_emacs (int sig)
|
||||
{
|
||||
if (kill (emacs_pid, sig) == -1)
|
||||
{
|
||||
fprintf (stderr, "gnuattach: Could not pass signal to emacs process\n");
|
||||
exit (1);
|
||||
}
|
||||
initialize_signals ();
|
||||
}
|
||||
|
||||
void
|
||||
initialize_signals ()
|
||||
{
|
||||
/* Set up signal handler to pass relevant signals to emacs process.
|
||||
We used to send SIGSEGV, SIGBUS, SIGPIPE, SIGILL and others to
|
||||
Emacs, but I think it's better not to. I can see no reason why
|
||||
Emacs should SIGSEGV whenever gnuclient SIGSEGV-s, etc. */
|
||||
signal (SIGHUP, pass_signal_to_emacs);
|
||||
signal (SIGQUIT, pass_signal_to_emacs);
|
||||
signal (SIGINT, pass_signal_to_emacs);
|
||||
#ifdef SIGWINCH
|
||||
signal (SIGWINCH, pass_signal_to_emacs);
|
||||
#endif
|
||||
|
||||
/* We want emacs to realize that we are resuming */
|
||||
signal (SIGCONT, tell_emacs_to_resume);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
get_current_working_directory -- return the cwd.
|
||||
*/
|
||||
static char *
|
||||
get_current_working_directory (void)
|
||||
{
|
||||
if (cp == NULL)
|
||||
{ /* haven't calculated it yet */
|
||||
#ifdef BSD
|
||||
if (getwd (cwd) == 0)
|
||||
#else /* !BSD */
|
||||
if (getcwd (cwd,MAXPATHLEN) == NULL)
|
||||
#endif /* !BSD */
|
||||
{
|
||||
perror (progname);
|
||||
fprintf (stderr, "%s: unable to get current working directory\n",
|
||||
progname);
|
||||
exit (1);
|
||||
} /* if */
|
||||
|
||||
/* on some systems, cwd can look like '@machine/' ... */
|
||||
/* ignore everything before the first '/' */
|
||||
for (cp = cwd; *cp && *cp != '/'; ++cp)
|
||||
;
|
||||
|
||||
} /* if */
|
||||
|
||||
return cp;
|
||||
|
||||
} /* get_current_working_directory */
|
||||
|
||||
|
||||
/*
|
||||
filename_expand -- try to convert the given filename into a fully-qualified
|
||||
pathname.
|
||||
*/
|
||||
static void
|
||||
filename_expand (char *fullpath, char *filename)
|
||||
/* fullpath - returned full pathname */
|
||||
/* filename - filename to expand */
|
||||
{
|
||||
int len;
|
||||
|
||||
fullpath[0] = '\0';
|
||||
|
||||
if (filename[0] && filename[0] != '/')
|
||||
{ /* relative filename */
|
||||
strcat (fullpath, get_current_working_directory ());
|
||||
len = strlen (fullpath);
|
||||
|
||||
if (len > 0 && fullpath[len-1] == '/') /* trailing slash already? */
|
||||
; /* yep */
|
||||
else
|
||||
strcat (fullpath, "/"); /* nope, append trailing slash */
|
||||
} /* if */
|
||||
|
||||
strcat (fullpath,filename);
|
||||
|
||||
} /* filename_expand */
|
||||
|
||||
/* Encase the string in quotes, escape all the backslashes and quotes
|
||||
in string. */
|
||||
static char *
|
||||
clean_string (const char *s)
|
||||
{
|
||||
int i = 0;
|
||||
char *p, *res;
|
||||
|
||||
for (p = s; *p; p++, i++)
|
||||
{
|
||||
if (*p == '\\' || *p == '\"')
|
||||
++i;
|
||||
else if (*p == '\004')
|
||||
i += 3;
|
||||
}
|
||||
p = res = (char *)malloc (i + 2 + 1);
|
||||
*p++ = '\"';
|
||||
for (; *s; p++, s++)
|
||||
{
|
||||
switch (*s)
|
||||
{
|
||||
case '\\':
|
||||
*p++ = '\\';
|
||||
*p = '\\';
|
||||
break;
|
||||
case '\"':
|
||||
*p++ = '\\';
|
||||
*p = '\"';
|
||||
break;
|
||||
case '\004':
|
||||
*p++ = '\\';
|
||||
*p++ = 'C';
|
||||
*p++ = '-';
|
||||
*p = 'd';
|
||||
break;
|
||||
default:
|
||||
*p = *s;
|
||||
}
|
||||
}
|
||||
*p++ = '\"';
|
||||
*p = '\0';
|
||||
return res;
|
||||
}
|
||||
|
||||
#define GET_ARGUMENT(var, desc) do { \
|
||||
if (*(p + 1)) (var) = p + 1; \
|
||||
else \
|
||||
{ \
|
||||
if (!argv[++i]) \
|
||||
{ \
|
||||
fprintf (stderr, "%s: `%s' must be followed by an argument\n", \
|
||||
progname, desc); \
|
||||
exit (1); \
|
||||
} \
|
||||
(var) = argv[i]; \
|
||||
} \
|
||||
over = 1; \
|
||||
} while (0)
|
||||
|
||||
/* A strdup immitation. */
|
||||
static char *
|
||||
my_strdup (const char *s)
|
||||
{
|
||||
char *new = malloc (strlen (s) + 1);
|
||||
if (new)
|
||||
strcpy (new, s);
|
||||
return new;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
int starting_line = 1; /* line to start editing at */
|
||||
char command[MAXPATHLEN+50]; /* emacs command buffer */
|
||||
char fullpath[MAXPATHLEN+1]; /* full pathname to file */
|
||||
char *eval_form = NULL; /* form to evaluate with `-eval' */
|
||||
char *eval_function = NULL; /* function to evaluate with `-f' */
|
||||
char *load_library = NULL; /* library to load */
|
||||
int quick = 0; /* quick edit, don't wait for user to
|
||||
finish */
|
||||
int batch = 0; /* batch mode */
|
||||
int view = 0; /* view only. */
|
||||
int nofiles = 0;
|
||||
int errflg = 0; /* option error */
|
||||
int s; /* socket / msqid to server */
|
||||
int connect_type; /* CONN_UNIX, CONN_INTERNET, or
|
||||
* CONN_IPC */
|
||||
int suppress_windows_system = 0;
|
||||
char *display = NULL;
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
char *hostarg = NULL; /* remote hostname */
|
||||
char *remotearg;
|
||||
char thishost[HOSTNAMSZ]; /* this hostname */
|
||||
char remotepath[MAXPATHLEN+1]; /* remote pathname */
|
||||
char *path;
|
||||
int rflg = 0; /* pathname given on cmdline */
|
||||
char *portarg;
|
||||
u_short port = 0; /* port to server */
|
||||
#endif /* INTERNET_DOMAIN_SOCKETS */
|
||||
#ifdef SYSV_IPC
|
||||
struct msgbuf *msgp; /* message */
|
||||
#endif /* SYSV_IPC */
|
||||
char *tty = NULL;
|
||||
char buffer[GSERV_BUFSZ + 1]; /* buffer to read pid */
|
||||
char result[GSERV_BUFSZ + 1];
|
||||
int i;
|
||||
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
memset (remotepath, 0, sizeof (remotepath));
|
||||
#endif /* INTERNET_DOMAIN_SOCKETS */
|
||||
|
||||
progname = strrchr (argv[0], '/');
|
||||
if (progname)
|
||||
++progname;
|
||||
else
|
||||
progname = argv[0];
|
||||
|
||||
display = getenv ("DISPLAY");
|
||||
if (!display)
|
||||
suppress_windows_system = 1;
|
||||
else
|
||||
display = my_strdup (display);
|
||||
|
||||
for (i = 1; argv[i] && !errflg; i++)
|
||||
{
|
||||
if (*argv[i] != '-')
|
||||
break;
|
||||
else if (*argv[i] == '-'
|
||||
&& (*(argv[i] + 1) == '\0'
|
||||
|| (*(argv[i] + 1) == '-' && *(argv[i] + 2) == '\0')))
|
||||
{
|
||||
/* `-' or `--' */
|
||||
++i;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!strcmp (argv[i], "-batch") || !strcmp (argv[i], "--batch"))
|
||||
batch = 1;
|
||||
else if (!strcmp (argv[i], "-eval") || !strcmp (argv[i], "--eval"))
|
||||
{
|
||||
if (!argv[++i])
|
||||
{
|
||||
fprintf (stderr, "%s: `-eval' must be followed by an argument\n",
|
||||
progname);
|
||||
exit (1);
|
||||
}
|
||||
eval_form = argv[i];
|
||||
}
|
||||
else if (!strcmp (argv[i], "-display") || !strcmp (argv[i], "--display"))
|
||||
{
|
||||
suppress_windows_system = 0;
|
||||
if (!argv[++i])
|
||||
{
|
||||
fprintf (stderr,
|
||||
"%s: `-display' must be followed by an argument\n",
|
||||
progname);
|
||||
exit (1);
|
||||
}
|
||||
if (display)
|
||||
free (display);
|
||||
/* no need to strdup. */
|
||||
display = argv[i];
|
||||
}
|
||||
else if (!strcmp (argv[i], "-nw"))
|
||||
suppress_windows_system = 1;
|
||||
else
|
||||
{
|
||||
/* Iterate over one-letter options. */
|
||||
char *p;
|
||||
int over = 0;
|
||||
for (p = argv[i] + 1; *p && !over; p++)
|
||||
{
|
||||
switch (*p)
|
||||
{
|
||||
case 'q':
|
||||
quick = 1;
|
||||
break;
|
||||
case 'v':
|
||||
view = 1;
|
||||
break;
|
||||
case 'f':
|
||||
GET_ARGUMENT (eval_function, "-f");
|
||||
break;
|
||||
case 'l':
|
||||
GET_ARGUMENT (load_library, "-l");
|
||||
break;
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
case 'h':
|
||||
GET_ARGUMENT (hostarg, "-h");
|
||||
break;
|
||||
case 'p':
|
||||
GET_ARGUMENT (portarg, "-p");
|
||||
port = atoi (portarg);
|
||||
break;
|
||||
case 'r':
|
||||
GET_ARGUMENT (remotearg, "-r");
|
||||
strcpy (remotepath, remotearg);
|
||||
rflg = 1;
|
||||
break;
|
||||
#endif /* INTERNET_DOMAIN_SOCKETS */
|
||||
default:
|
||||
errflg = 1;
|
||||
}
|
||||
} /* for */
|
||||
} /* else */
|
||||
} /* for */
|
||||
|
||||
if (errflg)
|
||||
{
|
||||
fprintf (stderr,
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
"usage: %s [-nw] [-display display] [-q] [-v] [-l library]\n"
|
||||
" [-batch] [-f function] [-eval form]\n"
|
||||
" [-h host] [-p port] [-r remote-path] [[+line] file] ...\n",
|
||||
#else /* !INTERNET_DOMAIN_SOCKETS */
|
||||
"usage: %s [-nw] [-q] [-v] [-l library] [-f function] [-eval form] "
|
||||
"[[+line] path] ...\n",
|
||||
#endif /* !INTERNET_DOMAIN_SOCKETS */
|
||||
progname);
|
||||
exit (1);
|
||||
}
|
||||
if (batch && argv[i])
|
||||
{
|
||||
fprintf (stderr, "%s: Cannot specify `-batch' with file names\n",
|
||||
progname);
|
||||
exit (1);
|
||||
}
|
||||
if (suppress_windows_system && hostarg)
|
||||
{
|
||||
fprintf (stderr, "%s: Remote editing is available only on X\n",
|
||||
progname);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
*result = '\0';
|
||||
if (eval_function || eval_form || load_library)
|
||||
{
|
||||
#if defined(INTERNET_DOMAIN_SOCKETS)
|
||||
connect_type = make_connection (hostarg, port, &s);
|
||||
#else
|
||||
connect_type = make_connection (NULL, (u_short) 0, &s);
|
||||
#endif
|
||||
sprintf (command, "(gnuserv-eval%s '(progn ", quick ? "-quickly" : "");
|
||||
send_string (s, command);
|
||||
if (load_library)
|
||||
{
|
||||
sprintf (command, " (load-library %s)", clean_string (load_library));
|
||||
send_string (s, command);
|
||||
}
|
||||
if (eval_form)
|
||||
{
|
||||
sprintf (command, " %s", eval_form);
|
||||
send_string (s, command);
|
||||
}
|
||||
if (eval_function)
|
||||
{
|
||||
sprintf (command, " (%s)", eval_function);
|
||||
send_string (s, command);
|
||||
}
|
||||
send_string (s, "))");
|
||||
send_string (s, EOT_STR);
|
||||
if (read_line (s, result) == 0)
|
||||
{
|
||||
fprintf (stderr, "%s: Could not read\n", progname);
|
||||
exit (1);
|
||||
}
|
||||
} /* eval_function || eval_form || load_library */
|
||||
else if (batch)
|
||||
{
|
||||
fprintf (stderr, "%s: `-batch' requires an evaluation\n",
|
||||
progname);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if (!batch)
|
||||
{
|
||||
if (suppress_windows_system)
|
||||
{
|
||||
tty = ttyname (0);
|
||||
if (!tty)
|
||||
{
|
||||
fprintf (stderr, "%s: Not connected to a tty", progname);
|
||||
exit (1);
|
||||
}
|
||||
#if defined(INTERNET_DOMAIN_SOCKETS)
|
||||
connect_type = make_connection (hostarg, port, &s);
|
||||
#else
|
||||
connect_type = make_connection (NULL, (u_short) 0, &s);
|
||||
#endif
|
||||
send_string (s, "(gnuserv-eval '(emacs-pid))");
|
||||
send_string (s, EOT_STR);
|
||||
|
||||
if (read_line (s, buffer) == 0)
|
||||
{
|
||||
fprintf (stderr, "%s: Could not establish Emacs procces id\n",
|
||||
progname);
|
||||
exit (1);
|
||||
}
|
||||
/* Don't do disconnect_from_server becasue we have already read
|
||||
data, and disconnect doesn't do anything else. */
|
||||
#ifndef INTERNET_DOMAIN_SOCKETS
|
||||
if (connect_type == (int) CONN_IPC)
|
||||
disconnect_from_ipc_server (s, msgp, FALSE);
|
||||
#endif /* !SYSV_IPC */
|
||||
|
||||
emacs_pid = (pid_t)atol(buffer);
|
||||
initialize_signals();
|
||||
} /* suppress_windows_system */
|
||||
|
||||
#if defined(INTERNET_DOMAIN_SOCKETS)
|
||||
connect_type = make_connection (hostarg, port, &s);
|
||||
#else
|
||||
connect_type = make_connection (NULL, (u_short) 0, &s);
|
||||
#endif
|
||||
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
if (connect_type == (int) CONN_INTERNET)
|
||||
{
|
||||
char *ptr;
|
||||
gethostname (thishost, HOSTNAMSZ);
|
||||
if (!rflg)
|
||||
{ /* attempt to generate a path
|
||||
* to this machine */
|
||||
if ((ptr = getenv ("GNU_NODE")) != NULL)
|
||||
/* user specified a path */
|
||||
strcpy (remotepath, ptr);
|
||||
}
|
||||
#if 0 /* This is really bogus... re-enable it if you must have it! */
|
||||
#if defined (hp9000s300) || defined (hp9000s800)
|
||||
else if (strcmp (thishost,hostarg))
|
||||
{ /* try /net/thishost */
|
||||
strcpy (remotepath, "/net/"); /* (this fails using internet
|
||||
addresses) */
|
||||
strcat (remotepath, thishost);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{ /* same machines, no need for path */
|
||||
remotepath[0] = '\0'; /* default is the empty path */
|
||||
}
|
||||
#endif /* INTERNET_DOMAIN_SOCKETS */
|
||||
|
||||
#ifdef SYSV_IPC
|
||||
if ((msgp = (struct msgbuf *)
|
||||
malloc (sizeof *msgp + GSERV_BUFSZ)) == NULL)
|
||||
{
|
||||
fprintf (stderr, "%s: not enough memory for message buffer\n", progname);
|
||||
exit (1);
|
||||
} /* if */
|
||||
|
||||
msgp->mtext[0] = '\0'; /* ready for later strcats */
|
||||
#endif /* SYSV_IPC */
|
||||
|
||||
if (suppress_windows_system)
|
||||
{
|
||||
char *term = getenv ("TERM");
|
||||
if (!term)
|
||||
{
|
||||
fprintf (stderr, "%s: unknown terminal type\n", progname);
|
||||
exit (1);
|
||||
}
|
||||
sprintf (command, "(gnuserv-edit-files '(tty %s %s %d) '(",
|
||||
clean_string (tty), clean_string (term), (int)getpid ());
|
||||
}
|
||||
else /* !suppress_windows_system */
|
||||
{
|
||||
sprintf (command, "(gnuserv-edit-files '(x %s) '(",
|
||||
clean_string (display));
|
||||
} /* !suppress_windows_system */
|
||||
send_string (s, command);
|
||||
|
||||
if (!argv[i])
|
||||
nofiles = 1;
|
||||
|
||||
for (; argv[i]; i++)
|
||||
{
|
||||
if (i < argc - 1 && *argv[i] == '+')
|
||||
starting_line = atoi (argv[i++]);
|
||||
else
|
||||
starting_line = 1;
|
||||
/* If the last argument is +something, treat it as a file. */
|
||||
if (i == argc)
|
||||
{
|
||||
starting_line = 1;
|
||||
--i;
|
||||
}
|
||||
filename_expand (fullpath, argv[i]);
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
path = malloc (strlen (remotepath) + strlen (fullpath) + 1);
|
||||
sprintf (path, "%s%s", remotepath, fullpath);
|
||||
#else
|
||||
path = my_strdup (fullpath);
|
||||
#endif
|
||||
sprintf (command, "(%d . %s)", starting_line, clean_string (path));
|
||||
send_string (s, command);
|
||||
free (path);
|
||||
} /* for */
|
||||
|
||||
sprintf (command, ")%s%s",
|
||||
(quick || (nofiles && !suppress_windows_system)) ? " 'quick" : "",
|
||||
view ? " 'view" : "");
|
||||
send_string (s, command);
|
||||
send_string (s, ")");
|
||||
|
||||
#ifdef SYSV_IPC
|
||||
if (connect_type == (int) CONN_IPC)
|
||||
disconnect_from_ipc_server (s, msgp, FALSE);
|
||||
#else /* !SYSV_IPC */
|
||||
if (connect_type != (int) CONN_IPC)
|
||||
disconnect_from_server (s, FALSE);
|
||||
#endif /* !SYSV_IPC */
|
||||
} /* not batch */
|
||||
|
||||
if (batch && !quick)
|
||||
printf ("%s\n", result);
|
||||
|
||||
return 0;
|
||||
|
||||
} /* main */
|
||||
|
||||
#endif /* SYSV_IPC || UNIX_DOMAIN_SOCKETS || INTERNET_DOMAIN_SOCKETS */
|
1044
src/daemon/gnuserv.c
1044
src/daemon/gnuserv.c
File diff suppressed because it is too large
Load Diff
@@ -1,190 +0,0 @@
|
||||
/* -*-C-*-
|
||||
|
||||
Header file for the GNU Emacs server and client C code.
|
||||
|
||||
This file is part of GNU Emacs.
|
||||
|
||||
Copying is permitted under those conditions described by the GNU
|
||||
General Public License.
|
||||
|
||||
Copyright (C) 1989 Free Software Foundation, Inc.
|
||||
|
||||
Author: Andy Norman (ange@hplb.hpl.hp.com), based on
|
||||
'etc/server.c' and 'etc/emacsclient.c' from the 18.52 GNU
|
||||
Emacs distribution.
|
||||
|
||||
Please mail bugs and suggestions to the author at the above address.
|
||||
*/
|
||||
|
||||
/* HISTORY
|
||||
* 11-Nov-1990 bristor@simba
|
||||
* Added EOT stuff.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file incorporates new features added by Bob Weiner <weiner@mot.com>,
|
||||
* Darrell Kindred <dkindred@cmu.edu> and Arup Mukherjee <arup@cmu.edu>.
|
||||
* Please see the note at the end of the README file for details.
|
||||
*
|
||||
* (If gnuserv came bundled with your emacs, the README file is probably
|
||||
* ../etc/gnuserv.README relative to the directory containing this file)
|
||||
*/
|
||||
|
||||
#if 0
|
||||
static char header_rcsid [] = "!Header: gnuserv.h,v 2.4 95/02/16 11:58:11 arup alpha !";
|
||||
#endif
|
||||
|
||||
#define NO_SHORTNAMES
|
||||
|
||||
#define PATCHLEVEL 2
|
||||
|
||||
#define NO_SHORTNAMES
|
||||
/* gnuserv should not be compiled using SOCKS */
|
||||
#define DO_NOT_SOCKSIFY
|
||||
#include <glibtop/global.h>
|
||||
#undef read
|
||||
#undef write
|
||||
#undef open
|
||||
#undef close
|
||||
#undef signal
|
||||
|
||||
/* Define the communication method between server and clients:
|
||||
* You can have either or both kinds of sockets, but you can't mix
|
||||
* sockets with sysv ipc
|
||||
*/
|
||||
|
||||
|
||||
#define INTERNET_DOMAIN_SOCKETS
|
||||
#define UNIX_DOMAIN_SOCKETS
|
||||
/* #define SYSV_IPC */
|
||||
|
||||
/*
|
||||
* Define additional authentication protocols to be used. These methods will
|
||||
* be tried before falling back to the default gnuserv protocol (based on
|
||||
* the GNU_SECURE environment variable). Currently, only MIT-MAGIC-COOKIE-1
|
||||
* is also supported.
|
||||
*
|
||||
* Comment out the next line(s) if you don't want to enable the
|
||||
* appropriate authentication protocol.
|
||||
*/
|
||||
|
||||
#if defined (HAVE_XAUTH)
|
||||
#define AUTH_MAGIC_COOKIE
|
||||
#endif /* HAVE_XAUTH */
|
||||
|
||||
/*
|
||||
* stuff related to supporting MIT-MAGIC-COOKIE-1
|
||||
*/
|
||||
|
||||
#define MCOOKIE_SCREEN "999" /* screen # to use as the gnuserv cookie */
|
||||
#define MCOOKIE_NAME "MAGIC-1" /* authentication protocol name */
|
||||
#define MCOOKIE_X_NAME "MIT-MAGIC-COOKIE-1" /* as needed by X */
|
||||
|
||||
|
||||
#define DEFAUTH_NAME "GNU-SECURE" /* name of default auth protocol */
|
||||
#define AUTH_TIMEOUT 15 /* # seconds to wait for auth data */
|
||||
#define AUTH_NAMESZ 15 /* max allows auth protocol name size */
|
||||
|
||||
|
||||
/*
|
||||
* Pick a default communication scheme, if none was specified.
|
||||
*/
|
||||
|
||||
#if !defined(SYSV_IPC) && !defined(UNIX_DOMAIN_SOCKETS) && !defined(INTERNET_DOMAIN_SOCKETS)
|
||||
|
||||
#ifdef HAVE_SYSVIPC
|
||||
#define SYSV_IPC /* SYSV systems use SYSV IPC by default */
|
||||
#endif /* HAVE_SYSVIPC */
|
||||
|
||||
#ifdef BSD
|
||||
#define UNIX_DOMAIN_SOCKETS /* BSD systems use Unix Domain sockets by default */
|
||||
#endif /* BSD */
|
||||
|
||||
#endif /* No communication method pre-defined */
|
||||
|
||||
/*
|
||||
* If you are using SYSV_IPC, you might want to make the buffer size bigger
|
||||
* since it limits the size of requests and responses. Don't make it bigger
|
||||
* than your system's max message size though (usually a couple of k) or else
|
||||
* msgsend will start failing. For sockets, using the system BUFSIZ is usually
|
||||
* what you want.
|
||||
*/
|
||||
|
||||
# define GSERV_BUFSZ BUFSIZ
|
||||
|
||||
|
||||
#ifdef SYSV_IPC
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/msg.h>
|
||||
|
||||
#define send_string(s,str) \
|
||||
if (strlen(msgp->mtext) + strlen(str) < GSERV_BUFSZ) \
|
||||
strcat(msgp->mtext,str); \
|
||||
else \
|
||||
{ \
|
||||
fprintf(stderr,"%s: not enough message buffer space\n",progname); \
|
||||
exit(1); \
|
||||
} \
|
||||
|
||||
#endif /* SYSV_IPC */
|
||||
|
||||
#if defined(INTERNET_DOMAIN_SOCKETS) || defined(UNIX_DOMAIN_SOCKETS)
|
||||
#include <sys/socket.h>
|
||||
#endif /* INTERNET_DOMAIN_SOCKETS || UNIX_DOMAIN_SOCKETS */
|
||||
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#define TABLE_SIZE 101 /* The number of entries in the hash table */
|
||||
#define HASH(host) host /* Rather simplistic hash function */
|
||||
#define DEFAULT_PORT 21490 /* default port number to use is
|
||||
* DEFAULT_PORT + uid */
|
||||
#endif /* INTERNET_DOMAIN_SOCKETS */
|
||||
|
||||
#ifdef UNIX_DOMAIN_SOCKETS
|
||||
#include <sys/un.h>
|
||||
#define HIDE_UNIX_SOCKET /* put the unix socket in a protected dir */
|
||||
#endif /* UNIX_DOMAIN_SOCKETS */
|
||||
|
||||
#define HOSTNAMSZ 255 /* max size of a hostname */
|
||||
#define REPLYSIZ 300 /* max size of reply from server to client */
|
||||
#undef FALSE
|
||||
#define FALSE 0
|
||||
#undef TRUE
|
||||
#define TRUE 1
|
||||
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
extern char *progname;
|
||||
|
||||
/* The casts shut Sun's compiler up and are safe in the context these
|
||||
are actually used. */
|
||||
#define max2(x,y) (((int) (x) > (int) (y)) ? (x) : (y))
|
||||
#define min2(x,y) (((int) (x) < (int) (y)) ? (x) : (y))
|
||||
|
||||
#ifndef _NFILE /* rough guess at maximum number of open files */
|
||||
#define _NFILE 20
|
||||
#endif
|
||||
|
||||
#define EOT_STR "\004"
|
||||
#define EOT_CHR '\004'
|
||||
|
||||
/* connection types */
|
||||
#define CONN_UNIX 0
|
||||
#define CONN_INTERNET 1
|
||||
#define CONN_IPC 2
|
||||
|
||||
/* function declarations */
|
||||
int make_connection (char *hostarg, int portarg, int *s);
|
||||
#ifdef SYSV_IPC
|
||||
void disconnect_from_ipc_server();
|
||||
#endif
|
||||
#if defined(INTERNET_DOMAIN_SOCKETS) || defined(UNIX_DOMAIN_SOCKETS)
|
||||
void send_string (int s, const char *msg);
|
||||
void disconnect_from_server (int s, int echo);
|
||||
int read_line (int s, char *dest);
|
||||
#endif
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
int internet_addr (char *host);
|
||||
#endif
|
@@ -1,454 +0,0 @@
|
||||
/* -*-C-*-
|
||||
Common library code for the GNU Emacs server and client.
|
||||
|
||||
This file is part of GNU Emacs.
|
||||
|
||||
Copying is permitted under those conditions described by the GNU
|
||||
General Public License.
|
||||
|
||||
Copyright (C) 1989 Free Software Foundation, Inc.
|
||||
|
||||
Author: Andy Norman (ange@hplb.hpl.hp.com), based on
|
||||
'etc/server.c' and 'etc/emacsclient.c' from the 18.52 GNU
|
||||
Emacs distribution.
|
||||
|
||||
Please mail bugs and suggestions to the author at the above address.
|
||||
*/
|
||||
|
||||
/* HISTORY
|
||||
* 11-Nov-1990 bristor@simba
|
||||
* Added EOT stuff.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file incorporates new features added by Bob Weiner <weiner@mot.com>,
|
||||
* Darrell Kindred <dkindred@cmu.edu> and Arup Mukherjee <arup@cmu.edu>.
|
||||
* Please see the note at the end of the README file for details.
|
||||
*
|
||||
* (If gnuserv came bundled with your emacs, the README file is probably
|
||||
* ../etc/gnuserv.README relative to the directory containing this file)
|
||||
*/
|
||||
|
||||
#if 0
|
||||
static char rcsid [] = "!Header: gnuslib.c,v 2.4 95/02/16 11:57:37 arup alpha !";
|
||||
#endif
|
||||
|
||||
#include "gnuserv.h"
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef SYSV_IPC
|
||||
static int connect_to_ipc_server (void);
|
||||
#endif
|
||||
#ifdef UNIX_DOMAIN_SOCKETS
|
||||
static int connect_to_unix_server (void);
|
||||
#endif
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
static int connect_to_internet_server (char *serverhost, u_short port);
|
||||
#endif
|
||||
|
||||
/* On some systems, e.g. DGUX, inet_addr returns a 'struct in_addr'. */
|
||||
#ifdef HAVE_BROKEN_INET_ADDR
|
||||
# define IN_ADDR struct in_addr
|
||||
# define NUMERIC_ADDR_ERROR (numeric_addr.s_addr == -1)
|
||||
#else
|
||||
# if (LONGBITS > 32)
|
||||
# define IN_ADDR unsigned int
|
||||
# else
|
||||
# define IN_ADDR unsigned long
|
||||
# endif
|
||||
# define NUMERIC_ADDR_ERROR (numeric_addr == (IN_ADDR) -1)
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif /* HAVE_UNISTD_H */
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif /* HAVE_STRING_H */
|
||||
|
||||
#include <arpa/inet.h>
|
||||
|
||||
char *progname = NULL;
|
||||
|
||||
int make_connection(hostarg, portarg, s)
|
||||
char *hostarg;
|
||||
int portarg;
|
||||
int *s;
|
||||
{
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
char *ptr;
|
||||
if (hostarg == NULL)
|
||||
hostarg = getenv("GNU_HOST");
|
||||
if (portarg == 0 && (ptr=getenv("GNU_PORT")) != NULL)
|
||||
portarg = atoi(ptr);
|
||||
#endif
|
||||
|
||||
if (hostarg != NULL) {
|
||||
/* hostname was given explicitly, via cmd line arg or GNU_HOST,
|
||||
* so obey it. */
|
||||
#ifdef UNIX_DOMAIN_SOCKETS
|
||||
if (!strcmp(hostarg, "unix")) {
|
||||
*s = connect_to_unix_server();
|
||||
return (int) CONN_UNIX;
|
||||
}
|
||||
#endif /* UNIX_DOMAIN_SOCKETS */
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
*s = connect_to_internet_server(hostarg, portarg);
|
||||
return (int) CONN_INTERNET;
|
||||
#endif
|
||||
#ifdef SYSV_IPC
|
||||
return -1; /* hostarg should always be NULL for SYSV_IPC */
|
||||
#endif
|
||||
} else {
|
||||
/* no hostname given. Use unix-domain/sysv-ipc, or
|
||||
* internet-domain connection to local host if they're not available. */
|
||||
#if defined(UNIX_DOMAIN_SOCKETS)
|
||||
*s = connect_to_unix_server();
|
||||
return (int) CONN_UNIX;
|
||||
#elif defined(SYSV_IPC)
|
||||
*s = connect_to_ipc_server();
|
||||
return (int) CONN_IPC;
|
||||
#elif defined(INTERNET_DOMAIN_SOCKETS)
|
||||
{
|
||||
char localhost[HOSTNAMSZ];
|
||||
gethostname(localhost,HOSTNAMSZ); /* use this host by default */
|
||||
*s = connect_to_internet_server(localhost, portarg);
|
||||
return (int) CONN_INTERNET;
|
||||
}
|
||||
#endif /* IPC type */
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SYSV_IPC
|
||||
/*
|
||||
connect_to_ipc_server -- establish connection with server process via SYSV IPC
|
||||
Returns msqid for server if successful.
|
||||
*/
|
||||
static int connect_to_ipc_server (void)
|
||||
{
|
||||
int s; /* connected msqid */
|
||||
key_t key; /* message key */
|
||||
char buf[GSERV_BUFSZ+1]; /* buffer for filename */
|
||||
|
||||
sprintf(buf,"/tmp/gsrv%d",(int)geteuid());
|
||||
creat(buf,0600);
|
||||
if ((key = ftok(buf,1)) == -1) {
|
||||
perror(progname);
|
||||
fprintf(stderr, "%s: unable to get ipc key from %s\n",
|
||||
progname, buf);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ((s = msgget(key,0600)) == -1) {
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to access msg queue\n",progname);
|
||||
exit(1);
|
||||
}; /* if */
|
||||
|
||||
return(s);
|
||||
|
||||
} /* connect_to_ipc_server */
|
||||
|
||||
|
||||
/*
|
||||
disconnect_from_ipc_server -- inform the server that sending has finished,
|
||||
and wait for its reply.
|
||||
*/
|
||||
void disconnect_from_ipc_server(s,msgp,echo)
|
||||
int s;
|
||||
struct msgbuf *msgp;
|
||||
int echo;
|
||||
{
|
||||
int len; /* length of received message */
|
||||
|
||||
send_string(s,EOT_STR); /* EOT terminates this message */
|
||||
msgp->mtype = 1;
|
||||
|
||||
if(msgsnd(s,msgp,strlen(msgp->mtext)+1,0) < 0) {
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to send message to server\n",progname);
|
||||
exit(1);
|
||||
}; /* if */
|
||||
|
||||
if((len = msgrcv(s,msgp,GSERV_BUFSZ,getpid(),0)) < 0) {
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to receive message from server\n",progname);
|
||||
exit(1);
|
||||
}; /* if */
|
||||
|
||||
if (echo) {
|
||||
msgp->mtext[len] = '\0'; /* string terminate message */
|
||||
fputs(msgp->mtext, stdout);
|
||||
if (msgp->mtext[len-1] != '\n') putchar ('\n');
|
||||
}; /* if */
|
||||
|
||||
} /* disconnect_from_ipc_server */
|
||||
#endif /* SYSV_IPC */
|
||||
|
||||
|
||||
#if defined(INTERNET_DOMAIN_SOCKETS) || defined(UNIX_DOMAIN_SOCKETS)
|
||||
/*
|
||||
send_string -- send string to socket.
|
||||
*/
|
||||
void send_string(s,msg)
|
||||
int s;
|
||||
const char *msg;
|
||||
{
|
||||
#if 0
|
||||
if (send(s,msg,strlen(msg),0) < 0) {
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to send\n",progname);
|
||||
exit(1);
|
||||
}; /* if */
|
||||
#else
|
||||
int len, left=strlen(msg);
|
||||
while (left > 0) {
|
||||
if ((len=write(s,msg,min2(left,GSERV_BUFSZ))) < 0) {
|
||||
/* XEmacs addition: robertl@arnet.com */
|
||||
if (errno == EPIPE) {
|
||||
return ;
|
||||
}
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to send\n",progname);
|
||||
exit(1);
|
||||
}; /* if */
|
||||
left -= len;
|
||||
msg += len;
|
||||
}; /* while */
|
||||
#endif
|
||||
} /* send_string */
|
||||
|
||||
/*
|
||||
read_line -- read a \n terminated line from a socket
|
||||
*/
|
||||
int read_line(int s, char *dest)
|
||||
{
|
||||
int length;
|
||||
int offset=0;
|
||||
char buffer[GSERV_BUFSZ+1];
|
||||
|
||||
while ((length=read(s,buffer+offset,1)>0) && buffer[offset]!='\n'
|
||||
&& buffer[offset] != EOT_CHR) {
|
||||
offset += length;
|
||||
if (offset >= GSERV_BUFSZ)
|
||||
break;
|
||||
}
|
||||
buffer[offset] = '\0';
|
||||
strcpy(dest,buffer);
|
||||
return 1;
|
||||
} /* read_line */
|
||||
#endif /* INTERNET_DOMAIN_SOCKETS || UNIX_DOMAIN_SOCKETS */
|
||||
|
||||
|
||||
#ifdef UNIX_DOMAIN_SOCKETS
|
||||
/*
|
||||
connect_to_unix_server -- establish connection with server process via a unix-
|
||||
domain socket. Returns socket descriptor for server
|
||||
if successful.
|
||||
*/
|
||||
static int connect_to_unix_server (void)
|
||||
{
|
||||
int s; /* connected socket descriptor */
|
||||
struct sockaddr_un server; /* for unix connections */
|
||||
|
||||
if ((s = socket(AF_UNIX,SOCK_STREAM,0)) < 0) {
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to create socket\n",progname);
|
||||
exit(1);
|
||||
}; /* if */
|
||||
|
||||
server.sun_family = AF_UNIX;
|
||||
#ifdef HIDE_UNIX_SOCKET
|
||||
sprintf(server.sun_path,"/tmp/gsrvdir%d/gsrv",(int)geteuid());
|
||||
#else /* HIDE_UNIX_SOCKET */
|
||||
sprintf(server.sun_path,"/tmp/gsrv%d",(int)geteuid());
|
||||
#endif /* HIDE_UNIX_SOCKET */
|
||||
if (connect(s,(struct sockaddr *)&server,strlen(server.sun_path)+2) < 0) {
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to connect to local\n",progname);
|
||||
exit(1);
|
||||
}; /* if */
|
||||
|
||||
return(s);
|
||||
|
||||
} /* connect_to_unix_server */
|
||||
#endif /* UNIX_DOMAIN_SOCKETS */
|
||||
|
||||
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
/*
|
||||
internet_addr -- return the internet addr of the hostname or
|
||||
internet address passed. Return -1 on error.
|
||||
*/
|
||||
int internet_addr(host)
|
||||
char *host;
|
||||
{
|
||||
struct hostent *hp; /* pointer to host info for remote host */
|
||||
IN_ADDR numeric_addr; /* host address */
|
||||
|
||||
numeric_addr = inet_addr(host);
|
||||
if (!NUMERIC_ADDR_ERROR)
|
||||
return numeric_addr;
|
||||
else if ((hp = gethostbyname(host)) != NULL)
|
||||
return ((struct in_addr *)(hp->h_addr))->s_addr;
|
||||
else
|
||||
return -1;
|
||||
|
||||
} /* internet_addr */
|
||||
|
||||
#ifdef AUTH_MAGIC_COOKIE
|
||||
# include <X11/X.h>
|
||||
# include <X11/Xauth.h>
|
||||
|
||||
static Xauth *server_xauth = NULL;
|
||||
#endif
|
||||
|
||||
/*
|
||||
connect_to_internet_server -- establish connection with server process via
|
||||
an internet domain socket. Returns socket
|
||||
descriptor for server if successful.
|
||||
*/
|
||||
static int connect_to_internet_server (char *serverhost, u_short port)
|
||||
{
|
||||
int s; /* connected socket descriptor */
|
||||
struct servent *sp; /* pointer to service information */
|
||||
struct sockaddr_in peeraddr_in; /* for peer socket address */
|
||||
char buf[512]; /* temporary buffer */
|
||||
|
||||
/* clear out address structures */
|
||||
memset((char *)&peeraddr_in,0,sizeof(struct sockaddr_in));
|
||||
|
||||
/* Set up the peer address to which we will connect. */
|
||||
peeraddr_in.sin_family = AF_INET;
|
||||
|
||||
/* look up the server host's internet address */
|
||||
if ((peeraddr_in.sin_addr.s_addr = internet_addr(serverhost)) == -1) {
|
||||
fprintf(stderr,"%s: unable to find %s in /etc/hosts or from YP\n",
|
||||
progname,serverhost);
|
||||
exit(1);
|
||||
}; /* if */
|
||||
|
||||
if (port == 0) {
|
||||
if ((sp = getservbyname ("gnuserv","tcp")) == NULL)
|
||||
peeraddr_in.sin_port = htons(DEFAULT_PORT+getuid());
|
||||
else
|
||||
peeraddr_in.sin_port = sp->s_port;
|
||||
} /* if */
|
||||
else
|
||||
peeraddr_in.sin_port = htons(port);
|
||||
|
||||
/* Create the socket. */
|
||||
if ((s = socket (AF_INET,SOCK_STREAM, 0))== -1) {
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to create socket\n",progname);
|
||||
exit(1);
|
||||
}; /* if */
|
||||
|
||||
/* Try to connect to the remote server at the address
|
||||
* which was just built into peeraddr.
|
||||
*/
|
||||
if (connect(s, (struct sockaddr *)&peeraddr_in,
|
||||
sizeof(struct sockaddr_in)) == -1) {
|
||||
perror(progname);
|
||||
fprintf(stderr, "%s: unable to connect to remote\n",progname);
|
||||
exit(1);
|
||||
}; /* if */
|
||||
|
||||
#ifdef AUTH_MAGIC_COOKIE
|
||||
|
||||
/* send credentials using MIT-MAGIC-COOKIE-1 protocol */
|
||||
|
||||
server_xauth =
|
||||
XauGetAuthByAddr(FamilyInternet,
|
||||
sizeof(peeraddr_in.sin_addr.s_addr),
|
||||
(char *) &peeraddr_in.sin_addr.s_addr,
|
||||
strlen(MCOOKIE_SCREEN), MCOOKIE_SCREEN,
|
||||
strlen(MCOOKIE_X_NAME), MCOOKIE_X_NAME);
|
||||
|
||||
if (server_xauth && server_xauth->data) {
|
||||
sprintf(buf, "%s\n%d\n", MCOOKIE_NAME, server_xauth->data_length);
|
||||
write (s, buf, strlen(buf));
|
||||
write (s, server_xauth->data, server_xauth->data_length);
|
||||
|
||||
return (s);
|
||||
}
|
||||
|
||||
#endif /* AUTH_MAGIC_COOKIE */
|
||||
|
||||
sprintf (buf, "%s\n", DEFAUTH_NAME);
|
||||
write (s, buf, strlen(buf));
|
||||
|
||||
return(s);
|
||||
|
||||
} /* connect_to_internet_server */
|
||||
#endif /* INTERNET_DOMAIN_SOCKETS */
|
||||
|
||||
|
||||
#if defined(INTERNET_DOMAIN_SOCKETS) || defined(UNIX_DOMAIN_SOCKETS)
|
||||
/*
|
||||
disconnect_from_server -- inform the server that sending has finished, and wait for
|
||||
its reply.
|
||||
*/
|
||||
void disconnect_from_server(s,echo)
|
||||
int s;
|
||||
int echo;
|
||||
{
|
||||
#if 0
|
||||
char buffer[REPLYSIZ+1];
|
||||
#else
|
||||
char buffer[GSERV_BUFSZ+1];
|
||||
#endif
|
||||
int add_newline = 1;
|
||||
int length;
|
||||
|
||||
send_string(s,EOT_STR); /* make sure server gets string */
|
||||
|
||||
#if !defined (linux) && !defined (_SCO_DS)
|
||||
/*
|
||||
* shutdown is completely hozed under linux. If s is a unix domain socket,
|
||||
* you'll get EOPNOTSUPP back from it. If s is an internet socket, you get
|
||||
* a broken pipe when you try to read a bit later. The latter
|
||||
* problem is fixed for linux versions >= 1.1.46, but the problem
|
||||
* with unix sockets persists. Sigh.
|
||||
*/
|
||||
|
||||
if (shutdown(s,1) == -1) {
|
||||
perror(progname);
|
||||
fprintf(stderr, "%s: unable to shutdown socket\n",progname);
|
||||
exit(1);
|
||||
}; /* if */
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
while((length = recv(s,buffer,REPLYSIZ,0)) > 0) {
|
||||
buffer[length] = '\0';
|
||||
if (echo) fputs(buffer,stdout);
|
||||
add_newline = (buffer[length-1] != '\n');
|
||||
}; /* while */
|
||||
#else
|
||||
while ((length = read(s,buffer,GSERV_BUFSZ)) > 0 ||
|
||||
(length == -1 && errno == EINTR)) {
|
||||
if (length) {
|
||||
buffer[length] = '\0';
|
||||
if (echo) {
|
||||
fputs(buffer,stdout);
|
||||
add_newline = (buffer[length-1] != '\n');
|
||||
}; /* if */
|
||||
}; /* if */
|
||||
}; /* while */
|
||||
#endif
|
||||
|
||||
if (echo && add_newline) putchar('\n');
|
||||
|
||||
if(length < 0) {
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to read the reply from the server\n",progname);
|
||||
exit(1);
|
||||
}; /* if */
|
||||
|
||||
} /* disconnect_from_server */
|
||||
#endif /* INTERNET_DOMAIN_SOCKETS || UNIX_DOMAIN_SOCKETS */
|
311
src/daemon/main.c
Normal file
311
src/daemon/main.c
Normal file
@@ -0,0 +1,311 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the Gnome Top Library.
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
The Gnome Top Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The Gnome Top Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <glibtop/gnuserv.h>
|
||||
|
||||
#include <glibtop/open.h>
|
||||
#include <glibtop/union.h>
|
||||
#include <glibtop/xmalloc.h>
|
||||
#include <glibtop/version.h>
|
||||
#include <glibtop/command.h>
|
||||
#include <glibtop/parameter.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <locale.h>
|
||||
|
||||
#undef REAL_DEBUG
|
||||
#define PARENT_DEBUG
|
||||
|
||||
#define MSG_BUFSZ sizeof (struct _glibtop_ipc_message)
|
||||
#define MSG_MSGSZ (MSG_BUFSZ - sizeof (long))
|
||||
|
||||
#if defined(HAVE_GETDTABLESIZE)
|
||||
#define GET_MAX_FDS() getdtablesize()
|
||||
#else
|
||||
/* Fallthrough case - please add other #elif cases above
|
||||
for different OS's as necessary */
|
||||
#define GET_MAX_FDS() 256
|
||||
#endif
|
||||
|
||||
extern void handle_slave_command __P((glibtop_command *, glibtop_response *, const void *));
|
||||
|
||||
#define _offset_union(p) ((char *) &resp->u.p - (char *) resp)
|
||||
#define _offset_data(p) _offset_union (data.p)
|
||||
|
||||
static void do_output __P((int, glibtop_response *, off_t, size_t, const void *));
|
||||
static int do_read __P((int, void *, size_t));
|
||||
|
||||
static void
|
||||
do_output (int s, glibtop_response *resp, off_t offset,
|
||||
size_t data_size, const void *data)
|
||||
{
|
||||
#ifdef REAL_DEBUG
|
||||
fprintf (stderr, "Really writing %d bytes at offset %lu.\n",
|
||||
sizeof (glibtop_response), offset);
|
||||
#endif
|
||||
|
||||
resp->offset = offset;
|
||||
resp->data_size = data_size;
|
||||
|
||||
if (send (s, resp, sizeof (glibtop_response), 0) < 0)
|
||||
glibtop_warn_io ("send");
|
||||
|
||||
if (resp->data_size) {
|
||||
#ifdef REAL_DEBUG
|
||||
fprintf (stderr, "Writing %d bytes of data.\n", resp->data_size);
|
||||
#endif
|
||||
|
||||
if (send (s, data, resp->data_size, 0) , 0)
|
||||
glibtop_warn_io ("send");
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
do_read (int s, void *ptr, size_t total_size)
|
||||
{
|
||||
int nread;
|
||||
size_t already_read = 0, remaining = total_size;
|
||||
|
||||
while (already_read < total_size) {
|
||||
if (s)
|
||||
nread = recv (s, ptr, remaining, 0);
|
||||
else
|
||||
nread = read (0, ptr, remaining);
|
||||
|
||||
if ((already_read == 0) && (nread == 0)) {
|
||||
glibtop_warn ("pid %d received eof.", getpid ());
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (nread <= 0) {
|
||||
glibtop_warn_io ("recv");
|
||||
return 0;
|
||||
}
|
||||
|
||||
already_read += nread;
|
||||
remaining -= nread;
|
||||
(char *) ptr += nread;
|
||||
|
||||
#ifdef REAL_DEBUG
|
||||
fprintf (stderr, "READ (%d): %d - %d - %d\n",
|
||||
nread, already_read, remaining, total_size);
|
||||
#endif
|
||||
}
|
||||
|
||||
return already_read;
|
||||
}
|
||||
|
||||
void
|
||||
handle_parent_connection (int s)
|
||||
{
|
||||
glibtop *server = glibtop_global_server;
|
||||
glibtop_response _resp, *resp = &_resp;
|
||||
glibtop_command _cmnd, *cmnd = &_cmnd;
|
||||
char parameter [BUFSIZ];
|
||||
pid_t pid;
|
||||
void *ptr;
|
||||
|
||||
fprintf (stderr, "Parent features = %lu\n", glibtop_server_features);
|
||||
|
||||
while (do_read (s, &cmnd, sizeof (glibtop_command))) {
|
||||
#ifdef PARENT_DEBUG
|
||||
fprintf (stderr, "Parent (%d) received command %d from client.\n",
|
||||
getpid (), cmnd->command);
|
||||
#endif
|
||||
|
||||
if (cmnd->data_size >= BUFSIZ) {
|
||||
glibtop_warn ("Client sent %d bytes, but buffer is %d", cmnd->size, BUFSIZ);
|
||||
return;
|
||||
}
|
||||
|
||||
memset (parameter, 0, sizeof (parameter));
|
||||
|
||||
if (cmnd->data_size) {
|
||||
#ifdef PARENT_DEBUG
|
||||
fprintf (stderr, "Client has %d bytes of data.\n", cmnd->data_size);
|
||||
#endif
|
||||
|
||||
do_read (s, parameter, cmnd->data_size);
|
||||
|
||||
} else if (cmnd->size) {
|
||||
memcpy (parameter, cmnd->parameter, cmnd->size);
|
||||
}
|
||||
|
||||
switch (cmnd->command) {
|
||||
case GLIBTOP_CMND_QUIT:
|
||||
do_output (s, resp, 0, 0, NULL);
|
||||
|
||||
fprintf (stderr, "Sending QUIT command (%d).\n",
|
||||
server->socket);
|
||||
|
||||
glibtop_call_l (server, GLIBTOP_CMND_QUIT,
|
||||
0, NULL, 0, NULL);
|
||||
|
||||
fprintf (stderr, "Done sending QUIT command (%d).\n",
|
||||
server->socket);
|
||||
|
||||
close (server->socket);
|
||||
return;
|
||||
case GLIBTOP_CMND_SYSDEPS:
|
||||
resp->u.sysdeps.features = GLIBTOP_SYSDEPS_ALL;
|
||||
do_output (s, resp, _offset_union (sysdeps), 0, NULL);
|
||||
break;
|
||||
case GLIBTOP_CMND_CPU:
|
||||
glibtop_get_cpu_l (server, &resp->u.data.cpu);
|
||||
do_output (s, resp, _offset_data (cpu), 0, NULL);
|
||||
break;
|
||||
case GLIBTOP_CMND_MEM:
|
||||
glibtop_get_mem_l (server, &resp->u.data.mem);
|
||||
do_output (s, resp, _offset_data (mem), 0, NULL);
|
||||
break;
|
||||
case GLIBTOP_CMND_SWAP:
|
||||
glibtop_get_swap_l (server, &resp->u.data.swap);
|
||||
do_output (s, resp, _offset_data (swap), 0, NULL);
|
||||
break;
|
||||
case GLIBTOP_CMND_UPTIME:
|
||||
glibtop_get_uptime_l (server, &resp->u.data.uptime);
|
||||
do_output (s, resp, _offset_data (uptime), 0, NULL);
|
||||
break;
|
||||
case GLIBTOP_CMND_LOADAVG:
|
||||
glibtop_get_loadavg_l (server, &resp->u.data.loadavg);
|
||||
do_output (s, resp, _offset_data (loadavg), 0, NULL);
|
||||
break;
|
||||
case GLIBTOP_CMND_SHM_LIMITS:
|
||||
glibtop_get_shm_limits_l (server, &resp->u.data.shm_limits);
|
||||
do_output (s, resp, _offset_data (shm_limits), 0, NULL);
|
||||
break;
|
||||
case GLIBTOP_CMND_MSG_LIMITS:
|
||||
glibtop_get_msg_limits_l (server, &resp->u.data.msg_limits);
|
||||
do_output (s, resp, _offset_data (msg_limits), 0, NULL);
|
||||
break;
|
||||
case GLIBTOP_CMND_SEM_LIMITS:
|
||||
glibtop_get_sem_limits_l (server, &resp->u.data.sem_limits);
|
||||
do_output (s, resp, _offset_data (sem_limits), 0, NULL);
|
||||
break;
|
||||
case GLIBTOP_CMND_PROCLIST:
|
||||
ptr = glibtop_get_proclist_l (server, &resp->u.data.proclist);
|
||||
do_output (s, resp, _offset_data (proclist),
|
||||
resp->u.data.proclist.total, ptr);
|
||||
glibtop_free_r (server, ptr);
|
||||
break;
|
||||
case GLIBTOP_CMND_PROC_STATE:
|
||||
memcpy (&pid, parameter, sizeof (pid_t));
|
||||
glibtop_get_proc_state_l
|
||||
(server, &resp->u.data.proc_state, pid);
|
||||
do_output (s, resp, _offset_data (proc_state), 0, NULL);
|
||||
break;
|
||||
case GLIBTOP_CMND_PROC_UID:
|
||||
memcpy (&pid, parameter, sizeof (pid_t));
|
||||
glibtop_get_proc_uid_l
|
||||
(server, &resp->u.data.proc_uid, pid);
|
||||
do_output (s, resp, _offset_data (proc_uid), 0, NULL);
|
||||
break;
|
||||
case GLIBTOP_CMND_PROC_MEM:
|
||||
memcpy (&pid, parameter, sizeof (pid_t));
|
||||
glibtop_get_proc_mem_l
|
||||
(server, &resp->u.data.proc_mem, pid);
|
||||
do_output (s, resp, _offset_data (proc_mem), 0, NULL);
|
||||
break;
|
||||
case GLIBTOP_CMND_PROC_TIME:
|
||||
memcpy (&pid, parameter, sizeof (pid_t));
|
||||
glibtop_get_proc_time_l
|
||||
(server, &resp->u.data.proc_time, pid);
|
||||
do_output (s, resp, _offset_data (proc_time), 0, NULL);
|
||||
break;
|
||||
case GLIBTOP_CMND_PROC_SIGNAL:
|
||||
memcpy (&pid, parameter, sizeof (pid_t));
|
||||
glibtop_get_proc_signal_l
|
||||
(server, &resp->u.data.proc_signal, pid);
|
||||
do_output (s, resp, _offset_data (proc_signal), 0, NULL);
|
||||
break;
|
||||
case GLIBTOP_CMND_PROC_KERNEL:
|
||||
memcpy (&pid, parameter, sizeof (pid_t));
|
||||
glibtop_get_proc_kernel_l
|
||||
(server, &resp->u.data.proc_kernel, pid);
|
||||
do_output (s, resp, _offset_data (proc_kernel), 0, NULL);
|
||||
break;
|
||||
case GLIBTOP_CMND_PROC_SEGMENT:
|
||||
memcpy (&pid, parameter, sizeof (pid_t));
|
||||
glibtop_get_proc_segment_l
|
||||
(server, &resp->u.data.proc_segment, pid);
|
||||
do_output (s, resp, _offset_data (proc_segment), 0, NULL);
|
||||
break;
|
||||
default:
|
||||
glibtop_warn ("Parent received unknown command %u",
|
||||
cmnd->command);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
handle_child_connection (int s)
|
||||
{
|
||||
glibtop *server = glibtop_global_server;
|
||||
glibtop_response _resp, *resp = &_resp;
|
||||
glibtop_command _cmnd, *cmnd = &_cmnd;
|
||||
char parameter [BUFSIZ];
|
||||
void *ptr;
|
||||
|
||||
while (do_read (s, cmnd, sizeof (glibtop_command))) {
|
||||
#ifdef CHILD_DEBUG
|
||||
fprintf (stderr, "Child (%d - %d) received command "
|
||||
"%d from client.\n", getpid (), s, cmnd->command);
|
||||
#endif
|
||||
|
||||
if (cmnd->data_size >= BUFSIZ) {
|
||||
glibtop_warn ("Client sent %d bytes, but buffer is %d", cmnd->size, BUFSIZ);
|
||||
return;
|
||||
}
|
||||
|
||||
memset (parameter, 0, sizeof (parameter));
|
||||
|
||||
if (cmnd->data_size) {
|
||||
#ifdef CHILD_DEBUG
|
||||
fprintf (stderr, "Client has %d bytes of data.\n", cmnd->data_size);
|
||||
#endif
|
||||
|
||||
do_read (s, parameter, cmnd->data_size);
|
||||
|
||||
} else if (cmnd->size) {
|
||||
memcpy (parameter, cmnd->parameter, cmnd->size);
|
||||
}
|
||||
|
||||
switch (cmnd->command) {
|
||||
case GLIBTOP_CMND_QUIT:
|
||||
do_output (s, resp, 0, 0, NULL);
|
||||
return;
|
||||
#if GLIBTOP_SUID_PROCLIST
|
||||
case GLIBTOP_CMND_PROCLIST:
|
||||
ptr = glibtop_get_proclist_p
|
||||
(server, &resp->u.data.proclist);
|
||||
do_output (s, resp, _offset_data (proclist),
|
||||
resp->u.data.proclist.total, ptr);
|
||||
glibtop_free_r (server, ptr);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
handle_slave_command (cmnd, resp, parameter);
|
||||
do_output (s, resp, resp->offset, 0, NULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
40
src/daemon/server_config.h.in
Normal file
40
src/daemon/server_config.h.in
Normal file
@@ -0,0 +1,40 @@
|
||||
/* This is a sample config file.
|
||||
*
|
||||
* Copy this file to 'server_config.h' and edit it to fix your needs !
|
||||
*
|
||||
* You can also use the 'server_config.pl' script to create 'server_config.h'.
|
||||
*
|
||||
/
|
||||
|
||||
#define SERVER_PORT 42800 /* Port the server should listen on. */
|
||||
|
||||
/* NOTE: On RedHat 5.1 nobody is UID 99 and GID 99.
|
||||
*
|
||||
* The 'server_config.pl' script will use the real UID and GID of 'nobody'
|
||||
* on your system as default.
|
||||
*
|
||||
* NOTE: This only works if the server is started as root or SUID to root.
|
||||
*/
|
||||
|
||||
#define SERVER_UID 99 /* User ID the server should run as. */
|
||||
#define SERVER_GID 99 /* Group ID the server should run as. */
|
||||
|
||||
#define HOST_TABLE_ENTRIES 1 /* Number of entries in the host table. */
|
||||
|
||||
/* List of hosts that should be authorized to connect to the server.
|
||||
*
|
||||
* SECURITY WARNING:
|
||||
* Enabling access for a particular hosts means the ALL USERS on this host will
|
||||
* be allowed to connect to the server !
|
||||
*
|
||||
* If you want security, let this table empty and use the 'xauth' method instead.
|
||||
* Look at the manpage of gnuserv (1) as shipped with GNU Emacs for more details
|
||||
* about security. The server uses the same security mechanisms like gnuserv from
|
||||
* XEmacs 20.3.
|
||||
*/
|
||||
|
||||
const char *permitted_host_names [HOST_TABLE_ENTRIES] =
|
||||
{ "localhost" };
|
||||
|
||||
unsigned long permitted_hosts [HOST_TABLE_ENTRIES];
|
||||
|
111
src/daemon/server_config.pl
Executable file
111
src/daemon/server_config.pl
Executable file
@@ -0,0 +1,111 @@
|
||||
#!/usr/bin/perl -w
|
||||
|
||||
require 5.004;
|
||||
use strict;
|
||||
|
||||
print "Enter port the server should listen on [42800]: ";
|
||||
|
||||
my $port = <stdin>; chop $port;
|
||||
$port = 42800 unless $port =~ /^\d+$/;
|
||||
|
||||
print "\nUser name or UID to run as [nobody]: ";
|
||||
|
||||
my $user = <stdin>; chop $user; $user = 'nobody' if $user eq '';
|
||||
|
||||
my ($login, $pass, $uid, $gid);
|
||||
|
||||
unless ($user =~ /^\d+$/) {
|
||||
($login, $pass, $uid, $gid) = getpwnam ($user) or
|
||||
die "User '$user' not in passwd file.";
|
||||
}
|
||||
|
||||
my $g_default = (defined $gid) ? $gid : 'nogroup';
|
||||
|
||||
print "Group name or GID to run as [$g_default]: ";
|
||||
|
||||
my $group = <stdin>; chop $group; $group = $g_default if $group eq '';
|
||||
|
||||
unless ($group =~ /^\d+$/) {
|
||||
$gid = getgrnam ($group) or
|
||||
die "Group '$group' not in group file.";
|
||||
}
|
||||
|
||||
print "\nEnter list of hosts which should be authorized to";
|
||||
print "\nconnect to the server (terminate with a blank line):\n\n";
|
||||
|
||||
print "SECURITY WARNING:\n";
|
||||
print " Enabling access for a particular hosts means the ALL USERS on this host will\n";
|
||||
print " be allowed to connect to the server !\n\n";
|
||||
|
||||
print " If you want security, let this table empty and use the 'xauth' method instead.\n";
|
||||
print " Look at the manpage of gnuserv (1) as shipped with GNU Emacs for more details\n";
|
||||
print " about security. The server uses the same security mechanisms like gnuserv from\n";
|
||||
print " XEmacs 20.3\n\n";
|
||||
|
||||
my @hosts = ();
|
||||
my @host_addrs = ();
|
||||
my @host_names = ();
|
||||
|
||||
while (1) {
|
||||
print "Host: ";
|
||||
|
||||
my $host = <stdin>; chop $host;
|
||||
last if $host eq '';
|
||||
|
||||
my ($name,$aliases,$addrtype,$length,@addrs) = gethostbyname ($host) or
|
||||
die "gethostbyname (): Can't resolve '$host'";
|
||||
|
||||
my ($a,$b,$c,$d) = unpack('C4',$addrs[0]);
|
||||
|
||||
push @hosts, sprintf ("0x%02X%02X%02X%02X", $d, $c, $b, $a);
|
||||
push @host_addrs, sprintf ("%d.%d.%d.%d", $a, $b, $c, $d);
|
||||
push @host_names, $name;
|
||||
};
|
||||
|
||||
print "\n";
|
||||
print "This is your config:\n";
|
||||
print "====================\n\n";
|
||||
|
||||
printf qq[%-30s: %d\n\n], 'Port', $port;
|
||||
printf qq[%-30s: %d\n], 'UID', $uid;
|
||||
printf qq[%-30s: %d\n\n], 'GID', $gid;
|
||||
|
||||
foreach (0..$#hosts) {
|
||||
printf qq[%-30s (%s - %s)\n], $host_names[$_], $hosts[$_], $host_addrs [$_];
|
||||
}
|
||||
|
||||
print "\n";
|
||||
|
||||
print "Accept? (yes/no) ";
|
||||
|
||||
my $accept = <stdin>; chop $accept;
|
||||
|
||||
exit unless $accept eq 'yes';
|
||||
|
||||
print "\n";
|
||||
|
||||
open CONFIG, "> server_config.h" or
|
||||
die "open (server_config.h): $!";
|
||||
select CONFIG;
|
||||
|
||||
printf qq[\#define SERVER_PORT\t\t%d\n\n], $port;
|
||||
|
||||
printf qq[\#define SERVER_UID\t\t%d\n], $uid;
|
||||
printf qq[\#define SERVER_GID\t\t%d\n\n], $gid;
|
||||
|
||||
printf qq[\#define HOST_TABLE_ENTRIES\t%d\n\n], $#hosts + 1;
|
||||
|
||||
foreach (@host_names) {
|
||||
$_ = qq["$_"];
|
||||
}
|
||||
|
||||
printf qq[const char *permitted_host_names [HOST_TABLE_ENTRIES] = \n];
|
||||
printf qq[{ %s };\n\n], join (', ', @host_names);
|
||||
|
||||
printf qq[unsigned long permitted_hosts [HOST_TABLE_ENTRIES];\n];
|
||||
|
||||
close CONFIG;
|
||||
|
||||
select STDOUT;
|
||||
|
||||
print "Your config has successfully been written to 'server_config.h'.\n";
|
155
src/daemon/slave.c
Normal file
155
src/daemon/slave.c
Normal file
@@ -0,0 +1,155 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
This file is part of the Gnome Top Library.
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
The Gnome Top Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The Gnome Top Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/gnuserv.h>
|
||||
|
||||
#include <glibtop/open.h>
|
||||
#include <glibtop/union.h>
|
||||
|
||||
#include <glibtop/command.h>
|
||||
#include <glibtop/parameter.h>
|
||||
|
||||
#define _offset_union(p) ((char *) &resp->u.p - (char *) resp)
|
||||
#define _offset_data(p) _offset_union (data.p)
|
||||
|
||||
void
|
||||
handle_slave_command (glibtop_command *cmnd, glibtop_response *resp,
|
||||
const void *parameter)
|
||||
{
|
||||
glibtop *server = glibtop_global_server;
|
||||
pid_t pid;
|
||||
|
||||
switch (cmnd->command) {
|
||||
case GLIBTOP_CMND_SYSDEPS:
|
||||
resp->u.sysdeps.features = glibtop_server_features;
|
||||
resp->offset = _offset_union (sysdeps);
|
||||
break;
|
||||
#if GLIBTOP_SUID_CPU
|
||||
case GLIBTOP_CMND_CPU:
|
||||
glibtop_get_cpu_p (server, &resp->u.data.cpu);
|
||||
resp->offset = _offset_data (cpu);
|
||||
break;
|
||||
#endif
|
||||
#if GLIBTOP_SUID_MEM
|
||||
case GLIBTOP_CMND_MEM:
|
||||
glibtop_get_mem_p (server, &resp->u.data.mem);
|
||||
resp->offset = _offset_data (mem);
|
||||
break;
|
||||
#endif
|
||||
#if GLIBTOP_SUID_SWAP
|
||||
case GLIBTOP_CMND_SWAP:
|
||||
glibtop_get_swap_p (server, &resp->u.data.swap);
|
||||
resp->offset = _offset_data (swap);
|
||||
break;
|
||||
#endif
|
||||
#if GLIBTOP_SUID_UPTIME
|
||||
case GLIBTOP_CMND_UPTIME:
|
||||
glibtop_get_uptime_p (server, &resp->u.data.uptime);
|
||||
resp->offset = _offset_data (uptime);
|
||||
break;
|
||||
#endif
|
||||
#if GLIBTOP_SUID_LOADAVG
|
||||
case GLIBTOP_CMND_LOADAVG:
|
||||
glibtop_get_loadavg_p (server, &resp->u.data.loadavg);
|
||||
resp->offset = _offset_data (loadavg);
|
||||
break;
|
||||
#endif
|
||||
#if GLIBTOP_SUID_SHM_LIMITS
|
||||
case GLIBTOP_CMND_SHM_LIMITS:
|
||||
glibtop_get_shm_limits_p (server, &resp->u.data.shm_limits);
|
||||
resp->offset = _offset_data (shm_limits);
|
||||
break;
|
||||
#endif
|
||||
#if GLIBTOP_SUID_MSG_LIMITS
|
||||
case GLIBTOP_CMND_MSG_LIMITS:
|
||||
glibtop_get_msg_limits_p (server, &resp->u.data.msg_limits);
|
||||
resp->offset = _offset_data (msg_limits);
|
||||
break;
|
||||
#endif
|
||||
#if GLIBTOP_SUID_SEM_LIMITS
|
||||
case GLIBTOP_CMND_SEM_LIMITS:
|
||||
glibtop_get_sem_limits_p (server, &resp->u.data.sem_limits);
|
||||
resp->offset = _offset_data (sem_limits);
|
||||
break;
|
||||
#endif
|
||||
#if GLIBTOP_SUID_PROC_STATE
|
||||
case GLIBTOP_CMND_PROC_STATE:
|
||||
memcpy (&pid, parameter, sizeof (pid_t));
|
||||
glibtop_get_proc_state_p
|
||||
(server, &resp->u.data.proc_state, pid);
|
||||
resp->offset = _offset_data (proc_state);
|
||||
break;
|
||||
#endif
|
||||
#if GLIBTOP_SUID_PROC_UID
|
||||
case GLIBTOP_CMND_PROC_UID:
|
||||
memcpy (&pid, parameter, sizeof (pid_t));
|
||||
glibtop_get_proc_uid_p
|
||||
(server, &resp->u.data.proc_uid, pid);
|
||||
resp->offset = _offset_data (proc_uid);
|
||||
break;
|
||||
#endif
|
||||
#if GLIBTOP_SUID_PROC_MEM
|
||||
case GLIBTOP_CMND_PROC_MEM:
|
||||
memcpy (&pid, parameter, sizeof (pid_t));
|
||||
glibtop_get_proc_mem_p
|
||||
(server, &resp->u.data.proc_mem, pid);
|
||||
resp->offset = _offset_data (proc_mem);
|
||||
break;
|
||||
#endif
|
||||
#if GLIBTOP_SUID_PROC_TIME
|
||||
case GLIBTOP_CMND_PROC_TIME:
|
||||
memcpy (&pid, parameter, sizeof (pid_t));
|
||||
glibtop_get_proc_time_p
|
||||
(server, &resp->u.data.proc_time, pid);
|
||||
resp->offset = _offset_data (proc_time);
|
||||
break;
|
||||
#endif
|
||||
#if GLIBTOP_SUID_PROC_SIGNAL
|
||||
case GLIBTOP_CMND_PROC_SIGNAL:
|
||||
memcpy (&pid, parameter, sizeof (pid_t));
|
||||
glibtop_get_proc_signal_p
|
||||
(server, &resp->u.data.proc_signal, pid);
|
||||
resp->offset = _offset_data (proc_signal);
|
||||
break;
|
||||
#endif
|
||||
#if GLIBTOP_SUID_PROC_KERNEL
|
||||
case GLIBTOP_CMND_PROC_KERNEL:
|
||||
memcpy (&pid, parameter, sizeof (pid_t));
|
||||
glibtop_get_proc_kernel_p
|
||||
(server, &resp->u.data.proc_kernel, pid);
|
||||
resp->offset = _offset_data (proc_kernel);
|
||||
break;
|
||||
#endif
|
||||
#if GLIBTOP_SUID_PROC_SEGMENT
|
||||
case GLIBTOP_CMND_PROC_SEGMENT:
|
||||
memcpy (&pid, parameter, sizeof (pid_t));
|
||||
glibtop_get_proc_segment_p
|
||||
(server, &resp->u.data.proc_segment, pid);
|
||||
resp->offset = _offset_data (proc_segment);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
glibtop_error ("Child received unknown command %u",
|
||||
cmnd->command);
|
||||
break;
|
||||
}
|
||||
}
|
@@ -12,5 +12,5 @@ gtop_proxy_SOURCES = main.c output.c version.c
|
||||
gtop_proxy_LDADD = $(top_builddir)/lib/libgtop.la \
|
||||
$(top_builddir)/sysdeps/common/libgtop_common.la \
|
||||
$(top_builddir)/sysdeps/@sysdeps_dir@/libgtop_sysdeps.la \
|
||||
@INTLLIBS@ @LIBSUPPORT@
|
||||
@INTLLIBS@ @LIBSUPPORT@ @libs_xauth@
|
||||
gtop_proxy_LDFLAGS = -static
|
||||
|
@@ -55,25 +55,8 @@ int main(int argc, char *argv[])
|
||||
uid = getuid (); euid = geteuid ();
|
||||
gid = getgid (); egid = getegid ();
|
||||
|
||||
if (setreuid (euid, uid)) _exit (1);
|
||||
|
||||
if (setregid (egid, gid)) _exit (1);
|
||||
|
||||
/* !!! END OF SUID ROOT PART !!! */
|
||||
|
||||
/* For security reasons, we temporarily drop our priviledges
|
||||
* before doing the gettext stuff. */
|
||||
|
||||
setlocale (LC_ALL, "");
|
||||
bindtextdomain (PACKAGE, GTOPLOCALEDIR);
|
||||
textdomain (PACKAGE);
|
||||
|
||||
glibtop_version ();
|
||||
|
||||
/* !!! WE ARE ROOT HERE - CHANGE WITH CAUTION !!! */
|
||||
|
||||
setreuid (uid, euid); setregid (gid, egid);
|
||||
|
||||
glibtop_open_r (&server, argv [0], 0, 0);
|
||||
|
||||
if (setreuid (euid, uid)) _exit (1);
|
||||
@@ -89,7 +72,6 @@ int main(int argc, char *argv[])
|
||||
|
||||
while(1) {
|
||||
/* block on read from client */
|
||||
/* fprintf (stderr, "waiting for input ...\n"); */
|
||||
nread = read (0, &size, sizeof (size_t));
|
||||
|
||||
/* will return 0 if parent exits. */
|
||||
|
@@ -8,5 +8,4 @@ CFLAGS = -Wall -W @CFLAGS@
|
||||
|
||||
lib_LTLIBRARIES = libgtop_common.la
|
||||
|
||||
libgtop_common_la_SOURCES = sysdeps.c xmalloc.c error.c
|
||||
|
||||
libgtop_common_la_SOURCES = sysdeps.c xmalloc.c error.c gnuslib.c
|
||||
|
@@ -21,6 +21,8 @@
|
||||
|
||||
#include <glibtop/error.h>
|
||||
|
||||
#define DEFAULT_NAME "ERROR"
|
||||
|
||||
/* Prints error message and exits. */
|
||||
|
||||
void
|
||||
@@ -30,7 +32,7 @@ glibtop_error_r (glibtop *server, char *format, ...)
|
||||
|
||||
va_start (ap, format);
|
||||
|
||||
fprintf (stderr, "%s: ", server->name);
|
||||
fprintf (stderr, "%s: ", server ? server->name : DEFAULT_NAME);
|
||||
vfprintf (stderr, format, ap);
|
||||
fprintf (stderr, "\n");
|
||||
|
||||
@@ -45,7 +47,7 @@ glibtop_error_io_r (glibtop *server, char *format, ...)
|
||||
|
||||
va_start (ap, format);
|
||||
|
||||
fprintf (stderr, "%s: ", server->name);
|
||||
fprintf (stderr, "%s: ", server ? server->name : DEFAULT_NAME);
|
||||
vfprintf (stderr, format, ap);
|
||||
fprintf (stderr, ": %s\n", strerror (errno));
|
||||
|
||||
@@ -60,7 +62,7 @@ glibtop_warn_r (glibtop *server, char *format, ...)
|
||||
|
||||
va_start (ap, format);
|
||||
|
||||
fprintf (stderr, "%s: ", server->name);
|
||||
fprintf (stderr, "%s: ", server ? server->name : DEFAULT_NAME);
|
||||
vfprintf (stderr, format, ap);
|
||||
fprintf (stderr, "\n");
|
||||
|
||||
@@ -74,7 +76,7 @@ glibtop_warn_io_r (glibtop *server, char *format, ...)
|
||||
|
||||
va_start (ap, format);
|
||||
|
||||
fprintf (stderr, "%s: ", server->name);
|
||||
fprintf (stderr, "%s: ", server ? server->name : DEFAULT_NAME);
|
||||
vfprintf (stderr, format, ap);
|
||||
fprintf (stderr, ": %s\n", strerror (errno));
|
||||
|
||||
|
274
sysdeps/common/fsusage.c
Normal file
274
sysdeps/common/fsusage.c
Normal file
@@ -0,0 +1,274 @@
|
||||
/* fsusage.c -- return space usage of mounted filesystems
|
||||
Copyright (C) 1991, 1992, 1996 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include "fsusage.h"
|
||||
|
||||
int statfs ();
|
||||
|
||||
#if HAVE_SYS_PARAM_H
|
||||
# include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_SYS_MOUNT_H
|
||||
# include <sys/mount.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_SYS_VFS_H
|
||||
# include <sys/vfs.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_SYS_FS_S5PARAM_H /* Fujitsu UXP/V */
|
||||
# include <sys/fs/s5param.h>
|
||||
#endif
|
||||
|
||||
#if defined (HAVE_SYS_FILSYS_H) && !defined (_CRAY)
|
||||
# include <sys/filsys.h> /* SVR2 */
|
||||
#endif
|
||||
|
||||
#if HAVE_FCNTL_H
|
||||
# include <fcntl.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_SYS_STATFS_H
|
||||
# include <sys/statfs.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_DUSTAT_H /* AIX PS/2 */
|
||||
# include <sys/dustat.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_SYS_STATVFS_H /* SVR4 */
|
||||
# include <sys/statvfs.h>
|
||||
int statvfs ();
|
||||
#endif
|
||||
|
||||
int safe_read ();
|
||||
|
||||
/* Return the number of TOSIZE-byte blocks used by
|
||||
BLOCKS FROMSIZE-byte blocks, rounding away from zero.
|
||||
TOSIZE must be positive. Return -1 if FROMSIZE is not positive. */
|
||||
|
||||
static long
|
||||
adjust_blocks (blocks, fromsize, tosize)
|
||||
long blocks;
|
||||
int fromsize, tosize;
|
||||
{
|
||||
if (tosize <= 0)
|
||||
abort ();
|
||||
if (fromsize <= 0)
|
||||
return -1;
|
||||
|
||||
if (fromsize == tosize) /* e.g., from 512 to 512 */
|
||||
return blocks;
|
||||
else if (fromsize > tosize) /* e.g., from 2048 to 512 */
|
||||
return blocks * (fromsize / tosize);
|
||||
else /* e.g., from 256 to 512 */
|
||||
return (blocks + (blocks < 0 ? -1 : 1)) / (tosize / fromsize);
|
||||
}
|
||||
|
||||
/* Fill in the fields of FSP with information about space usage for
|
||||
the filesystem on which PATH resides.
|
||||
DISK is the device on which PATH is mounted, for space-getting
|
||||
methods that need to know it.
|
||||
Return 0 if successful, -1 if not. When returning -1, ensure that
|
||||
ERRNO is either a system error value, or zero if DISK is NULL
|
||||
on a system that requires a non-NULL value. */
|
||||
int
|
||||
get_fs_usage (path, disk, fsp)
|
||||
const char *path;
|
||||
const char *disk;
|
||||
struct fs_usage *fsp;
|
||||
{
|
||||
#ifdef STAT_STATFS3_OSF1
|
||||
# define CONVERT_BLOCKS(B) adjust_blocks ((B), fsd.f_fsize, 512)
|
||||
|
||||
struct statfs fsd;
|
||||
|
||||
if (statfs (path, &fsd, sizeof (struct statfs)) != 0)
|
||||
return -1;
|
||||
|
||||
#endif /* STAT_STATFS3_OSF1 */
|
||||
|
||||
#ifdef STAT_STATFS2_FS_DATA /* Ultrix */
|
||||
# define CONVERT_BLOCKS(B) adjust_blocks ((B), 1024, 512)
|
||||
|
||||
struct fs_data fsd;
|
||||
|
||||
if (statfs (path, &fsd) != 1)
|
||||
return -1;
|
||||
fsp->fsu_blocks = CONVERT_BLOCKS (fsd.fd_req.btot);
|
||||
fsp->fsu_bfree = CONVERT_BLOCKS (fsd.fd_req.bfree);
|
||||
fsp->fsu_bavail = CONVERT_BLOCKS (fsd.fd_req.bfreen);
|
||||
fsp->fsu_files = fsd.fd_req.gtot;
|
||||
fsp->fsu_ffree = fsd.fd_req.gfree;
|
||||
|
||||
#endif /* STAT_STATFS2_FS_DATA */
|
||||
|
||||
#ifdef STAT_READ_FILSYS /* SVR2 */
|
||||
# ifndef SUPERBOFF
|
||||
# define SUPERBOFF (SUPERB * 512)
|
||||
# endif
|
||||
# define CONVERT_BLOCKS(B) \
|
||||
adjust_blocks ((B), (fsd.s_type == Fs2b ? 1024 : 512), 512)
|
||||
|
||||
struct filsys fsd;
|
||||
int fd;
|
||||
|
||||
if (! disk)
|
||||
{
|
||||
errno = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
fd = open (disk, O_RDONLY);
|
||||
if (fd < 0)
|
||||
return -1;
|
||||
lseek (fd, (long) SUPERBOFF, 0);
|
||||
if (safe_read (fd, (char *) &fsd, sizeof fsd) != sizeof fsd)
|
||||
{
|
||||
close (fd);
|
||||
return -1;
|
||||
}
|
||||
close (fd);
|
||||
fsp->fsu_blocks = CONVERT_BLOCKS (fsd.s_fsize);
|
||||
fsp->fsu_bfree = CONVERT_BLOCKS (fsd.s_tfree);
|
||||
fsp->fsu_bavail = CONVERT_BLOCKS (fsd.s_tfree);
|
||||
fsp->fsu_files = (fsd.s_isize - 2) * INOPB * (fsd.s_type == Fs2b ? 2 : 1);
|
||||
fsp->fsu_ffree = fsd.s_tinode;
|
||||
|
||||
#endif /* STAT_READ_FILSYS */
|
||||
|
||||
#ifdef STAT_STATFS2_BSIZE /* 4.3BSD, SunOS 4, HP-UX, AIX */
|
||||
# define CONVERT_BLOCKS(B) adjust_blocks ((B), fsd.f_bsize, 512)
|
||||
|
||||
struct statfs fsd;
|
||||
|
||||
if (statfs (path, &fsd) < 0)
|
||||
return -1;
|
||||
|
||||
# ifdef STATFS_TRUNCATES_BLOCK_COUNTS
|
||||
|
||||
/* In SunOS 4.1.2, 4.1.3, and 4.1.3_U1, the block counts in the
|
||||
struct statfs are truncated to 2GB. These conditions detect that
|
||||
truncation, presumably without botching the 4.1.1 case, in which
|
||||
the values are not truncated. The correct counts are stored in
|
||||
undocumented spare fields. */
|
||||
if (fsd.f_blocks == 0x1fffff && fsd.f_spare[0] > 0)
|
||||
{
|
||||
fsd.f_blocks = fsd.f_spare[0];
|
||||
fsd.f_bfree = fsd.f_spare[1];
|
||||
fsd.f_bavail = fsd.f_spare[2];
|
||||
}
|
||||
# endif /* STATFS_TRUNCATES_BLOCK_COUNTS */
|
||||
|
||||
#endif /* STAT_STATFS2_BSIZE */
|
||||
|
||||
#ifdef STAT_STATFS2_FSIZE /* 4.4BSD */
|
||||
# define CONVERT_BLOCKS(B) adjust_blocks ((B), fsd.f_fsize, 512)
|
||||
|
||||
struct statfs fsd;
|
||||
|
||||
if (statfs (path, &fsd) < 0)
|
||||
return -1;
|
||||
|
||||
#endif /* STAT_STATFS2_FSIZE */
|
||||
|
||||
#ifdef STAT_STATFS4 /* SVR3, Dynix, Irix, AIX */
|
||||
# if _AIX || defined(_CRAY)
|
||||
# define CONVERT_BLOCKS(B) adjust_blocks ((B), fsd.f_bsize, 512)
|
||||
# ifdef _CRAY
|
||||
# define f_bavail f_bfree
|
||||
# endif
|
||||
# else
|
||||
# define CONVERT_BLOCKS(B) (B)
|
||||
# ifndef _SEQUENT_ /* _SEQUENT_ is DYNIX/ptx */
|
||||
# ifndef DOLPHIN /* DOLPHIN 3.8.alfa/7.18 has f_bavail */
|
||||
# define f_bavail f_bfree
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
|
||||
struct statfs fsd;
|
||||
|
||||
if (statfs (path, &fsd, sizeof fsd, 0) < 0)
|
||||
return -1;
|
||||
/* Empirically, the block counts on most SVR3 and SVR3-derived
|
||||
systems seem to always be in terms of 512-byte blocks,
|
||||
no matter what value f_bsize has. */
|
||||
|
||||
#endif /* STAT_STATFS4 */
|
||||
|
||||
#ifdef STAT_STATVFS /* SVR4 */
|
||||
# define CONVERT_BLOCKS(B) \
|
||||
adjust_blocks ((B), fsd.f_frsize ? fsd.f_frsize : fsd.f_bsize, 512)
|
||||
|
||||
struct statvfs fsd;
|
||||
|
||||
if (statvfs (path, &fsd) < 0)
|
||||
return -1;
|
||||
/* f_frsize isn't guaranteed to be supported. */
|
||||
|
||||
#endif /* STAT_STATVFS */
|
||||
|
||||
#if !defined(STAT_STATFS2_FS_DATA) && !defined(STAT_READ_FILSYS)
|
||||
/* !Ultrix && !SVR2 */
|
||||
|
||||
fsp->fsu_blocks = CONVERT_BLOCKS (fsd.f_blocks);
|
||||
fsp->fsu_bfree = CONVERT_BLOCKS (fsd.f_bfree);
|
||||
fsp->fsu_bavail = CONVERT_BLOCKS (fsd.f_bavail);
|
||||
fsp->fsu_files = fsd.f_files;
|
||||
fsp->fsu_ffree = fsd.f_ffree;
|
||||
|
||||
#endif /* not STAT_STATFS2_FS_DATA && not STAT_READ_FILSYS */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(_AIX) && defined(_I386)
|
||||
/* AIX PS/2 does not supply statfs. */
|
||||
|
||||
int
|
||||
statfs (path, fsb)
|
||||
char *path;
|
||||
struct statfs *fsb;
|
||||
{
|
||||
struct stat stats;
|
||||
struct dustat fsd;
|
||||
|
||||
if (stat (path, &stats))
|
||||
return -1;
|
||||
if (dustat (stats.st_dev, 0, &fsd, sizeof (fsd)))
|
||||
return -1;
|
||||
fsb->f_type = 0;
|
||||
fsb->f_bsize = fsd.du_bsize;
|
||||
fsb->f_blocks = fsd.du_fsize - fsd.du_isize;
|
||||
fsb->f_bfree = fsd.du_tfree;
|
||||
fsb->f_bavail = fsd.du_tfree;
|
||||
fsb->f_files = (fsd.du_isize - 2) * fsd.du_inopb;
|
||||
fsb->f_ffree = fsd.du_tinode;
|
||||
fsb->f_fsid.val[0] = fsd.du_site;
|
||||
fsb->f_fsid.val[1] = fsd.du_pckno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* _AIX && _I386 */
|
37
sysdeps/common/fsusage.h
Normal file
37
sysdeps/common/fsusage.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/* fsusage.h -- declarations for filesystem space usage info
|
||||
Copyright (C) 1991, 1992 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Space usage statistics for a filesystem. Blocks are 512-byte. */
|
||||
struct fs_usage
|
||||
{
|
||||
long fsu_blocks; /* Total blocks. */
|
||||
long fsu_bfree; /* Free blocks available to superuser. */
|
||||
long fsu_bavail; /* Free blocks available to non-superuser. */
|
||||
long fsu_files; /* Total file nodes. */
|
||||
long fsu_ffree; /* Free file nodes. */
|
||||
};
|
||||
|
||||
#ifndef __P
|
||||
#if defined (__GNUC__) || (defined (__STDC__) && __STDC__)
|
||||
#define __P(args) args
|
||||
#else
|
||||
#define __P(args) ()
|
||||
#endif /* GCC. */
|
||||
#endif /* Not __P. */
|
||||
|
||||
int get_fs_usage __P ((const char *path, const char *disk,
|
||||
struct fs_usage *fsp));
|
@@ -1,19 +1,19 @@
|
||||
/* -*-C-*-
|
||||
Common library code for the GNU Emacs server and client.
|
||||
|
||||
This file is part of GNU Emacs.
|
||||
|
||||
Copying is permitted under those conditions described by the GNU
|
||||
General Public License.
|
||||
|
||||
Copyright (C) 1989 Free Software Foundation, Inc.
|
||||
|
||||
Author: Andy Norman (ange@hplb.hpl.hp.com), based on
|
||||
'etc/server.c' and 'etc/emacsclient.c' from the 18.52 GNU
|
||||
Emacs distribution.
|
||||
|
||||
Please mail bugs and suggestions to the author at the above address.
|
||||
*/
|
||||
* Common library code for the GNU Emacs server and client.
|
||||
*
|
||||
* This file is part of GNU Emacs.
|
||||
*
|
||||
* Copying is permitted under those conditions described by the GNU
|
||||
* General Public License.
|
||||
*
|
||||
* Copyright (C) 1989 Free Software Foundation, Inc.
|
||||
*
|
||||
* Author: Andy Norman (ange@hplb.hpl.hp.com), based on
|
||||
* 'etc/server.c' and 'etc/emacsclient.c' from the 18.52 GNU
|
||||
* Emacs distribution.
|
||||
*
|
||||
* Please mail bugs and suggestions to the author at the above address.
|
||||
*/
|
||||
|
||||
/* HISTORY
|
||||
* 11-Nov-1990 bristor@simba
|
||||
@@ -29,192 +29,111 @@
|
||||
* ../etc/gnuserv.README relative to the directory containing this file)
|
||||
*/
|
||||
|
||||
#if 0
|
||||
static char rcsid [] = "!Header: gnuslib.c,v 2.4 95/02/16 11:57:37 arup alpha !";
|
||||
#endif
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/gnuserv.h>
|
||||
|
||||
#include "gnuserv.h"
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifdef SYSV_IPC
|
||||
static int connect_to_ipc_server (void);
|
||||
#endif
|
||||
#ifdef UNIX_DOMAIN_SOCKETS
|
||||
static int connect_to_unix_server (void);
|
||||
static int connect_to_unix_server __P((void));
|
||||
#endif
|
||||
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
static int connect_to_internet_server (char *serverhost, u_short port);
|
||||
static int connect_to_internet_server __P((const char *, u_short));
|
||||
#endif
|
||||
|
||||
/* On some systems, e.g. DGUX, inet_addr returns a 'struct in_addr'. */
|
||||
#ifdef HAVE_BROKEN_INET_ADDR
|
||||
# define IN_ADDR struct in_addr
|
||||
# define NUMERIC_ADDR_ERROR (numeric_addr.s_addr == -1)
|
||||
#define IN_ADDR struct in_addr
|
||||
#define NUMERIC_ADDR_ERROR (numeric_addr.s_addr == -1)
|
||||
#else
|
||||
# if (LONGBITS > 32)
|
||||
# define IN_ADDR unsigned int
|
||||
# else
|
||||
# define IN_ADDR unsigned long
|
||||
# endif
|
||||
# define NUMERIC_ADDR_ERROR (numeric_addr == (IN_ADDR) -1)
|
||||
#if (LONGBITS > 32)
|
||||
#define IN_ADDR unsigned int
|
||||
#else
|
||||
#define IN_ADDR unsigned long
|
||||
#endif
|
||||
#define NUMERIC_ADDR_ERROR (numeric_addr == (IN_ADDR) -1)
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif /* HAVE_UNISTD_H */
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif /* HAVE_STRING_H */
|
||||
|
||||
#include <arpa/inet.h>
|
||||
|
||||
char *progname = NULL;
|
||||
|
||||
int make_connection(hostarg, portarg, s)
|
||||
char *hostarg;
|
||||
int
|
||||
glibtop_make_connection (hostarg, portarg, s)
|
||||
const char *hostarg;
|
||||
int portarg;
|
||||
int *s;
|
||||
{
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
char *ptr;
|
||||
|
||||
if (hostarg == NULL)
|
||||
hostarg = getenv("GNU_HOST");
|
||||
if (portarg == 0 && (ptr=getenv("GNU_PORT")) != NULL)
|
||||
portarg = atoi(ptr);
|
||||
hostarg = getenv ("LIBGTOP_HOST");
|
||||
if (portarg == 0 && (ptr = getenv ("LIBGTOP_PORT")) != NULL)
|
||||
portarg = atoi (ptr);
|
||||
#endif
|
||||
|
||||
if (hostarg != NULL) {
|
||||
/* hostname was given explicitly, via cmd line arg or GNU_HOST,
|
||||
* so obey it. */
|
||||
/* hostname was given explicitly, via cmd line arg or
|
||||
* LIBGTOP_HOST, * so obey it. */
|
||||
#ifdef UNIX_DOMAIN_SOCKETS
|
||||
if (!strcmp(hostarg, "unix")) {
|
||||
*s = connect_to_unix_server();
|
||||
if (!strcmp (hostarg, "unix")) {
|
||||
*s = connect_to_unix_server ();
|
||||
return (int) CONN_UNIX;
|
||||
}
|
||||
#endif /* UNIX_DOMAIN_SOCKETS */
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
*s = connect_to_internet_server(hostarg, portarg);
|
||||
*s = connect_to_internet_server (hostarg, portarg);
|
||||
return (int) CONN_INTERNET;
|
||||
#endif
|
||||
#ifdef SYSV_IPC
|
||||
return -1; /* hostarg should always be NULL for SYSV_IPC */
|
||||
#endif
|
||||
} else {
|
||||
/* no hostname given. Use unix-domain/sysv-ipc, or
|
||||
* internet-domain connection to local host if they're not available. */
|
||||
/* no hostname given. Use unix-domain/sysv-ipc, or *
|
||||
* internet-domain connection to local host if they're not
|
||||
* available. */
|
||||
#if defined(UNIX_DOMAIN_SOCKETS)
|
||||
*s = connect_to_unix_server();
|
||||
*s = connect_to_unix_server ();
|
||||
return (int) CONN_UNIX;
|
||||
#elif defined(SYSV_IPC)
|
||||
*s = connect_to_ipc_server();
|
||||
return (int) CONN_IPC;
|
||||
#elif defined(INTERNET_DOMAIN_SOCKETS)
|
||||
{
|
||||
char localhost[HOSTNAMSZ];
|
||||
gethostname(localhost,HOSTNAMSZ); /* use this host by default */
|
||||
*s = connect_to_internet_server(localhost, portarg);
|
||||
|
||||
gethostname (localhost, HOSTNAMSZ); /* use this
|
||||
* host by
|
||||
* default */
|
||||
*s = connect_to_internet_server (localhost, portarg);
|
||||
return (int) CONN_INTERNET;
|
||||
}
|
||||
#endif /* IPC type */
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SYSV_IPC
|
||||
/*
|
||||
connect_to_ipc_server -- establish connection with server process via SYSV IPC
|
||||
Returns msqid for server if successful.
|
||||
*/
|
||||
static int connect_to_ipc_server (void)
|
||||
{
|
||||
int s; /* connected msqid */
|
||||
key_t key; /* message key */
|
||||
char buf[GSERV_BUFSZ+1]; /* buffer for filename */
|
||||
|
||||
sprintf(buf,"/tmp/gsrv%d",(int)geteuid());
|
||||
creat(buf,0600);
|
||||
if ((key = ftok(buf,1)) == -1) {
|
||||
perror(progname);
|
||||
fprintf(stderr, "%s: unable to get ipc key from %s\n",
|
||||
progname, buf);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ((s = msgget(key,0600)) == -1) {
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to access msg queue\n",progname);
|
||||
exit(1);
|
||||
}; /* if */
|
||||
|
||||
return(s);
|
||||
|
||||
} /* connect_to_ipc_server */
|
||||
|
||||
|
||||
/*
|
||||
disconnect_from_ipc_server -- inform the server that sending has finished,
|
||||
and wait for its reply.
|
||||
*/
|
||||
void disconnect_from_ipc_server(s,msgp,echo)
|
||||
int s;
|
||||
struct msgbuf *msgp;
|
||||
int echo;
|
||||
{
|
||||
int len; /* length of received message */
|
||||
|
||||
send_string(s,EOT_STR); /* EOT terminates this message */
|
||||
msgp->mtype = 1;
|
||||
|
||||
if(msgsnd(s,msgp,strlen(msgp->mtext)+1,0) < 0) {
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to send message to server\n",progname);
|
||||
exit(1);
|
||||
}; /* if */
|
||||
|
||||
if((len = msgrcv(s,msgp,GSERV_BUFSZ,getpid(),0)) < 0) {
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to receive message from server\n",progname);
|
||||
exit(1);
|
||||
}; /* if */
|
||||
|
||||
if (echo) {
|
||||
msgp->mtext[len] = '\0'; /* string terminate message */
|
||||
fputs(msgp->mtext, stdout);
|
||||
if (msgp->mtext[len-1] != '\n') putchar ('\n');
|
||||
}; /* if */
|
||||
|
||||
} /* disconnect_from_ipc_server */
|
||||
#endif /* SYSV_IPC */
|
||||
|
||||
|
||||
#if defined(INTERNET_DOMAIN_SOCKETS) || defined(UNIX_DOMAIN_SOCKETS)
|
||||
/*
|
||||
send_string -- send string to socket.
|
||||
*/
|
||||
void send_string(s,msg)
|
||||
* send_string -- send string to socket.
|
||||
*/
|
||||
#if 0
|
||||
static void
|
||||
send_string (s, msg)
|
||||
int s;
|
||||
const char *msg;
|
||||
{
|
||||
#if 0
|
||||
if (send(s,msg,strlen(msg),0) < 0) {
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to send\n",progname);
|
||||
exit(1);
|
||||
if (send (s, msg, strlen (msg), 0) < 0) {
|
||||
perror (progname);
|
||||
fprintf (stderr, "%s: unable to send\n", progname);
|
||||
exit (1);
|
||||
}; /* if */
|
||||
#else
|
||||
int len, left=strlen(msg);
|
||||
int len, left = strlen (msg);
|
||||
|
||||
while (left > 0) {
|
||||
if ((len=write(s,msg,min2(left,GSERV_BUFSZ))) < 0) {
|
||||
if ((len = write (s, msg, min2 (left, GSERV_BUFSZ))) < 0) {
|
||||
/* XEmacs addition: robertl@arnet.com */
|
||||
if (errno == EPIPE) {
|
||||
return ;
|
||||
return;
|
||||
}
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to send\n",progname);
|
||||
exit(1);
|
||||
perror (progname);
|
||||
fprintf (stderr, "%s: unable to send\n", progname);
|
||||
exit (1);
|
||||
}; /* if */
|
||||
left -= len;
|
||||
msg += len;
|
||||
@@ -223,57 +142,54 @@ void send_string(s,msg)
|
||||
} /* send_string */
|
||||
|
||||
/*
|
||||
read_line -- read a \n terminated line from a socket
|
||||
*/
|
||||
int read_line(int s, char *dest)
|
||||
* read_line -- read a \n terminated line from a socket
|
||||
*/
|
||||
static int
|
||||
read_line (int s, char *dest)
|
||||
{
|
||||
int length;
|
||||
int offset=0;
|
||||
char buffer[GSERV_BUFSZ+1];
|
||||
int offset = 0;
|
||||
char buffer[GSERV_BUFSZ + 1];
|
||||
|
||||
while ((length=read(s,buffer+offset,1)>0) && buffer[offset]!='\n'
|
||||
while ((length = read (s, buffer + offset, 1) > 0) && buffer[offset] != '\n'
|
||||
&& buffer[offset] != EOT_CHR) {
|
||||
offset += length;
|
||||
if (offset >= GSERV_BUFSZ)
|
||||
break;
|
||||
}
|
||||
buffer[offset] = '\0';
|
||||
strcpy(dest,buffer);
|
||||
strcpy (dest, buffer);
|
||||
return 1;
|
||||
} /* read_line */
|
||||
#endif
|
||||
#endif /* INTERNET_DOMAIN_SOCKETS || UNIX_DOMAIN_SOCKETS */
|
||||
|
||||
|
||||
#ifdef UNIX_DOMAIN_SOCKETS
|
||||
/*
|
||||
connect_to_unix_server -- establish connection with server process via a unix-
|
||||
domain socket. Returns socket descriptor for server
|
||||
if successful.
|
||||
*/
|
||||
static int connect_to_unix_server (void)
|
||||
* connect_to_unix_server -- establish connection with server process via a unix-
|
||||
* domain socket. Returns socket descriptor for server
|
||||
* if successful.
|
||||
*/
|
||||
static int
|
||||
connect_to_unix_server (void)
|
||||
{
|
||||
int s; /* connected socket descriptor */
|
||||
struct sockaddr_un server; /* for unix connections */
|
||||
|
||||
if ((s = socket(AF_UNIX,SOCK_STREAM,0)) < 0) {
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to create socket\n",progname);
|
||||
exit(1);
|
||||
}; /* if */
|
||||
if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) < 0)
|
||||
glibtop_error_io ("unable to create socket");
|
||||
|
||||
server.sun_family = AF_UNIX;
|
||||
#ifdef HIDE_UNIX_SOCKET
|
||||
sprintf(server.sun_path,"/tmp/gsrvdir%d/gsrv",(int)geteuid());
|
||||
sprintf (server.sun_path, "/tmp/lgtddir%d/lgtd", (int) geteuid ());
|
||||
#else /* HIDE_UNIX_SOCKET */
|
||||
sprintf(server.sun_path,"/tmp/gsrv%d",(int)geteuid());
|
||||
sprintf (server.sun_path, "/tmp/lgtd%d", (int) geteuid ());
|
||||
#endif /* HIDE_UNIX_SOCKET */
|
||||
if (connect(s,(struct sockaddr *)&server,strlen(server.sun_path)+2) < 0) {
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to connect to local\n",progname);
|
||||
exit(1);
|
||||
}; /* if */
|
||||
if (connect (s, (struct sockaddr *) &server, strlen (server.sun_path) + 2) < 0)
|
||||
glibtop_error_io ("unable to connect to local");
|
||||
|
||||
return(s);
|
||||
return (s);
|
||||
|
||||
} /* connect_to_unix_server */
|
||||
#endif /* UNIX_DOMAIN_SOCKETS */
|
||||
@@ -281,11 +197,12 @@ static int connect_to_unix_server (void)
|
||||
|
||||
#ifdef INTERNET_DOMAIN_SOCKETS
|
||||
/*
|
||||
internet_addr -- return the internet addr of the hostname or
|
||||
internet address passed. Return -1 on error.
|
||||
*/
|
||||
int internet_addr(host)
|
||||
char *host;
|
||||
* internet_addr -- return the internet addr of the hostname or
|
||||
* internet address passed. Return -1 on error.
|
||||
*/
|
||||
long
|
||||
glibtop_internet_addr (host)
|
||||
const char *host;
|
||||
{
|
||||
struct hostent *hp; /* pointer to host info for remote host */
|
||||
IN_ADDR numeric_addr; /* host address */
|
||||
@@ -294,27 +211,29 @@ int internet_addr(host)
|
||||
if (!NUMERIC_ADDR_ERROR)
|
||||
return numeric_addr;
|
||||
else if ((hp = gethostbyname (host)) != NULL)
|
||||
return ((struct in_addr *)(hp->h_addr))->s_addr;
|
||||
return ((struct in_addr *) (hp->h_addr))->s_addr;
|
||||
else {
|
||||
glibtop_warn_io ("gethostbyname (%s)", host);
|
||||
return -1;
|
||||
}
|
||||
|
||||
} /* internet_addr */
|
||||
} /* glibtop_internet_addr */
|
||||
|
||||
#ifdef AUTH_MAGIC_COOKIE
|
||||
# include <X11/X.h>
|
||||
# include <X11/Xauth.h>
|
||||
#include <X11/X.h>
|
||||
#include <X11/Xauth.h>
|
||||
|
||||
static Xauth *server_xauth = NULL;
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
connect_to_internet_server -- establish connection with server process via
|
||||
an internet domain socket. Returns socket
|
||||
descriptor for server if successful.
|
||||
*/
|
||||
static int connect_to_internet_server (char *serverhost, u_short port)
|
||||
* connect_to_internet_server -- establish connection with server process via
|
||||
* an internet domain socket. Returns socket
|
||||
* descriptor for server if successful.
|
||||
*/
|
||||
static int
|
||||
connect_to_internet_server (const char *serverhost, u_short port)
|
||||
{
|
||||
int s; /* connected socket descriptor */
|
||||
struct servent *sp; /* pointer to service information */
|
||||
@@ -322,69 +241,59 @@ static int connect_to_internet_server (char *serverhost, u_short port)
|
||||
char buf[512]; /* temporary buffer */
|
||||
|
||||
/* clear out address structures */
|
||||
memset((char *)&peeraddr_in,0,sizeof(struct sockaddr_in));
|
||||
memset ((char *) &peeraddr_in, 0, sizeof (struct sockaddr_in));
|
||||
|
||||
/* Set up the peer address to which we will connect. */
|
||||
peeraddr_in.sin_family = AF_INET;
|
||||
|
||||
/* look up the server host's internet address */
|
||||
if ((peeraddr_in.sin_addr.s_addr = internet_addr(serverhost)) == -1) {
|
||||
fprintf(stderr,"%s: unable to find %s in /etc/hosts or from YP\n",
|
||||
progname,serverhost);
|
||||
exit(1);
|
||||
}; /* if */
|
||||
if (((long) peeraddr_in.sin_addr.s_addr = glibtop_internet_addr (serverhost)) == -1)
|
||||
glibtop_error ("unable to find %s in /etc/hosts or from YP", serverhost);
|
||||
|
||||
if (port == 0) {
|
||||
if ((sp = getservbyname ("gnuserv","tcp")) == NULL)
|
||||
peeraddr_in.sin_port = htons(DEFAULT_PORT+getuid());
|
||||
if ((sp = getservbyname ("gtopd", "tcp")) == NULL)
|
||||
peeraddr_in.sin_port = htons (DEFAULT_PORT + getuid ());
|
||||
else
|
||||
peeraddr_in.sin_port = sp->s_port;
|
||||
} /* if */
|
||||
}
|
||||
/* if */
|
||||
else
|
||||
peeraddr_in.sin_port = htons(port);
|
||||
peeraddr_in.sin_port = htons (port);
|
||||
|
||||
/* Create the socket. */
|
||||
if ((s = socket (AF_INET,SOCK_STREAM, 0))== -1) {
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to create socket\n",progname);
|
||||
exit(1);
|
||||
}; /* if */
|
||||
if ((s = socket (AF_INET, SOCK_STREAM, 0)) == -1)
|
||||
glibtop_error_io ("unable to create socket");
|
||||
|
||||
/* Try to connect to the remote server at the address
|
||||
* which was just built into peeraddr.
|
||||
*/
|
||||
if (connect(s, (struct sockaddr *)&peeraddr_in,
|
||||
sizeof(struct sockaddr_in)) == -1) {
|
||||
perror(progname);
|
||||
fprintf(stderr, "%s: unable to connect to remote\n",progname);
|
||||
exit(1);
|
||||
}; /* if */
|
||||
/* Try to connect to the remote server at the address * which was
|
||||
* just built into peeraddr. */
|
||||
if (connect (s, (struct sockaddr *) &peeraddr_in,
|
||||
sizeof (struct sockaddr_in)) == -1)
|
||||
glibtop_error_io ("unable to connect to remote");
|
||||
|
||||
#ifdef AUTH_MAGIC_COOKIE
|
||||
|
||||
/* send credentials using MIT-MAGIC-COOKIE-1 protocol */
|
||||
|
||||
server_xauth =
|
||||
XauGetAuthByAddr(FamilyInternet,
|
||||
sizeof(peeraddr_in.sin_addr.s_addr),
|
||||
XauGetAuthByAddr (FamilyInternet,
|
||||
sizeof (peeraddr_in.sin_addr.s_addr),
|
||||
(char *) &peeraddr_in.sin_addr.s_addr,
|
||||
strlen(MCOOKIE_SCREEN), MCOOKIE_SCREEN,
|
||||
strlen(MCOOKIE_X_NAME), MCOOKIE_X_NAME);
|
||||
strlen (MCOOKIE_SCREEN), MCOOKIE_SCREEN,
|
||||
strlen (MCOOKIE_X_NAME), MCOOKIE_X_NAME);
|
||||
|
||||
if (server_xauth && server_xauth->data) {
|
||||
sprintf(buf, "%s\n%d\n", MCOOKIE_NAME, server_xauth->data_length);
|
||||
write (s, buf, strlen(buf));
|
||||
sprintf (buf, "%s\n%d\n", MCOOKIE_NAME, server_xauth->data_length);
|
||||
write (s, buf, strlen (buf));
|
||||
write (s, server_xauth->data, server_xauth->data_length);
|
||||
|
||||
return (s);
|
||||
}
|
||||
|
||||
#endif /* AUTH_MAGIC_COOKIE */
|
||||
|
||||
sprintf (buf, "%s\n", DEFAUTH_NAME);
|
||||
write (s, buf, strlen(buf));
|
||||
write (s, buf, strlen (buf));
|
||||
|
||||
return(s);
|
||||
return (s);
|
||||
|
||||
} /* connect_to_internet_server */
|
||||
#endif /* INTERNET_DOMAIN_SOCKETS */
|
||||
@@ -392,22 +301,26 @@ static int connect_to_internet_server (char *serverhost, u_short port)
|
||||
|
||||
#if defined(INTERNET_DOMAIN_SOCKETS) || defined(UNIX_DOMAIN_SOCKETS)
|
||||
/*
|
||||
disconnect_from_server -- inform the server that sending has finished, and wait for
|
||||
its reply.
|
||||
*/
|
||||
void disconnect_from_server(s,echo)
|
||||
* disconnect_from_server -- inform the server that sending has finished, and wait for
|
||||
* its reply.
|
||||
*/
|
||||
#if 0
|
||||
static void
|
||||
disconnect_from_server (s, echo)
|
||||
int s;
|
||||
int echo;
|
||||
{
|
||||
#if 0
|
||||
char buffer[REPLYSIZ+1];
|
||||
char buffer[REPLYSIZ + 1];
|
||||
|
||||
#else
|
||||
char buffer[GSERV_BUFSZ+1];
|
||||
char buffer[GSERV_BUFSZ + 1];
|
||||
|
||||
#endif
|
||||
int add_newline = 1;
|
||||
int length;
|
||||
|
||||
send_string(s,EOT_STR); /* make sure server gets string */
|
||||
send_string (s, EOT_STR); /* make sure server gets string */
|
||||
|
||||
#if !defined (linux) && !defined (_SCO_DS)
|
||||
/*
|
||||
@@ -418,39 +331,42 @@ void disconnect_from_server(s,echo)
|
||||
* with unix sockets persists. Sigh.
|
||||
*/
|
||||
|
||||
if (shutdown(s,1) == -1) {
|
||||
perror(progname);
|
||||
fprintf(stderr, "%s: unable to shutdown socket\n",progname);
|
||||
exit(1);
|
||||
if (shutdown (s, 1) == -1) {
|
||||
perror (progname);
|
||||
fprintf (stderr, "%s: unable to shutdown socket\n", progname);
|
||||
exit (1);
|
||||
}; /* if */
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
while((length = recv(s,buffer,REPLYSIZ,0)) > 0) {
|
||||
while ((length = recv (s, buffer, REPLYSIZ, 0)) > 0) {
|
||||
buffer[length] = '\0';
|
||||
if (echo) fputs(buffer,stdout);
|
||||
add_newline = (buffer[length-1] != '\n');
|
||||
if (echo)
|
||||
fputs (buffer, stdout);
|
||||
add_newline = (buffer[length - 1] != '\n');
|
||||
}; /* while */
|
||||
#else
|
||||
while ((length = read(s,buffer,GSERV_BUFSZ)) > 0 ||
|
||||
while ((length = read (s, buffer, GSERV_BUFSZ)) > 0 ||
|
||||
(length == -1 && errno == EINTR)) {
|
||||
if (length) {
|
||||
buffer[length] = '\0';
|
||||
if (echo) {
|
||||
fputs(buffer,stdout);
|
||||
add_newline = (buffer[length-1] != '\n');
|
||||
fputs (buffer, stdout);
|
||||
add_newline = (buffer[length - 1] != '\n');
|
||||
}; /* if */
|
||||
}; /* if */
|
||||
}; /* while */
|
||||
#endif
|
||||
|
||||
if (echo && add_newline) putchar('\n');
|
||||
if (echo && add_newline)
|
||||
putchar ('\n');
|
||||
|
||||
if(length < 0) {
|
||||
perror(progname);
|
||||
fprintf(stderr,"%s: unable to read the reply from the server\n",progname);
|
||||
exit(1);
|
||||
if (length < 0) {
|
||||
perror (progname);
|
||||
fprintf (stderr, "%s: unable to read the reply from the server\n", progname);
|
||||
exit (1);
|
||||
}; /* if */
|
||||
|
||||
} /* disconnect_from_server */
|
||||
#endif
|
||||
#endif /* INTERNET_DOMAIN_SOCKETS || UNIX_DOMAIN_SOCKETS */
|
||||
|
586
sysdeps/common/mountlist.c
Normal file
586
sysdeps/common/mountlist.c
Normal file
@@ -0,0 +1,586 @@
|
||||
/* mountlist.c -- return a list of mounted filesystems
|
||||
Copyright (C) 1991, 1992 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include "mountlist.h"
|
||||
|
||||
#ifdef STDC_HEADERS
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
void free ();
|
||||
#endif
|
||||
#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
|
||||
#include <string.h>
|
||||
#else
|
||||
#include <strings.h>
|
||||
#endif
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/xmalloc.h>
|
||||
|
||||
#undef xmalloc
|
||||
#undef xrealloc
|
||||
#undef xstrdup
|
||||
|
||||
#define xmalloc(p1) glibtop_malloc_r (NULL, p1)
|
||||
#define xrealloc(p1,p2) glibtop_realloc_r (NULL, p1, p2)
|
||||
#define xstrdup(p1) glibtop_strdup_r (NULL, p1)
|
||||
#define xfree(p1) glibtop_free_r (NULL, p1)
|
||||
|
||||
char *strstr ();
|
||||
void error ();
|
||||
|
||||
#ifdef HAVE_SYS_PARAM_H
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#if defined (MOUNTED_GETFSSTAT) /* __alpha running OSF_1 */
|
||||
# include <sys/mount.h>
|
||||
# include <sys/fs_types.h>
|
||||
#endif /* MOUNTED_GETFSSTAT */
|
||||
|
||||
#ifdef MOUNTED_GETMNTENT1 /* 4.3BSD, SunOS, HP-UX, Dynix, Irix. */
|
||||
#include <mntent.h>
|
||||
#if !defined(MOUNTED)
|
||||
# if defined(MNT_MNTTAB) /* HP-UX. */
|
||||
# define MOUNTED MNT_MNTTAB
|
||||
# endif
|
||||
# if defined(MNTTABNAME) /* Dynix. */
|
||||
# define MOUNTED MNTTABNAME
|
||||
# endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef MOUNTED_GETMNTINFO /* 4.4BSD. */
|
||||
#include <sys/mount.h>
|
||||
#endif
|
||||
|
||||
#ifdef MOUNTED_GETMNT /* Ultrix. */
|
||||
#include <sys/mount.h>
|
||||
#include <sys/fs_types.h>
|
||||
#endif
|
||||
|
||||
#ifdef MOUNTED_FREAD /* SVR2. */
|
||||
#include <mnttab.h>
|
||||
#endif
|
||||
|
||||
#ifdef MOUNTED_FREAD_FSTYP /* SVR3. */
|
||||
#include <mnttab.h>
|
||||
#include <sys/fstyp.h>
|
||||
#include <sys/statfs.h>
|
||||
#endif
|
||||
|
||||
#ifdef MOUNTED_LISTMNTENT
|
||||
#include <mntent.h>
|
||||
#endif
|
||||
|
||||
#ifdef MOUNTED_GETMNTENT2 /* SVR4. */
|
||||
#include <sys/mnttab.h>
|
||||
#endif
|
||||
|
||||
#ifdef MOUNTED_VMOUNT /* AIX. */
|
||||
#include <fshelp.h>
|
||||
#include <sys/vfs.h>
|
||||
#endif
|
||||
|
||||
#ifdef DOLPHIN
|
||||
/* So special that it's not worth putting this in autoconf. */
|
||||
#undef MOUNTED_FREAD_FSTYP
|
||||
#define MOUNTED_GETMNTTBL
|
||||
#endif
|
||||
|
||||
#ifdef MOUNTED_GETMNTENT1 /* 4.3BSD, SunOS, HP-UX, Dynix, Irix. */
|
||||
/* Return the value of the hexadecimal number represented by CP.
|
||||
No prefix (like '0x') or suffix (like 'h') is expected to be
|
||||
part of CP. */
|
||||
|
||||
static int
|
||||
xatoi (cp)
|
||||
char *cp;
|
||||
{
|
||||
int val;
|
||||
|
||||
val = 0;
|
||||
while (*cp)
|
||||
{
|
||||
if (*cp >= 'a' && *cp <= 'f')
|
||||
val = val * 16 + *cp - 'a' + 10;
|
||||
else if (*cp >= 'A' && *cp <= 'F')
|
||||
val = val * 16 + *cp - 'A' + 10;
|
||||
else if (*cp >= '0' && *cp <= '9')
|
||||
val = val * 16 + *cp - '0';
|
||||
else
|
||||
break;
|
||||
cp++;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
#endif /* MOUNTED_GETMNTENT1. */
|
||||
|
||||
#if defined (MOUNTED_GETMNTINFO) && !defined (__NetBSD__)
|
||||
static char *
|
||||
fstype_to_string (t)
|
||||
short t;
|
||||
{
|
||||
switch (t)
|
||||
{
|
||||
#ifdef MOUNT_PC
|
||||
case MOUNT_PC:
|
||||
return "pc";
|
||||
#endif
|
||||
#ifdef MOUNT_MFS
|
||||
case MOUNT_MFS:
|
||||
return "mfs";
|
||||
#endif
|
||||
#ifdef MOUNT_LO
|
||||
case MOUNT_LO:
|
||||
return "lo";
|
||||
#endif
|
||||
#ifdef MOUNT_TFS
|
||||
case MOUNT_TFS:
|
||||
return "tfs";
|
||||
#endif
|
||||
#ifdef MOUNT_TMP
|
||||
case MOUNT_TMP:
|
||||
return "tmp";
|
||||
#endif
|
||||
#ifdef MOUNT_UFS
|
||||
case MOUNT_UFS:
|
||||
return "ufs" ;
|
||||
#endif
|
||||
#ifdef MOUNT_NFS
|
||||
case MOUNT_NFS:
|
||||
return "nfs" ;
|
||||
#endif
|
||||
#ifdef MOUNT_MSDOS
|
||||
case MOUNT_MSDOS:
|
||||
return "msdos" ;
|
||||
#endif
|
||||
#ifdef MOUNT_LFS
|
||||
case MOUNT_LFS:
|
||||
return "lfs" ;
|
||||
#endif
|
||||
#ifdef MOUNT_LOFS
|
||||
case MOUNT_LOFS:
|
||||
return "lofs" ;
|
||||
#endif
|
||||
#ifdef MOUNT_FDESC
|
||||
case MOUNT_FDESC:
|
||||
return "fdesc" ;
|
||||
#endif
|
||||
#ifdef MOUNT_PORTAL
|
||||
case MOUNT_PORTAL:
|
||||
return "portal" ;
|
||||
#endif
|
||||
#ifdef MOUNT_NULL
|
||||
case MOUNT_NULL:
|
||||
return "null" ;
|
||||
#endif
|
||||
#ifdef MOUNT_UMAP
|
||||
case MOUNT_UMAP:
|
||||
return "umap" ;
|
||||
#endif
|
||||
#ifdef MOUNT_KERNFS
|
||||
case MOUNT_KERNFS:
|
||||
return "kernfs" ;
|
||||
#endif
|
||||
#ifdef MOUNT_PROCFS
|
||||
case MOUNT_PROCFS:
|
||||
return "procfs" ;
|
||||
#endif
|
||||
#ifdef MOUNT_AFS
|
||||
case MOUNT_AFS:
|
||||
return "afs" ;
|
||||
#endif
|
||||
#ifdef MOUNT_CD9660
|
||||
case MOUNT_CD9660:
|
||||
return "cd9660" ;
|
||||
#endif
|
||||
#ifdef MOUNT_UNION
|
||||
case MOUNT_UNION:
|
||||
return "union" ;
|
||||
#endif
|
||||
#ifdef MOUNT_DEVFS
|
||||
case MOUNT_DEVFS:
|
||||
return "devfs" ;
|
||||
#endif
|
||||
#ifdef MOUNT_EXT2FS
|
||||
case MOUNT_EXT2FS:
|
||||
return "ext2fs" ;
|
||||
#endif
|
||||
default:
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
#endif /* MOUNTED_GETMNTINFO */
|
||||
|
||||
#ifdef MOUNTED_VMOUNT /* AIX. */
|
||||
static char *
|
||||
fstype_to_string (t)
|
||||
int t;
|
||||
{
|
||||
struct vfs_ent *e;
|
||||
|
||||
e = getvfsbytype (t);
|
||||
if (!e || !e->vfsent_name)
|
||||
return "none";
|
||||
else
|
||||
return e->vfsent_name;
|
||||
}
|
||||
#endif /* MOUNTED_VMOUNT */
|
||||
|
||||
/* Return a list of the currently mounted filesystems, or NULL on error.
|
||||
Add each entry to the tail of the list so that they stay in order.
|
||||
If NEED_FS_TYPE is nonzero, ensure that the filesystem type fields in
|
||||
the returned list are valid. Otherwise, they might not be.
|
||||
If ALL_FS is zero, do not return entries for filesystems that
|
||||
are automounter (dummy) entries. */
|
||||
|
||||
struct mount_entry *
|
||||
read_filesystem_list (need_fs_type, all_fs)
|
||||
int need_fs_type, all_fs;
|
||||
{
|
||||
struct mount_entry *mount_list;
|
||||
struct mount_entry *me;
|
||||
struct mount_entry *mtail;
|
||||
|
||||
/* Start the list off with a dummy entry. */
|
||||
me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
|
||||
me->me_next = NULL;
|
||||
mount_list = mtail = me;
|
||||
|
||||
#ifdef MOUNTED_LISTMNTENT
|
||||
{
|
||||
struct tabmntent *mntlist, *p;
|
||||
struct mntent *mnt;
|
||||
struct mount_entry *me;
|
||||
|
||||
/* the third and fourth arguments could be used to filter mounts,
|
||||
but Crays doesn't seem to have any mounts that we want to
|
||||
remove. Specifically, automount create normal NFS mounts.
|
||||
*/
|
||||
|
||||
if(listmntent(&mntlist, KMTAB, NULL, NULL) < 0)
|
||||
return NULL;
|
||||
p = mntlist;
|
||||
while(p){
|
||||
mnt = p->ment;
|
||||
me = (struct mount_entry*) xmalloc(sizeof (struct mount_entry));
|
||||
me->me_devname = xstrdup(mnt->mnt_fsname);
|
||||
me->me_mountdir = xstrdup(mnt->mnt_dir);
|
||||
me->me_type = xstrdup(mnt->mnt_type);
|
||||
me->me_dev = -1;
|
||||
me->me_next = NULL;
|
||||
mtail->me_next = me;
|
||||
mtail = me;
|
||||
p = p->next;
|
||||
}
|
||||
freemntlist(mntlist);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef MOUNTED_GETMNTENT1 /* 4.3BSD, SunOS, HP-UX, Dynix, Irix. */
|
||||
{
|
||||
struct mntent *mnt;
|
||||
char *table = MOUNTED;
|
||||
FILE *fp;
|
||||
char *devopt;
|
||||
|
||||
fp = setmntent (table, "r");
|
||||
if (fp == NULL)
|
||||
return NULL;
|
||||
|
||||
while ((mnt = getmntent (fp)))
|
||||
{
|
||||
if (!all_fs && (!strcmp (mnt->mnt_type, "ignore")
|
||||
|| !strcmp (mnt->mnt_type, "auto")))
|
||||
continue;
|
||||
|
||||
me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
|
||||
me->me_devname = xstrdup (mnt->mnt_fsname);
|
||||
me->me_mountdir = xstrdup (mnt->mnt_dir);
|
||||
me->me_type = xstrdup (mnt->mnt_type);
|
||||
devopt = strstr (mnt->mnt_opts, "dev=");
|
||||
if (devopt)
|
||||
{
|
||||
if (devopt[4] == '0' && (devopt[5] == 'x' || devopt[5] == 'X'))
|
||||
me->me_dev = xatoi (devopt + 6);
|
||||
else
|
||||
me->me_dev = xatoi (devopt + 4);
|
||||
}
|
||||
else
|
||||
me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
|
||||
me->me_next = NULL;
|
||||
|
||||
/* Add to the linked list. */
|
||||
mtail->me_next = me;
|
||||
mtail = me;
|
||||
}
|
||||
|
||||
if (endmntent (fp) == 0)
|
||||
return NULL;
|
||||
}
|
||||
#endif /* MOUNTED_GETMNTENT1. */
|
||||
|
||||
#ifdef MOUNTED_GETMNTINFO /* 4.4BSD. */
|
||||
{
|
||||
struct statfs *fsp;
|
||||
int entries;
|
||||
|
||||
entries = getmntinfo (&fsp, MNT_NOWAIT);
|
||||
if (entries < 0)
|
||||
return NULL;
|
||||
while (entries-- > 0)
|
||||
{
|
||||
me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
|
||||
me->me_devname = xstrdup (fsp->f_mntfromname);
|
||||
me->me_mountdir = xstrdup (fsp->f_mntonname);
|
||||
#ifdef __NetBSD__
|
||||
me->me_type = xstrdup (fsp->f_fstypename);
|
||||
#else
|
||||
me->me_type = fstype_to_string (fsp->f_type);
|
||||
#endif
|
||||
me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
|
||||
me->me_next = NULL;
|
||||
|
||||
/* Add to the linked list. */
|
||||
mtail->me_next = me;
|
||||
mtail = me;
|
||||
fsp++;
|
||||
}
|
||||
}
|
||||
#endif /* MOUNTED_GETMNTINFO */
|
||||
|
||||
#ifdef MOUNTED_GETMNT /* Ultrix. */
|
||||
{
|
||||
int offset = 0;
|
||||
int val;
|
||||
struct fs_data fsd;
|
||||
|
||||
while ((val = getmnt (&offset, &fsd, sizeof (fsd), NOSTAT_MANY,
|
||||
(char *) 0)) > 0)
|
||||
{
|
||||
me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
|
||||
me->me_devname = xstrdup (fsd.fd_req.devname);
|
||||
me->me_mountdir = xstrdup (fsd.fd_req.path);
|
||||
me->me_type = gt_names[fsd.fd_req.fstype];
|
||||
me->me_dev = fsd.fd_req.dev;
|
||||
me->me_next = NULL;
|
||||
|
||||
/* Add to the linked list. */
|
||||
mtail->me_next = me;
|
||||
mtail = me;
|
||||
}
|
||||
if (val < 0)
|
||||
return NULL;
|
||||
}
|
||||
#endif /* MOUNTED_GETMNT. */
|
||||
|
||||
#if defined (MOUNTED_GETFSSTAT) /* __alpha running OSF_1 */
|
||||
{
|
||||
int numsys, counter, bufsize;
|
||||
struct statfs *stats;
|
||||
|
||||
numsys = getfsstat ((struct statfs *)0, 0L, MNT_WAIT);
|
||||
if (numsys < 0)
|
||||
return (NULL);
|
||||
|
||||
bufsize = (1 + numsys) * sizeof (struct statfs);
|
||||
stats = (struct statfs *)xmalloc (bufsize);
|
||||
numsys = getfsstat (stats, bufsize, MNT_WAIT);
|
||||
|
||||
if (numsys < 0)
|
||||
{
|
||||
free (stats);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
for (counter = 0; counter < numsys; counter++)
|
||||
{
|
||||
me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
|
||||
me->me_devname = xstrdup (stats[counter].f_mntfromname);
|
||||
me->me_mountdir = xstrdup (stats[counter].f_mntonname);
|
||||
me->me_type = mnt_names[stats[counter].f_type];
|
||||
me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
|
||||
me->me_next = NULL;
|
||||
|
||||
/* Add to the linked list. */
|
||||
mtail->me_next = me;
|
||||
mtail = me;
|
||||
}
|
||||
|
||||
free (stats);
|
||||
}
|
||||
#endif /* MOUNTED_GETFSSTAT */
|
||||
|
||||
#if defined (MOUNTED_FREAD) || defined (MOUNTED_FREAD_FSTYP) /* SVR[23]. */
|
||||
{
|
||||
struct mnttab mnt;
|
||||
char *table = "/etc/mnttab";
|
||||
FILE *fp;
|
||||
|
||||
fp = fopen (table, "r");
|
||||
if (fp == NULL)
|
||||
return NULL;
|
||||
|
||||
while (fread (&mnt, sizeof mnt, 1, fp) > 0)
|
||||
{
|
||||
me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
|
||||
#ifdef GETFSTYP /* SVR3. */
|
||||
me->me_devname = xstrdup (mnt.mt_dev);
|
||||
#else
|
||||
me->me_devname = xmalloc (strlen (mnt.mt_dev) + 6);
|
||||
strcpy (me->me_devname, "/dev/");
|
||||
strcpy (me->me_devname + 5, mnt.mt_dev);
|
||||
#endif
|
||||
me->me_mountdir = xstrdup (mnt.mt_filsys);
|
||||
me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
|
||||
me->me_type = "";
|
||||
#ifdef GETFSTYP /* SVR3. */
|
||||
if (need_fs_type)
|
||||
{
|
||||
struct statfs fsd;
|
||||
char typebuf[FSTYPSZ];
|
||||
|
||||
if (statfs (me->me_mountdir, &fsd, sizeof fsd, 0) != -1
|
||||
&& sysfs (GETFSTYP, fsd.f_fstyp, typebuf) != -1)
|
||||
me->me_type = xstrdup (typebuf);
|
||||
}
|
||||
#endif
|
||||
me->me_next = NULL;
|
||||
|
||||
/* Add to the linked list. */
|
||||
mtail->me_next = me;
|
||||
mtail = me;
|
||||
}
|
||||
|
||||
if (fclose (fp) == EOF)
|
||||
return NULL;
|
||||
}
|
||||
#endif /* MOUNTED_FREAD || MOUNTED_FREAD_FSTYP. */
|
||||
|
||||
#ifdef MOUNTED_GETMNTTBL /* DolphinOS goes it's own way */
|
||||
{
|
||||
struct mntent **mnttbl=getmnttbl(),**ent;
|
||||
for (ent=mnttbl;*ent;ent++)
|
||||
{
|
||||
me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
|
||||
me->me_devname = xstrdup ( (*ent)->mt_resource);
|
||||
me->me_mountdir = xstrdup( (*ent)->mt_directory);
|
||||
me->me_type = xstrdup ((*ent)->mt_fstype);
|
||||
me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
|
||||
me->me_next = NULL;
|
||||
|
||||
/* Add to the linked list. */
|
||||
mtail->me_next = me;
|
||||
mtail = me;
|
||||
}
|
||||
endmnttbl();
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef MOUNTED_GETMNTENT2 /* SVR4. */
|
||||
{
|
||||
struct mnttab mnt;
|
||||
char *table = MNTTAB;
|
||||
FILE *fp;
|
||||
int ret;
|
||||
|
||||
fp = fopen (table, "r");
|
||||
if (fp == NULL)
|
||||
return NULL;
|
||||
|
||||
while ((ret = getmntent (fp, &mnt)) == 0)
|
||||
{
|
||||
me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
|
||||
me->me_devname = xstrdup (mnt.mnt_special);
|
||||
me->me_mountdir = xstrdup (mnt.mnt_mountp);
|
||||
me->me_type = xstrdup (mnt.mnt_fstype);
|
||||
me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
|
||||
me->me_next = NULL;
|
||||
|
||||
/* Add to the linked list. */
|
||||
mtail->me_next = me;
|
||||
mtail = me;
|
||||
}
|
||||
|
||||
if (ret > 0)
|
||||
return NULL;
|
||||
if (fclose (fp) == EOF)
|
||||
return NULL;
|
||||
}
|
||||
#endif /* MOUNTED_GETMNTENT2. */
|
||||
|
||||
#ifdef MOUNTED_VMOUNT /* AIX. */
|
||||
{
|
||||
int bufsize;
|
||||
char *entries, *thisent;
|
||||
struct vmount *vmp;
|
||||
|
||||
/* Ask how many bytes to allocate for the mounted filesystem info. */
|
||||
mntctl (MCTL_QUERY, sizeof bufsize, (struct vmount *) &bufsize);
|
||||
entries = xmalloc (bufsize);
|
||||
|
||||
/* Get the list of mounted filesystems. */
|
||||
mntctl (MCTL_QUERY, bufsize, (struct vmount *) entries);
|
||||
|
||||
for (thisent = entries; thisent < entries + bufsize;
|
||||
thisent += vmp->vmt_length)
|
||||
{
|
||||
vmp = (struct vmount *) thisent;
|
||||
me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
|
||||
if (vmp->vmt_flags & MNT_REMOTE)
|
||||
{
|
||||
char *host, *path;
|
||||
|
||||
/* Prepend the remote pathname. */
|
||||
host = thisent + vmp->vmt_data[VMT_HOSTNAME].vmt_off;
|
||||
path = thisent + vmp->vmt_data[VMT_OBJECT].vmt_off;
|
||||
me->me_devname = xmalloc (strlen (host) + strlen (path) + 2);
|
||||
strcpy (me->me_devname, host);
|
||||
strcat (me->me_devname, ":");
|
||||
strcat (me->me_devname, path);
|
||||
}
|
||||
else
|
||||
{
|
||||
me->me_devname = xstrdup (thisent +
|
||||
vmp->vmt_data[VMT_OBJECT].vmt_off);
|
||||
}
|
||||
me->me_mountdir = xstrdup (thisent + vmp->vmt_data[VMT_STUB].vmt_off);
|
||||
me->me_type = xstrdup (fstype_to_string (vmp->vmt_gfstype));
|
||||
me->me_dev = (dev_t) -1; /* vmt_fsid might be the info we want. */
|
||||
me->me_next = NULL;
|
||||
|
||||
/* Add to the linked list. */
|
||||
mtail->me_next = me;
|
||||
mtail = me;
|
||||
}
|
||||
free (entries);
|
||||
}
|
||||
#endif /* MOUNTED_VMOUNT. */
|
||||
|
||||
/* Free the dummy head. */
|
||||
me = mount_list;
|
||||
mount_list = mount_list->me_next;
|
||||
free (me);
|
||||
return mount_list;
|
||||
}
|
32
sysdeps/common/mountlist.h
Normal file
32
sysdeps/common/mountlist.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/* mountlist.h -- declarations for list of mounted filesystems
|
||||
Copyright (C) 1991, 1992 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* A mount table entry. */
|
||||
struct mount_entry
|
||||
{
|
||||
char *me_devname; /* Device node pathname, including "/dev/". */
|
||||
char *me_mountdir; /* Mount point directory pathname. */
|
||||
char *me_type; /* "nfs", "4.2", etc. */
|
||||
dev_t me_dev; /* Device number of me_mountdir. */
|
||||
struct mount_entry *me_next;
|
||||
};
|
||||
|
||||
#if __STDC__
|
||||
struct mount_entry *read_filesystem_list (int need_fs_type, int all_fs);
|
||||
#else
|
||||
struct mount_entry *read_filesystem_list ();
|
||||
#endif
|
@@ -53,48 +53,48 @@ glibtop_get_sysdeps_r (glibtop *server, glibtop_sysdeps *buf)
|
||||
/* Call all system dependent functions to check which values
|
||||
* they return. */
|
||||
|
||||
glibtop_get_cpu_r (server, &data.cpu);
|
||||
glibtop_get_cpu_l (server, &data.cpu);
|
||||
buf->cpu = data.cpu.flags;
|
||||
|
||||
glibtop_get_mem_r (server, &data.mem);
|
||||
glibtop_get_mem_l (server, &data.mem);
|
||||
buf->mem = data.mem.flags;
|
||||
|
||||
glibtop_get_swap_r (server, &data.swap);
|
||||
glibtop_get_swap_l (server, &data.swap);
|
||||
buf->swap = data.swap.flags;
|
||||
|
||||
glibtop_get_uptime_r (server, &data.uptime);
|
||||
glibtop_get_uptime_l (server, &data.uptime);
|
||||
buf->uptime = data.uptime.flags;
|
||||
|
||||
glibtop_get_loadavg_r (server, &data.loadavg);
|
||||
glibtop_get_loadavg_l (server, &data.loadavg);
|
||||
buf->loadavg = data.loadavg.flags;
|
||||
|
||||
glibtop_get_shm_limits_r (server, &data.shm_limits);
|
||||
glibtop_get_shm_limits_l (server, &data.shm_limits);
|
||||
buf->shm_limits = data.shm_limits.flags;
|
||||
|
||||
glibtop_get_msg_limits_r (server, &data.msg_limits);
|
||||
glibtop_get_msg_limits_l (server, &data.msg_limits);
|
||||
buf->msg_limits = data.msg_limits.flags;
|
||||
|
||||
glibtop_get_sem_limits_r (server, &data.sem_limits);
|
||||
glibtop_get_sem_limits_l (server, &data.sem_limits);
|
||||
buf->sem_limits = data.sem_limits.flags;
|
||||
|
||||
glibtop_get_proclist_r (server, &data.proclist);
|
||||
glibtop_get_proclist_l (server, &data.proclist);
|
||||
buf->proclist = data.proclist.flags;
|
||||
|
||||
glibtop_get_proc_state_r (server, &data.proc_state, 0);
|
||||
glibtop_get_proc_state_l (server, &data.proc_state, 0);
|
||||
buf->proc_state = data.proc_state.flags;
|
||||
|
||||
glibtop_get_proc_uid_r (server, &data.proc_uid, 0);
|
||||
glibtop_get_proc_uid_l (server, &data.proc_uid, 0);
|
||||
buf->proc_uid = data.proc_uid.flags;
|
||||
|
||||
glibtop_get_proc_mem_r (server, &data.proc_mem, 0);
|
||||
glibtop_get_proc_mem_l (server, &data.proc_mem, 0);
|
||||
buf->proc_mem = data.proc_mem.flags;
|
||||
|
||||
glibtop_get_proc_time_r (server, &data.proc_time, 0);
|
||||
glibtop_get_proc_time_l (server, &data.proc_time, 0);
|
||||
buf->proc_time = data.proc_time.flags;
|
||||
|
||||
glibtop_get_proc_kernel_r (server, &data.proc_kernel, 0);
|
||||
glibtop_get_proc_kernel_l (server, &data.proc_kernel, 0);
|
||||
buf->proc_kernel = data.proc_kernel.flags;
|
||||
|
||||
glibtop_get_proc_segment_r (server, &data.proc_segment, 0);
|
||||
glibtop_get_proc_segment_l (server, &data.proc_segment, 0);
|
||||
buf->proc_segment = data.proc_segment.flags;
|
||||
}
|
||||
|
@@ -59,6 +59,12 @@ glibtop_realloc_r (glibtop *server, void *ptr, size_t size)
|
||||
return buf;
|
||||
}
|
||||
|
||||
char *
|
||||
glibtop_strdup_r (glibtop *server, const char *string)
|
||||
{
|
||||
return strcpy (glibtop_malloc_r (server, strlen (string) + 1), string);
|
||||
}
|
||||
|
||||
void
|
||||
glibtop_free_r (glibtop *server, void *ptr)
|
||||
{
|
||||
|
@@ -18,8 +18,8 @@ libgtop_guile_la_SOURCES = guile.c
|
||||
|
||||
BUILT_SOURCES = guile.c
|
||||
|
||||
guile.c: guile.awk $(top_builddir)/config.h $(top_builddir)/features.def
|
||||
$(AWK) -f $(srcdir)/guile.awk < $(top_builddir)/features.def > gnc-t
|
||||
guile.c: guile.awk $(top_builddir)/config.h $(top_srcdir)/features.def
|
||||
$(AWK) -f $(srcdir)/guile.awk < $(top_srcdir)/features.def > gnc-t
|
||||
mv gnc-t guile.c
|
||||
|
||||
EXTRA_DIST = guile.awk
|
||||
|
@@ -55,7 +55,7 @@ BEGIN {
|
||||
print "";
|
||||
print "\tif (ptr) {";
|
||||
print "\t\tfor (i = 0; i < proclist.number; i++)";
|
||||
print "\t\t\tlist = gh_append";
|
||||
print "\t\t\tlist = scm_append";
|
||||
print "\t\t\t\t(gh_list (list,";
|
||||
print "\t\t\t\t\t gh_list (gh_ulong2scm ((unsigned long) ptr [i])),";
|
||||
print "\t\t\t\t\t SCM_UNDEFINED));";
|
||||
|
@@ -12,8 +12,8 @@ libgtop_guile_names_la_SOURCES = guile-names.c
|
||||
|
||||
BUILT_SOURCES = guile-names.c
|
||||
|
||||
guile-names.c: guile-names.awk $(top_builddir)/config.h $(top_builddir)/features.def
|
||||
$(AWK) -f $(srcdir)/guile-names.awk < $(top_builddir)/features.def > gnc-t
|
||||
guile-names.c: guile-names.awk $(top_builddir)/config.h $(top_srcdir)/features.def
|
||||
$(AWK) -f $(srcdir)/guile-names.awk < $(top_srcdir)/features.def > gnc-t
|
||||
mv gnc-t guile-names.c
|
||||
|
||||
EXTRA_DIST = guile-names.awk
|
||||
|
@@ -22,7 +22,7 @@ function output(feature) {
|
||||
print "\tlist = gh_list (SCM_UNDEFINED);";
|
||||
print "";
|
||||
print "\tfor (i = 0; i < GLIBTOP_MAX_"toupper(feature)"; i++)";
|
||||
print "\t\tlist = gh_append";
|
||||
print "\t\tlist = scm_append";
|
||||
print "\t\t\t(gh_list (list,";
|
||||
print "\t\t\t\t gh_list (gh_str02scm ((char *) glibtop_names_"feature" [i])),";
|
||||
print "\t\t\t\t SCM_UNDEFINED));";
|
||||
@@ -41,7 +41,7 @@ function output(feature) {
|
||||
print "\tlist = gh_list (SCM_UNDEFINED);";
|
||||
print "";
|
||||
print "\tfor (i = 0; i < GLIBTOP_MAX_"toupper(feature)"; i++)";
|
||||
print "\t\tlist = gh_append";
|
||||
print "\t\tlist = scm_append";
|
||||
print "\t\t\t(gh_list (list,";
|
||||
print "\t\t\t\t gh_list (gh_ulong2scm (glibtop_types_"feature" [i])),";
|
||||
print "\t\t\t\t SCM_UNDEFINED));";
|
||||
@@ -60,7 +60,7 @@ function output(feature) {
|
||||
print "\tlist = gh_list (SCM_UNDEFINED);";
|
||||
print "";
|
||||
print "\tfor (i = 0; i < GLIBTOP_MAX_"toupper(feature)"; i++)";
|
||||
print "\t\tlist = gh_append";
|
||||
print "\t\tlist = scm_append";
|
||||
print "\t\t\t(gh_list (list,";
|
||||
print "\t\t\t\t gh_list (gh_str02scm (gettext";
|
||||
print "\t\t\t\t\t\t\t(glibtop_labels_"feature" [i]))),";
|
||||
@@ -80,7 +80,7 @@ function output(feature) {
|
||||
print "\tlist = gh_list (SCM_UNDEFINED);";
|
||||
print "";
|
||||
print "\tfor (i = 0; i < GLIBTOP_MAX_"toupper(feature)"; i++)";
|
||||
print "\t\tlist = gh_append";
|
||||
print "\t\tlist = scm_append";
|
||||
print "\t\t\t(gh_list (list,";
|
||||
print "\t\t\t\t gh_list (gh_str02scm (gettext";
|
||||
print "\t\t\t\t\t\t\t(glibtop_descriptions_"feature" [i]))),";
|
||||
|
@@ -14,4 +14,4 @@ libgtop_sysdeps_la_SOURCES = init.c open.c close.c cpu.c mem.c swap.c \
|
||||
proctime.c procmem.c procsignal.c prockernel.c \
|
||||
procsegment.c
|
||||
|
||||
include_HEADERS = glibtop_server.h
|
||||
include_HEADERS = glibtop_server.h glibtop_machine.h
|
||||
|
@@ -35,8 +35,7 @@ static const unsigned long _glibtop_sysdeps_cpu =
|
||||
void
|
||||
glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
|
||||
{
|
||||
char buffer [BUFSIZ], *tmp;
|
||||
int fd = 0, ret;
|
||||
FILE *f;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
@@ -44,37 +43,15 @@ glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
|
||||
|
||||
buf->flags = _glibtop_sysdeps_cpu;
|
||||
|
||||
#ifdef GLIBTOP_CACHE_OPEN
|
||||
fd = server->machine.fd_stat;
|
||||
#endif
|
||||
if (fd == 0) {
|
||||
fd = open (FILENAME, O_RDONLY);
|
||||
if (fd == -1)
|
||||
glibtop_error_r (server, "open (%s): %s",
|
||||
FILENAME, strerror (errno));
|
||||
} else {
|
||||
lseek (fd, 0, SEEK_SET);
|
||||
}
|
||||
f = fopen ("/proc/stat", "r");
|
||||
if (!f) return;
|
||||
|
||||
ret = read (fd, buffer, BUFSIZ);
|
||||
if (ret == -1)
|
||||
glibtop_error_r (server, "read (%s): %s",
|
||||
FILENAME, strerror (errno));
|
||||
|
||||
tmp = strchr (buffer, '\n');
|
||||
tmp = skip_token (tmp); /* "cpu" */
|
||||
buf->user = strtoul (tmp, &tmp, 10);
|
||||
buf->nice = strtoul (tmp, &tmp, 10);
|
||||
buf->sys = strtoul (tmp, &tmp, 10);
|
||||
buf->idle = strtoul (tmp, &tmp, 10);
|
||||
fscanf (f, "cpu %lu %lu %lu %lu\n",
|
||||
&buf->user, &buf->nice, &buf->sys, &buf->idle);
|
||||
|
||||
buf->total = buf->user + buf->nice + buf->sys + buf->idle;
|
||||
|
||||
buf->frequency = 100;
|
||||
|
||||
#ifdef GLIBTOP_CACHE_OPEN
|
||||
server->machine.fd_stat = fd;
|
||||
#else
|
||||
close (fd);
|
||||
#endif
|
||||
fclose (f);
|
||||
}
|
||||
|
@@ -33,8 +33,7 @@ static const unsigned long _glibtop_sysdeps_loadavg =
|
||||
void
|
||||
glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
|
||||
{
|
||||
char buffer [BUFSIZ], *tmp;
|
||||
int fd = 0, ret;
|
||||
FILE *f;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
@@ -42,30 +41,11 @@ glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
|
||||
|
||||
buf->flags = _glibtop_sysdeps_loadavg;
|
||||
|
||||
#ifdef GLIBTOP_CACHE_OPEN
|
||||
fd = server->machine.fd_loadavg;
|
||||
#endif
|
||||
if (fd == 0) {
|
||||
fd = open (FILENAME, O_RDONLY);
|
||||
if (fd == -1)
|
||||
glibtop_error_r (server, "open (%s): %s",
|
||||
FILENAME, strerror (errno));
|
||||
} else {
|
||||
lseek (fd, 0, SEEK_SET);
|
||||
}
|
||||
f = fopen ("/proc/loadavg", "r");
|
||||
if (!f) return;
|
||||
|
||||
ret = read (fd, buffer, BUFSIZ);
|
||||
if (ret == -1)
|
||||
glibtop_error_r (server, "read (%s): %s",
|
||||
FILENAME, strerror (errno));
|
||||
fscanf (f, "%lf %lf %lf\n",
|
||||
&buf->loadavg [0], &buf->loadavg [1], &buf->loadavg [2]);
|
||||
|
||||
buf->loadavg [0] = strtod (buffer, &tmp);
|
||||
buf->loadavg [1] = strtod (tmp, &tmp);
|
||||
buf->loadavg [2] = strtod (tmp, &tmp);
|
||||
|
||||
#ifdef GLIBTOP_CACHE_OPEN
|
||||
server->machine.fd_loadavg = fd;
|
||||
#else
|
||||
close (fd);
|
||||
#endif
|
||||
fclose (f);
|
||||
}
|
||||
|
@@ -36,8 +36,7 @@ static const unsigned long _glibtop_sysdeps_mem =
|
||||
void
|
||||
glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
|
||||
{
|
||||
char buffer [BUFSIZ], *tmp;
|
||||
int fd = 0, ret;
|
||||
FILE *f;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
@@ -45,39 +44,14 @@ glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
|
||||
|
||||
buf->flags = _glibtop_sysdeps_mem;
|
||||
|
||||
#ifdef GLIBTOP_CACHE_OPEN
|
||||
fd = server->machine.fd_meminfo;
|
||||
#endif
|
||||
if (fd == 0) {
|
||||
fd = open (FILENAME, O_RDONLY);
|
||||
if (fd == -1)
|
||||
glibtop_error_r (server, "open (%s): %s",
|
||||
FILENAME, strerror (errno));
|
||||
} else {
|
||||
lseek (fd, 0, SEEK_SET);
|
||||
}
|
||||
f = fopen ("/proc/meminfo", "r");
|
||||
if (!f) return;
|
||||
|
||||
ret = read (fd, buffer, BUFSIZ);
|
||||
if (ret == -1)
|
||||
glibtop_error_r (server, "read (%s): %s",
|
||||
FILENAME, strerror (errno));
|
||||
|
||||
tmp = strchr (buffer, '\n');
|
||||
tmp = skip_token (tmp); /* "Mem:" */
|
||||
tmp = skip_token (tmp); /* total memory */
|
||||
|
||||
buf->total = strtoul (tmp, &tmp, 10);
|
||||
buf->used = strtoul (tmp, &tmp, 10);
|
||||
buf->free = strtoul (tmp, &tmp, 10);
|
||||
buf->shared = strtoul (tmp, &tmp, 10);
|
||||
buf->buffer = strtoul (tmp, &tmp, 10);
|
||||
buf->cached = strtoul (tmp, &tmp, 10);
|
||||
fscanf (f, "%*[^\n]\nMem: %lu %lu %lu %lu %lu %lu\n",
|
||||
&buf->total, &buf->used, &buf->free, &buf->shared,
|
||||
&buf->buffer, &buf->cached);
|
||||
|
||||
buf->user = buf->total - buf->free - buf->shared - buf->buffer;
|
||||
|
||||
#ifdef GLIBTOP_CACHE_OPEN
|
||||
server->machine.fd_meminfo = fd;
|
||||
#else
|
||||
close (fd);
|
||||
#endif
|
||||
fclose (f);
|
||||
}
|
||||
|
@@ -54,7 +54,6 @@ void
|
||||
glibtop_open_r (glibtop *server, const char *program_name,
|
||||
const unsigned long features, const unsigned flags)
|
||||
{
|
||||
memset (server, 0, sizeof (glibtop));
|
||||
server->name = program_name;
|
||||
|
||||
set_linux_version ();
|
||||
|
@@ -34,8 +34,9 @@ static const unsigned long _glibtop_sysdeps_proc_kernel =
|
||||
void
|
||||
glibtop_get_proc_kernel_s (glibtop *server, glibtop_proc_kernel *buf, pid_t pid)
|
||||
{
|
||||
char buffer [BUFSIZ], input [BUFSIZ], *tmp;
|
||||
int fd = 0, nread;
|
||||
char input [BUFSIZ], *tmp;
|
||||
int nread;
|
||||
FILE *f;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
@@ -47,41 +48,24 @@ glibtop_get_proc_kernel_s (glibtop *server, glibtop_proc_kernel *buf, pid_t pid)
|
||||
return;
|
||||
}
|
||||
|
||||
if (pid != server->machine.last_pid) {
|
||||
server->machine.last_pid = pid;
|
||||
server->machine.no_update = 0;
|
||||
}
|
||||
|
||||
if (!server->machine.no_update) {
|
||||
server->machine.proc_status [0] = 0;
|
||||
server->machine.proc_statm [0] = 0;
|
||||
server->machine.proc_stat [0] = 0;
|
||||
}
|
||||
|
||||
if (server->machine.proc_stat [0]) {
|
||||
strcpy (buffer, server->machine.proc_stat);
|
||||
} else {
|
||||
sprintf (input, "/proc/%d/stat", pid);
|
||||
|
||||
fd = open (input, O_RDONLY);
|
||||
if (fd == -1)
|
||||
glibtop_error_r (server, "open (%s): %s",
|
||||
input, strerror (errno));
|
||||
f = fopen (input, "r");
|
||||
if (!f) return;
|
||||
|
||||
nread = read (fd, buffer, BUFSIZ);
|
||||
if (nread == -1)
|
||||
glibtop_error_r (server, "read (%s): %s",
|
||||
input, strerror (errno));
|
||||
nread = fread (input, 1, BUFSIZ, f);
|
||||
|
||||
buffer [nread] = 0;
|
||||
strcpy (server->machine.proc_stat, buffer);
|
||||
close (fd);
|
||||
if (nread < 0) {
|
||||
fclose (f);
|
||||
return;
|
||||
}
|
||||
|
||||
input [nread] = 0;
|
||||
|
||||
/* This is from guile-utils/gtop/proc/readproc.c */
|
||||
|
||||
/* split into "PID (cmd" and "<rest>" */
|
||||
tmp = strrchr (buffer, ')');
|
||||
tmp = strrchr (input, ')');
|
||||
*tmp = '\0'; /* replace trailing ')' with NUL */
|
||||
/* parse these two strings separately, skipping the leading "(". */
|
||||
|
||||
@@ -93,5 +77,7 @@ glibtop_get_proc_kernel_s (glibtop *server, glibtop_proc_kernel *buf, pid_t pid)
|
||||
&buf->maj_flt, &buf->cmaj_flt, &buf->kstk_esp,
|
||||
&buf->kstk_eip, &buf->wchan);
|
||||
|
||||
fclose (f);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_kernel;
|
||||
}
|
||||
|
@@ -33,8 +33,9 @@ static const unsigned long _glibtop_sysdeps_proc_mem =
|
||||
void
|
||||
glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid)
|
||||
{
|
||||
char buffer [BUFSIZ], input [BUFSIZ], *tmp;
|
||||
int fd = 0, nread;
|
||||
char input [BUFSIZ], *tmp;
|
||||
int nread;
|
||||
FILE *f;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
@@ -46,41 +47,24 @@ glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid)
|
||||
return;
|
||||
}
|
||||
|
||||
if (pid != server->machine.last_pid) {
|
||||
server->machine.last_pid = pid;
|
||||
server->machine.no_update = 0;
|
||||
}
|
||||
|
||||
if (!server->machine.no_update) {
|
||||
server->machine.proc_status [0] = 0;
|
||||
server->machine.proc_statm [0] = 0;
|
||||
server->machine.proc_stat [0] = 0;
|
||||
}
|
||||
|
||||
if (server->machine.proc_stat [0]) {
|
||||
strcpy (buffer, server->machine.proc_stat);
|
||||
} else {
|
||||
sprintf (input, "/proc/%d/stat", pid);
|
||||
|
||||
fd = open (input, O_RDONLY);
|
||||
if (fd == -1)
|
||||
glibtop_error_r (server, "open (%s): %s",
|
||||
input, strerror (errno));
|
||||
f = fopen (input, "r");
|
||||
if (!f) return;
|
||||
|
||||
nread = read (fd, buffer, BUFSIZ);
|
||||
if (nread == -1)
|
||||
glibtop_error_r (server, "read (%s): %s",
|
||||
input, strerror (errno));
|
||||
nread = fread (input, 1, BUFSIZ, f);
|
||||
|
||||
buffer [nread] = 0;
|
||||
strcpy (server->machine.proc_stat, buffer);
|
||||
close (fd);
|
||||
if (nread < 0) {
|
||||
fclose (f);
|
||||
return;
|
||||
}
|
||||
|
||||
input [nread] = 0;
|
||||
|
||||
/* This is from guile-utils/gtop/proc/readproc.c */
|
||||
|
||||
/* split into "PID (cmd" and "<rest>" */
|
||||
tmp = strrchr (buffer, ')');
|
||||
tmp = strrchr (input, ')');
|
||||
*tmp = '\0'; /* replace trailing ')' with NUL */
|
||||
/* parse these two strings separately, skipping the leading "(". */
|
||||
sscanf(tmp + 2, /* skip space after ')' too */
|
||||
@@ -88,28 +72,26 @@ glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid)
|
||||
"%*d %*d %*d %*d %*d %*d %*u %*u %*d %lu "
|
||||
"%lu %lu", &buf->vsize, &buf->rss, &buf->rss_rlim);
|
||||
|
||||
if (server->machine.proc_statm [0]) {
|
||||
strcpy (buffer, server->machine.proc_statm);
|
||||
} else {
|
||||
fclose (f);
|
||||
|
||||
sprintf (input, "/proc/%d/statm", pid);
|
||||
|
||||
fd = open (input, O_RDONLY);
|
||||
if (fd == -1)
|
||||
glibtop_error_r (server, "open (%s): %s",
|
||||
input, strerror (errno));
|
||||
f = fopen (input, "r");
|
||||
if (!f) return;
|
||||
|
||||
nread = read (fd, buffer, BUFSIZ);
|
||||
if (nread == -1)
|
||||
glibtop_error_r (server, "read (%s): %s",
|
||||
input, strerror (errno));
|
||||
nread = fread (input, 1, BUFSIZ, f);
|
||||
|
||||
buffer [nread] = 0;
|
||||
strcpy (server->machine.proc_statm, buffer);
|
||||
close (fd);
|
||||
if (nread < 0) {
|
||||
fclose (f);
|
||||
return;
|
||||
}
|
||||
|
||||
sscanf (buffer, "%ld %ld %ld",
|
||||
input [nread] = 0;
|
||||
|
||||
sscanf (input, "%ld %ld %ld",
|
||||
&buf->size, &buf->resident, &buf->share);
|
||||
|
||||
fclose (f);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_mem;
|
||||
}
|
||||
|
@@ -35,8 +35,9 @@ void
|
||||
glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf,
|
||||
pid_t pid)
|
||||
{
|
||||
char buffer [BUFSIZ], input [BUFSIZ], *tmp;
|
||||
int fd = 0, nread;
|
||||
char input [BUFSIZ], *tmp;
|
||||
int nread;
|
||||
FILE *f;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
@@ -48,41 +49,24 @@ glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf,
|
||||
return;
|
||||
}
|
||||
|
||||
if (pid != server->machine.last_pid) {
|
||||
server->machine.last_pid = pid;
|
||||
server->machine.no_update = 0;
|
||||
}
|
||||
|
||||
if (!server->machine.no_update) {
|
||||
server->machine.proc_status [0] = 0;
|
||||
server->machine.proc_statm [0] = 0;
|
||||
server->machine.proc_stat [0] = 0;
|
||||
}
|
||||
|
||||
if (server->machine.proc_stat [0]) {
|
||||
strcpy (buffer, server->machine.proc_stat);
|
||||
} else {
|
||||
sprintf (input, "/proc/%d/stat", pid);
|
||||
|
||||
fd = open (input, O_RDONLY);
|
||||
if (fd == -1)
|
||||
glibtop_error_r (server, "open (%s): %s",
|
||||
input, strerror (errno));
|
||||
f = fopen (input, "r");
|
||||
if (!f) return;
|
||||
|
||||
nread = read (fd, buffer, BUFSIZ);
|
||||
if (nread == -1)
|
||||
glibtop_error_r (server, "read (%s): %s",
|
||||
input, strerror (errno));
|
||||
nread = fread (input, 1, BUFSIZ, f);
|
||||
|
||||
buffer [nread] = 0;
|
||||
strcpy (server->machine.proc_stat, buffer);
|
||||
close (fd);
|
||||
if (nread < 0) {
|
||||
fclose (f);
|
||||
return;
|
||||
}
|
||||
|
||||
input [nread] = 0;
|
||||
|
||||
/* This is from guile-utils/gtop/proc/readproc.c */
|
||||
|
||||
/* split into "PID (cmd" and "<rest>" */
|
||||
tmp = strrchr (buffer, ')');
|
||||
tmp = strrchr (input, ')');
|
||||
*tmp = '\0'; /* replace trailing ')' with NUL */
|
||||
/* parse these two strings separately, skipping the leading "(". */
|
||||
sscanf(tmp + 2, /* skip space after ')' too */
|
||||
@@ -91,28 +75,26 @@ glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf,
|
||||
"%*u %*u %lu %lu %lu", &buf->start_code,
|
||||
&buf->end_code, &buf->start_stack);
|
||||
|
||||
if (server->machine.proc_statm [0]) {
|
||||
strcpy (buffer, server->machine.proc_statm);
|
||||
} else {
|
||||
fclose (f);
|
||||
|
||||
sprintf (input, "/proc/%d/statm", pid);
|
||||
|
||||
fd = open (input, O_RDONLY);
|
||||
if (fd == -1)
|
||||
glibtop_error_r (server, "open (%s): %s",
|
||||
input, strerror (errno));
|
||||
f = fopen (input, "r");
|
||||
if (!f) return;
|
||||
|
||||
nread = read (fd, buffer, BUFSIZ);
|
||||
if (nread == -1)
|
||||
glibtop_error_r (server, "read (%s): %s",
|
||||
input, strerror (errno));
|
||||
nread = fread (input, 1, BUFSIZ, f);
|
||||
|
||||
buffer [nread] = 0;
|
||||
strcpy (server->machine.proc_statm, buffer);
|
||||
close (fd);
|
||||
if (nread < 0) {
|
||||
fclose (f);
|
||||
return;
|
||||
}
|
||||
|
||||
sscanf (buffer, "%*d %*d %*d %ld %ld %ld %ld",
|
||||
input [nread] = 0;
|
||||
|
||||
sscanf (input, "%*d %*d %*d %ld %ld %ld %ld",
|
||||
&buf->trs, &buf->lrs, &buf->drs, &buf->dt);
|
||||
|
||||
fclose (f);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_segment;
|
||||
}
|
||||
|
@@ -32,8 +32,9 @@ static const unsigned long _glibtop_sysdeps_proc_signal =
|
||||
void
|
||||
glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf, pid_t pid)
|
||||
{
|
||||
char buffer [BUFSIZ], input [BUFSIZ], *tmp;
|
||||
int fd = 0, nread;
|
||||
char input [BUFSIZ], *tmp;
|
||||
int nread;
|
||||
FILE *f;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
@@ -45,41 +46,24 @@ glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf, pid_t pid)
|
||||
return;
|
||||
}
|
||||
|
||||
if (pid != server->machine.last_pid) {
|
||||
server->machine.last_pid = pid;
|
||||
server->machine.no_update = 0;
|
||||
}
|
||||
|
||||
if (!server->machine.no_update) {
|
||||
server->machine.proc_status [0] = 0;
|
||||
server->machine.proc_statm [0] = 0;
|
||||
server->machine.proc_stat [0] = 0;
|
||||
}
|
||||
|
||||
if (server->machine.proc_stat [0]) {
|
||||
strcpy (buffer, server->machine.proc_stat);
|
||||
} else {
|
||||
sprintf (input, "/proc/%d/stat", pid);
|
||||
|
||||
fd = open (input, O_RDONLY);
|
||||
if (fd == -1)
|
||||
glibtop_error_r (server, "open (%s): %s",
|
||||
input, strerror (errno));
|
||||
f = fopen (input, "r");
|
||||
if (!f) return;
|
||||
|
||||
nread = read (fd, buffer, BUFSIZ);
|
||||
if (nread == -1)
|
||||
glibtop_error_r (server, "read (%s): %s",
|
||||
input, strerror (errno));
|
||||
nread = fread (input, 1, BUFSIZ, f);
|
||||
|
||||
buffer [nread] = 0;
|
||||
strcpy (server->machine.proc_stat, buffer);
|
||||
close (fd);
|
||||
if (nread < 0) {
|
||||
fclose (f);
|
||||
return;
|
||||
}
|
||||
|
||||
input [nread] = 0;
|
||||
|
||||
/* This is from guile-utils/gtop/proc/readproc.c */
|
||||
|
||||
/* split into "PID (cmd" and "<rest>" */
|
||||
tmp = strrchr (buffer, ')');
|
||||
tmp = strrchr (input, ')');
|
||||
*tmp = '\0'; /* replace trailing ')' with NUL */
|
||||
/* parse these two strings separately, skipping the leading "(". */
|
||||
sscanf(tmp + 2, /* skip space after ')' too */
|
||||
@@ -89,5 +73,7 @@ glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf, pid_t pid)
|
||||
&buf->signal, &buf->blocked, &buf->sigignore,
|
||||
&buf->sigcatch);
|
||||
|
||||
fclose (f);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_signal;
|
||||
}
|
||||
|
@@ -34,9 +34,10 @@ static const unsigned long _glibtop_sysdeps_proc_state =
|
||||
void
|
||||
glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, pid_t pid)
|
||||
{
|
||||
char buffer [BUFSIZ], input [BUFSIZ], *tmp;
|
||||
char input [BUFSIZ], *tmp;
|
||||
struct stat statb;
|
||||
int fd, nread;
|
||||
int nread;
|
||||
FILE *f;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
@@ -48,12 +49,6 @@ glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, pid_t pid)
|
||||
return;
|
||||
}
|
||||
|
||||
server->machine.last_pid = pid;
|
||||
server->machine.no_update = 0;
|
||||
server->machine.proc_status [0] = 0;
|
||||
server->machine.proc_statm [0] = 0;
|
||||
server->machine.proc_stat [0] = 0;
|
||||
|
||||
sprintf (input, "/proc/%d/stat", pid);
|
||||
|
||||
/* IMPORTANT NOTICE: For security reasons it is extremely important
|
||||
@@ -68,32 +63,29 @@ glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, pid_t pid)
|
||||
buf->uid = statb.st_uid;
|
||||
buf->gid = statb.st_gid;
|
||||
|
||||
fd = open (input, O_RDONLY);
|
||||
if (fd == -1)
|
||||
glibtop_error_r (server, "open (%s): %s",
|
||||
input, strerror (errno));
|
||||
f = fopen (input, "r");
|
||||
if (!f) return;
|
||||
|
||||
nread = read (fd, buffer, BUFSIZ);
|
||||
if (nread == -1)
|
||||
glibtop_error_r (server, "read (%s): %s",
|
||||
input, strerror (errno));
|
||||
nread = fread (input, 1, BUFSIZ, f);
|
||||
|
||||
buffer [nread] = 0;
|
||||
if (nread < 0) {
|
||||
fclose (f);
|
||||
return;
|
||||
}
|
||||
|
||||
server->machine.last_pid = pid;
|
||||
strcpy (server->machine.proc_stat, buffer);
|
||||
fclose (f);
|
||||
|
||||
input [nread] = 0;
|
||||
|
||||
/* This is from guile-utils/gtop/proc/readproc.c */
|
||||
|
||||
/* split into "PID (cmd" and "<rest>" */
|
||||
tmp = strrchr (buffer, ')');
|
||||
tmp = strrchr (input, ')');
|
||||
*tmp = '\0'; /* replace trailing ')' with NUL */
|
||||
/* parse these two strings separately, skipping the leading "(". */
|
||||
memset (buf->cmd, 0, sizeof (buf->cmd));
|
||||
sscanf (buffer, "%d (%39c", &pid, buf->cmd);
|
||||
sscanf (input, "%d (%39c", &pid, buf->cmd);
|
||||
sscanf(tmp + 2, "%c", &buf->state); /* skip space after ')' too */
|
||||
|
||||
close (fd);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_state;
|
||||
}
|
||||
|
@@ -34,8 +34,9 @@ static const unsigned long _glibtop_sysdeps_proc_time =
|
||||
void
|
||||
glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf, pid_t pid)
|
||||
{
|
||||
char buffer [BUFSIZ], input [BUFSIZ], *tmp;
|
||||
int fd = 0, nread;
|
||||
char input [BUFSIZ], *tmp;
|
||||
int nread;
|
||||
FILE *f;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
@@ -47,41 +48,24 @@ glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf, pid_t pid)
|
||||
return;
|
||||
}
|
||||
|
||||
if (pid != server->machine.last_pid) {
|
||||
server->machine.last_pid = pid;
|
||||
server->machine.no_update = 0;
|
||||
}
|
||||
|
||||
if (!server->machine.no_update) {
|
||||
server->machine.proc_status [0] = 0;
|
||||
server->machine.proc_statm [0] = 0;
|
||||
server->machine.proc_stat [0] = 0;
|
||||
}
|
||||
|
||||
if (server->machine.proc_stat [0]) {
|
||||
strcpy (buffer, server->machine.proc_stat);
|
||||
} else {
|
||||
sprintf (input, "/proc/%d/stat", pid);
|
||||
|
||||
fd = open (input, O_RDONLY);
|
||||
if (fd == -1)
|
||||
glibtop_error_r (server, "open (%s): %s",
|
||||
input, strerror (errno));
|
||||
f = fopen (input, "r");
|
||||
if (!f) return;
|
||||
|
||||
nread = read (fd, buffer, BUFSIZ);
|
||||
if (nread == -1)
|
||||
glibtop_error_r (server, "read (%s): %s",
|
||||
input, strerror (errno));
|
||||
nread = fread (input, 1, BUFSIZ, f);
|
||||
|
||||
buffer [nread] = 0;
|
||||
strcpy (server->machine.proc_stat, buffer);
|
||||
close (fd);
|
||||
if (nread < 0) {
|
||||
fclose (f);
|
||||
return;
|
||||
}
|
||||
|
||||
input [nread] = 0;
|
||||
|
||||
/* This is from guile-utils/gtop/proc/readproc.c */
|
||||
|
||||
/* split into "PID (cmd" and "<rest>" */
|
||||
tmp = strrchr (buffer, ')');
|
||||
tmp = strrchr (input, ')');
|
||||
*tmp = '\0'; /* replace trailing ')' with NUL */
|
||||
/* parse these two strings separately, skipping the leading "(". */
|
||||
sscanf(tmp + 2, /* skip space after ')' too */
|
||||
@@ -90,5 +74,7 @@ glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf, pid_t pid)
|
||||
&buf->utime, &buf->stime, &buf->cutime, &buf->cstime,
|
||||
&buf->timeout, &buf->it_real_value, &buf->start_time);
|
||||
|
||||
fclose (f);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_time;
|
||||
}
|
||||
|
@@ -38,8 +38,9 @@ static const unsigned long _glibtop_sysdeps_proc_uid =
|
||||
void
|
||||
glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid)
|
||||
{
|
||||
char buffer [BUFSIZ], input [BUFSIZ], *tmp;
|
||||
int fd = 0, nread;
|
||||
char input [BUFSIZ], *tmp;
|
||||
int nread;
|
||||
FILE *f;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
@@ -51,40 +52,23 @@ glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid)
|
||||
return;
|
||||
}
|
||||
|
||||
if (pid != server->machine.last_pid) {
|
||||
server->machine.last_pid = pid;
|
||||
server->machine.no_update = 0;
|
||||
}
|
||||
|
||||
if (!server->machine.no_update) {
|
||||
server->machine.proc_status [0] = 0;
|
||||
server->machine.proc_statm [0] = 0;
|
||||
server->machine.proc_stat [0] = 0;
|
||||
}
|
||||
|
||||
if (server->machine.proc_status [0]) {
|
||||
strcpy (buffer, server->machine.proc_status);
|
||||
} else {
|
||||
sprintf (input, "/proc/%d/status", pid);
|
||||
|
||||
fd = open (input, O_RDONLY);
|
||||
if (fd == -1)
|
||||
glibtop_error_r (server, "open (%s): %s",
|
||||
input, strerror (errno));
|
||||
f = fopen (input, "r");
|
||||
if (!f) return;
|
||||
|
||||
nread = read (fd, buffer, BUFSIZ);
|
||||
if (nread == -1)
|
||||
glibtop_error_r (server, "read (%s): %s",
|
||||
input, strerror (errno));
|
||||
nread = fread (input, 1, BUFSIZ, f);
|
||||
|
||||
buffer [nread] = 0;
|
||||
strcpy (server->machine.proc_status, buffer);
|
||||
close (fd);
|
||||
if (nread < 0) {
|
||||
fclose (f);
|
||||
return;
|
||||
}
|
||||
|
||||
input [nread] = 0;
|
||||
|
||||
/* Search substring 'Pid:' */
|
||||
|
||||
tmp = strstr (buffer, "Pid:");
|
||||
tmp = strstr (input, "Pid:");
|
||||
|
||||
if (tmp == NULL) return;
|
||||
|
||||
@@ -92,30 +76,26 @@ glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid)
|
||||
"Gid: %u %u %*u %*u\n", &buf->pid, &buf->ppid,
|
||||
&buf->uid, &buf->euid, &buf->gid, &buf->egid);
|
||||
|
||||
if (server->machine.proc_stat [0]) {
|
||||
strcpy (buffer, server->machine.proc_stat);
|
||||
} else {
|
||||
fclose (f);
|
||||
|
||||
sprintf (input, "/proc/%d/stat", pid);
|
||||
|
||||
fd = open (input, O_RDONLY);
|
||||
if (fd == -1)
|
||||
glibtop_error_r (server, "open (%s): %s",
|
||||
input, strerror (errno));
|
||||
f = fopen (input, "r");
|
||||
if (!f) return;
|
||||
|
||||
nread = read (fd, buffer, BUFSIZ);
|
||||
if (nread == -1)
|
||||
glibtop_error_r (server, "read (%s): %s",
|
||||
input, strerror (errno));
|
||||
nread = fread (input, 1, BUFSIZ, f);
|
||||
|
||||
buffer [nread] = 0;
|
||||
strcpy (server->machine.proc_stat, buffer);
|
||||
close (fd);
|
||||
if (nread < 0) {
|
||||
fclose (f);
|
||||
return;
|
||||
}
|
||||
|
||||
input [nread] = 0;
|
||||
|
||||
/* This is from guile-utils/gtop/proc/readproc.c */
|
||||
|
||||
/* split into "PID (cmd" and "<rest>" */
|
||||
tmp = strrchr (buffer, ')');
|
||||
tmp = strrchr (input, ')');
|
||||
*tmp = '\0'; /* replace trailing ')' with NUL */
|
||||
/* parse these two strings separately, skipping the leading "(". */
|
||||
sscanf(tmp + 2, /* skip space after ')' too */
|
||||
@@ -137,5 +117,7 @@ glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid)
|
||||
/* when tty wasn't full devno */
|
||||
buf->tty = 4*0x100 + buf->tty;
|
||||
|
||||
fclose (f);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_uid;
|
||||
}
|
||||
|
@@ -24,6 +24,16 @@
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/sem.h>
|
||||
|
||||
#ifdef _SEM_SEMUN_UNDEFINED
|
||||
union semun
|
||||
{
|
||||
int val;
|
||||
struct semid_ds *buf;
|
||||
unsigned short int *array;
|
||||
struct seminfo *__buf;
|
||||
};
|
||||
#endif
|
||||
|
||||
static unsigned long _glibtop_sysdeps_sem_limits =
|
||||
(1 << GLIBTOP_IPC_SEMMAP) + (1 << GLIBTOP_IPC_SEMMNI) +
|
||||
(1 << GLIBTOP_IPC_SEMMNS) + (1 << GLIBTOP_IPC_SEMMNU) +
|
||||
|
@@ -34,8 +34,7 @@ static unsigned long _glibtop_sysdeps_swap =
|
||||
void
|
||||
glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
|
||||
{
|
||||
char buffer [BUFSIZ], *tmp;
|
||||
int fd = 0, ret;
|
||||
FILE *f;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
@@ -43,34 +42,11 @@ glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
|
||||
|
||||
buf->flags = _glibtop_sysdeps_swap;
|
||||
|
||||
#ifdef GLIBTOP_CACHE_OPEN
|
||||
fd = server->machine.fd_meminfo;
|
||||
#endif
|
||||
if (fd == 0) {
|
||||
fd = open (FILENAME, O_RDONLY);
|
||||
if (fd == -1)
|
||||
glibtop_error_r (server, "open (%s): %s",
|
||||
FILENAME, strerror (errno));
|
||||
} else {
|
||||
lseek (fd, 0, SEEK_SET);
|
||||
}
|
||||
f = fopen ("/proc/meminfo", "r");
|
||||
if (!f) return;
|
||||
|
||||
ret = read (fd, buffer, BUFSIZ);
|
||||
if (ret == -1)
|
||||
glibtop_error_r (server, "read (%s): %s",
|
||||
FILENAME, strerror (errno));
|
||||
fscanf (f, "%*[^\n]\n%*[^\n]\nSwap: %lu %lu %lu\n",
|
||||
&buf->total, &buf->used, &buf->free);
|
||||
|
||||
tmp = strchr (buffer, '\n');
|
||||
tmp = strchr (tmp+1, '\n');
|
||||
|
||||
tmp = skip_token (tmp); /* "Swap:" */
|
||||
buf->total = strtoul (tmp, &tmp, 10);
|
||||
buf->used = strtoul (tmp, &tmp, 10);
|
||||
buf->free = strtoul (tmp, &tmp, 10);
|
||||
|
||||
#ifdef GLIBTOP_CACHE_OPEN
|
||||
server->machine.fd_meminfo = fd;
|
||||
#else
|
||||
close (fd);
|
||||
#endif
|
||||
fclose (f);
|
||||
}
|
||||
|
@@ -33,8 +33,7 @@ static unsigned long _glibtop_sysdeps_uptime =
|
||||
void
|
||||
glibtop_get_uptime_s (glibtop *server, glibtop_uptime *buf)
|
||||
{
|
||||
int fd, ret;
|
||||
char buffer [BUFSIZ];
|
||||
FILE *f;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
@@ -42,17 +41,10 @@ glibtop_get_uptime_s (glibtop *server, glibtop_uptime *buf)
|
||||
|
||||
buf->flags = _glibtop_sysdeps_uptime;
|
||||
|
||||
fd = open (FILENAME, O_RDONLY);
|
||||
if (fd == -1)
|
||||
glibtop_error_r (server, "open (%s): %s",
|
||||
FILENAME, strerror (errno));
|
||||
f = fopen ("/proc/uptime", "r");
|
||||
if (!f) return;
|
||||
|
||||
ret = read (fd, buffer, BUFSIZ);
|
||||
if (ret == -1)
|
||||
glibtop_error_r (server, "read (%s): %s",
|
||||
FILENAME, strerror (errno));
|
||||
fscanf (f, "%lf %lf\n", &buf->uptime, &buf->idletime);
|
||||
|
||||
sscanf (buffer, "%lf %lf\n", &buf->uptime, &buf->idletime);
|
||||
|
||||
close (fd);
|
||||
fclose (f);
|
||||
}
|
||||
|
@@ -24,5 +24,5 @@
|
||||
/* Closes pipe to gtop server. */
|
||||
|
||||
void
|
||||
glibtop_close (glibtop *server)
|
||||
glibtop_close_l (glibtop *server)
|
||||
{ }
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user