[dovecot-cvs] dovecot/src/util Makefile.am, 1.7, 1.8 gdbhelper.c, NONE, 1.1

cras at dovecot.org cras at dovecot.org
Sat Jan 14 14:46:35 EET 2006


Update of /var/lib/cvs/dovecot/src/util
In directory talvi:/tmp/cvs-serv1112/src/util

Modified Files:
	Makefile.am 
Added Files:
	gdbhelper.c 
Log Message:
Added gdbhelper binary.



Index: Makefile.am
===================================================================
RCS file: /var/lib/cvs/dovecot/src/util/Makefile.am,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- Makefile.am	20 Oct 2004 23:06:12 -0000	1.7
+++ Makefile.am	14 Jan 2006 12:46:33 -0000	1.8
@@ -1,6 +1,6 @@
 pkglibexecdir = $(libexecdir)/dovecot
 
-pkglibexec_PROGRAMS = rawlog
+pkglibexec_PROGRAMS = rawlog gdbhelper
 sbin_PROGRAMS = dovecotpw
 
 AM_CPPFLAGS = \
@@ -13,6 +13,12 @@
 rawlog_SOURCES = \
 	rawlog.c
 
+gdbhelper_LDADD = \
+	../lib/liblib.a
+
+gdbhelper_SOURCES = \
+	gdbhelper.c
+
 dovecotpw_LDADD = \
 	../auth/libpassword.a \
 	../lib-ntlm/libntlm.a \

--- NEW FILE: gdbhelper.c ---
/* Copyright (C) 2006 Timo Sirainen */

#include "lib.h"

#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <time.h>
#include <sys/wait.h>

int main(int argc, char *argv[])
{
	pid_t pid = fork();
	const char *path, *cmd;
	int fd_in[2], fd_log, status;

	if (argc < 2)
		i_fatal("Usage: gdbhelper <program> [<args>]");

	switch (pid) {
	case 1:
		i_fatal("fork() failed: %m");
	case 0:
		/* child */
		(void)execvp(argv[1], argv+1);
		i_fatal("execvp(%s) failed: %m", argv[1]);
	default:
		path = t_strdup_printf("/tmp/gdbhelper.%s.%s",
				       dec2str(time(NULL)), dec2str(pid));
		fd_log = open(path, O_CREAT | O_WRONLY, 0600);
		if (fd_log < 0)
			i_fatal("open(%s) failed: %m", path);

		if (pipe(fd_in) < 0)
			i_fatal("pipe() failed: %m");
		cmd = "handle SIGPIPE nostop\n"
			"handle SIGALRM nostop\n"
			"cont\n"
			"where\n"
			"quit\n";
		if (write(fd_in[1], cmd, strlen(cmd)) < 0)
			i_fatal("write() failed: %m");

		if (dup2(fd_in[0], 0) < 0 ||
		    dup2(fd_log, 1) < 0 ||
		    dup2(fd_log, 2) < 0)
			i_fatal("dup2() failed: %m");

		cmd = t_strdup_printf("gdb %s %s", argv[1], dec2str(pid));
		if (system(cmd) < 0)
			i_fatal("system() failed: %m");

		if (wait(&status) < 0)
			i_fatal("wait() failed: %m");
		if (status == 0) {
			if (unlink(path) < 0 && errno != ENOENT)
				i_error("unlink(%s) failed: %m", path);
		}
	}
	return 0;
}



More information about the dovecot-cvs mailing list