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

Annotation of src/usr.bin/cvs/worklist.c, Revision 1.2

1.2     ! joris       1: /*     $OpenBSD: worklist.c,v 1.1 2006/03/08 20:18:41 joris Exp $      */
1.1       joris       2: /*
                      3:  * Copyright (c) 2006 Joris Vink <joris@openbsd.org>
                      4:  * All rights reserved.
                      5:  *
                      6:  * Redistribution and use in source and binary forms, with or without
                      7:  * modification, are permitted provided that the following conditions
                      8:  * are met:
                      9:  *
                     10:  * 1. Redistributions of source code must retain the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer.
                     12:  * 2. The name of the author may not be used to endorse or promote products
                     13:  *    derived from this software without specific prior written permission.
                     14:  *
                     15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
                     16:  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
                     17:  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
                     18:  * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
                     19:  * EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLUDING, BUT NOT LIMITED TO,
                     20:  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
                     21:  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
                     22:  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
                     23:  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
                     24:  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     25:  */
                     26:
                     27: #include "includes.h"
                     28:
                     29: #include "log.h"
                     30: #include "worklist.h"
                     31: #include "xmalloc.h"
                     32:
                     33: /*
                     34:  * adds an path to a worklist.
                     35:  */
                     36: void
                     37: cvs_worklist_add(const char *path, struct cvs_wklhead *worklist)
                     38: {
                     39:        size_t len;
                     40:        struct cvs_worklist *wkl;
                     41:        sigset_t old, new;
                     42:
                     43:        wkl = (struct cvs_worklist *)xmalloc(sizeof(*wkl));
                     44:        memset(wkl, 0, sizeof(*wkl));
                     45:
                     46:        len = strlcpy(wkl->wkl_path, path, sizeof(wkl->wkl_path));
                     47:        if (len >= sizeof(wkl->wkl_path))
                     48:                fatal("path truncation in cvs_worklist_add");
                     49:
                     50:        sigfillset(&new);
                     51:        sigprocmask(SIG_BLOCK, &new, &old);
                     52:        SLIST_INSERT_HEAD(worklist, wkl, wkl_list);
                     53:        sigprocmask(SIG_SETMASK, &old, NULL);
                     54: }
                     55:
                     56: /*
                     57:  * run over the given worklist, calling cb for each element.
                     58:  * this is just like cvs_worklist_clean(), except we block signals first.
                     59:  */
                     60: void
                     61: cvs_worklist_run(struct cvs_wklhead *list, void (*cb)(struct cvs_worklist *))
                     62: {
                     63:        sigset_t old, new;
1.2     ! joris      64:        struct cvs_worklist *wkl;
1.1       joris      65:
                     66:        sigfillset(&new);
                     67:        sigprocmask(SIG_BLOCK, &new, &old);
                     68:
                     69:        cvs_worklist_clean(list, cb);
                     70:
1.2     ! joris      71:        while ((wkl = SLIST_FIRST(list)) != NULL) {
        !            72:                SLIST_REMOVE_HEAD(list, wkl_list);
        !            73:                xfree(wkl);
        !            74:        }
        !            75:
1.1       joris      76:        sigprocmask(SIG_SETMASK, &old, NULL);
                     77: }
                     78:
                     79: /*
1.2     ! joris      80:  * pass elements to the specified callback, which has to be signal safe.
1.1       joris      81:  */
                     82: void
                     83: cvs_worklist_clean(struct cvs_wklhead *list, void (*cb)(struct cvs_worklist *))
                     84: {
                     85:        struct cvs_worklist *wkl;
                     86:
1.2     ! joris      87:        while ((wkl = SLIST_FIRST(list)) != NULL)
1.1       joris      88:                cb(wkl);
                     89: }
                     90:
                     91: void
                     92: cvs_worklist_unlink(struct cvs_worklist *wkl)
                     93: {
                     94:        (void)unlink(wkl->wkl_path);
                     95: }