diff options
author | Jean-Francois Brousseau <jfb@cvs.openbsd.org> | 2004-08-02 17:35:38 +0000 |
---|---|---|
committer | Jean-Francois Brousseau <jfb@cvs.openbsd.org> | 2004-08-02 17:35:38 +0000 |
commit | d3ab8d966c8daf959bb22be920aec3d166da0362 (patch) | |
tree | afe14dc848472ed99a9e65f2af3917421fe83f01 /usr.bin/cvs | |
parent | 57617783e6226d76b08d9c129e25dff6b0f7f970 (diff) |
Get a step closer to reality
Diffstat (limited to 'usr.bin/cvs')
-rw-r--r-- | usr.bin/cvs/server.c | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/usr.bin/cvs/server.c b/usr.bin/cvs/server.c index 0319726232c..f1a60d969d4 100644 --- a/usr.bin/cvs/server.c +++ b/usr.bin/cvs/server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server.c,v 1.4 2004/07/30 23:12:12 jfb Exp $ */ +/* $OpenBSD: server.c,v 1.5 2004/08/02 17:35:37 jfb Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -37,6 +37,7 @@ #include "cvs.h" #include "log.h" #include "sock.h" +#include "proto.h" @@ -64,27 +65,43 @@ u_int cvs_case = 0; int cvs_server(int argc, char **argv) { - ssize_t ret; + size_t len; char reqbuf[128]; - struct cvsroot *root; if (argc != 1) { return (EX_USAGE); } + /* make sure standard in and standard out are line-buffered */ + (void)setvbuf(stdin, NULL, _IOLBF, 0); + (void)setvbuf(stdout, NULL, _IOLBF, 0); + + if (cvs_sock_connect(CVSD_SOCK_PATH) < 0) { + cvs_log(LP_ERR, "failed to connect to CVS server socket"); + return (-1); + } + + for (;;) { - ret = read(STDIN_FILENO, reqbuf, sizeof(reqbuf)); - if (ret == 0) { - break; + if (fgets(reqbuf, sizeof(reqbuf), stdin) == NULL) { + if (feof(stdin)) + break; + else if (ferror(stdin)) + return (EX_DATAERR); } + len = strlen(reqbuf); + if (len == 0) + continue; + else if (reqbuf[len - 1] != '\n') { + cvs_log(LP_ERR, "truncated request"); + return (EX_DATAERR); + } + reqbuf[--len] = '\0'; - } + cvs_req_handle(reqbuf); - if (cvs_sock_connect(root->cr_dir) < 0) { - cvs_log(LP_ERR, "failed to connect to CVS server socket"); - return (-1); } cvs_sock_disconnect(); |