byte-range lock warning should include pid
authorDerrick Brashear <shadow@dementia.org>
Wed, 17 Feb 2010 05:48:03 +0000 (00:48 -0500)
committerDerrick Brashear <shadow@dementia.org>
Thu, 22 Apr 2010 04:57:23 +0000 (21:57 -0700)
is is the same pid cmdebug would print. just include it in the logged
byte-range lock warning.

FIXES 126438

Change-Id: Idd83a4c4a56edf43ab257b3a7f08e1bbb774f04a
Reviewed-on: http://gerrit.openafs.org/1333
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>

src/afs/VNOPS/afs_vnop_flock.c

index 97fb461..5bf9367 100644 (file)
@@ -36,7 +36,7 @@ static int GetFlockCount(struct vcache *avc, struct vrequest *areq);
 static int lockIdcmp2(struct AFS_FLOCK *flock1, struct vcache *vp,
                      register struct SimpleLocks *alp, int onlymine,
                      int clid);
-static void DoLockWarning(void);
+static void DoLockWarning(afs_ucred_t * acred);
 
 /* int clid;  * non-zero on SGI, OSF, SunOS, Darwin, xBSD ** XXX ptr type */
 
@@ -498,26 +498,41 @@ HandleFlock(register struct vcache *avc, int acom, struct vrequest *areq,
 
 /* warn a user that a lock has been ignored */
 afs_int32 lastWarnTime = 0;    /* this is used elsewhere */
+static afs_int32 lastWarnPid = 0;
 static void
-DoLockWarning(void)
+DoLockWarning(afs_ucred_t * acred)
 {
     register afs_int32 now;
+    pid_t pid = MyPidxx2Pid(MyPidxx);
+    char *procname;
+
     now = osi_Time();
 
     AFS_STATCNT(DoLockWarning);
-    /* check if we've already warned someone recently */
-    if (now < lastWarnTime + 120)
-       return;
+    /* check if we've already warned this user recently */
+    if (!((now < lastWarnTime + 120) && (lastWarnPid == pid))) {
+       procname = afs_osi_Alloc(256);
+
+       if (!procname)
+           return;
 
-    /* otherwise, it is time to nag the user */
-    lastWarnTime = now;
+       /* Copies process name to allocated procname, see osi_machdeps for details of macro */
+       osi_procname(procname, 256);
+       procname[255] = '\0';
+
+       /* otherwise, it is time to nag the user */
+       lastWarnTime = now;
+       lastWarnPid = pid;
 #ifdef AFS_LINUX26_ENV
-    afs_warn
-       ("afs: byte-range locks only enforced for processes on this machine.\n");
+       afs_warnuser
+           ("afs: byte-range locks only enforced for processes on this machine (pid %d (%s), user %ld).\n", pid, procname, afs_cr_uid(acred));
 #else
-    afs_warn
-       ("afs: byte-range lock/unlock ignored; make sure no one else is running this program.\n");
+       afs_warnuser
+           ("afs: byte-range lock/unlock ignored; make sure no one else is running this program (pid %d (%s), user %ld).\n", pid, procname, afs_cr_uid(acred));
 #endif
+       afs_osi_Free(procname, 256);
+    }
+    return;
 }
 
 
@@ -569,7 +584,7 @@ int afs_lockctl(struct vcache * avc, struct AFS_FLOCK * af, int acmd,
     /* next line makes byte range locks always succeed,
      * even when they should block */
     if (af->l_whence != 0 || af->l_start != 0 || af->l_len != 0) {
-       DoLockWarning();
+       DoLockWarning(acred);
        code = 0;
        goto done;
     }