nixpkgs/pkgs/applications/networking/browsers/mozilla-plugins/google-talk-plugin/preload.c
Eelco Dolstra 1405f49820 * With a nice bit of hackery, get the Google Talk plugin to work. Yay
for proprietary software.  Tested with Firefox and Chrome.

svn path=/nixpkgs/trunk/; revision=33519
2012-04-01 15:21:30 +00:00

33 lines
988 B
C

/* Google Talk Plugin executes a helper program in /opt. This
LD_PRELOAD library intercepts execvp() calls to redirect them to
the corresponding location in $out. */
#define _GNU_SOURCE
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <dlfcn.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <limits.h>
char origDir [] = "/opt/google/talkplugin/GoogleTalkPlugin";
char realDir [] = OUT "/libexec/google/talkplugin/GoogleTalkPlugin";
const char * rewrite(const char * path, char * buf)
{
if (strncmp(path, origDir, sizeof(origDir) - 1) != 0) return path;
if (snprintf(buf, PATH_MAX, "%s%s", realDir, path + sizeof(origDir) - 1) >= PATH_MAX)
abort();
return buf;
}
int execvp(const char * path, char * const argv[])
{
fprintf(stderr, "foo %s\n", path);
int (*_execvp) (const char *, char * const argv[]) = dlsym(RTLD_NEXT, "execvp");
char buf[PATH_MAX];
return _execvp(rewrite(path, buf), argv);
}