Static compilation of 0.10.2
Olivier Mehani
shtrom+cgit at ssji.net
Wed Jan 14 05:16:13 CET 2015
Hi,
I am running cgit in an OpenBSD chroot. Because of this, I need a static
binary. This worked up to 0.9.2 out of the box.
Somewhere on the way to 0.10, the filtering approach has changed, by
hooking, AFAIK, the system's `write` to cgit's own, dlopening the
system's if needed.
Unfortunately, this breaks static compilation, for obvious reasons (two
symbols named `write`). I believe is why 0.9.2 version that still ships
with OpenBSD ports for this reason.
I tried to bump this port to 0.10.2, and came up with the two attached
patches. This is rather basic, and probably incomplete: all the -ldl
magic (i.e, cgit_init_filters, cgit_cleanup_filters, and write) is
conditionaly enabled depending on a preprocessor macro (STATIC) being
declared.
This works for about-filters, which was my use-case. I suspect this
might break the commit filter, which is what I understand this hooking
was introduced to start with, and perhaps others too.
I also haven't added the Makefile logic to do
CFLAGS+=-DSTATIC
LDFLAGS+=-static
but this should probably be done too.
All in all, this is pretty raw, but it works in my context. I'm not sure
it does in all (or at least most), so I wanted to have a discussion
about this.
Comments?
--
Olivier Mehani <shtrom at ssji.net>
PGP fingerprint: 4435 CF6A 7C8D DD9B E2DE F5F9 F012 A6E2 98C6 6655
Confidentiality cannot be guaranteed on emails sent or received unencrypted.
-------------- next part --------------
$OpenBSD$
--- cgit.c.orig Tue Jan 13 13:48:45 2015
+++ cgit.c Tue Jan 13 13:46:08 2015
@@ -1015,8 +1015,10 @@ int main(int argc, const char **argv)
const char *path;
int err, ttl;
+#ifndef STATIC
cgit_init_filters();
atexit(cgit_cleanup_filters);
+#endif
prepare_context();
cgit_repolist.length = 0;
@@ -1070,7 +1072,9 @@ int main(int argc, const char **argv)
ctx.cfg.cache_size = 0;
err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root,
ctx.qry.raw, ttl, process_request);
+#ifndef STATIC
cgit_cleanup_filters();
+#endif
if (err)
cgit_print_error("Error processing page: %s (%d)",
strerror(err), err);
-------------- next part --------------
$OpenBSD$
--- filter.c.orig Tue Jan 13 13:48:14 2015
+++ filter.c Tue Jan 13 13:29:10 2015
@@ -31,6 +31,7 @@ static inline void reap_filter(struct cgit_filter *fil
filter->cleanup(filter);
}
+#ifndef STATIC
void cgit_cleanup_filters(void)
{
int i;
@@ -60,6 +61,7 @@ ssize_t write(int fd, const void *buf, size_t count)
return libc_write(fd, buf, count);
return filter_write(current_write_filter, buf, count);
}
+#endif
static inline void hook_write(struct cgit_filter *filter, ssize_t (*new_write)(struct cgit_filter *base, const void *buf, size_t count))
{
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 603 bytes
Desc: Digital signature
URL: <http://lists.zx2c4.com/pipermail/cgit/attachments/20150114/eeffbbda/attachment.asc>
More information about the CGit
mailing list