summaryrefslogtreecommitdiffstats
path: root/bus/bus.c
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2007-03-12 22:52:40 +0000
committerHavoc Pennington <hp@redhat.com>2007-03-12 22:52:40 +0000
commit9362aac398e3f2ec680e30c61ebfcb1e407eff72 (patch)
treefaeb94c89d680598d1a809f6a3d952910dd3c741 /bus/bus.c
parentcc0aea750cb03ffa6a9e94e493455920ab3e612b (diff)
2007-03-11 Havoc Pennington <hp@redhat.com>
* tools/dbus-launch.c (do_close_stderr): fix C89 problem and formatting problem * Mostly fix the DBusPipe mess. - put line break after function return types - put space before parens - do not pass structs around by value - don't use dbus_strerror after calling supposedly cross-platform api - don't name pipe variables "fd" - abstract special fd numbers like -1 and 1
Diffstat (limited to 'bus/bus.c')
-rw-r--r--bus/bus.c42
1 files changed, 24 insertions, 18 deletions
diff --git a/bus/bus.c b/bus/bus.c
index b54ea2d8..fb9322a9 100644
--- a/bus/bus.c
+++ b/bus/bus.c
@@ -527,8 +527,8 @@ process_config_postinit (BusContext *context,
BusContext*
bus_context_new (const DBusString *config_file,
ForceForkSetting force_fork,
- DBusPipe print_addr_fd,
- DBusPipe print_pid_fd,
+ DBusPipe *print_addr_pipe,
+ DBusPipe *print_pid_pipe,
DBusError *error)
{
BusContext *context;
@@ -598,12 +598,12 @@ bus_context_new (const DBusString *config_file,
if (!dbus_server_allocate_data_slot (&server_data_slot))
_dbus_assert_not_reached ("second ref of server data slot failed");
- /* Note that we don't know whether the print_addr_fd is
+ /* Note that we don't know whether the print_addr_pipe is
* one of the sockets we're using to listen on, or some
* other random thing. But I think the answer is "don't do
* that then"
*/
- if (_dbus_pipe_is_valid(print_addr_fd))
+ if (print_addr_pipe != NULL && _dbus_pipe_is_valid (print_addr_pipe))
{
DBusString addr;
const char *a = bus_context_get_address (context);
@@ -625,17 +625,20 @@ bus_context_new (const DBusString *config_file,
}
bytes = _dbus_string_get_length (&addr);
- if (_dbus_pipe_write(print_addr_fd, &addr, 0, bytes) != bytes)
+ if (_dbus_pipe_write (print_addr_pipe, &addr, 0, bytes, error) != bytes)
{
- dbus_set_error (error, DBUS_ERROR_FAILED,
- "Printing message bus address: %s\n",
- _dbus_strerror (errno));
+ /* pipe write returns an error on failure but not short write */
+ if (error != NULL && !dbus_error_is_set (error))
+ {
+ dbus_set_error (error, DBUS_ERROR_FAILED,
+ "Printing message bus address: did not write all bytes\n");
+ }
_dbus_string_free (&addr);
goto failed;
}
- if (_dbus_pipe_is_special(print_addr_fd))
- _dbus_pipe_close(print_addr_fd, NULL);
+ if (!_dbus_pipe_is_stdout_or_stderr (print_addr_pipe))
+ _dbus_pipe_close (print_addr_pipe, NULL);
_dbus_string_free (&addr);
}
@@ -681,7 +684,7 @@ bus_context_new (const DBusString *config_file,
_dbus_string_init_const (&u, context->pidfile);
if (!_dbus_become_daemon (context->pidfile ? &u : NULL,
- print_pid_fd,
+ print_pid_pipe,
error))
{
_DBUS_ASSERT_ERROR_IS_SET (error);
@@ -706,7 +709,7 @@ bus_context_new (const DBusString *config_file,
}
/* Write PID if requested */
- if (_dbus_pipe_is_valid(print_pid_fd))
+ if (print_pid_pipe != NULL && _dbus_pipe_is_valid (print_pid_pipe))
{
DBusString pid;
int bytes;
@@ -726,17 +729,20 @@ bus_context_new (const DBusString *config_file,
}
bytes = _dbus_string_get_length (&pid);
- if (_dbus_pipe_write (print_pid_fd, &pid, 0, bytes) != bytes)
+ if (_dbus_pipe_write (print_pid_pipe, &pid, 0, bytes, error) != bytes)
{
- dbus_set_error (error, DBUS_ERROR_FAILED,
- "Printing message bus PID: %s\n",
- _dbus_strerror (errno));
+ /* pipe_write sets error on failure but not short write */
+ if (error != NULL && !dbus_error_is_set (error))
+ {
+ dbus_set_error (error, DBUS_ERROR_FAILED,
+ "Printing message bus PID: did not write enough bytes\n");
+ }
_dbus_string_free (&pid);
goto failed;
}
- if (_dbus_pipe_is_special (print_pid_fd))
- _dbus_pipe_close (print_pid_fd, NULL);
+ if (!_dbus_pipe_is_stdout_or_stderr (print_pid_pipe))
+ _dbus_pipe_close (print_pid_pipe, NULL);
_dbus_string_free (&pid);
}