List for cgit developers and users
 help / color / mirror / Atom feed
From: shtrom+cgit at ssji.net (Olivier Mehani)
Subject: Static compilation of 0.10.2
Date: Wed, 14 Jan 2015 15:16:13 +1100	[thread overview]
Message-ID: <20150114041613.GA12513@blasturvion.dynhost.nicta.com.au> (raw)

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>


                 reply	other threads:[~2015-01-14  4:16 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150114041613.GA12513@blasturvion.dynhost.nicta.com.au \
    --to=cgit@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).