* bus/bus.c, bus/bus.h, bus/main.c, bus/test.c, dbus/dbus-sysdeps-unix.c, dbus/dbus-sysdeps-util-unix.c, dbus/dbus-sysdeps-util-win.c, bus/dbus-sysdeps-win.c,dbus/dbus-sysdeps.h: renamed _dbus_xxx_pipe to _dbus_pipe_xxx, completed _dbus_pipe support.

This commit is contained in:
Ralf Habacker 2007-03-10 09:10:36 +00:00
parent f3fd4d60ad
commit 47e318a6e1
10 changed files with 187 additions and 34 deletions

View file

@ -1,4 +1,12 @@
2007-03-09 Ralf Habacker <ralf.habacker@freenet.de>
2007-03-10 Ralf Habacker <ralf.habacker@freenet.de>
* bus/bus.c, bus/bus.h, bus/main.c, bus/test.c,
dbus/dbus-sysdeps-unix.c, dbus/dbus-sysdeps-util-unix.c,
dbus/dbus-sysdeps-util-win.c, dbus/dbus-sysdeps-win.c,
dbus/dbus-sysdeps.h: renamed _dbus_xxx_pipe to _dbus_pipe_xxx,
completed _dbus_pipe support.
2007-03-10 Ralf Habacker <ralf.habacker@freenet.de>
* dbus/dbus-sysdeps.h (_dbus_listen_tcp_socket):
changed type or port to pointer, because the port is given back.

View file

