Merge 1.8.0~pre4 packaging into master
[pkg-k5-afs_openafs.git] / src / afs / DARWIN / osi_gcpags.c
blob79209b08b1d83aeb9c6fbee5f28e89331187d63f
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
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 */
10 #include <afsconfig.h>
11 #include "afs/param.h"
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 */
18 #if AFS_GCPAGS
20 /* afs_osi_TraverseProcTable() - Walk through the systems process
21 * table, calling afs_GCPAGs_perproc_func() for each process.
25 #if (defined(AFS_DARWIN_ENV) && !defined(AFS_DARWIN80_ENV))
26 void
27 afs_osi_TraverseProcTable(void)
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);
40 #endif
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.
47 #if defined(AFS_DARWIN80_ENV)
49 const afs_ucred_t *
50 afs_osi_proc2cred(afs_proc_t * pr)
52 afs_ucred_t *rv = NULL;
53 static afs_ucred_t cr;
54 struct ucred *pcred;
56 if (pr == NULL) {
57 return NULL;
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;
67 #else
69 const afs_ucred_t *
70 afs_osi_proc2cred(afs_proc_t * pr)
72 afs_ucred_t *rv = NULL;
73 static afs_ucred_t cr;
75 if (pr == NULL) {
76 return NULL;
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;
91 return rv;
94 #endif
96 #endif /* AFS_GCPAGS */