New file. This is a private header file which defines `struct
1999-12-19 Martin Baulig <martin@home-of-linux.org> * glibtop-server-private.h: New file. This is a private header file which defines `struct _glibtop_server_private'. * glibtop.h (glibtop): Added `glibtop_server_private *_priv' field and moved some private fields there.
This commit is contained in:
committed by
Martin Baulig
parent
339e1f4557
commit
d4b712db86
@@ -1,3 +1,11 @@
|
|||||||
|
1999-12-19 Martin Baulig <martin@home-of-linux.org>
|
||||||
|
|
||||||
|
* glibtop-server-private.h: New file. This is a private header
|
||||||
|
file which defines `struct _glibtop_server_private'.
|
||||||
|
|
||||||
|
* glibtop.h (glibtop): Added `glibtop_server_private *_priv' field
|
||||||
|
and moved some private fields there.
|
||||||
|
|
||||||
1999-12-12 Martin Baulig <martin@home-of-linux.org>
|
1999-12-12 Martin Baulig <martin@home-of-linux.org>
|
||||||
|
|
||||||
* include/glibtop/procargs.h (glibtop_proc_args): Removed.
|
* include/glibtop/procargs.h (glibtop_proc_args): Removed.
|
||||||
|
@@ -10,6 +10,8 @@ SUBDIRS = po intl $(support) macros misc include sysdeps lib src doc \
|
|||||||
include_HEADERS = glibtop.h
|
include_HEADERS = glibtop.h
|
||||||
configincludedir = $(pkglibdir)/include
|
configincludedir = $(pkglibdir)/include
|
||||||
|
|
||||||
|
noinst_HEADERS = glibtop-server-private.h
|
||||||
|
|
||||||
EXTRA_DIST = autogen.sh libgtop.spec.in copyright.txt libgtopConf.sh.in \
|
EXTRA_DIST = autogen.sh libgtop.spec.in copyright.txt libgtopConf.sh.in \
|
||||||
LIBGTOP-VERSION features.def structures.def libgtop-config.in \
|
LIBGTOP-VERSION features.def structures.def libgtop-config.in \
|
||||||
RELNOTES-0.25 RELNOTES-1.0 RELNOTES-1.1.x libgtop-sysdeps.m4 README \
|
RELNOTES-0.25 RELNOTES-1.0 RELNOTES-1.1.x libgtop-sysdeps.m4 README \
|
||||||
|
42
glibtop-server-private.h
Normal file
42
glibtop-server-private.h
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
/* Copyright (C) 1998-99 Martin Baulig
|
||||||
|
This file is part of LibGTop 1.0.
|
||||||
|
|
||||||
|
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||||
|
|
||||||
|
LibGTop 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 of the License,
|
||||||
|
or (at your option) any later version.
|
||||||
|
|
||||||
|
LibGTop 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 LibGTop; see the file COPYING. If not, write to the
|
||||||
|
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||||
|
Boston, MA 02111-1307, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __GLIBTOP_SERVER_PRIVATE_H__
|
||||||
|
#define __GLIBTOP_SERVER_PRIVATE_H__
|
||||||
|
|
||||||
|
#ifdef HAVE_GLIBTOP_MACHINE_H
|
||||||
|
#include <glibtop_machine.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct _glibtop_server_private
|
||||||
|
{
|
||||||
|
#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 */
|
||||||
|
pid_t pid; /* PID of the server */
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
39
glibtop.h
39
glibtop.h
@@ -34,27 +34,24 @@
|
|||||||
#include <glibtop_server.h>
|
#include <glibtop_server.h>
|
||||||
#include <glibtop/types.h>
|
#include <glibtop/types.h>
|
||||||
|
|
||||||
#ifdef HAVE_GLIBTOP_MACHINE_H
|
BEGIN_LIBGTOP_DECLS
|
||||||
#include <glibtop_machine.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct _glibtop glibtop;
|
typedef struct _glibtop glibtop;
|
||||||
|
typedef struct _glibtop_server_private glibtop_server_private;
|
||||||
|
|
||||||
#include <glibtop/sysdeps.h>
|
#include <glibtop/sysdeps.h>
|
||||||
#include <glibtop/errors.h>
|
#include <glibtop/errors.h>
|
||||||
|
|
||||||
|
#ifdef _IN_LIBGTOP
|
||||||
|
#include <glibtop-server-private.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
struct _glibtop
|
struct _glibtop
|
||||||
{
|
{
|
||||||
int refcount; /* Reference count */
|
int refcount; /* Reference count */
|
||||||
unsigned flags;
|
unsigned flags;
|
||||||
unsigned method; /* Server Method */
|
unsigned method; /* Server Method */
|
||||||
unsigned error_method; /* Error Method */
|
unsigned error_method; /* Error 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 */
|
|
||||||
int ncpu; /* Number of CPUs, zero if single-processor */
|
int ncpu; /* Number of CPUs, zero if single-processor */
|
||||||
unsigned long os_version_code; /* Version code of the operating system */
|
unsigned long os_version_code; /* Version code of the operating system */
|
||||||
const char *name; /* Program name for error messages */
|
const char *name; /* Program name for error messages */
|
||||||
@@ -67,7 +64,7 @@ struct _glibtop
|
|||||||
glibtop_sysdeps sysdeps; /* Detailed feature list */
|
glibtop_sysdeps sysdeps; /* Detailed feature list */
|
||||||
glibtop_sysdeps required; /* Required feature list */
|
glibtop_sysdeps required; /* Required feature list */
|
||||||
glibtop_sysdeps wanted; /* We only want this features */
|
glibtop_sysdeps wanted; /* We only want this features */
|
||||||
pid_t pid; /* PID of the server */
|
glibtop_server_private *_priv; /* Private data */
|
||||||
};
|
};
|
||||||
|
|
||||||
extern glibtop *glibtop_global_server;
|
extern glibtop *glibtop_global_server;
|
||||||
@@ -94,24 +91,6 @@ glibtop_server_ref (glibtop *server);
|
|||||||
void
|
void
|
||||||
glibtop_server_unref (glibtop *server);
|
glibtop_server_unref (glibtop *server);
|
||||||
|
|
||||||
#ifdef GLIBTOP_GUILE
|
END_LIBGTOP_DECLS
|
||||||
|
|
||||||
/* You need to link with -lgtop_guile to get this stuff here. */
|
|
||||||
|
|
||||||
void glibtop_boot_guile (void);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef GLIBTOP_GUILE_NAMES
|
|
||||||
|
|
||||||
/* You need to link with -lgtop_guile_names to get this stuff here. */
|
|
||||||
|
|
||||||
void glibtop_boot_guile_names (void);
|
|
||||||
|
|
||||||
#ifndef GLIBTOP_NAMES
|
|
||||||
#define GLIBTOP_NAMES
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -37,14 +37,14 @@ glibtop_close_r (glibtop *server)
|
|||||||
glibtop_call_l (server, GLIBTOP_CMND_QUIT,
|
glibtop_call_l (server, GLIBTOP_CMND_QUIT,
|
||||||
0, NULL, 0, NULL, NULL);
|
0, NULL, 0, NULL, NULL);
|
||||||
|
|
||||||
if (close (server->socket))
|
if (close (server->_priv->socket))
|
||||||
glibtop_warn_io ("close");
|
glibtop_warn_io ("close");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case GLIBTOP_METHOD_PIPE:
|
case GLIBTOP_METHOD_PIPE:
|
||||||
kill (server->pid, SIGKILL);
|
kill (server->_priv->pid, SIGKILL);
|
||||||
close (server->input [0]);
|
close (server->_priv->input [0]);
|
||||||
close (server->output [1]);
|
close (server->_priv->output [1]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
28
lib/open.c
28
lib/open.c
@@ -38,6 +38,10 @@ glibtop_open_l (glibtop *server, const char *program_name,
|
|||||||
{
|
{
|
||||||
int connect_type;
|
int connect_type;
|
||||||
|
|
||||||
|
if (!server->_priv)
|
||||||
|
server->_priv = glibtop_calloc_r
|
||||||
|
(server, 1, sizeof (glibtop_server_private));
|
||||||
|
|
||||||
server->name = program_name;
|
server->name = program_name;
|
||||||
|
|
||||||
/* It is important to set _GLIBTOP_INIT_STATE_OPEN here when we
|
/* It is important to set _GLIBTOP_INIT_STATE_OPEN here when we
|
||||||
@@ -66,7 +70,7 @@ glibtop_open_l (glibtop *server, const char *program_name,
|
|||||||
|
|
||||||
connect_type = glibtop_make_connection
|
connect_type = glibtop_make_connection
|
||||||
(server->server_host, server->server_port,
|
(server->server_host, server->server_port,
|
||||||
&server->socket);
|
&server->_priv->socket);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf (stderr, "Connect Type is %d.\n", connect_type);
|
fprintf (stderr, "Connect Type is %d.\n", connect_type);
|
||||||
@@ -82,7 +86,7 @@ glibtop_open_l (glibtop *server, const char *program_name,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
connect_type = glibtop_make_connection
|
connect_type = glibtop_make_connection
|
||||||
("unix", 0, &server->socket);
|
("unix", 0, &server->_priv->socket);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf (stderr, "Connect Type is %d.\n", connect_type);
|
fprintf (stderr, "Connect Type is %d.\n", connect_type);
|
||||||
@@ -98,26 +102,28 @@ glibtop_open_l (glibtop *server, const char *program_name,
|
|||||||
LIBGTOP_SERVER);
|
LIBGTOP_SERVER);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (pipe (server->input) || pipe (server->output))
|
if (pipe (server->_priv->input) ||
|
||||||
|
pipe (server->_priv->output))
|
||||||
glibtop_error_io_r (server, "cannot make a pipe");
|
glibtop_error_io_r (server, "cannot make a pipe");
|
||||||
|
|
||||||
server->pid = fork ();
|
server->_priv->pid = fork ();
|
||||||
|
|
||||||
if (server->pid < 0) {
|
if (server->_priv->pid < 0) {
|
||||||
glibtop_error_io_r (server, "fork failed");
|
glibtop_error_io_r (server, "fork failed");
|
||||||
} else if (server->pid == 0) {
|
} else if (server->_priv->pid == 0) {
|
||||||
close (0); close (1);
|
close (0); close (1);
|
||||||
close (server->input [0]); close (server->output [1]);
|
close (server->_priv->input [0]);
|
||||||
dup2 (server->input [1], 1);
|
close (server->_priv->output [1]);
|
||||||
dup2 (server->output [0], 0);
|
dup2 (server->_priv->input [1], 1);
|
||||||
|
dup2 (server->_priv->output [0], 0);
|
||||||
execl (LIBGTOP_SERVER, "libgtop-server", NULL);
|
execl (LIBGTOP_SERVER, "libgtop-server", NULL);
|
||||||
glibtop_error_io_r (server, "execl (%s)",
|
glibtop_error_io_r (server, "execl (%s)",
|
||||||
LIBGTOP_SERVER);
|
LIBGTOP_SERVER);
|
||||||
_exit (2);
|
_exit (2);
|
||||||
}
|
}
|
||||||
|
|
||||||
close (server->input [1]);
|
close (server->_priv->input [1]);
|
||||||
close (server->output [0]);
|
close (server->_priv->output [0]);
|
||||||
|
|
||||||
server->flags |= _GLIBTOP_INIT_STATE_SERVER;
|
server->flags |= _GLIBTOP_INIT_STATE_SERVER;
|
||||||
|
|
||||||
|
@@ -65,10 +65,10 @@ glibtop_read_l (glibtop *server, size_t size, void *buf)
|
|||||||
fprintf (stderr, "LIBRARY: really reading %d bytes.\n", size);
|
fprintf (stderr, "LIBRARY: really reading %d bytes.\n", size);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (server->socket) {
|
if (server->_priv->socket) {
|
||||||
do_read (server->socket, buf, size);
|
do_read (server->_priv->socket, buf, size);
|
||||||
} else {
|
} else {
|
||||||
ret = read (server->input [0], buf, size);
|
ret = read (server->_priv->input [0], buf, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
|
@@ -39,10 +39,12 @@ glibtop_read_data_l (glibtop *server)
|
|||||||
fprintf (stderr, "LIBRARY: reading %d data bytes.\n", sizeof (size_t));
|
fprintf (stderr, "LIBRARY: reading %d data bytes.\n", sizeof (size_t));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (server->socket) {
|
if (server->_priv->socket) {
|
||||||
ret = recv (server->socket, (void *)&size, sizeof (size_t), 0);
|
ret = recv (server->_priv->socket, (void *)&size,
|
||||||
|
sizeof (size_t), 0);
|
||||||
} else {
|
} else {
|
||||||
ret = read (server->input [0], (void *)&size, sizeof (size_t));
|
ret = read (server->_priv->input [0], (void *)&size,
|
||||||
|
sizeof (size_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
@@ -56,10 +58,10 @@ glibtop_read_data_l (glibtop *server)
|
|||||||
|
|
||||||
ptr = glibtop_malloc_r (server, size);
|
ptr = glibtop_malloc_r (server, size);
|
||||||
|
|
||||||
if (server->socket) {
|
if (server->_priv->socket) {
|
||||||
ret = recv (server->socket, ptr, size, 0);
|
ret = recv (server->_priv->socket, ptr, size, 0);
|
||||||
} else {
|
} else {
|
||||||
ret = read (server->input [0], ptr, size);
|
ret = read (server->_priv->input [0], ptr, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
|
@@ -38,10 +38,10 @@ glibtop_write_l (glibtop *server, size_t size, void *buf)
|
|||||||
fprintf (stderr, "LIBRARY: really writing %d bytes.\n", size);
|
fprintf (stderr, "LIBRARY: really writing %d bytes.\n", size);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (server->socket) {
|
if (server->_priv->socket) {
|
||||||
ret = send (server->socket, buf, size, 0);
|
ret = send (server->_priv->socket, buf, size, 0);
|
||||||
} else {
|
} else {
|
||||||
ret = write (server->output [1], buf, size);
|
ret = write (server->_priv->output [1], buf, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
|
Reference in New Issue
Block a user