Commit | Line | Data |
---|---|---|
805e021f CE |
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 | #ifdef EXPORTED_TASKLIST_LOCK | |
26 | extern rwlock_t tasklist_lock __attribute__((weak)); | |
27 | #endif | |
28 | void | |
29 | afs_osi_TraverseProcTable(void) | |
30 | { | |
31 | #if !defined(LINUX_KEYRING_SUPPORT) && (!defined(STRUCT_TASK_STRUCT_HAS_CRED) || defined(HAVE_LINUX_RCU_READ_LOCK)) | |
32 | struct task_struct *p; | |
33 | ||
34 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) && defined(EXPORTED_TASKLIST_LOCK) | |
35 | if (&tasklist_lock) | |
36 | read_lock(&tasklist_lock); | |
37 | #endif /* EXPORTED_TASKLIST_LOCK */ | |
38 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) | |
39 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) && defined(EXPORTED_TASKLIST_LOCK) | |
40 | else | |
41 | #endif /* EXPORTED_TASKLIST_LOCK && LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) */ | |
42 | rcu_read_lock(); | |
43 | #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) */ | |
44 | ||
45 | #if defined(for_each_process) | |
46 | for_each_process(p) if (p->pid) { | |
47 | #ifdef STRUCT_TASK_STRUCT_HAS_EXIT_STATE | |
48 | if (p->exit_state) | |
49 | continue; | |
50 | #else | |
51 | if (p->state & TASK_ZOMBIE) | |
52 | continue; | |
53 | #endif | |
54 | afs_GCPAGs_perproc_func(p); | |
55 | } | |
56 | #else | |
57 | for_each_task(p) if (p->pid) { | |
58 | #ifdef STRUCT_TASK_STRUCT_HAS_EXIT_STATE | |
59 | if (p->exit_state) | |
60 | continue; | |
61 | #else | |
62 | if (p->state & TASK_ZOMBIE) | |
63 | continue; | |
64 | #endif | |
65 | afs_GCPAGs_perproc_func(p); | |
66 | } | |
67 | #endif | |
68 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) && defined(EXPORTED_TASKLIST_LOCK) | |
69 | if (&tasklist_lock) | |
70 | read_unlock(&tasklist_lock); | |
71 | #endif /* EXPORTED_TASKLIST_LOCK */ | |
72 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) | |
73 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) && defined(EXPORTED_TASKLIST_LOCK) | |
74 | else | |
75 | #endif /* EXPORTED_TASKLIST_LOCK && LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) */ | |
76 | rcu_read_unlock(); | |
77 | #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) */ | |
78 | #endif | |
79 | } | |
80 | ||
81 | /* return a pointer (sometimes a static copy ) to the cred for a | |
82 | * given afs_proc_t. | |
83 | * subsequent calls may overwrite the previously returned value. | |
84 | */ | |
85 | ||
86 | #if !defined(LINUX_KEYRING_SUPPORT) && (!defined(STRUCT_TASK_STRUCT_HAS_CRED) || defined(HAVE_LINUX_RCU_READ_LOCK)) | |
87 | const afs_ucred_t * | |
88 | afs_osi_proc2cred(afs_proc_t * pr) | |
89 | { | |
90 | afs_ucred_t *rv = NULL; | |
91 | static afs_ucred_t cr; | |
92 | ||
93 | if (pr == NULL) { | |
94 | return NULL; | |
95 | } | |
96 | ||
97 | if ((pr->state == TASK_RUNNING) || (pr->state == TASK_INTERRUPTIBLE) | |
98 | || (pr->state == TASK_UNINTERRUPTIBLE) | |
99 | || (pr->state == TASK_STOPPED)) { | |
100 | /* This is dangerous. If anyone ever crfree's the cred that's | |
101 | * returned from here, we'll go boom, because it's statically | |
102 | * allocated. */ | |
103 | atomic_set(&cr.cr_ref, 1); | |
104 | afs_set_cr_uid(&cr, task_uid(pr)); | |
105 | #if defined(STRUCT_TASK_STRUCT_HAS_CRED) | |
106 | get_group_info(pr->cred->group_info); | |
107 | afs_set_cr_group_info(&cr, pr->cred->group_info); | |
108 | #else | |
109 | get_group_info(pr->group_info); | |
110 | afs_set_cr_group_info(&cr, pr->group_info); | |
111 | #endif | |
112 | rv = &cr; | |
113 | } | |
114 | ||
115 | return rv; | |
116 | } | |
117 | #endif | |
118 | ||
119 | #endif /* AFS_GCPAGS */ |