-int main(int argc, char *argv[]) {
-
- _cleanup_bus_unref_ sd_bus *a = NULL, *b = NULL;
- sd_id128_t server_id;
- int r, in_fd, out_fd;
- bool got_hello = false;
- bool is_unix;
- struct ucred ucred = {};
- _cleanup_free_ char *peersec = NULL;
-
- log_set_target(LOG_TARGET_JOURNAL_OR_KMSG);
- log_parse_environment();
- log_open();
-
- r = parse_argv(argc, argv);
- if (r <= 0)
- goto finish;
-
- r = sd_listen_fds(0);
- if (r == 0) {
- in_fd = STDIN_FILENO;
- out_fd = STDOUT_FILENO;
- } else if (r == 1) {
- in_fd = SD_LISTEN_FDS_START;
- out_fd = SD_LISTEN_FDS_START;
- } else {
- log_error("Illegal number of file descriptors passed");
- goto finish;
- }
-
- is_unix =
- sd_is_socket(in_fd, AF_UNIX, 0, 0) > 0 &&
- sd_is_socket(out_fd, AF_UNIX, 0, 0) > 0;
-
- if (is_unix) {
- getpeercred(in_fd, &ucred);
- getpeersec(in_fd, &peersec);
- }
-
- r = sd_bus_new(&a);
- if (r < 0) {
- log_error("Failed to allocate bus: %s", strerror(-r));
- goto finish;
- }
-
- r = sd_bus_set_name(a, "sd-proxy");
- if (r < 0) {
- log_error("Failed to set bus name: %s", strerror(-r));
- goto finish;
- }
-
- r = sd_bus_set_address(a, arg_address);
- if (r < 0) {
- log_error("Failed to set address to connect to: %s", strerror(-r));
- goto finish;
- }
-
- r = sd_bus_negotiate_fds(a, is_unix);
- if (r < 0) {
- log_error("Failed to set FD negotiation: %s", strerror(-r));
- goto finish;
- }
-
- if (ucred.pid > 0) {
- a->fake_creds.pid = ucred.pid;
- a->fake_creds.uid = ucred.uid;
- a->fake_creds.gid = ucred.gid;
- a->fake_creds_valid = true;
- }