X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=tools%2Fdbus-launch.c;h=bbaac2c3a8907db15db3fb093cb29182879bbc9a;hb=e48de6be84f89636f11159b9e7ea56b6dc49d577;hp=6a10ffa3701124f8123e857106385aac9060902c;hpb=46b48ac65414181b60085534475006de42b018cd;p=platform%2Fupstream%2Fdbus.git diff --git a/tools/dbus-launch.c b/tools/dbus-launch.c index 6a10ffa..bbaac2c 100644 --- a/tools/dbus-launch.c +++ b/tools/dbus-launch.c @@ -18,9 +18,11 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ + +#include #include "dbus-launch.h" #include #include @@ -335,7 +337,7 @@ do_waitpid (pid_t pid) static pid_t bus_pid_to_kill = -1; static void -kill_bus() +kill_bus(void) { verbose ("Killing message bus and exiting babysitter\n"); kill (bus_pid_to_kill, SIGTERM); @@ -363,9 +365,9 @@ print_variables (const char *bus_address, pid_t bus_pid, long bus_wid, { if (binary_syntax) { - write (1, bus_address, strlen (bus_address) + 1); - write (1, &bus_pid, sizeof bus_pid); - write (1, &bus_wid, sizeof bus_wid); + do_write (1, bus_address, strlen (bus_address) + 1); + do_write (1, &bus_pid, sizeof bus_pid); + do_write (1, &bus_wid, sizeof bus_wid); return; } else if (c_shell_syntax) @@ -402,7 +404,10 @@ signal_handler (int sig) { switch (sig) { +#ifdef SIGHUP case SIGHUP: +#endif + case SIGINT: case SIGTERM: got_sighup = TRUE; break; @@ -427,6 +432,7 @@ kill_bus_when_session_ends (void) act.sa_flags = 0; sigaction (SIGHUP, &act, NULL); sigaction (SIGTERM, &act, NULL); + sigaction (SIGINT, &act, NULL); #ifdef DBUS_BUILD_X11 x11_init(); @@ -458,6 +464,17 @@ kill_bus_when_session_ends (void) while (TRUE) { +#ifdef DBUS_BUILD_X11 + /* Dump events on the floor, and let + * IO error handler run if we lose + * the X connection. It's important to + * run this before going into select() since + * we might have queued outgoing messages or + * events. + */ + x11_handle_event (); +#endif + FD_ZERO (&read_set); FD_ZERO (&err_set); @@ -472,7 +489,7 @@ kill_bus_when_session_ends (void) FD_SET (x_fd, &read_set); FD_SET (x_fd, &err_set); } - + select (MAX (tty_fd, x_fd) + 1, &read_set, NULL, &err_set, NULL); @@ -483,15 +500,12 @@ kill_bus_when_session_ends (void) } #ifdef DBUS_BUILD_X11 - /* Dump events on the floor, and let - * IO error handler run if we lose - * the X connection + /* Events will be processed before we select again */ if (x_fd >= 0) verbose ("X fd condition reading = %d error = %d\n", FD_ISSET (x_fd, &read_set), FD_ISSET (x_fd, &err_set)); - x11_handle_event (); #endif if (tty_fd >= 0) @@ -676,10 +690,11 @@ pass_info (const char *runprog, const char *bus_address, pid_t bus_pid, int binary_syntax, int argc, char **argv, int remaining_args) { + char *envvar = NULL; + char **args = NULL; + if (runprog) { - char *envvar; - char **args; int i; envvar = malloc (strlen ("DBUS_SESSION_BUS_ADDRESS=") + @@ -723,6 +738,12 @@ pass_info (const char *runprog, const char *bus_address, pid_t bus_pid, close (2); exit (0); oom: + if (envvar) + free (envvar); + + if (args) + free (args); + fprintf (stderr, "Out of memory!"); exit (1); } @@ -896,7 +917,11 @@ main (int argc, char **argv) fprintf (stderr, "Autolaunch requested, but X11 support not compiled in.\n" "Cannot continue.\n"); exit (1); -#else +#else /* DBUS_BUILD_X11 */ +#ifndef DBUS_ENABLE_X11_AUTOLAUNCH + fprintf (stderr, "X11 autolaunch support disabled at compile time.\n"); + exit (1); +#else /* DBUS_ENABLE_X11_AUTOLAUNCH */ char *address; pid_t pid; long wid; @@ -933,11 +958,12 @@ main (int argc, char **argv) bourne_shell_syntax, binary_syntax, argc, argv, remaining_args); exit (0); } +#endif /* DBUS_ENABLE_X11_AUTOLAUNCH */ } - else if (read_machine_uuid_if_needed()) + else if (read_machine_uuid_if_needed()) { x11_init(); -#endif +#endif /* DBUS_BUILD_X11 */ } @@ -1156,7 +1182,7 @@ main (int argc, char **argv) close (bus_pid_to_launcher_pipe[READ_END]); -#ifdef DBUS_BUILD_X11 +#ifdef DBUS_ENABLE_X11_AUTOLAUNCH if (xdisplay != NULL) { verbose("Saving x11 address\n");