From: Ralf Habacker Date: Fri, 18 Dec 2009 12:32:37 +0000 (+0100) Subject: moved out DBusPipe implementation into separate files X-Git-Tag: dbus-1.3.1~129 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=35eb740bda2cc330f1e0a9eb3275f28fcdd7eb60;p=platform%2Fupstream%2Fdbus.git moved out DBusPipe implementation into separate files --- diff --git a/cmake/dbus/CMakeLists.txt b/cmake/dbus/CMakeLists.txt index ff0d493..ed2fb1f 100644 --- a/cmake/dbus/CMakeLists.txt +++ b/cmake/dbus/CMakeLists.txt @@ -133,6 +133,7 @@ set (DBUS_SHARED_SOURCES ${DBUS_DIR}/dbus-mempool.c ${DBUS_DIR}/dbus-string.c ${DBUS_DIR}/dbus-sysdeps.c + ${DBUS_DIR}/dbus-pipe.c ) set (DBUS_SHARED_HEADERS @@ -144,6 +145,7 @@ set (DBUS_SHARED_HEADERS ${DBUS_DIR}/dbus-mempool.h ${DBUS_DIR}/dbus-string.h ${DBUS_DIR}/dbus-string-private.h + ${DBUS_DIR}/dbus-pipe.h ${DBUS_DIR}/dbus-sysdeps.h ) @@ -185,6 +187,7 @@ set (DBUS_UTIL_HEADERS if (WIN32) set (DBUS_SHARED_SOURCES ${DBUS_SHARED_SOURCES} ${DBUS_DIR}/dbus-sysdeps-win.c + ${DBUS_DIR}/dbus-pipe-win.c ${DBUS_DIR}/dbus-sysdeps-thread-win.c ${DBUS_DIR}/dbus-spawn-win.c ) @@ -198,6 +201,7 @@ if (WIN32) set (LIBS ${LIBS} ws2_32 advapi32 netapi32) else (WIN32) set (DBUS_SHARED_SOURCES ${DBUS_SHARED_SOURCES} + ${DBUS_DIR}/dbus-pipe-unix.c ${DBUS_DIR}/dbus-sysdeps-unix.c ${DBUS_DIR}/dbus-sysdeps-pthread.c ${DBUS_DIR}/dbus-spawn.c diff --git a/dbus/Makefile.am b/dbus/Makefile.am index db90b87..cabe2b0 100644 --- a/dbus/Makefile.am +++ b/dbus/Makefile.am @@ -59,6 +59,7 @@ DBUS_LIB_arch_sources = \ dbus-server-win.h DBUS_SHARED_arch_sources = \ + dbus-pipe-win.c \ dbus-sysdeps-win.c \ dbus-sysdeps-win.h \ dbus-sysdeps-thread-win.c \ @@ -76,6 +77,7 @@ DBUS_LIB_arch_sources = \ dbus-server-unix.h DBUS_SHARED_arch_sources = \ + dbus-pipe-unix.c \ dbus-sysdeps-unix.c \ dbus-sysdeps-unix.h \ dbus-sysdeps-pthread.c \ @@ -191,6 +193,8 @@ DBUS_SHARED_SOURCES= \ dbus-memory.c \ dbus-mempool.c \ dbus-mempool.h \ + dbus-pipe.c \ + dbus-pipe.h \ dbus-string.c \ dbus-string.h \ dbus-string-private.h \ diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index eb6f963..0d3e999 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -458,57 +458,6 @@ _dbus_write_socket_with_unix_fds_two(int fd, } /** - * 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 - * @param error error return - * @returns the number of bytes written or -1 on error - */ -int -_dbus_pipe_write (DBusPipe *pipe, - const DBusString *buffer, - int start, - int len, - DBusError *error) -{ - int written; - - written = _dbus_write (pipe->fd_or_handle, buffer, start, len); - if (written < 0) - { - dbus_set_error (error, DBUS_ERROR_FAILED, - "Writing to pipe: %s\n", - _dbus_strerror (errno)); - } - return written; -} - -/** - * 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) -{ - if (_dbus_close (pipe->fd_or_handle, error) < 0) - { - return -1; - } - else - { - _dbus_pipe_invalidate (pipe); - return 0; - } -} - -/** * Like _dbus_write_two() but only works on sockets and is thus * available on Windows. * diff --git a/dbus/dbus-sysdeps-win.c b/dbus/dbus-sysdeps-win.c index 376b5f5..2a8100a 100644 --- a/dbus/dbus-sysdeps-win.c +++ b/dbus/dbus-sysdeps-win.c @@ -109,62 +109,6 @@ _dbus_win_free_error_string (char *string) } /** - * 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 - * @param error error return - * @returns the number of bytes written or -1 on error - */ -int -_dbus_pipe_write (DBusPipe *pipe, - const DBusString *buffer, - int start, - int len, - DBusError *error) -{ - int written; - const char *buffer_c = _dbus_string_get_const_data (buffer); - - written = _write (pipe->fd_or_handle, buffer_c + start, len); - if (written < 0) - { - dbus_set_error (error, DBUS_ERROR_FAILED, - "Writing to pipe: %s\n", - strerror (errno)); - } - return written; -} - -/** - * 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) -{ - _DBUS_ASSERT_ERROR_IS_CLEAR (error); - - if (_close (pipe->fd_or_handle) < 0) - { - dbus_set_error (error, _dbus_error_from_errno (errno), - "Could not close pipe %d: %s", pipe->fd_or_handle, strerror (errno)); - return -1; - } - else - { - _dbus_pipe_invalidate (pipe); - return 0; - } -} - -/** * Socket interface * */ diff --git a/dbus/dbus-sysdeps.c b/dbus/dbus-sysdeps.c index 74be7db..1f4c3a2 100644 --- a/dbus/dbus-sysdeps.c +++ b/dbus/dbus-sysdeps.c @@ -242,65 +242,6 @@ _dbus_get_environment (void) return environment; } -/* - * init a pipe instance. - * - * @param pipe the pipe - * @param fd the file descriptor to init from - */ -void -_dbus_pipe_init (DBusPipe *pipe, - int fd) -{ - pipe->fd_or_handle = fd; -} - -/** - * init a pipe with stdout - * - * @param pipe the pipe - */ -void -_dbus_pipe_init_stdout (DBusPipe *pipe) -{ - _dbus_pipe_init (pipe, 1); -} - -/** - * check if a pipe is valid; pipes can be set invalid, similar to - * a -1 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_or_handle >= 0; -} - -/** - * Check if a pipe is stdout or stderr. - * - * @param pipe the pipe instance - * @returns #TRUE if pipe is one of the standard out/err channels - */ -dbus_bool_t -_dbus_pipe_is_stdout_or_stderr (DBusPipe *pipe) -{ - return pipe->fd_or_handle == 1 || pipe->fd_or_handle == 2; -} - -/** - * Initializes a pipe to an invalid value. - * @param pipe the pipe - */ -void -_dbus_pipe_invalidate (DBusPipe *pipe) -{ - pipe->fd_or_handle = -1; -} - /** * Split paths into a list of char strings * diff --git a/dbus/dbus-sysdeps.h b/dbus/dbus-sysdeps.h index 7e52b51..9ed6bae 100644 --- a/dbus/dbus-sysdeps.h +++ b/dbus/dbus-sysdeps.h @@ -27,7 +27,42 @@ #include +/** + * @addtogroup DBusSysdeps + * + * @{ + */ + +/* The idea of this file is to encapsulate everywhere that we're + * relying on external libc features, for ease of security + * auditing. The idea is from vsftpd. This also gives us a chance to + * make things more convenient to use, e.g. by reading into a + * DBusString. Operating system headers aren't intended to be used + * outside of this file and a limited number of others (such as + * dbus-memory.c) + */ + +#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4) +#define _DBUS_GNUC_PRINTF( format_idx, arg_idx ) \ + __attribute__((__format__ (__printf__, format_idx, arg_idx))) +#define _DBUS_GNUC_NORETURN \ + __attribute__((__noreturn__)) +#else /* !__GNUC__ */ +#define _DBUS_GNUC_PRINTF( format_idx, arg_idx ) +#define _DBUS_GNUC_NORETURN +#endif /* !__GNUC__ */ + +/** @def _DBUS_GNUC_PRINTF + * used to tell gcc about printf format strings + */ +/** @def _DBUS_GNUC_NORETURN + * used to tell gcc about functions that never return, such as _dbus_abort() + */ + +/** @} */ + #include +#include /* this is perhaps bogus, but strcmp() etc. are faster if we use the * stuff straight out of string.h, so have this here for now. @@ -69,32 +104,6 @@ typedef struct DBusCredentials DBusCredentials; * @{ */ -/* The idea of this file is to encapsulate everywhere that we're - * relying on external libc features, for ease of security - * auditing. The idea is from vsftpd. This also gives us a chance to - * make things more convenient to use, e.g. by reading into a - * DBusString. Operating system headers aren't intended to be used - * outside of this file and a limited number of others (such as - * dbus-memory.c) - */ - -#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4) -#define _DBUS_GNUC_PRINTF( format_idx, arg_idx ) \ - __attribute__((__format__ (__printf__, format_idx, arg_idx))) -#define _DBUS_GNUC_NORETURN \ - __attribute__((__noreturn__)) -#else /* !__GNUC__ */ -#define _DBUS_GNUC_PRINTF( format_idx, arg_idx ) -#define _DBUS_GNUC_NORETURN -#endif /* !__GNUC__ */ - -/** @def _DBUS_GNUC_PRINTF - * used to tell gcc about printf format strings - */ -/** @def _DBUS_GNUC_NORETURN - * used to tell gcc about functions that never return, such as _dbus_abort() - */ - void _dbus_abort (void) _DBUS_GNUC_NORETURN; const char* _dbus_getenv (const char *varname); @@ -355,25 +364,6 @@ dbus_bool_t _dbus_get_standard_system_servicedirs (DBusList **dirs); dbus_bool_t _dbus_append_system_config_file (DBusString *str); dbus_bool_t _dbus_append_session_config_file (DBusString *str); -typedef struct { - int fd_or_handle; -} DBusPipe; - -void _dbus_pipe_init (DBusPipe *pipe, - int fd); -void _dbus_pipe_init_stdout (DBusPipe *pipe); -int _dbus_pipe_write (DBusPipe *pipe, - const DBusString *buffer, - int start, - int len, - DBusError *error); -int _dbus_pipe_close (DBusPipe *pipe, - DBusError *error); -dbus_bool_t _dbus_pipe_is_valid (DBusPipe *pipe); -void _dbus_pipe_invalidate (DBusPipe *pipe); -dbus_bool_t _dbus_pipe_is_stdout_or_stderr (DBusPipe *pipe); - - /** Opaque type for reading a directory listing */ typedef struct DBusDirIter DBusDirIter;