venus: Remove dedebug
[openafs.git] / src / afs / DARWIN / osi_gcpags.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #include <afsconfig.h>
11 #include "afs/param.h"
12
13
14 #include "afs/sysincludes.h"    /* Standard vendor system headers */
15 #include "afsincludes.h"        /* Afs-based standard headers */
16 #include "afs/afs_stats.h"      /* afs statistics */
17
18 #if AFS_GCPAGS
19
20 /* afs_osi_TraverseProcTable() - Walk through the systems process
21  * table, calling afs_GCPAGs_perproc_func() for each process.
22  */
23
24
25 #if (defined(AFS_DARWIN_ENV) && !defined(AFS_DARWIN80_ENV))
26 void
27 afs_osi_TraverseProcTable(void)
28 {
29     afs_proc_t *p;
30     LIST_FOREACH(p, &allproc, p_list) {
31         if (p->p_stat == SIDL)
32             continue;
33         if (p->p_stat == SZOMB)
34             continue;
35         if (p->p_flag & P_SYSTEM)
36             continue;
37         afs_GCPAGs_perproc_func(p);
38     }
39 }
40 #endif
41
42 /* return a pointer (sometimes a static copy ) to the cred for a
43  * given afs_proc_t.
44  * subsequent calls may overwrite the previously returned value.
45  */
46
47 #if defined(AFS_DARWIN80_ENV)
48
49 const afs_ucred_t *
50 afs_osi_proc2cred(afs_proc_t * pr)
51 {
52     afs_ucred_t *rv = NULL;
53     static afs_ucred_t cr;
54     struct ucred *pcred;
55
56     if (pr == NULL) {
57         return NULL;
58     }
59     pcred = proc_ucred(pr);
60     cr.cr_ref = 1;
61     afs_set_cr_uid(&cr, afs_cr_uid(pcred));
62     cr.cr_ngroups = pcred->cr_ngroups;
63     memcpy(cr.cr_groups, pcred->cr_groups,
64            NGROUPS * sizeof(gid_t));
65     return &cr;
66 }
67 #else
68
69 const afs_ucred_t *
70 afs_osi_proc2cred(afs_proc_t * pr)
71 {
72     afs_ucred_t *rv = NULL;
73     static afs_ucred_t cr;
74
75     if (pr == NULL) {
76         return NULL;
77     }
78
79     if ((pr->p_stat == SSLEEP) || (pr->p_stat == SRUN)
80         || (pr->p_stat == SSTOP)) {
81         pcred_readlock(pr);
82         cr.cr_ref = 1;
83         afs_set_cr_uid(&cr, afs_cr_uid(pr->p_cred->pc_ucred));
84         cr.cr_ngroups = pr->p_cred->pc_ucred->cr_ngroups;
85         memcpy(cr.cr_groups, pr->p_cred->pc_ucred->cr_groups,
86                NGROUPS * sizeof(gid_t));
87         pcred_unlock(pr);
88         rv = &cr;
89     }
90
91     return rv;
92 }
93
94 #endif
95
96 #endif /* AFS_GCPAGS */