| 1429 | /* |
| 1430 | * MacPorts specific D-Bus implementation |
| 1431 | * |
| 1432 | * When building under MacPorts on darwin |
| 1433 | * plaforms (including Mac OS X), the |
| 1434 | * symbols G_OS_UNIX and __APPLE__ are |
| 1435 | * asserted. |
| 1436 | * |
| 1437 | * The D-Bus session daemon is controlled |
| 1438 | * using the Apple launchd facility. |
| 1439 | * |
| 1440 | * For launchd command details see |
| 1441 | * http://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages |
| 1442 | * |
| 1443 | * launchd(8) |
| 1444 | * launchctl(1) |
| 1445 | * launchd.plist(5) |
| 1446 | */ |
| 1447 | |
| 1448 | #if defined (G_OS_UNIX) && defined (__APPLE__) |
| 1449 | static gchar * |
| 1450 | get_session_address_macports_specific (GError **error) |
| 1451 | { |
| 1452 | gchar *ret; |
| 1453 | gchar *command_line; |
| 1454 | gchar *launchctl_stdout; |
| 1455 | gchar *launchctl_stderr; |
| 1456 | gint exit_status; |
| 1457 | |
| 1458 | ret = NULL; |
| 1459 | command_line = NULL; |
| 1460 | launchctl_stdout = NULL; |
| 1461 | launchctl_stderr = NULL; |
| 1462 | |
| 1463 | command_line = g_strdup ("launchctl getenv DBUS_LAUNCHD_SESSION_BUS_SOCKET"); |
| 1464 | |
| 1465 | if (G_UNLIKELY (_g_dbus_debug_address ())) |
| 1466 | { |
| 1467 | _g_dbus_debug_print_lock (); |
| 1468 | g_print ("GDBus-debug:Address: launchctl command line: `%s'\n", command_line); |
| 1469 | _g_dbus_debug_print_unlock (); |
| 1470 | } |
| 1471 | |
| 1472 | if (g_spawn_command_line_sync (command_line, |
| 1473 | &launchctl_stdout, |
| 1474 | &launchctl_stderr, |
| 1475 | &exit_status, |
| 1476 | error)) |
| 1477 | { |
| 1478 | if (g_spawn_check_exit_status (exit_status, error)) |
| 1479 | { |
| 1480 | if (launchctl_stdout != NULL) |
| 1481 | { |
| 1482 | if (G_UNLIKELY (_g_dbus_debug_address ())) |
| 1483 | { |
| 1484 | gchar *s; |
| 1485 | _g_dbus_debug_print_lock (); |
| 1486 | g_print ("GDBus-debug:Address: launchctl stdout:"); |
| 1487 | s = _g_dbus_hexdump (launchctl_stdout, strlen (launchctl_stdout) + 1, 2); |
| 1488 | g_print ("\n%s", s); |
| 1489 | g_free (s); |
| 1490 | _g_dbus_debug_print_unlock (); |
| 1491 | } |
| 1492 | |
| 1493 | if (*launchctl_stdout != '\0') |
| 1494 | { |
| 1495 | gchar *lastchar; |
| 1496 | |
| 1497 | lastchar = launchctl_stdout + strlen(launchctl_stdout) - 1; |
| 1498 | if (*lastchar == '\n') *lastchar = '\0'; |
| 1499 | ret = g_strdup_printf ("unix:path=%s", launchctl_stdout); |
| 1500 | } |
| 1501 | else |
| 1502 | { |
| 1503 | g_set_error (error, |
| 1504 | G_IO_ERROR, |
| 1505 | G_IO_ERROR_FAILED, |
| 1506 | _("Session D-Bus not running. Try running `launchctl load -w /Library/LaunchAgents/org.freedesktop.dbus-session.plist'.")); |
| 1507 | } |
| 1508 | } |
| 1509 | } |
| 1510 | else |
| 1511 | { |
| 1512 | g_prefix_error (error, _("Error spawning command line `%s': "), command_line); |
| 1513 | } |
| 1514 | } |
| 1515 | |
| 1516 | g_free (command_line); |
| 1517 | g_free (launchctl_stdout); |
| 1518 | g_free (launchctl_stderr); |
| 1519 | |
| 1520 | return ret; |
| 1521 | } |
| 1522 | #endif |
| 1523 | |
| 1524 | /* ---------------------------------------------------------------------------------------------------- */ |
| 1525 | |