source: trunk/athena/bin/attach/mul.c @ 8650

Revision 8650, 2.2 KB checked in by cfields, 28 years ago (diff)
Add comments explaining why we do what we do in a MUL detach. Rewrite the loop so it's easier to understand. NULL out attachtab_first before calling detach, otherwise detach calls get_attachtab which calls free_attachtab which frees the structure that we had cached to look at, which can cause us to seg fault under some conditions.
Line 
1/*
2 * $Header: /afs/dev.mit.edu/source/repository/athena/bin/attach/mul.c,v 1.7 1996-07-01 02:36:06 cfields Exp $
3 *
4 * Copyright (c) 1990 by the Massachusetts Institute of Technology.
5 */
6
7static char *rcsid_mul_c = "$Header: /afs/dev.mit.edu/source/repository/athena/bin/attach/mul.c,v 1.7 1996-07-01 02:36:06 cfields Exp $";
8
9
10#include "attach.h"
11#include <string.h>
12
13int mul_attach(atp, mopt, errorout)
14struct _attachtab *atp;
15struct mntopts *mopt;
16int errorout;
17{
18        char mul_buf[BUFSIZ], *cp = mul_buf, *mp;
19       
20        strcpy(mul_buf, atp->hostdir);
21        while (mp = cp) {
22                cp = strchr(mp, ',');
23                if (cp)
24                        *cp = '\0';
25                attach(mp);
26                if (cp)
27                        cp++;
28        }
29        return SUCCESS;
30}
31
32/*
33 * Detach all of the components of the MUL filesystem in the reverse
34 * order that they were attached. Currently, when detach -a is done,
35 * the components of the MUL are detached before the MUL, so if the
36 * MUL tries to detach them, detach will complain to the user that
37 * they are not attached. This is silly, so we check to make sure that
38 * the components are actually still attached before we try to detach
39 * them. If they are already detached, we stay quiet. Meanwhile, if
40 * we try to detach a component that was there when we started, but
41 * detach returns that it isn't attached, we assume that another
42 * detach was racing with us and don't return failure for the
43 * operation.
44 */
45int mul_detach(atp)
46struct _attachtab *atp;
47{
48    int status = SUCCESS;
49    int tempexp;
50    char mul_buf[BUFSIZ], *cp;
51    extern struct _attachtab    *attachtab_last, *attachtab_first;
52    struct _attachtab *atptmp;
53
54    lock_attachtab();
55    get_attachtab();
56    unlock_attachtab();
57
58    atptmp = attachtab_first;
59
60    tempexp = explicit;
61    mul_buf[0] = ',';
62    strcpy(mul_buf + 1, atp->hostdir);
63
64    while (cp = strrchr(mul_buf, ','))
65      {
66        *cp++ = '\0';
67        explicit = 0;
68        attachtab_first = atptmp;
69
70        if (attachtab_lookup(cp))
71          {
72            attachtab_first = NULL;
73            if (detach(cp) != SUCCESS &&
74                error_status != ERR_DETACHNOTATTACHED)
75              status = FAILURE;
76          }
77      }
78
79    attachtab_first = atptmp;
80    free_attachtab();
81    explicit = tempexp;
82    error_status = (status == SUCCESS) ? ERR_NONE : ERR_SOMETHING;
83    return status;
84}
Note: See TracBrowser for help on using the repository browser.