[BACK]Return to client.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / cvs

Annotation of src/usr.bin/cvs/client.c, Revision 1.97

1.97    ! tobias      1: /*     $OpenBSD: client.c,v 1.96 2008/02/03 15:08:04 tobias Exp $      */
1.1       jfb         2: /*
1.9       joris       3:  * Copyright (c) 2006 Joris Vink <joris@openbsd.org>
1.1       jfb         4:  *
1.9       joris       5:  * Permission to use, copy, modify, and distribute this software for any
                      6:  * purpose with or without fee is hereby granted, provided that the above
                      7:  * copyright notice and this permission notice appear in all copies.
                      8:  *
                      9:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     10:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     11:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     12:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     13:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     14:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     15:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1.1       jfb        16:  */
                     17:
1.59      otto       18: #include <sys/param.h>
                     19: #include <sys/dirent.h>
                     20: #include <sys/stat.h>
1.97    ! tobias     21: #include <sys/time.h>
1.59      otto       22:
                     23: #include <errno.h>
                     24: #include <fcntl.h>
                     25: #include <libgen.h>
                     26: #include <limits.h>
                     27: #include <pwd.h>
                     28: #include <stdlib.h>
                     29: #include <string.h>
                     30: #include <unistd.h>
1.1       jfb        31:
                     32: #include "cvs.h"
1.9       joris      33: #include "remote.h"
1.1       jfb        34:
1.9       joris      35: struct cvs_req cvs_requests[] = {
                     36:        /* this is what our client will use, the server should support it */
                     37:        { "Root",               1,      cvs_server_root, REQ_NEEDED },
                     38:        { "Valid-responses",    1,      cvs_server_validresp, REQ_NEEDED },
                     39:        { "valid-requests",     1,      cvs_server_validreq, REQ_NEEDED },
                     40:        { "Directory",          0,      cvs_server_directory, REQ_NEEDED },
1.66      joris      41:        { "Static-directory",   0,      cvs_server_static_directory,
                     42:            REQ_NEEDED | REQ_NEEDDIR },
                     43:        { "Sticky",             0,      cvs_server_sticky,
                     44:            REQ_NEEDED | REQ_NEEDDIR },
                     45:        { "Entry",              0,      cvs_server_entry,
                     46:            REQ_NEEDED | REQ_NEEDDIR },
                     47:        { "Modified",           0,      cvs_server_modified,
                     48:            REQ_NEEDED | REQ_NEEDDIR },
1.9       joris      49:        { "UseUnchanged",       0,      cvs_server_useunchanged, REQ_NEEDED },
1.66      joris      50:        { "Unchanged",          0,      cvs_server_unchanged,
                     51:            REQ_NEEDED | REQ_NEEDDIR },
1.9       joris      52:        { "Questionable",       0,      cvs_server_questionable, REQ_NEEDED },
                     53:        { "Argument",           0,      cvs_server_argument, REQ_NEEDED },
1.24      xsa        54:        { "Argumentx",          0,      cvs_server_argumentx, REQ_NEEDED },
                     55:        { "Global_option",      0,      cvs_server_globalopt, REQ_NEEDED },
1.26      xsa        56:        { "Set",                0,      cvs_server_set, REQ_NEEDED },
1.1       jfb        57:
1.9       joris      58:        /*
                     59:         * used to tell the server what is going on in our
                     60:         * working copy, unsupported until we are told otherwise
                     61:         */
                     62:        { "Max-dotdot",                 0,      NULL, 0 },
                     63:        { "Checkin-prog",               0,      NULL, 0 },
                     64:        { "Update-prog",                0,      NULL, 0 },
                     65:        { "Kopt",                       0,      NULL, 0 },
                     66:        { "Checkin-time",               0,      NULL, 0 },
                     67:        { "Is-modified",                0,      NULL, 0 },
                     68:        { "Notify",                     0,      NULL, 0 },
                     69:        { "Case",                       0,      NULL, 0 },
                     70:        { "Gzip-stream",                0,      NULL, 0 },
1.25      xsa        71:        { "wrapper-sendme-rcsOptions",  0,      NULL, 0 },
1.9       joris      72:        { "Kerberos-encrypt",           0,      NULL, 0 },
                     73:        { "Gssapi-encrypt",             0,      NULL, 0 },
                     74:        { "Gssapi-authenticate",        0,      NULL, 0 },
                     75:        { "expand-modules",             0,      NULL, 0 },
                     76:
                     77:        /* commands that might be supported */
1.95      xsa        78:        { "ci",                 0,      cvs_server_commit,      REQ_NEEDDIR },
                     79:        { "co",                 0,      cvs_server_checkout,    REQ_NEEDDIR },
                     80:        { "update",             0,      cvs_server_update,      REQ_NEEDDIR },
                     81:        { "diff",               0,      cvs_server_diff,        REQ_NEEDDIR },
                     82:        { "log",                0,      cvs_server_log,         REQ_NEEDDIR },
                     83:        { "rlog",               0,      cvs_server_rlog, 0 },
                     84:        { "add",                0,      cvs_server_add,         REQ_NEEDDIR },
                     85:        { "remove",             0,      cvs_server_remove,      REQ_NEEDDIR },
                     86:        { "update-patches",     0,      cvs_server_update_patches, 0 },
                     87:        { "gzip-file-contents", 0,      NULL, 0 },
                     88:        { "status",             0,      cvs_server_status,      REQ_NEEDDIR },
                     89:        { "rdiff",              0,      NULL, 0 },
                     90:        { "tag",                0,      cvs_server_tag,         REQ_NEEDDIR },
                     91:        { "rtag",               0,      cvs_server_rtag, 0 },
                     92:        { "import",             0,      cvs_server_import,      REQ_NEEDDIR },
                     93:        { "admin",              0,      cvs_server_admin,       REQ_NEEDDIR },
                     94:        { "export",             0,      cvs_server_export,      REQ_NEEDDIR },
                     95:        { "history",            0,      NULL, 0 },
                     96:        { "release",            0,      cvs_server_release,     REQ_NEEDDIR },
                     97:        { "watch-on",           0,      NULL, 0 },
                     98:        { "watch-off",          0,      NULL, 0 },
                     99:        { "watch-add",          0,      NULL, 0 },
                    100:        { "watch-remove",       0,      NULL, 0 },
                    101:        { "watchers",           0,      NULL, 0 },
                    102:        { "editors",            0,      NULL, 0 },
                    103:        { "init",               0,      cvs_server_init, 0 },
                    104:        { "annotate",           0,      cvs_server_annotate,    REQ_NEEDDIR },
                    105:        { "rannotate",          0,      cvs_server_rannotate, 0 },
                    106:        { "noop",               0,      NULL, 0 },
                    107:        { "version",            0,      cvs_server_version, 0 },
                    108:        { "",                   -1,     NULL, 0 }
1.9       joris     109: };
                    110:
1.16      xsa       111: static void     client_check_directory(char *);
                    112: static char    *client_get_supported_responses(void);
                    113: static char    *lastdir = NULL;
                    114: static int      end_of_response = 0;
                    115:
                    116: static void    cvs_client_initlog(void);
                    117:
                    118: /*
                    119:  * File descriptors for protocol logging when the CVS_CLIENT_LOG environment
                    120:  * variable is set.
                    121:  */
                    122: static int     cvs_client_logon = 0;
1.42      joris     123: int    cvs_client_inlog_fd = -1;
                    124: int    cvs_client_outlog_fd = -1;
1.16      xsa       125:
1.9       joris     126:
1.37      joris     127: int server_response = SERVER_OK;
                    128:
1.9       joris     129: static char *
                    130: client_get_supported_responses(void)
                    131: {
                    132:        BUF *bp;
                    133:        char *d;
                    134:        int i, first;
                    135:
                    136:        first = 0;
                    137:        bp = cvs_buf_alloc(512, BUF_AUTOEXT);
                    138:        for (i = 0; cvs_responses[i].supported != -1; i++) {
                    139:                if (cvs_responses[i].hdlr == NULL)
                    140:                        continue;
                    141:
                    142:                if (first != 0)
                    143:                        cvs_buf_append(bp, " ", 1);
                    144:                else
                    145:                        first++;
                    146:                cvs_buf_append(bp, cvs_responses[i].name,
                    147:                    strlen(cvs_responses[i].name));
                    148:        }
                    149:
                    150:        cvs_buf_putc(bp, '\0');
                    151:        d = cvs_buf_release(bp);
                    152:        return (d);
                    153: }
1.1       jfb       154:
1.10      joris     155: static void
                    156: client_check_directory(char *data)
                    157: {
                    158:        CVSENTRIES *entlist;
1.54      otto      159:        char entry[CVS_ENT_MAXLINELEN], *parent, *base;
1.10      joris     160:
                    161:        STRIP_SLASH(data);
                    162:
1.69      joris     163:        cvs_mkpath(data, NULL);
1.10      joris     164:
1.90      tobias    165:        if (cvs_cmdop == CVS_OP_EXPORT)
                    166:                return;
                    167:
1.10      joris     168:        if ((base = basename(data)) == NULL)
                    169:                fatal("client_check_directory: overflow");
                    170:
                    171:        if ((parent = dirname(data)) == NULL)
                    172:                fatal("client_check_directory: overflow");
1.11      joris     173:
                    174:        if (!strcmp(parent, "."))
                    175:                return;
1.10      joris     176:
1.57      xsa       177:        (void)xsnprintf(entry, CVS_ENT_MAXLINELEN, "D/%s////", base);
1.10      joris     178:
                    179:        entlist = cvs_ent_open(parent);
                    180:        cvs_ent_add(entlist, entry);
                    181:        cvs_ent_close(entlist, ENT_SYNC);
                    182: }
                    183:
1.9       joris     184: void
                    185: cvs_client_connect_to_server(void)
                    186: {
1.26      xsa       187:        struct cvs_var *vp;
1.9       joris     188:        char *cmd, *argv[9], *resp;
                    189:        int ifd[2], ofd[2], argc;
1.45      joris     190:
                    191:        if (cvs_server_active == 1)
                    192:                fatal("cvs_client_connect: I was already connected to server");
1.1       jfb       193:
1.9       joris     194:        switch (current_cvsroot->cr_method) {
                    195:        case CVS_METHOD_PSERVER:
                    196:        case CVS_METHOD_KSERVER:
                    197:        case CVS_METHOD_GSERVER:
                    198:        case CVS_METHOD_FORK:
                    199:        case CVS_METHOD_EXT:
1.14      joris     200:                fatal("the specified connection method is not supported");
1.9       joris     201:        default:
                    202:                break;
                    203:        }
                    204:
                    205:        if (pipe(ifd) == -1)
                    206:                fatal("cvs_client_connect: %s", strerror(errno));
                    207:        if (pipe(ofd) == -1)
                    208:                fatal("cvs_client_connect: %s", strerror(errno));
                    209:
                    210:        switch (fork()) {
                    211:        case -1:
                    212:                fatal("cvs_client_connect: fork failed: %s", strerror(errno));
                    213:        case 0:
                    214:                if (dup2(ifd[0], STDIN_FILENO) == -1)
                    215:                        fatal("cvs_client_connect: %s", strerror(errno));
                    216:                if (dup2(ofd[1], STDOUT_FILENO) == -1)
                    217:                        fatal("cvs_client_connect: %s", strerror(errno));
1.1       jfb       218:
1.9       joris     219:                close(ifd[1]);
                    220:                close(ofd[0]);
1.1       jfb       221:
1.9       joris     222:                if ((cmd = getenv("CVS_SERVER")) == NULL)
                    223:                        cmd = CVS_SERVER_DEFAULT;
1.1       jfb       224:
                    225:                argc = 0;
                    226:                argv[argc++] = cvs_rsh;
                    227:
1.9       joris     228:                if (current_cvsroot->cr_user != NULL) {
1.1       jfb       229:                        argv[argc++] = "-l";
1.9       joris     230:                        argv[argc++] = current_cvsroot->cr_user;
1.1       jfb       231:                }
                    232:
1.9       joris     233:                argv[argc++] = current_cvsroot->cr_host;
                    234:                argv[argc++] = cmd;
1.1       jfb       235:                argv[argc++] = "server";
                    236:                argv[argc] = NULL;
                    237:
1.9       joris     238:                cvs_log(LP_TRACE, "connecting to server %s",
                    239:                    current_cvsroot->cr_host);
                    240:
1.1       jfb       241:                execvp(argv[0], argv);
1.9       joris     242:                fatal("cvs_client_connect: failed to execute cvs server");
                    243:        default:
                    244:                break;
1.1       jfb       245:        }
                    246:
1.9       joris     247:        close(ifd[0]);
                    248:        close(ofd[1]);
                    249:
                    250:        if ((current_cvsroot->cr_srvin = fdopen(ifd[1], "w")) == NULL)
                    251:                fatal("cvs_client_connect: %s", strerror(errno));
                    252:        if ((current_cvsroot->cr_srvout = fdopen(ofd[0], "r")) == NULL)
                    253:                fatal("cvs_client_connect: %s", strerror(errno));
1.1       jfb       254:
1.9       joris     255:        setvbuf(current_cvsroot->cr_srvin, NULL,_IOLBF, 0);
                    256:        setvbuf(current_cvsroot->cr_srvout, NULL, _IOLBF, 0);
1.1       jfb       257:
1.16      xsa       258:        cvs_client_initlog();
                    259:
1.18      xsa       260:        if (cvs_cmdop != CVS_OP_INIT)
                    261:                cvs_client_send_request("Root %s", current_cvsroot->cr_dir);
1.1       jfb       262:
1.9       joris     263:        resp = client_get_supported_responses();
                    264:        cvs_client_send_request("Valid-responses %s", resp);
                    265:        xfree(resp);
1.1       jfb       266:
1.9       joris     267:        cvs_client_send_request("valid-requests");
                    268:        cvs_client_get_responses();
1.1       jfb       269:
1.28      xsa       270:        cvs_client_send_request("UseUnchanged");
                    271:
1.20      xsa       272:        if (cvs_nolog == 1)
                    273:                cvs_client_send_request("Global_option -l");
                    274:
1.19      xsa       275:        if (cvs_noexec == 1)
                    276:                cvs_client_send_request("Global_option -n");
                    277:
1.76      tobias    278:        switch (verbosity) {
                    279:        case 0:
1.19      xsa       280:                cvs_client_send_request("Global_option -Q");
1.76      tobias    281:                break;
                    282:        case 1:
                    283:                /* Be quiet. This is the default in OpenCVS. */
                    284:                cvs_client_send_request("Global_option -q");
                    285:                break;
                    286:        default:
                    287:                break;
                    288:        }
1.19      xsa       289:
                    290:        if (cvs_readonly == 1)
                    291:                cvs_client_send_request("Global_option -r");
                    292:
                    293:        if (cvs_trace == 1)
1.9       joris     294:                cvs_client_send_request("Global_option -t");
1.26      xsa       295:
                    296:        /* XXX: If 'Set' is supported? */
                    297:        TAILQ_FOREACH(vp, &cvs_variables, cv_link)
                    298:                cvs_client_send_request("Set %s=%s", vp->cv_name, vp->cv_val);
1.1       jfb       299: }
                    300:
