ff04176e34e8a936c2d3d8b9e284882928ad7c60
[openafs.git] / src / afs / LINUX24 / 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 #include "afs/sysincludes.h"    /* Standard vendor system headers */
14 #include "afsincludes.h"        /* Afs-based standard headers */
15 #include "afs/afs_stats.h"      /* afs statistics */
16
17 #if AFS_GCPAGS
18
19 /* afs_osi_TraverseProcTable() - Walk through the systems process
20  * table, calling afs_GCPAGs_perproc_func() for each process.
21  */
22
23 #ifdef EXPORTED_TASKLIST_LOCK
24 extern rwlock_t tasklist_lock __attribute__((weak));
25 #endif
26 void
27 afs_osi_TraverseProcTable(void)
28 {
29 #if !defined(LINUX_KEYRING_SUPPORT) && (!defined(STRUCT_TASK_HAS_CRED) || defined(EXPORTED_RCU_READ_LOCK))
30     struct task_struct *p;
31
32 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) && defined(EXPORTED_TASKLIST_LOCK)
33     if (&tasklist_lock)
34         read_lock(&tasklist_lock);
35 #endif /* EXPORTED_TASKLIST_LOCK */
36
37 #ifdef DEFINED_FOR_EACH_PROCESS
38     for_each_process(p) if (p->pid) {
39 #ifdef STRUCT_TASK_STRUCT_HAS_EXIT_STATE
40         if (p->exit_state)
41             continue;
42 #else
43         if (p->state & TASK_ZOMBIE)
44             continue;
45 #endif
46         afs_GCPAGs_perproc_func(p);
47     }
48 #else
49     for_each_task(p) if (p->pid) {
50 #ifdef STRUCT_TASK_STRUCT_HAS_EXIT_STATE
51         if (p->exit_state)
52             continue;
53 #else
54         if (p->state & TASK_ZOMBIE)
55             continue;
56 #endif
57         afs_GCPAGs_perproc_func(p);
58     }
59 #endif
60 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) && defined(EXPORTED_TASKLIST_LOCK)
61     if (&tasklist_lock)
62         read_unlock(&tasklist_lock);
63 #endif /* EXPORTED_TASKLIST_LOCK */
64 #endif
65 }
66
67 /* return a pointer (sometimes a static copy ) to the cred for a
68  * given afs_proc_t.
69  * subsequent calls may overwrite the previously returned value.
70  */
71
72 const afs_ucred_t *
73 afs_osi_proc2cred(afs_proc_t * pr)
74 {
75         afs_ucred_t *rv = NULL;
76         static afs_ucred_t cr;
77
78         if (pr == NULL) {
79                 return NULL;
80         }
81
82         if ((pr->state == TASK_RUNNING) || (pr->state == TASK_INTERRUPTIBLE)
83                 || (pr->state == TASK_UNINTERRUPTIBLE)
84                 || (pr->state == TASK_STOPPED)) {
85
86                 /* This is dangerous. If anyone ever crfree's the cred that's
87                 * returned from here, we'll go boom, because it's statically
88                 * allocated. */
89
90                 atomic_set(&cr.cr_ref, 1);
91                 afs_set_cr_uid(&cr, task_uid(pr));
92
93                 cr.cr_ngroups = pr->ngroups;
94                 memcpy(cr.cr_groups, pr->groups, NGROUPS * sizeof(gid_t));
95
96                 rv = &cr;
97         }
98
99         return rv;
100 }
101
102 #endif /* AFS_GCPAGS */