@ -527,8 +527,8 @@ process_config_postinit (BusContext *context,
BusContext*
bus_context_new (const DBusString *config_file,
ForceForkSetting force_fork,
int print_addr_fd,
int print_pid_fd,
DBusPipe print_addr_fd,
DBusPipe print_pid_fd,
DBusError *error)
{
BusContext *context;
@ -603,7 +603,7 @@ bus_context_new (const DBusString *config_file,
* other random thing. But I think the answer is "don't do
* that then"
*/
if (print_addr_fd >= 0)
if (_dbus_pipe_is_valid(print_addr_fd))
{
DBusString addr;
const char *a = bus_context_get_address (context);
@ -625,7 +625,7 @@ bus_context_new (const DBusString *config_file,
}
bytes = _dbus_string_get_length (&addr);
if (_dbus_write_pipe (print_addr_fd, &addr, 0, bytes) != bytes)
if (_dbus_pipe_write(print_addr_fd, &addr, 0, bytes) != bytes)
{
dbus_set_error (error, DBUS_ERROR_FAILED,
"Printing message bus address: %s\n",
@ -634,8 +634,8 @@ bus_context_new (const DBusString *config_file,
goto failed;
}
if (print_addr_fd > 2)
_dbus_close_socket (print_addr_fd, NULL);
if (_dbus_pipe_is_special(print_addr_fd))
_dbus_pipe_close(print_addr_fd, NULL);
_dbus_string_free (&addr);
}
@ -706,7 +706,7 @@ bus_context_new (const DBusString *config_file,
}
/* Write PID if requested */
if (print_pid_fd >= 0)
if (_dbus_pipe_is_valid(print_pid_fd))
{
DBusString pid;
int bytes;
@ -726,7 +726,7 @@ bus_context_new (const DBusString *config_file,
}
bytes = _dbus_string_get_length (&pid);
if (_dbus_write_pipe (print_pid_fd, &pid, 0, bytes) != bytes)
if (_dbus_pipe_write (print_pid_fd, &pid, 0, bytes) != bytes)
{
dbus_set_error (error, DBUS_ERROR_FAILED,
"Printing message bus PID: %s\n",
@ -735,8 +735,8 @@ bus_context_new (const DBusString *config_file,
goto failed;
}
if (print_pid_fd > 2)
_dbus_close_socket (print_pid_fd, NULL);
if (_dbus_pipe_is_special (print_pid_fd))
_dbus_pipe_close (print_pid_fd, NULL);
_dbus_string_free (&pid);
}

View file

@ -70,8 +70,8 @@ typedef enum
BusContext* bus_context_new (const DBusString *config_file,
ForceForkSetting force_fork,
int print_addr_fd,
int print_pid_fd,
DBusPipe print_addr_fd,
DBusPipe print_pid_fd,
DBusError *error);
dbus_bool_t bus_context_reload_config (BusContext *context,
DBusError *error);

View file

@ -247,8 +247,8 @@ main (int argc, char **argv)
DBusString addr_fd;
DBusString pid_fd;
const char *prev_arg;
int print_addr_fd;
int print_pid_fd;
DBusPipe print_addr_fd;
DBusPipe print_pid_fd;
int i;
dbus_bool_t print_address;
dbus_bool_t print_pid;
@ -387,10 +387,10 @@ main (int argc, char **argv)
usage ();
}
print_addr_fd = -1;
print_addr_fd = _dbus_pipe_init(-1);
if (print_address)
{
print_addr_fd = 1; /* stdout */
print_addr_fd = _dbus_pipe_init(1); /* stdout */
if (_dbus_string_get_length (&addr_fd) > 0)
{
long val;
@ -404,15 +404,15 @@ main (int argc, char **argv)
exit (1);
}
print_addr_fd = val;
print_addr_fd = _dbus_pipe_init(val);
}
}
_dbus_string_free (&addr_fd);
print_pid_fd = -1;
print_pid_fd = _dbus_pipe_init(-1);
if (print_pid)
{
print_pid_fd = 1; /* stdout */
print_pid_fd = _dbus_pipe_init(1); /* stdout */
if (_dbus_string_get_length (&pid_fd) > 0)
{
long val;
@ -426,7 +426,7 @@ main (int argc, char **argv)
exit (1);
}
print_pid_fd = val;
print_pid_fd = _dbus_pipe_init(val);
}
}
_dbus_string_free (&pid_fd);

View file

@ -27,6 +27,7 @@
#include "test.h"
#include <dbus/dbus-internals.h>
#include <dbus/dbus-list.h>
#include <dbus/dbus-sysdeps.h>
/* The "debug client" watch/timeout handlers don't dispatch messages,
* as we manually pull them in order to verify them. This is why they
@ -297,6 +298,7 @@ bus_context_new_test (const DBusString *test_data_dir,
DBusString config_file;
DBusString relative;
BusContext *context;
DBusPipe pipe;
if (!_dbus_string_init (&config_file))
{
@ -322,7 +324,8 @@ bus_context_new_test (const DBusString *test_data_dir,
}
dbus_error_init (&error);
context = bus_context_new (&config_file, FALSE, -1, -1, &error);
pipe = _dbus_pipe_init(-1);
context = bus_context_new (&config_file, FALSE, pipe, pipe, &error);
if (context == NULL)
{
_DBUS_ASSERT_ERROR_IS_SET (&error);

View file

@ -169,15 +169,76 @@ _dbus_write_socket (int fd,
return _dbus_write (fd, buffer, start, len);
}
/**
* init a pipe instance.
*
* @param fd the file descriptor to init from
* @returns a DBusPipe instance
*/
DBusPipe _dbus_pipe_init(int fd)
{
DBusPipe pipe;
pipe.fd = fd;
return pipe;
}
/**
* write data to a pipe.
*
* @param pipe the pipe instance
* @param buffer the buffer to write data from
* @param start the first byte in the buffer to write
* @param len the number of bytes to try to write
* @returns the number of bytes written or -1 on error
*/
int
_dbus_write_pipe (DBusPipe pipe,
_dbus_pipe_write (DBusPipe pipe,
const DBusString *buffer,
int start,
int len)
{
return _dbus_write (pipe, buffer, start, len);
return _dbus_write (pipe.fd, buffer, start, len);
}
/**
* close a pipe.
*
* @param pipe the pipe instance
* @param error return location for an error
* @returns #FALSE if error is set
*/
int
_dbus_pipe_close (DBusPipe pipe,
DBusError *error)
{
return _dbus_close (pipe.fd, error);
}
/**
* check if a pipe is valid, which means is constructed
* by a valid file descriptor
*
* @param pipe the pipe instance
* @returns #FALSE if pipe is not valid
*/
dbus_bool_t _dbus_pipe_is_valid(DBusPipe pipe)
{
return pipe.fd >= 0;
}
/**
* check if a pipe is a special pipe, which means using
* a non default file descriptor (>2)
*
* @param pipe the pipe instance
* @returns #FALSE if pipe is not a special pipe
*/
dbus_bool_t _dbus_pipe_is_special(DBusPipe pipe)
{
return pipe.fd > 2;
}
/**
* Like _dbus_write_two() but only works on sockets and is thus
* available on Windows.

View file

@ -67,7 +67,7 @@
*/
dbus_bool_t
_dbus_become_daemon (const DBusString *pidfile,
int print_pid_fd,
DBusPipe print_pid_fd,
DBusError *error)
{
const char *s;
@ -157,7 +157,7 @@ _dbus_become_daemon (const DBusString *pidfile,
}
bytes = _dbus_string_get_length (&pid);
if (_dbus_write_socket (print_pid_fd, &pid, 0, bytes) != bytes)
if (_dbus_pipe_write (print_pid_fd, &pid, 0, bytes) != bytes)
{
dbus_set_error (error, DBUS_ERROR_FAILED,
"Printing message bus PID: %s\n",

View file

@ -52,7 +52,7 @@
*/
dbus_bool_t
_dbus_become_daemon (const DBusString *pidfile,
int print_pid_fd,
DBusPipe print_pid_fd,
DBusError *error)
{
return TRUE;

View file

@ -266,27 +266,97 @@ dbus_bool_t _dbus_fstat (DBusFile *file,
return fstat(file->FDATA, sb) >= 0;
}
/**
* init a pipe instance.
*
* @param fd the file descriptor to init from
* @returns a DBusPipe instance
*/
DBusPipe _dbus_pipe_init(int fd)
{
DBusPipe pipe;
pipe.fd = fd;
return pipe;
}
/**
* write data to a pipe.
*
* @param pipe the pipe instance
* @param buffer the buffer to write data from
* @param start the first byte in the buffer to write
* @param len the number of bytes to try to write
* @returns the number of bytes written or -1 on error
*/
int
_dbus_write_pipe (DBusPipe pipe,
_dbus_pipe_write (DBusPipe pipe,
const DBusString *buffer,
int start,
int len)
{
DBusFile file;
file.FDATA = pipe;
file.FDATA = pipe.fd;
return _dbus_write_file(&file, buffer, start, len);
}
/**
* read data from a pipe.
*
* @param pipe the pipe instance
* @param buffer the buffer to read data in
* @param count the number of bytes to try to read
* @returns the number of bytes read or -1 on error
*/
int
_dbus_read_pipe(DBusPipe pipe,
_dbus_pipe_read(DBusPipe pipe,
DBusString *buffer,
int count)
{
DBusFile file;
file.FDATA = pipe;
file.FDATA = pipe.fd;
return _dbus_read_file(&file, buffer, count);
}
/**
* close a pipe.
*
* @param pipe the pipe instance
* @param error return location for an error
* @returns #FALSE if error is set
*/
int
_dbus_pipe_close(DBusPipe pipe,
DBusError *error)
{
DBusFile file;
file.FDATA = pipe.fd;
return _dbus_close_file(&file, error);
}
/**
* check if a pipe is valid, which means is constructed
* by a valid file descriptor
*
* @param pipe the pipe instance
* @returns #FALSE if pipe is not valid
*/
dbus_bool_t _dbus_pipe_is_valid(DBusPipe pipe)
{
return pipe.fd >= 0;
}
/**
* check if a pipe is a special pipe, which means using
* a non default file descriptor (>2)
*
* @param pipe the pipe instance
* @returns #FALSE if pipe is not a special pipe
*/
dbus_bool_t _dbus_pipe_is_special(DBusPipe pipe)
{
return pipe.fd > 2;
}
#undef FDATA
/**

View file

@ -302,12 +302,23 @@ dbus_bool_t _dbus_path_is_absolute (const DBusString *filename);
dbus_bool_t _dbus_get_standard_session_servicedirs (DBusList **dirs);
typedef int DBusPipe;
int _dbus_write_pipe (DBusPipe pipe,
typedef struct {
int fd;
} DBusPipe;
DBusPipe _dbus_pipe_init(int fd);
int _dbus_pipe_write (DBusPipe pipe,
const DBusString *buffer,
int start,
int len);
int _dbus_pipe_close (DBusPipe pipe,
DBusError *error);
dbus_bool_t _dbus_pipe_is_valid(DBusPipe pipe);
dbus_bool_t _dbus_pipe_is_special(DBusPipe pipe);
/** Opaque type for reading a directory listing */
typedef struct DBusDirIter DBusDirIter;
@ -374,7 +385,7 @@ dbus_bool_t _dbus_full_duplex_pipe (int *fd1,
void _dbus_print_backtrace (void);
dbus_bool_t _dbus_become_daemon (const DBusString *pidfile,
int print_pid_fd,
DBusPipe print_pid_fd,
DBusError *error);
dbus_bool_t _dbus_write_pid_file (const DBusString *filename,
unsigned long pid,