--- dbus-send.c.old 2008-04-08 16:09:17.000000000 -0500 +++ dbus-send.c 2008-04-09 06:19:51.000000000 -0500 @@ -33,7 +33,7 @@ static void usage (int ecode) { - fprintf (stderr, "Usage: %s [--help] [--system | --session] [--dest=NAME] [--type=TYPE] [--print-reply=(literal)] [--reply-timeout=MSEC] [contents ...]\n", appname); + fprintf (stderr, "Usage: %s [--help] [--system | --session | --private=PEERBUS] [--dest=NAME] [--type=TYPE] [--print-reply[=LITERALLY]] [--reply-timeout=MSEC] [contents ...]\n", appname); exit (ecode); } @@ -222,11 +222,15 @@ const char *path = NULL; int message_type = DBUS_MESSAGE_TYPE_SIGNAL; const char *type_str = NULL; + const char *peerbus = NULL; appname = argv[0]; if (argc < 3) - usage (1); + { + fprintf (stderr, "Too few arguments\n"); + usage (1); + } print_reply = FALSE; print_reply_literal = FALSE; @@ -240,6 +244,8 @@ type = DBUS_BUS_SYSTEM; else if (strcmp (arg, "--session") == 0) type = DBUS_BUS_SESSION; + else if (strstr (arg, "--private=") == arg) + peerbus = strchr (arg, '=') + 1; else if (strncmp (arg, "--print-reply", 13) == 0) { print_reply = TRUE; @@ -259,17 +265,33 @@ else if (!strcmp(arg, "--help")) usage (0); else if (arg[0] == '-') - usage (1); - else if (path == NULL) + { + fprintf (stderr, "Unknown option \"%s\"\n", + arg); + usage (1); + } + else if (path == NULL) path = arg; else if (name == NULL) name = arg; else - usage (1); - } + { + fprintf (stderr, "Unknown argument \"%s\"\n", + arg); + usage (1); + } + } + if (path == NULL) + { + fprintf (stderr, "Missing destination object path\n"); + usage (1); + } if (name == NULL) - usage (1); + { + fprintf (stderr, "Missing message name\n"); + usage (1); + } if (type_str != NULL) { @@ -281,15 +303,30 @@ type_str); exit (1); } + + if (print_reply && (message_type != DBUS_MESSAGE_TYPE_METHOD_CALL)) + { + fprintf (stderr, "\"--print-reply\" implies \"--type=method_call\"\n"); + exit (1); + } } dbus_error_init (&error); - connection = dbus_bus_get (type, &error); - if (connection == NULL) - { + + if (peerbus != NULL) + { + connection = dbus_connection_open (peerbus, &error); + } + else { + connection = dbus_bus_get (type, &error); + } + + if (connection == NULL) + { fprintf (stderr, "Failed to open connection to %s message bus: %s\n", - (type == DBUS_BUS_SYSTEM) ? "system" : "session", - error.message); + ((peerbus != NULL) ? "private" : + ((type == DBUS_BUS_SYSTEM) ? "system" : "session")), + error.message); dbus_error_free (&error); exit (1); } @@ -485,3 +522,4 @@ exit (0); } + --- dbus-send.1.old 2008-04-08 16:09:17.000000000 -0500 +++ dbus-send.1 2008-04-09 06:20:30.000000000 -0500 @@ -8,8 +8,8 @@ .SH SYNOPSIS .PP .B dbus-send -[\-\-system | \-\-session] [\-\-dest=NAME] [\-\-print-reply] -[\-\-type=TYPE] [contents ...] +[\-\-system\ |\ \-\-session\ |\ \-\-private=PEERBUS] [\-\-dest=NAME] [\-\-print\-reply[=LITERALLY]] +[\-\-type=TYPE] [\-\-reply\-timeout=MSEC] [contents ...] .SH DESCRIPTION @@ -22,8 +22,9 @@ (installed on many systems as the "messagebus" service) and the per-user-login-session message bus (started each time a user logs in). The \-\-system and \-\-session options direct \fIdbus-send\fP to send -messages to the system or session buses respectively. If neither is -specified, \fIdbus-send\fP sends to the session bus. +messages to the system or session buses respectively. It is also possible +to use a private peer\-to\-peer message bus, using the \-\-private option. +If none of these are specified, \fIdbus-send\fP sends to the session bus. .PP Nearly all uses of \fIdbus-send\fP must provide the \-\-dest argument @@ -75,17 +76,27 @@ .I "--dest=NAME" Specify the name of the connection to receive the message. .TP -.I "--print-reply" +.I "--print-reply[=LITERALLY]" Block for a reply to the message sent, and print any reply received. +When specified, --type=method_call is set, and if the optional +LITERALLY value is specified, the resulting method reply will not +be formatted with type information and new lines. LITERALLY may be +any non-blank value. .TP -.I "--system" -Send to the system message bus. +.I "--private=PEERBUS" +Send to the private peer\-to\-peer message bus, specified by PEERBUS. .TP .I "--session" Send to the session message bus. (This is the default.) .TP +.I "--system" +Send to the system message bus. +.TP +.I "--reply-timeout=MSEC" +Specifies the number of milliseconds before the request will timeout (default is to wait forever). +.TP .I "--type=TYPE" -Specify "method_call" or "signal" (defaults to "signal"). +Specify "method_call" or "signal" (defaults to "signal" unless --print-reply is specified). .SH AUTHOR dbus-send was written by Philip Blundell.