[Swan-dev] LIBRESWAN_SNAPSHOT_MALLOC_FAIL

D. Hugh Redelmeier hugh at mimosa.com
Sat Mar 15 20:49:28 EET 2014


In lib/libswan/alloc.c, function alloc_bytes_raw, when malloc fails, the 
program (generally Pluto) is aborted.

But just before that happens, this code appears:
                if (getenv("LIBRESWAN_SNAPSHOT_MALLOC_FAIL")) {
			if (fork() == 0)	/* in child */
				lsw_abort();
		}
What the heck is that supposed to accomplish?

Why abort in the child (when you will abort in the parent in a few lines 
anyway)?  Actually, the parent might exit-with-diagnostic.  Perhaps what 
is wanted is a debugging facility that could be simpler and more
general: ABORT_INSTEAD_OF_EXIT, to be implemented by exit_log().

If you've run out of RAM, forking seems like a dubious response.
Surely that takes even more RAM.

The string LIBRESWAN_SNAPSHOT_MALLOC_FAIL doesn't appear anywhere else in 
the tree, so it isn't used by testing.

lsw_abort is a macto that expands to:
	libreswan_log_abort(__FILE__, __LINE__)

libreswan_log_abort is a function that does:
        libreswan_loglog(RC_LOG_SERIOUS, "ABORT at %s:%d", file_str, line_no);
        abort();

libreswan_loglog prints stuff to stderr and syslog (if appropriate).

Even though these are carefully in lib/libswan/lswlog.c and ostensibly
separate from Pluto, they use variables that are only in Pluto.  So it
looks to me as if there has only been an incomplete separation, at
some cost and no benefit.

What parts of lib/libswan are actually used by things other than
Pluto?

Paul wants to reduce the diversity of logging routines.  This question
is related to that project.

For now, I'm just going to get rid of that funny
LIBRESWAN_SNAPSHOT_MALLOC_FAIL code.


More information about the Swan-dev mailing list