1.9       joris     301: void
                    302: cvs_client_send_request(char *fmt, ...)
                    303: {
                    304:        va_list ap;
                    305:        char *data, *s;
                    306:        struct cvs_req *req;
                    307:
                    308:        va_start(ap, fmt);
                    309:        vasprintf(&data, fmt, ap);
                    310:        va_end(ap);
1.1       jfb       311:
1.9       joris     312:        if ((s = strchr(data, ' ')) != NULL)
                    313:                *s = '\0';
1.1       jfb       314:
1.9       joris     315:        req = cvs_remote_get_request_info(data);
                    316:        if (req == NULL)
                    317:                fatal("'%s' is an unknown request", data);
1.1       jfb       318:
1.9       joris     319:        if (req->supported != 1)
                    320:                fatal("remote cvs server does not support '%s'", data);
1.1       jfb       321:
1.9       joris     322:        if (s != NULL)
                    323:                *s = ' ';
1.1       jfb       324:
1.12      joris     325:        cvs_log(LP_TRACE, "%s", data);
1.16      xsa       326:
1.9       joris     327:        cvs_remote_output(data);
                    328:        xfree(data);
                    329: }
1.1       jfb       330:
1.9       joris     331: void
                    332: cvs_client_read_response(void)
1.1       jfb       333: {
1.9       joris     334:        char *cmd, *data;
                    335:        struct cvs_resp *resp;
1.1       jfb       336:
1.9       joris     337:        cmd = cvs_remote_input();
                    338:        if ((data = strchr(cmd, ' ')) != NULL)
                    339:                (*data++) = '\0';
1.1       jfb       340:
1.9       joris     341:        resp = cvs_remote_get_response_info(cmd);
                    342:        if (resp == NULL)
                    343:                fatal("response '%s' is not supported by our client", cmd);
1.1       jfb       344:
1.9       joris     345:        if (resp->hdlr == NULL)
                    346:                fatal("opencvs client does not support '%s'", cmd);
1.16      xsa       347:
1.9       joris     348:        (*resp->hdlr)(data);
1.16      xsa       349:
1.9       joris     350:        xfree(cmd);
1.1       jfb       351: }
                    352:
1.9       joris     353: void
                    354: cvs_client_get_responses(void)
                    355: {
                    356:        while (end_of_response != 1)
                    357:                cvs_client_read_response();
1.1       jfb       358:
1.9       joris     359:        end_of_response = 0;
1.72      joris     360: }
                    361:
                    362: void
                    363: cvs_client_send_logmsg(char *msg)
                    364: {
                    365:        char *buf, *p, *q;
                    366:
                    367:        (void)xasprintf(&buf, "%s\n", msg);
                    368:
                    369:        cvs_client_send_request("Argument -m");
                    370:        if ((p = strchr(buf, '\n')) != NULL)
                    371:                *p++ = '\0';
                    372:        cvs_client_send_request("Argument %s", buf);
                    373:        for (q = p; p != NULL; q = p) {
                    374:                if ((p = strchr(q, '\n')) != NULL) {
                    375:                        *p++ = '\0';
                    376:                        cvs_client_send_request("Argumentx %s", q);
                    377:                }
                    378:        }
                    379:
1.73      joris     380:        xfree(buf);
1.9       joris     381: }
1.1       jfb       382:
1.9       joris     383: void
                    384: cvs_client_senddir(const char *dir)
