Compare commits

...

2 Commits
1.0 ... master

Author SHA1 Message Date
Dan A. Muresan 43a4dbe44c buildsys: Put libs after objects when linking
Nowadays libs must appear after objects when linking
or else we get undefined symbol errors with LD_PRELOAD.
2013-03-22 20:02:58 +01:00
Vitaliy Filippov b338e6fa9d Several fixes to tdpkg.
* Fix usage when dpkg first calls FIGETBSZ
* Disable garbage messages (may be reenabled with #define TDPKG_INFO)
* Fix "files list for package ... is not a regular file" error
2012-10-04 23:00:30 +04:00
2 changed files with 24 additions and 5 deletions

View File

@ -6,7 +6,7 @@ SQLITELIBS = -lsqlite3
TOKYOLIBS = -ltokyocabinet
LDFLAGS = -nostdlib -shared
COMPILE = $(CC) $(CFLAGS)
LINK = $(CC) $(LDFLAGS) $(LIBS)
LINK = $(CC) $(LDFLAGS)
SRCS = tdpkg.c util.c cache-$(CACHE).c
OBJS = $(subst .c,.o,$(SRCS))
@ -14,13 +14,13 @@ all: libtdpkg.so
libtdpkg.so: $(OBJS)
ifeq ($(CACHE),sqlite)
$(LINK) $(SQLITELIBS) -o libtdpkg.so $+
$(LINK) -o libtdpkg.so $+ $(LIBS) $(SQLITELIBS)
else
$(LINK) $(TOKYOLIBS) -o libtdpkg.so $+
$(LINK) -o libtdpkg.so $+ $(LIBS) $(TOKYOLIBS)
endif
%.o: %.c
$(COMPILE) -c $<
clean:
rm -f libtdpkg.so *.o
rm -f libtdpkg.so *.o

21
tdpkg.c
View File

@ -50,6 +50,7 @@ static struct OpenState
char* contents;
size_t len;
size_t read;
char *fn;
} open_state;
static int cache_initialized;
@ -140,16 +141,22 @@ _tdpkg_open (const char *path, int oflag, int mode)
if (!is_list_file (path) || (oflag & O_RDONLY) != O_RDONLY)
return realopen (path, oflag, mode);
if (open_state.fd >= 0)
// sometimes dpkg calls FIGETBSZ first time, open_state.fn fixes it
if (open_state.fd >= 0 && open_state.fn != path)
{
#ifdef TDPKG_INFO
fprintf (stderr, "tdpkg: nested open(%s, %d, %d) detected, no wrapping\n", path, oflag, mode);
#endif
return realopen (path, oflag, mode);
}
open_state.fn = (char*)path;
open_state.contents = tdpkg_cache_read_filename (path);
if (!open_state.contents)
{
#ifdef TDPKG_INFO
fprintf (stderr, "tdpkg: file %s not up-to-date in cache, rebuild cache\n", path);
#endif
if (tdpkg_cache_rebuild ())
{
fprintf (stderr, "tdpkg: can't rebuild cache, no wrapping\n");
@ -202,11 +209,14 @@ __fxstat (int ver, int fd, struct stat* buf)
if (open_state.fd != fd)
{
#ifdef TDPKG_INFO
fprintf (stderr, "tdpkg: nested __fxstat(%d) detected, no wrapping\n", fd);
#endif
return real__fxstat (ver, fd, buf);
}
buf->st_size = open_state.len;
buf->st_mode = S_IFREG;
return 0;
}
@ -221,11 +231,14 @@ __fxstat64 (int ver, int fd, struct stat64* buf)
if (open_state.fd != fd)
{
#ifdef TDPKG_INFO
fprintf (stderr, "tdpkg: nested __fxstat64(%d) detected, no wrapping\n", fd);
#endif
return real__fxstat64 (ver, fd, buf);
}
buf->st_size = open_state.len;
buf->st_mode = S_IFREG;
return 0;
}
@ -240,13 +253,17 @@ read (int fildes, void *buf, size_t nbyte)
if (open_state.fd != fildes)
{
#ifdef TDPKG_INFO
fprintf (stderr, "tdpkg: nested read(%d) detected, no wrapping\n", fildes);
#endif
return realread (fildes, buf, nbyte);
}
if (open_state.read > open_state.len)
{
#ifdef TDPKG_INFO
fprintf (stderr, "tdpkg: useless read(%d) detected, returning 0\n", open_state.fd);
#endif
return 0;
}
@ -267,7 +284,9 @@ close (int fd)
if (open_state.fd != fd)
{
#ifdef TDPKG_INFO
fprintf (stderr, "tdpkg: close() on unknown fd %d, no wrapping\n", fd);
#endif
return realclose (fd);
}