Author: kib
Date: Thu Jul 28 11:43:25 2016
New Revision: 303432
URL: https://svnweb.freebsd.org/changeset/base/303432

Log:
  MFC r303151:
  Provide counter_warning(9) KPI.
  
  MFC r303155:
  Hide counted_warning(9) under #ifdef _KERNEL braces.
  
  Approved by:  re (gjb)

Modified:
  stable/11/sys/dev/pty/pty.c
  stable/11/sys/kern/subr_prf.c
  stable/11/sys/sys/systm.h
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/dev/pty/pty.c
==============================================================================
--- stable/11/sys/dev/pty/pty.c Thu Jul 28 11:10:13 2016        (r303431)
+++ stable/11/sys/dev/pty/pty.c Thu Jul 28 11:43:25 2016        (r303432)
@@ -52,10 +52,10 @@ __FBSDID("$FreeBSD$");
  * binary emulation.
  */
 
-static unsigned int pty_warningcnt = 1;
+static unsigned pty_warningcnt = 1;
 SYSCTL_UINT(_kern, OID_AUTO, tty_pty_warningcnt, CTLFLAG_RW,
-       &pty_warningcnt, 0,
-       "Warnings that will be triggered upon legacy PTY allocation");
+    &pty_warningcnt, 0,
+    "Warnings that will be triggered upon legacy PTY allocation");
 
 static int
 ptydev_fdopen(struct cdev *dev, int fflags, struct thread *td, struct file *fp)
@@ -77,12 +77,7 @@ ptydev_fdopen(struct cdev *dev, int ffla
        }
 
        /* Raise a warning when a legacy PTY has been allocated. */
-       if (pty_warningcnt > 0) {
-               pty_warningcnt--;
-               log(LOG_INFO, "pid %d (%s) is using legacy pty devices%s\n",
-                   td->td_proc->p_pid, td->td_name,
-                   pty_warningcnt ? "" : " - not logging anymore");
-       }
+       counted_warning(&pty_warningcnt, "is using legacy pty devices");
 
        return (0);
 }

Modified: stable/11/sys/kern/subr_prf.c
==============================================================================
--- stable/11/sys/kern/subr_prf.c       Thu Jul 28 11:10:13 2016        
(r303431)
+++ stable/11/sys/kern/subr_prf.c       Thu Jul 28 11:43:25 2016        
(r303432)
@@ -1196,3 +1196,24 @@ sbuf_hexdump(struct sbuf *sb, const void
        }
 }
 
+#ifdef _KERNEL
+void
+counted_warning(unsigned *counter, const char *msg)
+{
+       struct thread *td;
+       unsigned c;
+
+       for (;;) {
+               c = *counter;
+               if (c == 0)
+                       break;
+               if (atomic_cmpset_int(counter, c, c - 1)) {
+                       td = curthread;
+                       log(LOG_INFO, "pid %d (%s) %s%s\n",
+                           td->td_proc->p_pid, td->td_name, msg,
+                           c > 1 ? "" : " - not logging anymore");
+                       break;
+               }
+       }
+}
+#endif

Modified: stable/11/sys/sys/systm.h
==============================================================================
--- stable/11/sys/sys/systm.h   Thu Jul 28 11:10:13 2016        (r303431)
+++ stable/11/sys/sys/systm.h   Thu Jul 28 11:43:25 2016        (r303432)
@@ -447,4 +447,6 @@ void        intr_prof_stack_use(struct thread *
 
 extern void (*softdep_ast_cleanup)(void);
 
+void counted_warning(unsigned *counter, const char *msg);
+
 #endif /* !_SYS_SYSTM_H_ */
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to