#include <ccan/oserver/oserver.h>
#include <ccan/oserver/oserver_types.h>
+#include <ccan/oserver/oserver_cdump.h>
#include <ccan/read_write_all/read_write_all.h>
#include <ccan/opt/opt.h>
#include <ccan/tevent/tevent.h>
#include <errno.h>
#include <signal.h>
#include <assert.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
static uint16_t state_flag_map[] = {
[SENDING_GREETING] = TEVENT_FD_WRITE,
}
}
-struct oserver *oserver_setup(struct tevent_context *ev, unsigned short port)
+static void dump(struct tevent_context *ev,
+ struct tevent_signal *se,
+ int signum,
+ int count,
+ void *siginfo,
+ void *_oserver)
+{
+ struct oserver *oserver = _oserver;
+ char *str;
+ int fd;
+
+ str = cdump_bundle(ev, cdump_struct_oserver, oserver);
+ fd = open(oserver->dumpfile, O_CREAT|O_TRUNC|O_WRONLY, 0600);
+ write(fd, str, strlen(str));
+ close(fd);
+ talloc_free(str);
+}
+
+struct oserver *oserver_setup(struct tevent_context *ev, unsigned short port,
+ const char *dumpfile)
{
struct oserver *oserver;
int one = 1;
return NULL;
}
+ oserver->dumpfile = dumpfile;
+ if (oserver->dumpfile) {
+ tevent_add_signal(ev, oserver, SIGHUP, SA_RESTART,
+ dump, oserver);
+ }
+
/* Don't kill us if client dies. */
signal(SIGPIPE, SIG_IGN);