Created
November 6, 2013 09:48
-
-
Save zonque/7333532 to your computer and use it in GitHub Desktop.
LD_PRELOAD hack for working on the kdbus bridge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* gcc -fPIC -shared -o dbus-redirect.so dbus-redirect.c -ldl */ | |
#include <sys/types.h> | |
#include <sys/socket.h> | |
#include <sys/un.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <string.h> | |
#include <dlfcn.h> | |
int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) | |
{ | |
int (*f)() = dlsym((void *) -1, "connect"); | |
struct sockaddr_un *a = (struct sockaddr_un *) addr; | |
int ret, do_free = 0; | |
if (a->sun_family == AF_UNIX && | |
strcmp(a->sun_path, "/var/run/dbus/system_bus_socket") == 0) { | |
a = (struct sockaddr_un *) malloc(addrlen); | |
if (!a) | |
return -1; | |
memcpy(a, addr, addrlen); | |
strcpy(a->sun_path, "/run/systemd/dbus-bridge/system"); | |
do_free = 1; | |
} | |
ret = f(sockfd, a, addrlen); | |
if (do_free) | |
free(a); | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment