summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Siegl <stesie@brokenpipe.de>2004-10-01 20:01:27 +0000
committerStefan Siegl <stesie@brokenpipe.de>2004-10-01 20:01:27 +0000
commitda08977aa3d1c70f5eea77cbea9da0acc243137d (patch)
treed1798ce71a155a7a3683f2340caa9be8e2ad4d26
parent19ce9a631762ac85f37bedadc6232ab3a96d64be (diff)
adding support for cvs' :ext: access method
-rw-r--r--Makefile2
-rw-r--r--cvs_ext.c115
-rw-r--r--cvs_ext.h26
3 files changed, 142 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 5c6fd79dd..0c8e80a1a 100644
--- a/Makefile
+++ b/Makefile
@@ -14,7 +14,7 @@ CFLAGS+=-std=gnu99 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
LDFLAGS+=-Wall -W -ggdb
LDFLAGS+=-lnetfs -lfshelp -liohelp -lthreads -lports
OBJS=tcpip.o cvsfs.o cvs_connect.o cvs_pserver.o cvs_tree.o netfs.o \
- node.o cvs_files.o
+ node.o cvs_files.o cvs_ext.o
all: cvsfs
diff --git a/cvs_ext.c b/cvs_ext.c
new file mode 100644
index 000000000..f860cec0c
--- /dev/null
+++ b/cvs_ext.c
@@ -0,0 +1,115 @@
+/**********************************************************
+ * cvs_ext.c
+ *
+ * Copyright 2004, Stefan Siegl <ssiegl@gmx.de>, Germany
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Publice License,
+ * version 2 or any later. The license is contained in the COPYING
+ * file that comes with the cvsfs4hurd distribution.
+ *
+ * connect to cvs :ext: server
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#define PACKAGE "cvsfs"
+
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <malloc.h>
+#include <sys/types.h>
+#include <signal.h>
+
+#include "cvsfs.h"
+#include "cvs_ext.h"
+#include "cvs_connect.h"
+
+
+
+/* cvs_ext_connect
+ *
+ * connect to the cvs :ext: server as further described in the cvsfs_config
+ * configuration structure
+ */
+error_t
+cvs_ext_connect(FILE **send, FILE **recv)
+{
+ int fd_to_rsh[2], fd_from_rsh[2];
+ pid_t pid;
+
+ fprintf(stderr, "gotta connect to remote host!\n");
+
+ if(pipe(fd_to_rsh))
+ return errno;
+ if(pipe(fd_from_rsh))
+ return errno;
+
+ if((pid = fork()) < 0)
+ {
+ perror(PACKAGE ": cannot fork remote shell client");
+ return pid;
+ }
+
+ fprintf(stderr, "successfully forked.\n");
+
+ if(! pid)
+ {
+ /* okay, child process, fork to remote shell client */
+ close(fd_to_rsh[1]); /* close writing end */
+ close(fd_from_rsh[0]); /* close reading end */
+
+ if(dup2(fd_to_rsh[0], 0) < 0 || dup2(fd_from_rsh[1], 1) < 0)
+ {
+ perror(PACKAGE ": unable to dup2 pipe to stdin/stdout");
+ exit(1);
+ }
+
+ execlp(config.cvs_shell_client, config.cvs_shell_client,
+ "-l", config.cvs_username, config.cvs_hostname,
+ "--", "cvs", "server", NULL);
+ exit(1);
+ }
+
+ close(fd_to_rsh[0]);
+ close(fd_from_rsh[1]);
+
+ fprintf(stderr, "now trying to fdopen ...\n");
+
+ *send = NULL; *recv = NULL;
+
+ if(! ((*send = fdopen(fd_to_rsh[1], "w"))
+ && (*recv = fdopen(fd_from_rsh[0], "r"))))
+ {
+ perror(PACKAGE ": unable to convert pipe's fds to file streams");
+
+ if(send)
+ fclose(*send);
+ else
+ close(fd_to_rsh[1]);
+
+ if(recv)
+ fclose(*recv);
+ else
+ close(fd_from_rsh[0]);
+
+ kill(pid, SIGTERM);
+ return EIO;
+ }
+
+ fprintf(stderr, "send: %p, recv: %p\n", *send, *recv);
+
+ if(setvbuf(*send, NULL, _IOLBF, 0) || setvbuf(*recv, NULL, _IOLBF, 0))
+ {
+ perror(PACKAGE ": cannot force streams to be linebuffered");
+ fclose(*send);
+ fclose(*recv);
+ return EIO;
+ }
+
+ fprintf(stderr, "cvs_ext_connect returning successful!\n");
+ return 0;
+}
diff --git a/cvs_ext.h b/cvs_ext.h
new file mode 100644
index 000000000..9b505428e
--- /dev/null
+++ b/cvs_ext.h
@@ -0,0 +1,26 @@
+/**********************************************************
+ * cvs_ext.h
+ *
+ * Copyright 2004, Stefan Siegl <ssiegl@gmx.de>, Germany
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Publice License,
+ * version 2 or any later. The license is contained in the COPYING
+ * file that comes with the cvsfs4hurd distribution.
+ *
+ * connect to cvs :ext: server
+ */
+
+#ifndef CVS_EXT_H
+#define CVS_EXT_H
+
+#include <stdio.h>
+#include "cvsfs.h"
+
+/* connect to the cvs :ext: server.
+ * return 0 on success, only in that case send and recv are guaranteed to
+ * be valid. send and recv are already set up to be line buffered.
+ */
+error_t cvs_ext_connect(FILE **send, FILE **recv);
+
+#endif /* CVS_EXT_H */