1.1       jfb       385: {
1.34      xsa       386:        struct stat st;
1.29      xsa       387:        int nb;
1.50      otto      388:        char *d, *date, fpath[MAXPATHLEN], repo[MAXPATHLEN], *tag;
1.29      xsa       389:
                    390:        d = NULL;
1.9       joris     391:
                    392:        if (lastdir != NULL && !strcmp(dir, lastdir))
                    393:                return;
1.1       jfb       394:
1.9       joris     395:        cvs_get_repository_path(dir, repo, MAXPATHLEN);
1.31      xsa       396:
1.81      tobias    397:        if (cvs_cmdop != CVS_OP_RLOG)
1.70      xsa       398:                cvs_client_send_request("Directory %s\n%s", dir, repo);
1.31      xsa       399:
1.58      xsa       400:        (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s",
                    401:            dir, CVS_PATH_STATICENTRIES);
1.34      xsa       402:
                    403:        if (stat(fpath, &st) == 0 && (st.st_mode & (S_IRUSR|S_IRGRP|S_IROTH)))
                    404:                cvs_client_send_request("Static-directory");
                    405:
1.29      xsa       406:        d = xstrdup(dir);
                    407:        cvs_parse_tagfile(d, &tag, &date, &nb);
                    408:
                    409:        if (tag != NULL || date != NULL) {
                    410:                char buf[128];
                    411:
1.82      chl       412:                if (tag != NULL && nb != 0) {
1.29      xsa       413:                        if (strlcpy(buf, "N", sizeof(buf)) >= sizeof(buf))
                    414:                                fatal("cvs_client_senddir: truncation");
                    415:                } else if (tag != NULL) {
                    416:                        if (strlcpy(buf, "T", sizeof(buf)) >= sizeof(buf))
                    417:                                fatal("cvs_client_senddir: truncation");
                    418:                } else {
                    419:                        if (strlcpy(buf, "D", sizeof(buf)) >= sizeof(buf))
                    420:                                fatal("cvs_client_senddir: truncation");
                    421:                }
                    422:
                    423:                if (strlcat(buf, tag ? tag : date, sizeof(buf)) >= sizeof(buf))
                    424:                        fatal("cvs_client_senddir: truncation");
                    425:
                    426:                cvs_client_send_request("Sticky %s", buf);
                    427:
                    428:                if (tag != NULL)
                    429:                        xfree(tag);
                    430:                if (date != NULL)
                    431:                        xfree(date);
                    432:        }
                    433:        if (d != NULL)
                    434:                xfree(d);
1.1       jfb       435:
1.9       joris     436:        if (lastdir != NULL)
                    437:                xfree(lastdir);
                    438:        lastdir = xstrdup(dir);
                    439: }
1.1       jfb       440:
1.9       joris     441: void
                    442: cvs_client_sendfile(struct cvs_file *cf)
1.1       jfb       443: {
1.9       joris     444:        size_t len;
1.92      xsa       445:        char rev[CVS_REV_BUFSZ], timebuf[CVS_TIME_BUFSZ], sticky[CVS_REV_BUFSZ];
1.1       jfb       446:
1.9       joris     447:        if (cf->file_type != CVS_FILE)
                    448:                return;
1.1       jfb       449:
1.9       joris     450:        cvs_client_senddir(cf->file_wd);
                    451:        cvs_remote_classify_file(cf);
                    452:
1.10      joris     453:        if (cf->file_type == CVS_DIR)
                    454:                return;
                    455:
1.85      tobias    456:        if (cf->file_ent != NULL && cvs_cmdop != CVS_OP_IMPORT) {
1.9       joris     457:                if (cf->file_status == FILE_ADDED) {
                    458:                        len = strlcpy(rev, "0", sizeof(rev));
                    459:                        if (len >= sizeof(rev))
                    460:                                fatal("cvs_client_sendfile: truncation");
                    461:
                    462:                        len = strlcpy(timebuf, "Initial ", sizeof(timebuf));
                    463:                        if (len >= sizeof(timebuf))
                    464:                                fatal("cvs_client_sendfile: truncation");
                    465:
                    466:                        len = strlcat(timebuf, cf->file_name, sizeof(timebuf));
                    467:                        if (len >= sizeof(timebuf))
                    468:                                fatal("cvs_client_sendfile: truncation");
                    469:                } else {
                    470:                        rcsnum_tostr(cf->file_ent->ce_rev, rev, sizeof(rev));
                    471:                        ctime_r(&cf->file_ent->ce_mtime, timebuf);
                    472:                }
1.1       jfb       473:
1.9       joris     474:                if (cf->file_ent->ce_conflict == NULL) {
1.88      tobias    475:                        timebuf[strcspn(timebuf, "\n")] = '\0';
1.9       joris     476:                } else {
                    477:                        len = strlcpy(timebuf, cf->file_ent->ce_conflict,
                    478:                            sizeof(timebuf));
                    479:                        if (len >= sizeof(timebuf))
                    480:                                fatal("cvs_client_sendfile: truncation");
1.56      joris     481:                        len = strlcat(timebuf, "+", sizeof(timebuf));
                    482:                        if (len >= sizeof(timebuf))
                    483:                                fatal("cvs_client_sendfile: truncation");
1.9       joris     484:                }
1.1       jfb       485:
1.9       joris     486:                sticky[0] = '\0';
                    487:                if (cf->file_ent->ce_tag != NULL) {
1.57      xsa       488:                        (void)xsnprintf(sticky, sizeof(sticky), "T%s",
1.9       joris     489:                            cf->file_ent->ce_tag);
1.1       jfb       490:                }
                    491:
1.55      otto      492:                cvs_client_send_request("Entry /%s/%s%s/%s/%s/%s",
1.9       joris     493:                    cf->file_name, (cf->file_status == FILE_REMOVED) ? "-" : "",
1.53      xsa       494:                    rev, timebuf, cf->file_ent->ce_opts ?
                    495:                    cf->file_ent->ce_opts : "", sticky);
1.9       joris     496:        }
                    497:
1.84      tobias    498:        if (cvs_cmdop == CVS_OP_ADD)
                    499:                cf->file_status = FILE_MODIFIED;
                    500:
1.9       joris     501:        switch (cf->file_status) {
                    502:        case FILE_UNKNOWN:
                    503:                if (cf->fd != -1)
                    504:                        cvs_client_send_request("Questionable %s",
                    505:                            cf->file_name);
                    506:                break;
                    507:        case FILE_ADDED:
                    508:        case FILE_MODIFIED:
                    509:                cvs_client_send_request("Modified %s", cf->file_name);
                    510:                cvs_remote_send_file(cf->file_path);
                    511:                break;
                    512:        case FILE_UPTODATE:
                    513:                cvs_client_send_request("Unchanged %s", cf->file_name);
                    514:                break;
1.1       jfb       515:        }
1.9       joris     516: }
1.1       jfb       517:
1.9       joris     518: void
                    519: cvs_client_send_files(char **argv, int argc)
                    520: {
                    521:        int i;
1.1       jfb       522:
1.9       joris     523:        for (i = 0; i < argc; i++)
                    524:                cvs_client_send_request("Argument %s", argv[i]);
                    525: }
