Correct incorrect type-punning fixes
[openafs.git] / src / afs / afs_osi_gcpags.c
index 6d8f3ba..2a13065 100644 (file)
@@ -203,7 +203,7 @@ afs_osi_TraverseProcTable(void)
 extern rwlock_t tasklist_lock __attribute__((weak));
 #endif
 void
-afs_osi_TraverseProcTable()
+afs_osi_TraverseProcTable(void)
 {
 #if !defined(LINUX_KEYRING_SUPPORT) && (!defined(STRUCT_TASK_HAS_CRED) || defined(EXPORTED_RCU_READ_LOCK))
     struct task_struct *p;
@@ -430,7 +430,19 @@ afs_osi_proc2cred(afs_proc_t * pr)
            NGROUPS * sizeof(gid_t));
     return &cr;
 }
-#elif defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
+#elif defined(AFS_FBSD_ENV)
+const afs_ucred_t *
+afs_osi_proc2cred(afs_proc_t * pr)
+{
+    /*
+     * This whole function is kind of an ugly hack.  For one, the
+     * 'const' is a lie.  Also, we should probably be holding the
+     * proc mutex around all accesses to the credentials structure,
+     * but the present API does not allow this.
+     */
+    return pr->p_ucred;
+}
+#elif defined(AFS_DARWIN_ENV)
 const afs_ucred_t *
 afs_osi_proc2cred(afs_proc_t * pr)
 {
@@ -470,7 +482,10 @@ afs_osi_proc2cred(afs_proc_t * pr)
     if ((pr->state == TASK_RUNNING) || (pr->state == TASK_INTERRUPTIBLE)
        || (pr->state == TASK_UNINTERRUPTIBLE)
        || (pr->state == TASK_STOPPED)) {
-       cr.cr_ref = 1;
+       /* This is dangerous. If anyone ever crfree's the cred that's
+        * returned from here, we'll go boom, because it's statically
+        * allocated. */
+       atomic_set(&cr.cr_ref, 1);
        afs_set_cr_uid(&cr, task_uid(pr));
 #if defined(AFS_LINUX26_ENV)
 #if defined(STRUCT_TASK_HAS_CRED)