Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
executable file 115 lines (86 sloc) 2.42 KB
#! /bin/bash
# case 3:
#
# main -----------------> libcommon
# \--- libmiddle ---> libcommon
#
# 1) start main as a daemon
# 2) update libcommon
# 3) rebuild libmiddle
# 4) wait until main dlopens and calls libmiddle.
#
# result: libmiddle compiled against new API, but calls old API
set -e
# install libcommon API 1
cat >libcommon.c <<"_EOF_"
#include <stdio.h>
void libcommon_test(char *caller) {
printf("libcommon_test V1 called by %s\n",caller);
}
_EOF_
cat >libcommon.h <<'_EOF_'
#define API_VERSION "1"
_EOF_
gcc -shared -fPIC -Wl,-soname=libcommon-1.so -o libcommon-1.so libcommon.c
ln -sf libcommon-1.so libcommon.so
# install libmiddle
cat >libmiddle.c <<_EOF_
#include <stdio.h>
#include "libcommon.h"
extern void libcommon_test(char *caller);
void libmiddle_test(char *caller) {
printf("libmiddle_test called by %s\n",caller);
libcommon_test("libmiddle expecting V" API_VERSION " API");
}
_EOF_
gcc -shared -fPIC -Wl,-soname=libmiddle-1.so -o libmiddle-1.so libmiddle.c
ln -sf libmiddle-1.so libmiddle.so
# install main
cat >main.c <<_EOF_
#include <stdio.h>
#include "libcommon.h"
#include <stdlib.h>
#include <unistd.h>
#include <dlfcn.h>
extern void libcommon_test(char *caller);
int main() {
void *libmiddle;
void (*libmiddle_test)(char *caller);
libcommon_test("main expecting V" API_VERSION " API");
printf("main waiting...\n");
sleep(3);
printf("dlopen libmiddle.so\n");
libmiddle=dlopen("./libmiddle.so", RTLD_LAZY);
if (libmiddle==0) {
fprintf(stderr,"./libmiddle.so : %s\n", dlerror());
exit(1);
}
libmiddle_test=dlsym(libmiddle, "libmiddle_test");
if (libmiddle_test==0) {
fprintf(stderr, "./libmiddle.so : libmiddle_test : %s\n", dlerror());
exit(1);
}
libmiddle_test("main");
}
_EOF_
gcc -o main -Wl,-rpath=. -L. -lcommon -ldl main.c
echo "########### start main"
./main &
sleep 1
echo "########### update libcommon"
cat >libcommon.c <<"_EOF_"
#include <stdio.h>
void libcommon_test(char *caller) {
printf("libcommon_test V2 called by %s\n",caller);
}
_EOF_
cat >libcommon.h <<'_EOF_'
#define API_VERSION "2"
_EOF_
gcc -shared -fPIC -Wl,-soname=libcommon-3.so -o libcommon-3.so libcommon.c
ln -sf libcommon-3.so libcommon.so
echo "########### rebuild libmiddle"
gcc -shared -fPIC -Wl,-soname=libmiddle-1.so -o libmiddle-1.so libmiddle.c
ln -sf libmiddle-1.so libmiddle.so
echo "########### wait for main"
wait