Removed method', server_command', server_host', server_user' and

2000-02-06  Martin Baulig  <martin@home-of-linux.org>

	* glibtop.h (glibtop): Removed `method', `server_command',
	`server_host', `server_user' and `server_rsh'.
	Added `glibtop_parameter _param' field and moved `error_method'
	there.

	* include/glibtop/parameter.h (glibtop_parameter): New structure.
	(GLIBTOP_PARAM_METHOD, GLIBTOP_PARAM_COMMAND): Removed.
	(GLIBTOP_PARAM_HOST, GLIBTOP_PARAM_PORT): Removed.
	(GLIBTOP_PARAM_REMOTE_USER, GLIBTOP_PARAM_PATH_RSH): Removed.
	(GLIBTOP_PARAM_NCPU, GLIBTOP_PARAM_OS_VERSION_CODE): Added.
This commit is contained in:
Martin Baulig
2000-02-06 14:43:55 +00:00
committed by Martin Baulig
parent 0daf65ef73
commit 55ff827b50
8 changed files with 64 additions and 224 deletions

View File

@@ -1,3 +1,16 @@
2000-02-06 Martin Baulig <martin@home-of-linux.org>
* glibtop.h (glibtop): Removed `method', `server_command',
`server_host', `server_user' and `server_rsh'.
Added `glibtop_parameter _param' field and moved `error_method'
there.
* include/glibtop/parameter.h (glibtop_parameter): New structure.
(GLIBTOP_PARAM_METHOD, GLIBTOP_PARAM_COMMAND): Removed.
(GLIBTOP_PARAM_HOST, GLIBTOP_PARAM_PORT): Removed.
(GLIBTOP_PARAM_REMOTE_USER, GLIBTOP_PARAM_PATH_RSH): Removed.
(GLIBTOP_PARAM_NCPU, GLIBTOP_PARAM_OS_VERSION_CODE): Added.
2000-02-06 Martin Baulig <martin@home-of-linux.org>
* include/glibtop/ppp.h (glibtop_get_ppp): Removed the `lockfile'

View File

@@ -44,6 +44,8 @@ typedef struct _glibtop_server_private glibtop_server_private;
#include <glibtop/sysdeps.h>
#include <glibtop/errors.h>
#include <glibtop/parameter.h>
#ifdef _IN_LIBGTOP
#include <glibtop-server-private.h>
#endif
@@ -52,20 +54,15 @@ struct _glibtop
{
int refcount; /* Reference count */
unsigned flags;
unsigned method; /* Server Method */
unsigned error_method; /* Error Method */
int ncpu; /* Number of CPUs, zero if single-processor */
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 */
const char *server_host; /* Host the server should run on */
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 */
glibtop_sysdeps sysdeps; /* Detailed feature list */
glibtop_sysdeps required; /* Required feature list */
glibtop_sysdeps wanted; /* We only want this features */
glibtop_parameter _param; /* Server parameter */
glibtop_server_private *_priv; /* Private data */
unsigned glibtop_errno;
};

View File

@@ -29,15 +29,22 @@
BEGIN_LIBGTOP_DECLS
#define GLIBTOP_PARAM_METHOD 1
#define GLIBTOP_PARAM_ERROR_METHOD 1
#define GLIBTOP_PARAM_FEATURES 2
#define GLIBTOP_PARAM_COMMAND 3
#define GLIBTOP_PARAM_HOST 4
#define GLIBTOP_PARAM_PORT 5
#define GLIBTOP_PARAM_ERROR_METHOD 6
#define GLIBTOP_PARAM_REQUIRED 7
#define GLIBTOP_PARAM_REMOTE_USER 8
#define GLIBTOP_PARAM_PATH_RSH 9
#define GLIBTOP_PARAM_NCPU 3
#define GLIBTOP_PARAM_OS_VERSION_CODE 4
#define GLIBTOP_PARAM_REQUIRED 5
typedef struct _glibtop_parameter glibtop_parameter;
struct _glibtop_parameter
{
unsigned error_method; /* Error Method */
u_int64_t features; /* Server is required for this features */
unsigned ncpu; /* Number of CPUs, zero if single-processor */
u_int64_t os_version_code; /* Version code of the operating system */
glibtop_sysdeps required; /* Required feature list */
};
#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)

View File

@@ -35,127 +35,6 @@
static glibtop _glibtop_global_server;
glibtop *glibtop_global_server = &_glibtop_global_server;
static void
_init_server (glibtop *server, const unsigned features)
{
char *command, *temp;
/* 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") : LIBGTOP_SERVER;
server->server_command = glibtop_strdup_r (server, temp);
}
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);
}
void
glibtop_server_ref (glibtop *server)
{
@@ -208,25 +87,12 @@ glibtop_init_r (glibtop **server_ptr, unsigned long features, unsigned flags)
features = GLIBTOP_SYSDEPS_ALL;
if (flags & GLIBTOP_FEATURES_NO_SERVER) {
server->method = GLIBTOP_METHOD_DIRECT;
features = 0;
}
server->features = features;
_init_server (server, features);
server->flags |= _GLIBTOP_INIT_STATE_INIT;
switch (server->method) {
case GLIBTOP_METHOD_PIPE:
case GLIBTOP_METHOD_UNIX:
if (glibtop_server_features & features)
break;
server->method = GLIBTOP_METHOD_DIRECT;
break;
}
}
/* Should we open the server? */

View File

@@ -45,7 +45,7 @@ print "\tu_int64_t old_required = *required;\n";
print "\t/* Return if we have all required fields. */";
print "\tif ((~present & old_required) == 0)";
print "\t\treturn;\n";
print "\tswitch (server->error_method) {";
print "\tswitch (server->_param.error_method) {";
print "\tcase GLIBTOP_ERROR_METHOD_WARN_ONCE:";
print "\t\t*required &= present;";
print "\tcase GLIBTOP_ERROR_METHOD_WARN:";

View File

@@ -36,6 +36,9 @@ glibtop_open_l (glibtop *server, const char *program_name,
_glibtop_open_sysdeps (server, "glibtop", features, flags);
server->_param.ncpu = server->ncpu;
server->_param.os_version_code = server->os_version_code;
server->flags |= _GLIBTOP_INIT_STATE_SYSDEPS;
}
}

View File

@@ -49,33 +49,21 @@ 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));
case GLIBTOP_PARAM_REMOTE_USER:
_write_data (server->server_user,
_strlen(server->server_user));
case GLIBTOP_PARAM_PATH_RSH:
_write_data (server->server_rsh,
_strlen(server->server_rsh));
case GLIBTOP_PARAM_ERROR_METHOD:
_write_data (&server->error_method,
sizeof (server->error_method));
_write_data (&server->_param.error_method,
sizeof (server->_param.error_method));
case GLIBTOP_PARAM_FEATURES:
_write_data (&server->_param.features,
sizeof (server->_param.features));
case GLIBTOP_PARAM_NCPU:
_write_data (&server->_param.ncpu,
sizeof (server->_param.ncpu));
case GLIBTOP_PARAM_OS_VERSION_CODE:
_write_data (&server->_param.os_version_code,
sizeof (server->_param.os_version_code));
case GLIBTOP_PARAM_REQUIRED:
_write_data (&server->required,
sizeof (server->required));
_write_data (&server->_param.required,
sizeof (server->_param.required));
}
return -GLIBTOP_ERROR_NO_SUCH_PARAMETER;
@@ -85,24 +73,16 @@ int
glibtop_get_parameter_size_l (glibtop *server, const unsigned parameter)
{
switch (parameter) {
case GLIBTOP_PARAM_METHOD:
return sizeof (server->method);
case GLIBTOP_PARAM_FEATURES:
return sizeof (server->features);
case GLIBTOP_PARAM_COMMAND:
return _strlen(server->server_command);
case GLIBTOP_PARAM_HOST:
return _strlen(server->server_host);
case GLIBTOP_PARAM_PORT:
return sizeof (server->server_port);
case GLIBTOP_PARAM_REMOTE_USER:
return _strlen(server->server_user);
case GLIBTOP_PARAM_PATH_RSH:
return _strlen(server->server_rsh);
case GLIBTOP_PARAM_ERROR_METHOD:
return sizeof (server->error_method);
return sizeof (server->_param.error_method);
case GLIBTOP_PARAM_FEATURES:
return sizeof (server->_param.features);
case GLIBTOP_PARAM_NCPU:
return sizeof (server->_param.ncpu);
case GLIBTOP_PARAM_OS_VERSION_CODE:
return sizeof (server->_param.os_version_code);
case GLIBTOP_PARAM_REQUIRED:
return sizeof (server->required);
return sizeof (server->_param.required);
}
return -GLIBTOP_ERROR_NO_SUCH_PARAMETER;
@@ -113,44 +93,18 @@ 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);
case GLIBTOP_PARAM_ERROR_METHOD:
_check_data (sizeof (server->_param.error_method));
memcpy (&server->_param.error_method, data_ptr, data_size);
break;
case GLIBTOP_PARAM_FEATURES:
case GLIBTOP_PARAM_NCPU:
case GLIBTOP_PARAM_OS_VERSION_CODE:
return -GLIBTOP_ERROR_READONLY_VALUE;
break;
case GLIBTOP_PARAM_COMMAND:
if (server->server_command)
glibtop_free_r (server, server->server_command);
server->server_command = glibtop_strdup_r (server, data_ptr);
break;
case GLIBTOP_PARAM_HOST:
if (server->server_host)
glibtop_free_r (server, server->server_host);
server->server_host = glibtop_strdup_r (server, data_ptr);
break;
case GLIBTOP_PARAM_PORT:
_check_data (sizeof (server->server_port));
memcpy (&server->server_port, data_ptr, data_size);
break;
case GLIBTOP_PARAM_REMOTE_USER:
if (server->server_user)
glibtop_free_r (server, server->server_user);
server->server_user = glibtop_strdup_r (server, data_ptr);
break;
case GLIBTOP_PARAM_PATH_RSH:
if (server->server_rsh)
glibtop_free_r (server, server->server_rsh);
server->server_rsh = glibtop_strdup_r (server, data_ptr);
break;
case GLIBTOP_PARAM_ERROR_METHOD:
_check_data (sizeof (server->error_method));
memcpy (&server->error_method, data_ptr, data_size);
break;
case GLIBTOP_PARAM_REQUIRED:
_check_data (sizeof (server->required));
memcpy (&server->required, data_ptr, data_size);
_check_data (sizeof (server->_param.required));
memcpy (&server->_param.required, data_ptr, data_size);
break;
default:
return -GLIBTOP_ERROR_NO_SUCH_PARAMETER;

View File

@@ -117,7 +117,7 @@ glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid)
/* the old notty val, update elsewhere bef. moving to 0 */
buf->tty = -1;
if (server->os_version_code < LINUX_VERSION(1,3,39)) {
if (server->_param.os_version_code < LINUX_VERSION(1,3,39)) {
/* map old meanings to new */
buf->priority = 2*15 - buf->priority;
buf->nice = 15 - buf->nice;