Compare commits

..

No commits in common. "master" and "1.0" have entirely different histories.
master ... 1.0

2 changed files with 5 additions and 24 deletions

View File

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

21
tdpkg.c
View File

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