1.1       jfb       526:
1.9       joris     527: void
                    528: cvs_client_ok(char *data)
                    529: {
                    530:        end_of_response = 1;
1.37      joris     531:        server_response = SERVER_OK;
1.1       jfb       532: }
                    533:
1.9       joris     534: void
                    535: cvs_client_error(char *data)
                    536: {
                    537:        end_of_response = 1;
1.37      joris     538:        server_response = SERVER_ERROR;
1.9       joris     539: }
1.1       jfb       540:
1.9       joris     541: void
                    542: cvs_client_validreq(char *data)
1.1       jfb       543: {
1.9       joris     544:        int i;
                    545:        char *sp, *ep;
                    546:        struct cvs_req *req;
                    547:
1.62      ray       548:        if ((sp = data) == NULL)
                    549:                fatal("Missing argument for Valid-requests");
                    550:
1.9       joris     551:        do {
                    552:                if ((ep = strchr(sp, ' ')) != NULL)
                    553:                        *ep = '\0';
                    554:
                    555:                req = cvs_remote_get_request_info(sp);
                    556:                if (req != NULL)
                    557:                        req->supported = 1;
                    558:
                    559:                if (ep != NULL)
                    560:                        sp = ep + 1;
                    561:        } while (ep != NULL);
                    562:
                    563:        for (i = 0; cvs_requests[i].supported != -1; i++) {
                    564:                req = &cvs_requests[i];
                    565:                if ((req->flags & REQ_NEEDED) &&
                    566:                    req->supported != 1) {
                    567:                        fatal("server does not support required '%s'",
                    568:                            req->name);
                    569:                }
1.1       jfb       570:        }
1.9       joris     571: }
1.1       jfb       572:
1.9       joris     573: void
                    574: cvs_client_e(char *data)
                    575: {
1.62      ray       576:        if (data == NULL)
                    577:                fatal("Missing argument for E");
                    578:
1.80      tobias    579:        fprintf(stderr, "%s\n", data);
1.9       joris     580: }
1.1       jfb       581:
1.9       joris     582: void
                    583: cvs_client_m(char *data)
                    584: {
1.62      ray       585:        if (data == NULL)
                    586:                fatal("Missing argument for M");
                    587:
1.80      tobias    588:        puts(data);
1.9       joris     589: }
1.1       jfb       590:
1.9       joris     591: void
                    592: cvs_client_checkedin(char *data)
                    593: {
                    594:        CVSENTRIES *entlist;
                    595:        struct cvs_ent *ent, *newent;
1.84      tobias    596:        size_t len;
1.67      xsa       597:        char *dir, *e, entry[CVS_ENT_MAXLINELEN], rev[CVS_REV_BUFSZ];
                    598:        char sticky[CVS_ENT_MAXLINELEN], timebuf[CVS_TIME_BUFSZ];
1.1       jfb       599:
1.62      ray       600:        if (data == NULL)
                    601:                fatal("Missing argument for Checked-in");
                    602:
1.9       joris     603:        dir = cvs_remote_input();
1.54      otto      604:        e = cvs_remote_input();
1.9       joris     605:        xfree(dir);
1.1       jfb       606:
1.9       joris     607:        entlist = cvs_ent_open(data);
1.54      otto      608:        newent = cvs_ent_parse(e);
1.9       joris     609:        ent = cvs_ent_get(entlist, newent->ce_name);
1.54      otto      610:        xfree(e);
1.1       jfb       611:
1.9       joris     612:        rcsnum_tostr(newent->ce_rev, rev, sizeof(rev));
1.1       jfb       613:
1.9       joris     614:        sticky[0] = '\0';
1.84      tobias    615:        if (ent == NULL) {
                    616:                len = strlcpy(rev, "0", sizeof(rev));
                    617:                if (len >= sizeof(rev))
                    618:                        fatal("cvs_client_sendfile: truncation");
                    619:
                    620:                len = strlcpy(timebuf, "Initial ", sizeof(timebuf));
                    621:                if (len >= sizeof(timebuf))
                    622:                        fatal("cvs_client_sendfile: truncation");
                    623:
                    624:                len = strlcat(timebuf, newent->ce_name, sizeof(timebuf));
                    625:                if (len >= sizeof(timebuf))
                    626:                        fatal("cvs_client_sendfile: truncation");
                    627:        } else {
                    628:                ctime_r(&ent->ce_mtime, timebuf);
                    629:                timebuf[strcspn(timebuf, "\n")] = '\0';
                    630:
                    631:                if (newent->ce_tag != NULL)
                    632:                        (void)xsnprintf(sticky, sizeof(sticky), "T%s",
                    633:                            ent->ce_tag);
                    634:                newent->ce_opts = ent->ce_opts;
                    635:
                    636:                cvs_ent_free(ent);
                    637:        }
1.1       jfb       638:
1.57      xsa       639:        (void)xsnprintf(entry, CVS_ENT_MAXLINELEN, "/%s/%s%s/%s/%s/%s",
1.44      joris     640:            newent->ce_name, (newent->ce_status == CVS_ENT_REMOVED) ? "-" : "",
1.84      tobias    641:            rev, timebuf, newent->ce_opts ? newent->ce_opts : "", sticky);
1.9       joris     642:
                    643:        cvs_ent_free(newent);
                    644:        cvs_ent_add(entlist, entry);
                    645:        cvs_ent_close(entlist, ENT_SYNC);
1.1       jfb       646: }
                    647:
1.9       joris     648: void
                    649: cvs_client_updated(char *data)
                    650: {
1.57      xsa       651:        int fd;
1.9       joris     652:        time_t now;
1.51      otto      653:        mode_t fmode, mask;
1.9       joris     654:        size_t flen;
                    655:        CVSENTRIES *ent;
                    656:        struct cvs_ent *e;
                    657:        const char *errstr;
                    658:        struct timeval tv[2];
1.67      xsa       659:        char repo[MAXPATHLEN], entry[CVS_ENT_MAXLINELEN];
                    660:        char timebuf[CVS_TIME_BUFSZ], revbuf[CVS_REV_BUFSZ];
                    661:        char *en, *mode, *len, *fpath, *rpath, *wdir;
1.69      joris     662:        char sticky[CVS_ENT_MAXLINELEN];
1.9       joris     663:
1.62      ray       664:        if (data == NULL)
                    665:                fatal("Missing argument for Updated");
                    666:
1.10      joris     667:        client_check_directory(data);
1.9       joris     668:
                    669:        rpath = cvs_remote_input();
1.54      otto      670:        en = cvs_remote_input();
1.9       joris     671:        mode = cvs_remote_input();
                    672:        len = cvs_remote_input();
                    673:
                    674:        cvs_get_repository_path(".", repo, MAXPATHLEN);
1.48      joris     675:
                    676:        STRIP_SLASH(repo);
1.9       joris     677:
                    678:        if (strlen(repo) + 1 > strlen(rpath))
                    679:                fatal("received a repository path that is too short");
                    680:
                    681:        fpath = rpath + strlen(repo) + 1;
                    682:        if ((wdir = dirname(fpath)) == NULL)
                    683:                fatal("cvs_client_updated: dirname: %s", strerror(errno));
                    684:
                    685:        flen = strtonum(len, 0, INT_MAX, &errstr);
                    686:        if (errstr != NULL)
                    687:                fatal("cvs_client_updated: %s: %s", len, errstr);
                    688:        xfree(len);
                    689:
                    690:        cvs_strtomode(mode, &fmode);
                    691:        xfree(mode);
1.51      otto      692:        mask = umask(0);
                    693:        umask(mask);
                    694:        fmode &= ~mask;
1.9       joris     695:
                    696:        time(&now);
1.52      joris     697:        asctime_r(gmtime(&now), timebuf);
1.88      tobias    698:        timebuf[strcspn(timebuf, "\n")] = '\0';
1.9       joris     699:
1.54      otto      700:        e = cvs_ent_parse(en);
                    701:        xfree(en);
1.69      joris     702:
                    703:        sticky[0] = '\0';
                    704:        if (e->ce_tag != NULL)
                    705:                (void)xsnprintf(sticky, sizeof(sticky), "T%s", e->ce_tag);
                    706:
1.9       joris     707:        rcsnum_tostr(e->ce_rev, revbuf, sizeof(revbuf));
1.69      joris     708:        (void)xsnprintf(entry, CVS_ENT_MAXLINELEN, "/%s/%s/%s/%s/%s",
                    709:            e->ce_name, revbuf, timebuf,
                    710:            e->ce_opts ? e->ce_opts : "", sticky);
1.9       joris     711:
                    712:        cvs_ent_free(e);
1.90      tobias    713:
                    714:        if (cvs_cmdop != CVS_OP_EXPORT) {
                    715:                ent = cvs_ent_open(wdir);
                    716:                cvs_ent_add(ent, entry);
                    717:                cvs_ent_close(ent, ENT_SYNC);
                    718:        }
1.9       joris     719:
                    720:        if ((fd = open(fpath, O_CREAT | O_WRONLY | O_TRUNC)) == -1)
                    721:                fatal("cvs_client_updated: open: %s: %s",
                    722:                    fpath, strerror(errno));
1.1       jfb       723:
1.46      joris     724:        cvs_remote_receive_file(fd, flen);
1.1       jfb       725:
1.9       joris     726:        tv[0].tv_sec = now;
                    727:        tv[0].tv_usec = 0;
                    728:        tv[1] = tv[0];
1.1       jfb       729:
1.9       joris     730:        if (futimes(fd, tv) == -1)
                    731:                fatal("cvs_client_updated: futimes: %s", strerror(errno));
1.1       jfb       732:
1.9       joris     733:        if (fchmod(fd, fmode) == -1)
                    734:                fatal("cvs_client_updated: fchmod: %s", strerror(errno));
1.1       jfb       735:
1.9       joris     736:        (void)close(fd);
1.1       jfb       737:
1.9       joris     738:        xfree(rpath);
1.1       jfb       739: }
                    740:
1.9       joris     741: void
                    742: cvs_client_merged(char *data)
                    743: {
1.56      joris     744:        int fd;
                    745:        time_t now;
1.83      tobias    746:        mode_t fmode, mask;
1.56      joris     747:        size_t flen;
                    748:        CVSENTRIES *ent;
                    749:        const char *errstr;
                    750:        struct timeval tv[2];
1.67      xsa       751:        char timebuf[CVS_TIME_BUFSZ], *repo, *rpath, *entry, *mode;
1.56      joris     752:        char *len, *fpath, *wdir;
                    753:
1.62      ray       754:        if (data == NULL)
                    755:                fatal("Missing argument for Merged");
                    756:
1.56      joris     757:        client_check_directory(data);
                    758:
                    759:        rpath = cvs_remote_input();
                    760:        entry = cvs_remote_input();
                    761:        mode = cvs_remote_input();
                    762:        len = cvs_remote_input();
                    763:
                    764:        repo = xmalloc(MAXPATHLEN);
                    765:        cvs_get_repository_path(".", repo, MAXPATHLEN);
                    766:
                    767:        STRIP_SLASH(repo);
                    768:
                    769:        if (strlen(repo) + 1 > strlen(rpath))
                    770:                fatal("received a repository path that is too short");
                    771:
                    772:        fpath = rpath + strlen(repo) + 1;
                    773:        if ((wdir = dirname(fpath)) == NULL)
                    774:                fatal("cvs_client_merged: dirname: %s", strerror(errno));
                    775:        xfree(repo);
                    776:
                    777:        flen = strtonum(len, 0, INT_MAX, &errstr);
                    778:        if (errstr != NULL)
                    779:                fatal("cvs_client_merged: %s: %s", len, errstr);
                    780:        xfree(len);
                    781:
                    782:        cvs_strtomode(mode, &fmode);
                    783:        xfree(mode);
1.83      tobias    784:        mask = umask(0);
                    785:        umask(mask);
                    786:        fmode &= ~mask;
1.56      joris     787:
                    788:        time(&now);
                    789:        asctime_r(gmtime(&now), timebuf);
1.88      tobias    790:        timebuf[strcspn(timebuf, "\n")] = '\0';
1.56      joris     791:
                    792:        ent = cvs_ent_open(wdir);
                    793:        cvs_ent_add(ent, entry);
                    794:        cvs_ent_close(ent, ENT_SYNC);
1.86      tobias    795:        xfree(entry);
1.56      joris     796:
                    797:        if ((fd = open(fpath, O_CREAT | O_WRONLY | O_TRUNC)) == -1)
                    798:                fatal("cvs_client_merged: open: %s: %s",
                    799:                    fpath, strerror(errno));
                    800:
                    801:        cvs_remote_receive_file(fd, flen);
                    802:
                    803:        tv[0].tv_sec = now;
                    804:        tv[0].tv_usec = 0;
                    805:        tv[1] = tv[0];
                    806:
                    807:        if (futimes(fd, tv) == -1)
                    808:                fatal("cvs_client_merged: futimes: %s", strerror(errno));
                    809:
                    810:        if (fchmod(fd, fmode) == -1)
                    811:                fatal("cvs_client_merged: fchmod: %s", strerror(errno));
                    812:
                    813:        (void)close(fd);
                    814:
                    815:        xfree(rpath);
1.9       joris     816: }
1.1       jfb       817:
1.9       joris     818: void
                    819: cvs_client_removed(char *data)
                    820: {
1.65      joris     821:        CVSENTRIES *entlist;
                    822:        char *rpath, *filename, fpath[MAXPATHLEN];
1.91      tobias    823:
                    824:        if (data == NULL)
                    825:                fatal("Missing argument for Removed");
1.65      joris     826:
                    827:        rpath = cvs_remote_input();
                    828:        if ((filename = strrchr(rpath, '/')) == NULL)
                    829:                fatal("bad rpath in cvs_client_removed: %s", rpath);
                    830:        filename++;
                    831:
                    832:        entlist = cvs_ent_open(data);
                    833:        cvs_ent_remove(entlist, filename);
                    834:        cvs_ent_close(entlist, ENT_SYNC);
                    835:
                    836:        (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s", data, filename);
                    837:        (void)unlink(fpath);
1.13      joris     838:
1.65      joris     839:        xfree(rpath);
1.9       joris     840: }
1.1       jfb       841:
1.9       joris     842: void
                    843: cvs_client_remove_entry(char *data)
1.1       jfb       844: {
1.38      xsa       845:        CVSENTRIES *entlist;
1.44      joris     846:        char *filename, *rpath;
1.41      joris     847:
1.62      ray       848:        if (data == NULL)
                    849:                fatal("Missing argument for Remove-entry");
                    850:
1.41      joris     851:        rpath = cvs_remote_input();
                    852:        if ((filename = strrchr(rpath, '/')) == NULL)
                    853:                fatal("bad rpath in cvs_client_remove_entry: %s", rpath);
1.61      ray       854:        filename++;
1.1       jfb       855:
1.38      xsa       856:        entlist = cvs_ent_open(data);
1.44      joris     857:        cvs_ent_remove(entlist, filename);
1.38      xsa       858:        cvs_ent_close(entlist, ENT_SYNC);
                    859:
1.44      joris     860:        xfree(rpath);
1.36      xsa       861: }
                    862:
                    863: void
                    864: cvs_client_set_static_directory(char *data)
                    865: {
                    866:        FILE *fp;
1.50      otto      867:        char *dir, fpath[MAXPATHLEN];
1.36      xsa       868:
1.62      ray       869:        if (data == NULL)
                    870:                fatal("Missing argument for Set-static-directory");
                    871:
1.36      xsa       872:        STRIP_SLASH(data);
                    873:
                    874:        dir = cvs_remote_input();
                    875:        xfree(dir);
                    876:
1.90      tobias    877:        if (cvs_cmdop == CVS_OP_EXPORT)
                    878:                return;
                    879:
1.58      xsa       880:        (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s",
                    881:            data, CVS_PATH_STATICENTRIES);
1.36      xsa       882:
                    883:        if ((fp = fopen(fpath, "w+")) == NULL) {
                    884:                cvs_log(LP_ERRNO, "%s", fpath);
1.50      otto      885:                return;
1.36      xsa       886:        }
                    887:        (void)fclose(fp);
1.16      xsa       888: }
1.35      xsa       889:
                    890: void
                    891: cvs_client_clear_static_directory(char *data)
                    892: {
1.50      otto      893:        char *dir, fpath[MAXPATHLEN];
1.35      xsa       894:
1.62      ray       895:        if (data == NULL)
                    896:                fatal("Missing argument for Clear-static-directory");
                    897:
1.35      xsa       898:        STRIP_SLASH(data);
                    899:
                    900:        dir = cvs_remote_input();
                    901:        xfree(dir);
                    902:
1.90      tobias    903:        if (cvs_cmdop == CVS_OP_EXPORT)
                    904:                return;
                    905:
1.58      xsa       906:        (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s",
                    907:            data, CVS_PATH_STATICENTRIES);
1.35      xsa       908:
                    909:        (void)cvs_unlink(fpath);
                    910: }
                    911:
                    912: void
                    913: cvs_client_set_sticky(char *data)
                    914: {
                    915:        FILE *fp;
1.50      otto      916:        char *dir, *tag, tagpath[MAXPATHLEN];
1.35      xsa       917:
1.62      ray       918:        if (data == NULL)
                    919:                fatal("Missing argument for Set-sticky");
                    920:
1.35      xsa       921:        STRIP_SLASH(data);
                    922:
                    923:        dir = cvs_remote_input();
                    924:        xfree(dir);
                    925:        tag = cvs_remote_input();
                    926:
1.90      tobias    927:        if (cvs_cmdop == CVS_OP_EXPORT)
                    928:                goto out;
                    929:
1.69      joris     930:        client_check_directory(data);
                    931:
1.58      xsa       932:        (void)xsnprintf(tagpath, MAXPATHLEN, "%s/%s", data, CVS_PATH_TAG);
1.35      xsa       933:
                    934:        if ((fp = fopen(tagpath, "w+")) == NULL) {
                    935:                cvs_log(LP_ERRNO, "%s", tagpath);
                    936:                goto out;
                    937:        }
                    938:
                    939:        (void)fprintf(fp, "%s\n", tag);
                    940:        (void)fclose(fp);
                    941: out:
                    942:        xfree(tag);
                    943: }
                    944:
                    945: void
                    946: cvs_client_clear_sticky(char *data)
                    947: {
1.50      otto      948:        char *dir, tagpath[MAXPATHLEN];
1.47      xsa       949:
1.62      ray       950:        if (data == NULL)
                    951:                fatal("Missing argument for Clear-sticky");
1.35      xsa       952:
                    953:        STRIP_SLASH(data);
                    954:
                    955:        dir = cvs_remote_input();
                    956:        xfree(dir);
1.90      tobias    957:
                    958:        if (cvs_cmdop == CVS_OP_EXPORT)
                    959:                return;
1.35      xsa       960:
1.69      joris     961:        client_check_directory(data);
                    962:
1.58      xsa       963:        (void)xsnprintf(tagpath, MAXPATHLEN, "%s/%s", data, CVS_PATH_TAG);
1.69      joris     964:        (void)unlink(tagpath);
1.35      xsa       965: }
                    966:
                    967:
1.16      xsa       968: /*
                    969:  * cvs_client_initlog()
                    970:  *
                    971:  * Initialize protocol logging if the CVS_CLIENT_LOG environment variable is
                    972:  * set.  In this case, the variable's value is used as a path to which the
                    973:  * appropriate suffix is added (".in" for client input and ".out" for server
                    974:  * output).
                    975:  */
                    976: static void
                    977: cvs_client_initlog(void)
                    978: {
                    979:        u_int i;
                    980:        char *env, *envdup, buf[MAXPATHLEN], fpath[MAXPATHLEN];
                    981:        char rpath[MAXPATHLEN], *s;
                    982:        struct stat st;
                    983:        time_t now;
                    984:        struct passwd *pwd;
                    985:
                    986:        /* avoid doing it more than once */
                    987:        if (cvs_client_logon)
                    988:                return;
                    989:
                    990:        if ((env = getenv("CVS_CLIENT_LOG")) == NULL)
                    991:                return;
                    992:
                    993:        envdup = xstrdup(env);
                    994:        if ((s = strchr(envdup, '%')) != NULL)
                    995:                *s = '\0';
                    996:
                    997:        if (strlcpy(buf, env, sizeof(buf)) >= sizeof(buf))
                    998:                fatal("cvs_client_initlog: truncation");
                    999:
                   1000:        if (strlcpy(rpath, envdup, sizeof(rpath)) >= sizeof(rpath))
                   1001:                fatal("cvs_client_initlog: truncation");
                   1002:
                   1003:        xfree(envdup);
                   1004:
                   1005:        s = buf;
                   1006:        while ((s = strchr(s, '%')) != NULL) {
                   1007:                s++;
                   1008:                switch (*s) {
                   1009:                case 'c':
1.87      tobias   1010:                        if (strlcpy(fpath, cmdp->cmd_name, sizeof(fpath)) >=
1.16      xsa      1011:                            sizeof(fpath))
                   1012:                                fatal("cvs_client_initlog: truncation");
                   1013:                        break;
                   1014:                case 'd':
                   1015:                        time(&now);
                   1016:                        if (strlcpy(fpath, ctime(&now), sizeof(fpath)) >=
                   1017:                            sizeof(fpath))
                   1018:                                fatal("cvs_client_initlog: truncation");
                   1019:                        break;
                   1020:                case 'p':
1.57      xsa      1021:                        (void)xsnprintf(fpath, sizeof(fpath), "%d", getpid());
1.16      xsa      1022:                        break;
                   1023:                case 'u':
                   1024:                        if ((pwd = getpwuid(getuid())) != NULL) {
                   1025:                                if (strlcpy(fpath, pwd->pw_name,
                   1026:                                    sizeof(fpath)) >= sizeof(fpath))
                   1027:                                        fatal("cvs_client_initlog: truncation");
                   1028:                        } else {
                   1029:                                fpath[0] = '\0';
                   1030:                        }
                   1031:                        endpwent();
                   1032:                        break;
                   1033:                default:
                   1034:                        fpath[0] = '\0';
                   1035:                        break;
                   1036:                }
                   1037:
                   1038:                if (fpath[0] != '\0') {
                   1039:                        if (strlcat(rpath, "-", sizeof(rpath)) >= sizeof(rpath))
                   1040:                                fatal("cvs_client_initlog: truncation");
                   1041:
                   1042:                        if (strlcat(rpath, fpath, sizeof(rpath))
                   1043:                            >= sizeof(rpath))
                   1044:                                fatal("cvs_client_initlog: truncation");
                   1045:                }
                   1046:        }
                   1047:
                   1048:        for (i = 0; i < UINT_MAX; i++) {
1.57      xsa      1049:                (void)xsnprintf(fpath, sizeof(fpath), "%s-%d.in", rpath, i);
1.16      xsa      1050:
                   1051:                if (stat(fpath, &st) != -1)
                   1052:                        continue;
                   1053:
                   1054:                if (errno != ENOENT)
                   1055:                        fatal("cvs_client_initlog() stat failed '%s'",
                   1056:                            strerror(errno));
                   1057:
                   1058:                break;
                   1059:        }
                   1060:
                   1061:        if ((cvs_client_inlog_fd = open(fpath,
1.60      xsa      1062:            O_RDWR | O_CREAT | O_TRUNC, 0644)) == -1) {
1.16      xsa      1063:                fatal("cvs_client_initlog: open `%s': %s",
                   1064:                    fpath, strerror(errno));
                   1065:        }
                   1066:
                   1067:        for (i = 0; i < UINT_MAX; i++) {
1.57      xsa      1068:                (void)xsnprintf(fpath, sizeof(fpath), "%s-%d.out", rpath, i);
1.16      xsa      1069:
                   1070:                if (stat(fpath, &st) != -1)
                   1071:                        continue;
                   1072:
                   1073:                if (errno != ENOENT)
                   1074:                        fatal("cvs_client_initlog() stat failed '%s'",
                   1075:                            strerror(errno));
                   1076:
                   1077:                break;
                   1078:        }
                   1079:
1.93      xsa      1080:        if ((cvs_client_outlog_fd = open(fpath,
1.60      xsa      1081:            O_RDWR | O_CREAT | O_TRUNC, 0644)) == -1) {
1.16      xsa      1082:                fatal("cvs_client_initlog: open `%s': %s",
                   1083:                    fpath, strerror(errno));
                   1084:        }
                   1085:
                   1086:        cvs_client_logon = 1;
1.1       jfb      1087: }