[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: ifupdown writes to /etc... a bug?



On Thu, 2003-03-13 at 21:11, Anthony Towns wrote:
> If ifup didn't need ifstate, it wouldn't have it.

Although I think it is worth thinking (as we are doing) about
how to provide persistent-until-reboot network-independent
storage, it is also worthwhile examining the alternative of
modifying programs so that they don't need such storage.

Here is how the problem might be solved with some generality.

For all programs that need to save some state describable
in a string, we use a little daemon "parrot" which stores the
string given as an argument and makes it available for reading
on a named fifo.  E.g., the program listed below behaves in the
following way:

jdthood@thanatos:~/tmp$ ls -l /tmp/parrot*
ls: /tmp/parrot*: No such file or directory
jdthood@thanatos:~/tmp$ ./parrot xyzzy /tmp/parrot &
[1] 1841
jdthood@thanatos:~/tmp$ ls -l /tmp/parrot*
prw-r--r--    1 jdthood  jdthood         0 2003-03-14 08:26 /tmp/parrot|
jdthood@thanatos:~/tmp$ read s < /tmp/parrot ; echo $s
xyzzy
jdthood@thanatos:~/tmp$ read s < /tmp/parrot ; echo $s
xyzzy

ifupdown could be modified so that instead of saving its state
in a file, it saves it in a parrot.

Here is the program.  (This is just an illustration.  Obviously
if we were to adopt this idea then the program would need more work.)

--- parrot.c ---
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <signal.h>

typedef void (*sighandler_t)(int);

static char *fn;

void s (int signum)
{
	unlink( fn );
	exit(0);
}

main(int argc, char * argv[])
{
	size_t l=0;
	int r;
	sighandler_t rs;
	int fd;

	if (argc < 2)
		exit(1);

	l = strlen(argv[1]);

	fn = "/tmp/parrot";
	if (argc > 2)
		fn = argv[2];
	if (!strlen(fn))
		exit(1);

	r = mkfifo( fn, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH );
	if (r)
		exit(1);
	rs = signal(SIGQUIT, (sighandler_t)s);
	if (rs == SIG_ERR)
		exit(1);
	rs = signal(SIGINT, (sighandler_t)s);
	if (rs == SIG_ERR)
		exit(1);
	rs = signal(SIGTERM, (sighandler_t)s);
	if (rs == SIG_ERR)
		exit(1);
	fd = open( fn,  S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH );
	if (!fd)
		exit(1);
	while(1) {
		write(fd, argv[1], l);
		write(fd, "\n", 1);
	}
}


-- 
Thomas Hood <jdthood0@yahoo.co.uk>

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com



Reply to: