Skip to content

Instantly share code, notes, and snippets.

@scumjr
Last active May 16, 2017 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scumjr/e5798ddccd90fd88e0ddabcf5bb47fd6 to your computer and use it in GitHub Desktop.
Save scumjr/e5798ddccd90fd88e0ddabcf5bb47fd6 to your computer and use it in GitHub Desktop.
Fix for Ubuntu Xenial irssi-plugin-otr package
/*
* The package irssi-plugin-otr provides a library file (libotr.so) which is
* incorrectly compiled on Ubuntu 16.04. There's an open issue
* (https://bugs.launchpad.net/ubuntu/+source/irssi-plugin-otr/+bug/1579548).
*
* This is a dirty workaround.
* Usage: LD_PRELOAD=$(pwd)/otr_preload.so irssi
*
* Makefile:
CFLAGS := -W -Wall -Wextra
LDFLAGS := -ldl
TARGET := otr_preload.so
ifeq ($(ARM),1)
CC := /usr/bin/arm-linux-gnueabihf-gcc
CFLAGS += -I/usr/arm-linux-gnueabihf/include
endif
all: $(TARGET)
%.so: %.o
$(CC) -shared $^ -o $@ $(LDFLAGS)
%.o: %.c
$(CC) $(CFLAGS) -fPIC -o $@ -c $^
clean:
rm -f $(TARGET) *.o
*/
#define _GNU_SOURCE
#include <dlfcn.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdbool.h>
#define IRSSI_ABI_VERSION 2
/* don't require glib header files */
#define gboolean bool
#define gchar char
#define gpointer unsigned long
#define GModule void
static gboolean (*orig_g_module_symbol)(GModule *, const gchar *, gpointer *);
void otr_abicheck(int *version)
{
*version = IRSSI_ABI_VERSION;
}
gboolean g_module_symbol(GModule *module, const gchar *symbol_name, gpointer *symbol)
{
if (strcmp(symbol_name, "otr_abicheck") == 0) {
*symbol = (gpointer)otr_abicheck;
return true;
} else {
return orig_g_module_symbol(module, symbol_name, symbol);
}
}
static int __attribute__ ((constructor)) initfunc(void)
{
orig_g_module_symbol = dlsym(RTLD_NEXT, "g_module_symbol");
if (orig_g_module_symbol == NULL) {
fprintf(stderr, "can't find g_module_symbol\n");
sleep(1);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment