[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.101

1.101   ! joris       1: /*     $OpenBSD: client.c,v 1.100 2008/02/05 21:49:29 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 },
1.99      tobias     89:        { "rdiff",              0,      cvs_server_rdiff, 0 },
1.95      xsa        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.98      joris     111: static void     client_check_directory(char *, char *);
1.16      xsa       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
1.98      joris     156: client_check_directory(char *data, char *repository)
1.10      joris     157: {
                    158:        CVSENTRIES *entlist;
1.98      joris     159:        char entry[CVS_ENT_MAXLINELEN], *parent, *base, *p;
1.10      joris     160:
                    161:        STRIP_SLASH(data);
                    162:
1.98      joris     163:        /* first directory we get is our module root */
1.101   ! joris     164:        if (module_repo_root == NULL && checkout_target_dir != NULL) {
1.98      joris     165:                p = repository + strlen(current_cvsroot->cr_dir) + 1;
                    166:                module_repo_root = xstrdup(p);
                    167:                p = strrchr(module_repo_root, '/');
                    168:                if (p != NULL)
                    169:                        *p = '\0';
                    170:        }
                    171:
1.69      joris     172:        cvs_mkpath(data, NULL);
1.10      joris     173:
1.90      tobias    174:        if (cvs_cmdop == CVS_OP_EXPORT)
                    175:                return;
                    176:
1.10      joris     177:        if ((base = basename(data)) == NULL)
                    178:                fatal("client_check_directory: overflow");
                    179:
                    180:        if ((parent = dirname(data)) == NULL)
                    181:                fatal("client_check_directory: overflow");
1.11      joris     182:
                    183:        if (!strcmp(parent, "."))
                    184:                return;
1.10      joris     185:
1.57      xsa       186:        (void)xsnprintf(entry, CVS_ENT_MAXLINELEN, "D/%s////", base);
1.10      joris     187:
                    188:        entlist = cvs_ent_open(parent);
                    189:        cvs_ent_add(entlist, entry);
                    190:        cvs_ent_close(entlist, ENT_SYNC);
                    191: }
                    192:
1.9       joris     193: void
                    194: cvs_client_connect_to_server(void)
                    195: {
1.26      xsa       196:        struct cvs_var *vp;
1.9       joris     197:        char *cmd, *argv[9], *resp;
                    198:        int ifd[2], ofd[2], argc;
1.45      joris     199:
                    200:        if (cvs_server_active == 1)
                    201:                fatal("cvs_client_connect: I was already connected to server");
1.1       jfb       202:
1.9       joris     203:        switch (current_cvsroot->cr_method) {
                    204:        case CVS_METHOD_PSERVER:
                    205:        case CVS_METHOD_KSERVER:
                    206:        case CVS_METHOD_GSERVER:
                    207:        case CVS_METHOD_FORK:
                    208:        case CVS_METHOD_EXT:
1.14      joris     209:                fatal("the specified connection method is not supported");
1.9       joris     210:        default:
                    211:                break;
                    212:        }
                    213:
                    214:        if (pipe(ifd) == -1)
                    215:                fatal("cvs_client_connect: %s", strerror(errno));
                    216:        if (pipe(ofd) == -1)
                    217:                fatal("cvs_client_connect: %s", strerror(errno));
                    218:
                    219:        switch (fork()) {
                    220:        case -1:
                    221:                fatal("cvs_client_connect: fork failed: %s", strerror(errno));
                    222:        case 0:
                    223:                if (dup2(ifd[0], STDIN_FILENO) == -1)
                    224:                        fatal("cvs_client_connect: %s", strerror(errno));
                    225:                if (dup2(ofd[1], STDOUT_FILENO) == -1)
                    226:                        fatal("cvs_client_connect: %s", strerror(errno));
1.1       jfb       227:
1.9       joris     228:                close(ifd[1]);
                    229:                close(ofd[0]);
1.1       jfb       230:
1.9       joris     231:                if ((cmd = getenv("CVS_SERVER")) == NULL)
                    232:                        cmd = CVS_SERVER_DEFAULT;
1.1       jfb       233:
                    234:                argc = 0;
                    235:                argv[argc++] = cvs_rsh;
                    236:
1.9       joris     237:                if (current_cvsroot->cr_user != NULL) {
1.1       jfb       238:                        argv[argc++] = "-l";
1.9       joris     239:                        argv[argc++] = current_cvsroot->cr_user;
1.1       jfb       240:                }
                    241:
1.9       joris     242:                argv[argc++] = current_cvsroot->cr_host;
                    243:                argv[argc++] = cmd;
1.1       jfb       244:                argv[argc++] = "server";
                    245:                argv[argc] = NULL;
                    246:
1.9       joris     247:                cvs_log(LP_TRACE, "connecting to server %s",
                    248:                    current_cvsroot->cr_host);
                    249:
1.1       jfb       250:                execvp(argv[0], argv);
1.9       joris     251:                fatal("cvs_client_connect: failed to execute cvs server");
                    252:        default:
                    253:                break;
1.1       jfb       254:        }
                    255:
1.9       joris     256:        close(ifd[0]);
                    257:        close(ofd[1]);
                    258:
                    259:        if ((current_cvsroot->cr_srvin = fdopen(ifd[1], "w")) == NULL)
                    260:                fatal("cvs_client_connect: %s", strerror(errno));
                    261:        if ((current_cvsroot->cr_srvout = fdopen(ofd[0], "r")) == NULL)
                    262:                fatal("cvs_client_connect: %s", strerror(errno));
1.1       jfb       263:
1.9       joris     264:        setvbuf(current_cvsroot->cr_srvin, NULL,_IOLBF, 0);
                    265:        setvbuf(current_cvsroot->cr_srvout, NULL, _IOLBF, 0);
1.1       jfb       266:
1.16      xsa       267:        cvs_client_initlog();
                    268:
1.18      xsa       269:        if (cvs_cmdop != CVS_OP_INIT)
                    270:                cvs_client_send_request("Root %s", current_cvsroot->cr_dir);
1.1       jfb       271:
1.9       joris     272:        resp = client_get_supported_responses();
                    273:        cvs_client_send_request("Valid-responses %s", resp);
                    274:        xfree(resp);
1.1       jfb       275:
1.9       joris     276:        cvs_client_send_request("valid-requests");
                    277:        cvs_client_get_responses();
1.1       jfb       278:
1.28      xsa       279:        cvs_client_send_request("UseUnchanged");
                    280:
1.20      xsa       281:        if (cvs_nolog == 1)
                    282:                cvs_client_send_request("Global_option -l");
                    283:
1.19      xsa       284:        if (cvs_noexec == 1)
                    285:                cvs_client_send_request("Global_option -n");
                    286:
1.76      tobias    287:        switch (verbosity) {
                    288:        case 0:
1.19      xsa       289:                cvs_client_send_request("Global_option -Q");
1.76      tobias    290:                break;
                    291:        case 1:
                    292:                /* Be quiet. This is the default in OpenCVS. */
                    293:                cvs_client_send_request("Global_option -q");
                    294:                break;
                    295:        default:
                    296:                break;
                    297:        }
1.19      xsa       298:
                    299:        if (cvs_readonly == 1)
                    300:                cvs_client_send_request("Global_option -r");
                    301:
                    302:        if (cvs_trace == 1)
1.9       joris     303:                cvs_client_send_request("Global_option -t");
1.26      xsa       304:
                    305:        /* XXX: If 'Set' is supported? */
                    306:        TAILQ_FOREACH(vp, &cvs_variables, cv_link)
                    307:                cvs_client_send_request("Set %s=%s", vp->cv_name, vp->cv_val);
1.1       jfb       308: }
                    309:
1.9       joris     310: void
                    311: cvs_client_send_request(char *fmt, ...)
                    312: {
                    313:        va_list ap;
                    314:        char *data, *s;
                    315:        struct cvs_req *req;
                    316:
                    317:        va_start(ap, fmt);
                    318:        vasprintf(&data, fmt, ap);
                    319:        va_end(ap);
1.1       jfb       320:
1.9       joris     321:        if ((s = strchr(data, ' ')) != NULL)
                    322:                *s = '\0';
1.1       jfb       323:
1.9       joris     324:        req = cvs_remote_get_request_info(data);
                    325:        if (req == NULL)
                    326:                fatal("'%s' is an unknown request", data);
1.1       jfb       327:
1.9       joris     328:        if (req->supported != 1)
                    329:                fatal("remote cvs server does not support '%s'", data);
1.1       jfb       330:
1.9       joris     331:        if (s != NULL)
                    332:                *s = ' ';
1.1       jfb       333:
1.12      joris     334:        cvs_log(LP_TRACE, "%s", data);
1.16      xsa       335:
1.9       joris     336:        cvs_remote_output(data);
                    337:        xfree(data);
                    338: }
1.1       jfb       339:
1.9       joris     340: void
                    341: cvs_client_read_response(void)
1.1       jfb       342: {
1.9       joris     343:        char *cmd, *data;
                    344:        struct cvs_resp *resp;
1.1       jfb       345:
1.9       joris     346:        cmd = cvs_remote_input();
                    347:        if ((data = strchr(cmd, ' ')) != NULL)
                    348:                (*data++) = '\0';
1.1       jfb       349:
1.9       joris     350:        resp = cvs_remote_get_response_info(cmd);
                    351:        if (resp == NULL)
                    352:                fatal("response '%s' is not supported by our client", cmd);
1.1       jfb       353:
1.9       joris     354:        if (resp->hdlr == NULL)
                    355:                fatal("opencvs client does not support '%s'", cmd);
1.16      xsa       356:
1.9       joris     357:        (*resp->hdlr)(data);
1.16      xsa       358:
1.9       joris     359:        xfree(cmd);
1.1       jfb       360: }
                    361:
1.9       joris     362: void
                    363: cvs_client_get_responses(void)
                    364: {
                    365:        while (end_of_response != 1)
                    366:                cvs_client_read_response();
1.1       jfb       367:
1.9       joris     368:        end_of_response = 0;
1.72      joris     369: }
                    370:
                    371: void
                    372: cvs_client_send_logmsg(char *msg)
                    373: {
                    374:        char *buf, *p, *q;
                    375:
                    376:        (void)xasprintf(&buf, "%s\n", msg);
                    377:
                    378:        cvs_client_send_request("Argument -m");
                    379:        if ((p = strchr(buf, '\n')) != NULL)
                    380:                *p++ = '\0';
                    381:        cvs_client_send_request("Argument %s", buf);
                    382:        for (q = p; p != NULL; q = p) {
                    383:                if ((p = strchr(q, '\n')) != NULL) {
                    384:                        *p++ = '\0';
                    385:                        cvs_client_send_request("Argumentx %s", q);
                    386:                }
                    387:        }
                    388:
1.73      joris     389:        xfree(buf);
1.9       joris     390: }
1.1       jfb       391:
1.9       joris     392: void
                    393: cvs_client_senddir(const char *dir)
1.1       jfb       394: {
1.34      xsa       395:        struct stat st;
1.29      xsa       396:        int nb;
1.50      otto      397:        char *d, *date, fpath[MAXPATHLEN], repo[MAXPATHLEN], *tag;
1.29      xsa       398:
                    399:        d = NULL;
1.9       joris     400:
                    401:        if (lastdir != NULL && !strcmp(dir, lastdir))
                    402:                return;
1.1       jfb       403:
1.9       joris     404:        cvs_get_repository_path(dir, repo, MAXPATHLEN);
1.31      xsa       405:
1.81      tobias    406:        if (cvs_cmdop != CVS_OP_RLOG)
1.70      xsa       407:                cvs_client_send_request("Directory %s\n%s", dir, repo);
1.31      xsa       408:
1.58      xsa       409:        (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s",
                    410:            dir, CVS_PATH_STATICENTRIES);
1.34      xsa       411:
                    412:        if (stat(fpath, &st) == 0 && (st.st_mode & (S_IRUSR|S_IRGRP|S_IROTH)))
                    413:                cvs_client_send_request("Static-directory");
                    414:
1.29      xsa       415:        d = xstrdup(dir);
                    416:        cvs_parse_tagfile(d, &tag, &date, &nb);
                    417:
                    418:        if (tag != NULL || date != NULL) {
                    419:                char buf[128];
                    420:
1.82      chl       421:                if (tag != NULL && nb != 0) {
1.29      xsa       422:                        if (strlcpy(buf, "N", sizeof(buf)) >= sizeof(buf))
                    423:                                fatal("cvs_client_senddir: truncation");
                    424:                } else if (tag != NULL) {
                    425:                        if (strlcpy(buf, "T", sizeof(buf)) >= sizeof(buf))
                    426:                                fatal("cvs_client_senddir: truncation");
                    427:                } else {
                    428:                        if (strlcpy(buf, "D", sizeof(buf)) >= sizeof(buf))
                    429:                                fatal("cvs_client_senddir: truncation");
                    430:                }
                    431:
                    432:                if (strlcat(buf, tag ? tag : date, sizeof(buf)) >= sizeof(buf))
                    433:                        fatal("cvs_client_senddir: truncation");
                    434:
                    435:                cvs_client_send_request("Sticky %s", buf);
                    436:
                    437:                if (tag != NULL)
                    438:                        xfree(tag);
                    439:                if (date != NULL)
                    440:                        xfree(date);
                    441:        }
                    442:        if (d != NULL)
                    443:                xfree(d);
1.1       jfb       444:
1.9       joris     445:        if (lastdir != NULL)
                    446:                xfree(lastdir);
                    447:        lastdir = xstrdup(dir);
                    448: }
1.1       jfb       449:
1.9       joris     450: void
                    451: cvs_client_sendfile(struct cvs_file *cf)
1.1       jfb       452: {
1.9       joris     453:        size_t len;
1.92      xsa       454:        char rev[CVS_REV_BUFSZ], timebuf[CVS_TIME_BUFSZ], sticky[CVS_REV_BUFSZ];
1.1       jfb       455:
1.9       joris     456:        if (cf->file_type != CVS_FILE)
                    457:                return;
1.1       jfb       458:
1.9       joris     459:        cvs_client_senddir(cf->file_wd);
                    460:        cvs_remote_classify_file(cf);
                    461:
1.10      joris     462:        if (cf->file_type == CVS_DIR)
                    463:                return;
                    464:
1.85      tobias    465:        if (cf->file_ent != NULL && cvs_cmdop != CVS_OP_IMPORT) {
1.9       joris     466:                if (cf->file_status == FILE_ADDED) {
                    467:                        len = strlcpy(rev, "0", sizeof(rev));
                    468:                        if (len >= sizeof(rev))
                    469:                                fatal("cvs_client_sendfile: truncation");
                    470:
                    471:                        len = strlcpy(timebuf, "Initial ", sizeof(timebuf));
                    472:                        if (len >= sizeof(timebuf))
                    473:                                fatal("cvs_client_sendfile: truncation");
                    474:
                    475:                        len = strlcat(timebuf, cf->file_name, sizeof(timebuf));
                    476:                        if (len >= sizeof(timebuf))
                    477:                                fatal("cvs_client_sendfile: truncation");
                    478:                } else {
                    479:                        rcsnum_tostr(cf->file_ent->ce_rev, rev, sizeof(rev));
                    480:                        ctime_r(&cf->file_ent->ce_mtime, timebuf);
                    481:                }
1.1       jfb       482:
1.9       joris     483:                if (cf->file_ent->ce_conflict == NULL) {
1.88      tobias    484:                        timebuf[strcspn(timebuf, "\n")] = '\0';
1.9       joris     485:                } else {
                    486:                        len = strlcpy(timebuf, cf->file_ent->ce_conflict,
                    487:                            sizeof(timebuf));
                    488:                        if (len >= sizeof(timebuf))
                    489:                                fatal("cvs_client_sendfile: truncation");
1.56      joris     490:                        len = strlcat(timebuf, "+", sizeof(timebuf));
                    491:                        if (len >= sizeof(timebuf))
                    492:                                fatal("cvs_client_sendfile: truncation");
1.9       joris     493:                }
1.1       jfb       494:
1.9       joris     495:                sticky[0] = '\0';
                    496:                if (cf->file_ent->ce_tag != NULL) {
1.57      xsa       497:                        (void)xsnprintf(sticky, sizeof(sticky), "T%s",
1.9       joris     498:                            cf->file_ent->ce_tag);
1.1       jfb       499:                }
                    500:
1.55      otto      501:                cvs_client_send_request("Entry /%s/%s%s/%s/%s/%s",
1.9       joris     502:                    cf->file_name, (cf->file_status == FILE_REMOVED) ? "-" : "",
1.53      xsa       503:                    rev, timebuf, cf->file_ent->ce_opts ?
                    504:                    cf->file_ent->ce_opts : "", sticky);
1.9       joris     505:        }
                    506:
1.84      tobias    507:        if (cvs_cmdop == CVS_OP_ADD)
                    508:                cf->file_status = FILE_MODIFIED;
                    509:
1.9       joris     510:        switch (cf->file_status) {
                    511:        case FILE_UNKNOWN:
                    512:                if (cf->fd != -1)
                    513:                        cvs_client_send_request("Questionable %s",
                    514:                            cf->file_name);
                    515:                break;
                    516:        case FILE_ADDED:
                    517:        case FILE_MODIFIED:
                    518:                cvs_client_send_request("Modified %s", cf->file_name);
                    519:                cvs_remote_send_file(cf->file_path);
                    520:                break;
                    521:        case FILE_UPTODATE:
                    522:                cvs_client_send_request("Unchanged %s", cf->file_name);
                    523:                break;
1.1       jfb       524:        }
1.9       joris     525: }
1.1       jfb       526:
1.9       joris     527: void
                    528: cvs_client_send_files(char **argv, int argc)
                    529: {
                    530:        int i;
1.1       jfb       531:
1.9       joris     532:        for (i = 0; i < argc; i++)
                    533:                cvs_client_send_request("Argument %s", argv[i]);
                    534: }
1.1       jfb       535:
1.9       joris     536: void
                    537: cvs_client_ok(char *data)
                    538: {
                    539:        end_of_response = 1;
1.37      joris     540:        server_response = SERVER_OK;
1.1       jfb       541: }
                    542:
1.9       joris     543: void
                    544: cvs_client_error(char *data)
                    545: {
                    546:        end_of_response = 1;
1.37      joris     547:        server_response = SERVER_ERROR;
1.9       joris     548: }
1.1       jfb       549:
1.9       joris     550: void
                    551: cvs_client_validreq(char *data)
1.1       jfb       552: {
1.9       joris     553:        int i;
                    554:        char *sp, *ep;
                    555:        struct cvs_req *req;
                    556:
1.62      ray       557:        if ((sp = data) == NULL)
                    558:                fatal("Missing argument for Valid-requests");
                    559:
1.9       joris     560:        do {
                    561:                if ((ep = strchr(sp, ' ')) != NULL)
                    562:                        *ep = '\0';
                    563:
                    564:                req = cvs_remote_get_request_info(sp);
                    565:                if (req != NULL)
                    566:                        req->supported = 1;
                    567:
                    568:                if (ep != NULL)
                    569:                        sp = ep + 1;
                    570:        } while (ep != NULL);
                    571:
                    572:        for (i = 0; cvs_requests[i].supported != -1; i++) {
                    573:                req = &cvs_requests[i];
                    574:                if ((req->flags & REQ_NEEDED) &&
                    575:                    req->supported != 1) {
                    576:                        fatal("server does not support required '%s'",
                    577:                            req->name);
                    578:                }
1.1       jfb       579:        }
1.9       joris     580: }
1.1       jfb       581:
1.9       joris     582: void
                    583: cvs_client_e(char *data)
                    584: {
1.62      ray       585:        if (data == NULL)
                    586:                fatal("Missing argument for E");
                    587:
1.80      tobias    588:        fprintf(stderr, "%s\n", data);
1.9       joris     589: }
1.1       jfb       590:
1.9       joris     591: void
                    592: cvs_client_m(char *data)
                    593: {
1.62      ray       594:        if (data == NULL)
                    595:                fatal("Missing argument for M");
                    596:
1.80      tobias    597:        puts(data);
1.9       joris     598: }
1.1       jfb       599:
1.9       joris     600: void
                    601: cvs_client_checkedin(char *data)
                    602: {
                    603:        CVSENTRIES *entlist;
                    604:        struct cvs_ent *ent, *newent;
1.84      tobias    605:        size_t len;
1.67      xsa       606:        char *dir, *e, entry[CVS_ENT_MAXLINELEN], rev[CVS_REV_BUFSZ];
                    607:        char sticky[CVS_ENT_MAXLINELEN], timebuf[CVS_TIME_BUFSZ];
1.1       jfb       608:
1.62      ray       609:        if (data == NULL)
                    610:                fatal("Missing argument for Checked-in");
                    611:
1.9       joris     612:        dir = cvs_remote_input();
1.54      otto      613:        e = cvs_remote_input();
1.9       joris     614:        xfree(dir);
1.1       jfb       615:
1.9       joris     616:        entlist = cvs_ent_open(data);
1.54      otto      617:        newent = cvs_ent_parse(e);
1.9       joris     618:        ent = cvs_ent_get(entlist, newent->ce_name);
1.54      otto      619:        xfree(e);
1.1       jfb       620:
1.9       joris     621:        rcsnum_tostr(newent->ce_rev, rev, sizeof(rev));
1.1       jfb       622:
1.9       joris     623:        sticky[0] = '\0';
1.84      tobias    624:        if (ent == NULL) {
                    625:                len = strlcpy(rev, "0", sizeof(rev));
                    626:                if (len >= sizeof(rev))
                    627:                        fatal("cvs_client_sendfile: truncation");
                    628:
                    629:                len = strlcpy(timebuf, "Initial ", sizeof(timebuf));
                    630:                if (len >= sizeof(timebuf))
                    631:                        fatal("cvs_client_sendfile: truncation");
                    632:
                    633:                len = strlcat(timebuf, newent->ce_name, sizeof(timebuf));
                    634:                if (len >= sizeof(timebuf))
                    635:                        fatal("cvs_client_sendfile: truncation");
                    636:        } else {
                    637:                ctime_r(&ent->ce_mtime, timebuf);
                    638:                timebuf[strcspn(timebuf, "\n")] = '\0';
                    639:
                    640:                if (newent->ce_tag != NULL)
                    641:                        (void)xsnprintf(sticky, sizeof(sticky), "T%s",
1.100     tobias    642:                            newent->ce_tag);
1.84      tobias    643:
                    644:                cvs_ent_free(ent);
                    645:        }
1.1       jfb       646:
1.57      xsa       647:        (void)xsnprintf(entry, CVS_ENT_MAXLINELEN, "/%s/%s%s/%s/%s/%s",
1.44      joris     648:            newent->ce_name, (newent->ce_status == CVS_ENT_REMOVED) ? "-" : "",
1.84      tobias    649:            rev, timebuf, newent->ce_opts ? newent->ce_opts : "", sticky);
1.9       joris     650:
                    651:        cvs_ent_free(newent);
                    652:        cvs_ent_add(entlist, entry);
                    653:        cvs_ent_close(entlist, ENT_SYNC);
1.1       jfb       654: }
                    655:
1.9       joris     656: void
                    657: cvs_client_updated(char *data)
                    658: {
1.57      xsa       659:        int fd;
1.9       joris     660:        time_t now;
1.51      otto      661:        mode_t fmode, mask;
1.9       joris     662:        size_t flen;
                    663:        CVSENTRIES *ent;
                    664:        struct cvs_ent *e;
                    665:        const char *errstr;
                    666:        struct timeval tv[2];
1.67      xsa       667:        char repo[MAXPATHLEN], entry[CVS_ENT_MAXLINELEN];
                    668:        char timebuf[CVS_TIME_BUFSZ], revbuf[CVS_REV_BUFSZ];
1.98      joris     669:        char *en, *mode, *len, *rpath;
                    670:        char sticky[CVS_ENT_MAXLINELEN], fpath[MAXPATHLEN];
1.9       joris     671:
1.62      ray       672:        if (data == NULL)
                    673:                fatal("Missing argument for Updated");
                    674:
1.9       joris     675:        rpath = cvs_remote_input();
1.54      otto      676:        en = cvs_remote_input();
1.9       joris     677:        mode = cvs_remote_input();
                    678:        len = cvs_remote_input();
                    679:
1.98      joris     680:        client_check_directory(data, rpath);
1.9       joris     681:        cvs_get_repository_path(".", repo, MAXPATHLEN);
1.48      joris     682:
                    683:        STRIP_SLASH(repo);
1.9       joris     684:
                    685:        if (strlen(repo) + 1 > strlen(rpath))
                    686:                fatal("received a repository path that is too short");
                    687:
1.98      joris     688:        (void)xsnprintf(fpath, sizeof(fpath), "%s/%s", data,
                    689:            strrchr(rpath, '/'));
1.9       joris     690:
                    691:        flen = strtonum(len, 0, INT_MAX, &errstr);
                    692:        if (errstr != NULL)
                    693:                fatal("cvs_client_updated: %s: %s", len, errstr);
                    694:        xfree(len);
                    695:
                    696:        cvs_strtomode(mode, &fmode);
                    697:        xfree(mode);
1.51      otto      698:        mask = umask(0);
                    699:        umask(mask);
                    700:        fmode &= ~mask;
1.9       joris     701:
                    702:        time(&now);
1.52      joris     703:        asctime_r(gmtime(&now), timebuf);
1.88      tobias    704:        timebuf[strcspn(timebuf, "\n")] = '\0';
1.9       joris     705:
1.54      otto      706:        e = cvs_ent_parse(en);
                    707:        xfree(en);
1.69      joris     708:
                    709:        sticky[0] = '\0';
                    710:        if (e->ce_tag != NULL)
                    711:                (void)xsnprintf(sticky, sizeof(sticky), "T%s", e->ce_tag);
                    712:
1.9       joris     713:        rcsnum_tostr(e->ce_rev, revbuf, sizeof(revbuf));
1.69      joris     714:        (void)xsnprintf(entry, CVS_ENT_MAXLINELEN, "/%s/%s/%s/%s/%s",
                    715:            e->ce_name, revbuf, timebuf,
                    716:            e->ce_opts ? e->ce_opts : "", sticky);
1.9       joris     717:
                    718:        cvs_ent_free(e);
1.90      tobias    719:
                    720:        if (cvs_cmdop != CVS_OP_EXPORT) {
1.98      joris     721:                ent = cvs_ent_open(data);
1.90      tobias    722:                cvs_ent_add(ent, entry);
                    723:                cvs_ent_close(ent, ENT_SYNC);
                    724:        }
1.9       joris     725:
                    726:        if ((fd = open(fpath, O_CREAT | O_WRONLY | O_TRUNC)) == -1)
                    727:                fatal("cvs_client_updated: open: %s: %s",
                    728:                    fpath, strerror(errno));
1.1       jfb       729:
1.46      joris     730:        cvs_remote_receive_file(fd, flen);
1.1       jfb       731:
1.9       joris     732:        tv[0].tv_sec = now;
                    733:        tv[0].tv_usec = 0;
                    734:        tv[1] = tv[0];
1.1       jfb       735:
1.9       joris     736:        if (futimes(fd, tv) == -1)
                    737:                fatal("cvs_client_updated: futimes: %s", strerror(errno));
1.1       jfb       738:
1.9       joris     739:        if (fchmod(fd, fmode) == -1)
                    740:                fatal("cvs_client_updated: fchmod: %s", strerror(errno));
1.1       jfb       741:
1.9       joris     742:        (void)close(fd);
1.1       jfb       743:
1.9       joris     744:        xfree(rpath);
1.1       jfb       745: }
                    746:
1.9       joris     747: void
                    748: cvs_client_merged(char *data)
                    749: {
1.56      joris     750:        int fd;
                    751:        time_t now;
1.83      tobias    752:        mode_t fmode, mask;
1.56      joris     753:        size_t flen;
                    754:        CVSENTRIES *ent;
                    755:        const char *errstr;
                    756:        struct timeval tv[2];
1.67      xsa       757:        char timebuf[CVS_TIME_BUFSZ], *repo, *rpath, *entry, *mode;
1.56      joris     758:        char *len, *fpath, *wdir;
                    759:
1.62      ray       760:        if (data == NULL)
                    761:                fatal("Missing argument for Merged");
                    762:
1.56      joris     763:        rpath = cvs_remote_input();
                    764:        entry = cvs_remote_input();
                    765:        mode = cvs_remote_input();
                    766:        len = cvs_remote_input();
                    767:
1.98      joris     768:        client_check_directory(data, rpath);
                    769:
1.56      joris     770:        repo = xmalloc(MAXPATHLEN);
                    771:        cvs_get_repository_path(".", repo, MAXPATHLEN);
                    772:
                    773:        STRIP_SLASH(repo);
                    774:
                    775:        if (strlen(repo) + 1 > strlen(rpath))
                    776:                fatal("received a repository path that is too short");
                    777:
                    778:        fpath = rpath + strlen(repo) + 1;
                    779:        if ((wdir = dirname(fpath)) == NULL)
                    780:                fatal("cvs_client_merged: dirname: %s", strerror(errno));
                    781:        xfree(repo);
                    782:
                    783:        flen = strtonum(len, 0, INT_MAX, &errstr);
                    784:        if (errstr != NULL)
                    785:                fatal("cvs_client_merged: %s: %s", len, errstr);
                    786:        xfree(len);
                    787:
                    788:        cvs_strtomode(mode, &fmode);
                    789:        xfree(mode);
1.83      tobias    790:        mask = umask(0);
                    791:        umask(mask);
                    792:        fmode &= ~mask;
1.56      joris     793:
                    794:        time(&now);
                    795:        asctime_r(gmtime(&now), timebuf);
1.88      tobias    796:        timebuf[strcspn(timebuf, "\n")] = '\0';
1.56      joris     797:
                    798:        ent = cvs_ent_open(wdir);
                    799:        cvs_ent_add(ent, entry);
                    800:        cvs_ent_close(ent, ENT_SYNC);
1.86      tobias    801:        xfree(entry);
1.56      joris     802:
                    803:        if ((fd = open(fpath, O_CREAT | O_WRONLY | O_TRUNC)) == -1)
                    804:                fatal("cvs_client_merged: open: %s: %s",
                    805:                    fpath, strerror(errno));
                    806:
                    807:        cvs_remote_receive_file(fd, flen);
                    808:
                    809:        tv[0].tv_sec = now;
                    810:        tv[0].tv_usec = 0;
                    811:        tv[1] = tv[0];
                    812:
                    813:        if (futimes(fd, tv) == -1)
                    814:                fatal("cvs_client_merged: futimes: %s", strerror(errno));
                    815:
                    816:        if (fchmod(fd, fmode) == -1)
                    817:                fatal("cvs_client_merged: fchmod: %s", strerror(errno));
                    818:
                    819:        (void)close(fd);
                    820:
                    821:        xfree(rpath);
1.9       joris     822: }
1.1       jfb       823:
1.9       joris     824: void
                    825: cvs_client_removed(char *data)
                    826: {
1.65      joris     827:        CVSENTRIES *entlist;
                    828:        char *rpath, *filename, fpath[MAXPATHLEN];
1.91      tobias    829:
                    830:        if (data == NULL)
                    831:                fatal("Missing argument for Removed");
1.65      joris     832:
                    833:        rpath = cvs_remote_input();
                    834:        if ((filename = strrchr(rpath, '/')) == NULL)
                    835:                fatal("bad rpath in cvs_client_removed: %s", rpath);
                    836:        filename++;
                    837:
                    838:        entlist = cvs_ent_open(data);
                    839:        cvs_ent_remove(entlist, filename);
                    840:        cvs_ent_close(entlist, ENT_SYNC);
                    841:
                    842:        (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s", data, filename);
                    843:        (void)unlink(fpath);
1.13      joris     844:
1.65      joris     845:        xfree(rpath);
1.9       joris     846: }
1.1       jfb       847:
1.9       joris     848: void
                    849: cvs_client_remove_entry(char *data)
1.1       jfb       850: {
1.38      xsa       851:        CVSENTRIES *entlist;
1.44      joris     852:        char *filename, *rpath;
1.41      joris     853:
1.62      ray       854:        if (data == NULL)
                    855:                fatal("Missing argument for Remove-entry");
                    856:
1.41      joris     857:        rpath = cvs_remote_input();
                    858:        if ((filename = strrchr(rpath, '/')) == NULL)
                    859:                fatal("bad rpath in cvs_client_remove_entry: %s", rpath);
1.61      ray       860:        filename++;
1.1       jfb       861:
1.38      xsa       862:        entlist = cvs_ent_open(data);
1.44      joris     863:        cvs_ent_remove(entlist, filename);
1.38      xsa       864:        cvs_ent_close(entlist, ENT_SYNC);
                    865:
1.44      joris     866:        xfree(rpath);
1.36      xsa       867: }
                    868:
                    869: void
                    870: cvs_client_set_static_directory(char *data)
                    871: {
                    872:        FILE *fp;
1.50      otto      873:        char *dir, fpath[MAXPATHLEN];
1.36      xsa       874:
1.62      ray       875:        if (data == NULL)
                    876:                fatal("Missing argument for Set-static-directory");
                    877:
1.36      xsa       878:        STRIP_SLASH(data);
                    879:
                    880:        dir = cvs_remote_input();
                    881:        xfree(dir);
                    882:
1.90      tobias    883:        if (cvs_cmdop == CVS_OP_EXPORT)
                    884:                return;
                    885:
1.58      xsa       886:        (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s",
                    887:            data, CVS_PATH_STATICENTRIES);
1.36      xsa       888:
                    889:        if ((fp = fopen(fpath, "w+")) == NULL) {
                    890:                cvs_log(LP_ERRNO, "%s", fpath);
1.50      otto      891:                return;
1.36      xsa       892:        }
                    893:        (void)fclose(fp);
1.16      xsa       894: }
1.35      xsa       895:
                    896: void
                    897: cvs_client_clear_static_directory(char *data)
                    898: {
1.50      otto      899:        char *dir, fpath[MAXPATHLEN];
1.35      xsa       900:
1.62      ray       901:        if (data == NULL)
                    902:                fatal("Missing argument for Clear-static-directory");
                    903:
1.35      xsa       904:        STRIP_SLASH(data);
                    905:
                    906:        dir = cvs_remote_input();
                    907:        xfree(dir);
                    908:
1.90      tobias    909:        if (cvs_cmdop == CVS_OP_EXPORT)
                    910:                return;
                    911:
1.58      xsa       912:        (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s",
                    913:            data, CVS_PATH_STATICENTRIES);
1.35      xsa       914:
                    915:        (void)cvs_unlink(fpath);
                    916: }
                    917:
                    918: void
                    919: cvs_client_set_sticky(char *data)
                    920: {
                    921:        FILE *fp;
1.50      otto      922:        char *dir, *tag, tagpath[MAXPATHLEN];
1.35      xsa       923:
1.62      ray       924:        if (data == NULL)
                    925:                fatal("Missing argument for Set-sticky");
                    926:
1.35      xsa       927:        STRIP_SLASH(data);
                    928:
                    929:        dir = cvs_remote_input();
                    930:        tag = cvs_remote_input();
                    931:
1.90      tobias    932:        if (cvs_cmdop == CVS_OP_EXPORT)
                    933:                goto out;
                    934:
1.98      joris     935:        client_check_directory(data, dir);
1.69      joris     936:
1.58      xsa       937:        (void)xsnprintf(tagpath, MAXPATHLEN, "%s/%s", data, CVS_PATH_TAG);
1.35      xsa       938:
                    939:        if ((fp = fopen(tagpath, "w+")) == NULL) {
                    940:                cvs_log(LP_ERRNO, "%s", tagpath);
                    941:                goto out;
                    942:        }
                    943:
                    944:        (void)fprintf(fp, "%s\n", tag);
                    945:        (void)fclose(fp);
                    946: out:
                    947:        xfree(tag);
1.98      joris     948:        xfree(dir);
1.35      xsa       949: }
                    950:
                    951: void
                    952: cvs_client_clear_sticky(char *data)
                    953: {
1.50      otto      954:        char *dir, tagpath[MAXPATHLEN];
1.47      xsa       955:
1.62      ray       956:        if (data == NULL)
                    957:                fatal("Missing argument for Clear-sticky");
1.35      xsa       958:
                    959:        STRIP_SLASH(data);
                    960:
                    961:        dir = cvs_remote_input();
1.90      tobias    962:
1.98      joris     963:        if (cvs_cmdop == CVS_OP_EXPORT) {
                    964:                xfree(dir);
1.90      tobias    965:                return;
1.98      joris     966:        }
1.35      xsa       967:
1.98      joris     968:        client_check_directory(data, dir);
1.69      joris     969:
1.58      xsa       970:        (void)xsnprintf(tagpath, MAXPATHLEN, "%s/%s", data, CVS_PATH_TAG);
1.69      joris     971:        (void)unlink(tagpath);
1.98      joris     972:
                    973:        xfree(dir);
1.35      xsa       974: }
                    975:
                    976:
1.16      xsa       977: /*
                    978:  * cvs_client_initlog()
                    979:  *
                    980:  * Initialize protocol logging if the CVS_CLIENT_LOG environment variable is
                    981:  * set.  In this case, the variable's value is used as a path to which the
                    982:  * appropriate suffix is added (".in" for client input and ".out" for server
                    983:  * output).
                    984:  */
                    985: static void
                    986: cvs_client_initlog(void)
                    987: {
                    988:        u_int i;
                    989:        char *env, *envdup, buf[MAXPATHLEN], fpath[MAXPATHLEN];
                    990:        char rpath[MAXPATHLEN], *s;
                    991:        struct stat st;
                    992:        time_t now;
                    993:        struct passwd *pwd;
                    994:
                    995:        /* avoid doing it more than once */
                    996:        if (cvs_client_logon)
                    997:                return;
                    998:
                    999:        if ((env = getenv("CVS_CLIENT_LOG")) == NULL)
                   1000:                return;
                   1001:
                   1002:        envdup = xstrdup(env);
                   1003:        if ((s = strchr(envdup, '%')) != NULL)
                   1004:                *s = '\0';
                   1005:
                   1006:        if (strlcpy(buf, env, sizeof(buf)) >= sizeof(buf))
                   1007:                fatal("cvs_client_initlog: truncation");
                   1008:
                   1009:        if (strlcpy(rpath, envdup, sizeof(rpath)) >= sizeof(rpath))
                   1010:                fatal("cvs_client_initlog: truncation");
                   1011:
                   1012:        xfree(envdup);
                   1013:
                   1014:        s = buf;
                   1015:        while ((s = strchr(s, '%')) != NULL) {
                   1016:                s++;
                   1017:                switch (*s) {
                   1018:                case 'c':
1.87      tobias   1019:                        if (strlcpy(fpath, cmdp->cmd_name, sizeof(fpath)) >=
1.16      xsa      1020:                            sizeof(fpath))
                   1021:                                fatal("cvs_client_initlog: truncation");
                   1022:                        break;
                   1023:                case 'd':
                   1024:                        time(&now);
                   1025:                        if (strlcpy(fpath, ctime(&now), sizeof(fpath)) >=
                   1026:                            sizeof(fpath))
                   1027:                                fatal("cvs_client_initlog: truncation");
                   1028:                        break;
                   1029:                case 'p':
1.57      xsa      1030:                        (void)xsnprintf(fpath, sizeof(fpath), "%d", getpid());
1.16      xsa      1031:                        break;
                   1032:                case 'u':
                   1033:                        if ((pwd = getpwuid(getuid())) != NULL) {
                   1034:                                if (strlcpy(fpath, pwd->pw_name,
                   1035:                                    sizeof(fpath)) >= sizeof(fpath))
                   1036:                                        fatal("cvs_client_initlog: truncation");
                   1037:                        } else {
                   1038:                                fpath[0] = '\0';
                   1039:                        }
                   1040:                        endpwent();
                   1041:                        break;
                   1042:                default:
                   1043:                        fpath[0] = '\0';
                   1044:                        break;
                   1045:                }
                   1046:
                   1047:                if (fpath[0] != '\0') {
                   1048:                        if (strlcat(rpath, "-", sizeof(rpath)) >= sizeof(rpath))
                   1049:                                fatal("cvs_client_initlog: truncation");
                   1050:
                   1051:                        if (strlcat(rpath, fpath, sizeof(rpath))
                   1052:                            >= sizeof(rpath))
                   1053:                                fatal("cvs_client_initlog: truncation");
                   1054:                }
                   1055:        }
                   1056:
                   1057:        for (i = 0; i < UINT_MAX; i++) {
1.57      xsa      1058:                (void)xsnprintf(fpath, sizeof(fpath), "%s-%d.in", rpath, i);
1.16      xsa      1059:
                   1060:                if (stat(fpath, &st) != -1)
                   1061:                        continue;
                   1062:
                   1063:                if (errno != ENOENT)
                   1064:                        fatal("cvs_client_initlog() stat failed '%s'",
                   1065:                            strerror(errno));
                   1066:
                   1067:                break;
                   1068:        }
                   1069:
                   1070:        if ((cvs_client_inlog_fd = open(fpath,
1.60      xsa      1071:            O_RDWR | O_CREAT | O_TRUNC, 0644)) == -1) {
1.16      xsa      1072:                fatal("cvs_client_initlog: open `%s': %s",
                   1073:                    fpath, strerror(errno));
                   1074:        }
                   1075:
                   1076:        for (i = 0; i < UINT_MAX; i++) {
1.57      xsa      1077:                (void)xsnprintf(fpath, sizeof(fpath), "%s-%d.out", rpath, i);
1.16      xsa      1078:
                   1079:                if (stat(fpath, &st) != -1)
                   1080:                        continue;
                   1081:
                   1082:                if (errno != ENOENT)
                   1083:                        fatal("cvs_client_initlog() stat failed '%s'",
                   1084:                            strerror(errno));
                   1085:
                   1086:                break;
                   1087:        }
                   1088:
1.93      xsa      1089:        if ((cvs_client_outlog_fd = open(fpath,
1.60      xsa      1090:            O_RDWR | O_CREAT | O_TRUNC, 0644)) == -1) {
1.16      xsa      1091:                fatal("cvs_client_initlog: open `%s': %s",
                   1092:                    fpath, strerror(errno));
                   1093:        }
                   1094:
                   1095:        cvs_client_logon = 1;
1.1       jfb      1096: }