Re: fontconfig-user.html location wrong in man pages

2015-07-14 Thread Matthieu Herrb
On Mon, Jul 13, 2015 at 07:59:00PM -0500, Chris Bennett wrote:
 After reading several man pages like fc-scan, etc.
 I found at the bottom:
 
 The fontconfig user's guide, in HTML format:
 /usr/share/doc/fontconfig/fontconfig-user.html.
 
 This is not the correct location, which is
 /usr/X11R6/share/doc/fontconfig/fontconfig-user.html
 
 OK?

No. I prefer to avoid this kind of local changes. They are painful to
maintain with CVS.

Either make that path configurable and let configure expand it, or do
some substituions in the OpenBSD makefile wrapper.

 
 Chris
 
 
 Index: fc-cache.1
 ===
 RCS file: /cvs/xenocara/dist/fontconfig/fc-cache/fc-cache.1,v
 retrieving revision 1.2
 diff -u -p -r1.2 fc-cache.1
 --- fc-cache.19 Mar 2013 13:58:47 -   1.2
 +++ fc-cache.114 Jul 2015 00:42:03 -
 @@ -77,7 +77,7 @@ appropriate fonts.
  \fBfc-scan\fR(1)
  .PP
  The fontconfig user's guide, in HTML format:
 -\fI/usr/share/doc/fontconfig/fontconfig-user.html\fR\.
 +\fI/usr/X11R6/share/doc/fontconfig/fontconfig-user.html\fR\.
  .SH AUTHOR
  .PP
  This manual page was written by Keith Packard
 Index: fc-cache.sgml
 ===
 RCS file: /cvs/xenocara/dist/fontconfig/fc-cache/fc-cache.sgml,v
 retrieving revision 1.2
 diff -u -p -r1.2 fc-cache.sgml
 --- fc-cache.sgml 9 Mar 2013 13:58:47 -   1.2
 +++ fc-cache.sgml 14 Jul 2015 00:43:16 -
 @@ -198,7 +198,7 @@ manpage.1: manpage.sgml
  /para
  
  paraThe fontconfig user's guide, in HTML format:
 -  
 filename/usr/share/doc/fontconfig/fontconfig-user.html/filename./para
 +  
 filename/usr/X11R6/share/doc/fontconfig/fontconfig-user.html/filename./para
  
   /refsect1
refsect1
 Index: fc-cat.1
 ===
 RCS file: /cvs/xenocara/dist/fontconfig/fc-cat/fc-cat.1,v
 retrieving revision 1.1.1.1
 diff -u -p -r1.1.1.1 fc-cat.1
 --- fc-cat.1  9 Mar 2013 13:34:09 -   1.1.1.1
 +++ fc-cat.1  14 Jul 2015 00:43:48 -
 @@ -39,7 +39,7 @@ Show version of the program and exit.
  \fBfc-scan\fR(1)
  .PP
  The fontconfig user's guide, in HTML format:
 -\fI/usr/share/doc/fontconfig/fontconfig-user.html\fR\.
 +\fI/usr/X11R6/share/doc/fontconfig/fontconfig-user.html\fR\.
  .SH AUTHOR
  .PP
  This manual page was written by Patrick Lam p...@mit.edu\.
 Index: fc-cat.sgml
 ===
 RCS file: /cvs/xenocara/dist/fontconfig/fc-cat/fc-cat.sgml,v
 retrieving revision 1.1.1.1
 diff -u -p -r1.1.1.1 fc-cat.sgml
 --- fc-cat.sgml   9 Mar 2013 13:34:09 -   1.1.1.1
 +++ fc-cat.sgml   14 Jul 2015 00:43:59 -
 @@ -140,7 +140,7 @@ manpage.1: manpage.sgml
  /para
  
  paraThe fontconfig user's guide, in HTML format:
 -  
 filename/usr/share/doc/fontconfig/fontconfig-user.html/filename./para
 +  
 filename/usr/X11R6/share/doc/fontconfig/fontconfig-user.html/filename./para
  
   /refsect1
refsect1
 Index: fc-list.1
 ===
 RCS file: /cvs/xenocara/dist/fontconfig/fc-list/fc-list.1,v
 retrieving revision 1.2
 diff -u -p -r1.2 fc-list.1
 --- fc-list.1 18 May 2014 10:33:05 -  1.2
 +++ fc-list.1 14 Jul 2015 00:44:27 -
 @@ -69,7 +69,7 @@ fonts.
  \fBfc-scan\fR(1)
  .PP
  The fontconfig user's guide, in HTML format:
 -\fI/usr/share/doc/fontconfig/fontconfig-user.html\fR\.
 +\fI/usr/X11R6/share/doc/fontconfig/fontconfig-user.html\fR\.
  .SH AUTHOR
  .PP
  This manual page was written by Keith Packard
 Index: fc-list.sgml
 ===
 RCS file: /cvs/xenocara/dist/fontconfig/fc-list/fc-list.sgml,v
 retrieving revision 1.2
 diff -u -p -r1.2 fc-list.sgml
 --- fc-list.sgml  18 May 2014 10:33:05 -  1.2
 +++ fc-list.sgml  14 Jul 2015 00:44:54 -
 @@ -197,7 +197,7 @@ manpage.1: manpage.sgml
  /para
  
  paraThe fontconfig user's guide, in HTML format:
 -  
 filename/usr/share/doc/fontconfig/fontconfig-user.html/filename./para
 +  
 filename/usr/X11R6/share/doc/fontconfig/fontconfig-user.html/filename./para
  
   /refsect1
refsect1
 Index: fc-match.1
 ===
 RCS file: /cvs/xenocara/dist/fontconfig/fc-match/fc-match.1,v
 retrieving revision 1.1.1.1
 diff -u -p -r1.1.1.1 fc-match.1
 --- fc-match.19 Mar 2013 13:34:26 -   1.1.1.1
 +++ fc-match.114 Jul 2015 00:45:23 -
 @@ -68,7 +68,7 @@ is displayed for matching fonts.
  \fBfc-scan\fR(1)
  .PP
  The fontconfig user's guide, in HTML format:
 -\fI/usr/share/doc/fontconfig/fontconfig-user.html\fR\.
 +\fI/usr/X11R6/share/doc/fontconfig/fontconfig-user.html\fR\.
  .SH AUTHOR
  .PP
  This manual page was updated by Patrick Lam p...@csail.mit.edu\.
 Index: fc-match.sgml
 

[patch v2] xlocale part 6: Switch _ctype_ from global variable to per-thread function

2015-07-14 Thread Sebastien Marie
On Sun, Jul 12, 2015 at 03:56:21PM +0200, Sebastien Marie wrote:
 _ctype_ is used in ctype.h header in order to define inline functions
 for determining character class: isalnum(3), isalpha(3), ...
 
 The character class comes from lc_ctype.
 
 Switch _ctype_ from global variable to function in order to retrieve the
 current locale state (global or per-thread).
 

Here an updated patch.

It includes changes in libstdc++ (as _ctype_ is directly used here too),
and I reformat the patch to follow style(9) a bit more.

-- 
Sebastien Marie

Index: b/include/ctype.h
===
--- a/include/ctype.h   2015-07-14 08:48:56.004595151 +0200
+++ b/include/ctype.h   2015-07-14 08:54:13.956819666 +0200
@@ -53,7 +53,7 @@
 
 __BEGIN_DECLS
 
-extern const char  *_ctype_;
+extern const char  *_ctype_(void);
 extern const short *_tolower_tab_;
 extern const short *_toupper_tab_;
 
@@ -90,57 +90,68 @@
 
 __only_inline int isalnum(int _c)
 {
-   return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c]  (_U|_L|_N)));
+   return (_c == -1 ?
+   0 : ((_ctype_() + 1)[(unsigned char)_c]  (_U|_L|_N)));
 }
 
 __only_inline int isalpha(int _c)
 {
-   return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c]  (_U|_L)));
+   return (_c == -1 ?
+   0 : ((_ctype_() + 1)[(unsigned char)_c]  (_U|_L)));
 }
 
 __only_inline int iscntrl(int _c)
 {
-   return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c]  _C));
+   return (_c == -1 ?
+   0 : ((_ctype_() + 1)[(unsigned char)_c]  _C));
 }
 
 __only_inline int isdigit(int _c)
 {
-   return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c]  _N));
+   return (_c == -1 ?
+   0 : ((_ctype_() + 1)[(unsigned char)_c]  _N));
 }
 
 __only_inline int isgraph(int _c)
 {
-   return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c]  
(_P|_U|_L|_N)));
+   return (_c == -1 ?
+   0 : ((_ctype_() + 1)[(unsigned char)_c]  (_P|_U|_L|_N)));
 }
 
 __only_inline int islower(int _c)
 {
-   return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c]  _L));
+   return (_c == -1 ?
+   0 : ((_ctype_() + 1)[(unsigned char)_c]  _L));
 }
 
 __only_inline int isprint(int _c)
 {
-   return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c]  
(_P|_U|_L|_N|_B)));
+   return (_c == -1 ?
+   0 : ((_ctype_() + 1)[(unsigned char)_c]  (_P|_U|_L|_N|_B)));
 }
 
 __only_inline int ispunct(int _c)
 {
-   return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c]  _P));
+   return (_c == -1 ?
+   0 : ((_ctype_() + 1)[(unsigned char)_c]  _P));
 }
 
 __only_inline int isspace(int _c)
 {
-   return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c]  _S));
+   return (_c == -1 ?
+   0 : ((_ctype_() + 1)[(unsigned char)_c]  _S));
 }
 
 __only_inline int isupper(int _c)
 {
-   return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c]  _U));
+   return (_c == -1 ?
+   0 : ((_ctype_() + 1)[(unsigned char)_c]  _U));
 }
 
 __only_inline int isxdigit(int _c)
 {
-   return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c]  (_N|_X)));
+   return (_c == -1 ?
+   0 : ((_ctype_() + 1)[(unsigned char)_c]  (_N|_X)));
 }
 
 __only_inline int tolower(int _c)
Index: b/lib/libc/gen/ctype_.c
===
--- a/lib/libc/gen/ctype_.c 2015-07-14 08:48:56.004595151 +0200
+++ b/lib/libc/gen/ctype_.c 2015-07-14 08:49:17.404801180 +0200
@@ -72,5 +72,3 @@
 0,  0,  0,  0,  0,  0,  0,  0, /* F0 */
 0,  0,  0,  0,  0,  0,  0,  0  /* F8 */
 };
-
-const char *_ctype_ = _C_ctype_;
Index: b/lib/libc/gen/isctype.c
===
--- a/lib/libc/gen/isctype.c2015-07-14 08:48:56.004595151 +0200
+++ b/lib/libc/gen/isctype.c2015-07-14 08:56:22.407746015 +0200
@@ -41,14 +41,16 @@
 int
 isalnum(int c)
 {
-   return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c]  (_U|_L|_N)));
+   return (c == EOF ?
+   0 : ((_ctype_() + 1)[(unsigned char)c]  (_U|_L|_N)));
 }
 
 #undef isalpha
 int
 isalpha(int c)
 {
-   return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c]  (_U|_L)));
+   return (c == EOF ?
+   0 : ((_ctype_() + 1)[(unsigned char)c]  (_U|_L)));
 }
 
 #undef isblank
@@ -62,63 +64,72 @@
 int
 iscntrl(int c)
 {
-   return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c]  _C));
+   return (c == EOF ?
+   0 : ((_ctype_() + 1)[(unsigned char)c]  _C));
 }
 
 #undef isdigit
 int
 isdigit(int c)
 {
-   return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c]  _N));
+   return (c == EOF ?
+   0 : ((_ctype_() + 1)[(unsigned char)c]  _N));
 }
 
 #undef isgraph
 int
 isgraph(int c)
 {
-   return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c]  
(_P|_U|_L|_N)));
+   return (c == EOF ?
+  

Re: unwritable PKG_CACHE directory

2015-07-14 Thread Dale Lindskog
If your point is that this is too trivial to waste more time on, then 
c'est la vie.  But just in case you also think you are right:

 It's simple. PKG_CACHE is a parameter to pkg_add.  If you run other 
 options, like -n or -s, there is an obvious interface conflict. What 
 should pkg_add obey ?
 
 ...  If PKG_CACHE is defined, pkg_add will obey it.

pkg_add doesn't always obey it:

# ls -ld $PKG_CACHE/gcal*
ls: /var/pkg_cache/gcal*: No such file or directory
# pkg_add -s gcal
quirks-2.54 signed on 2015-03-08T12:33:05Z
# ls -ld $PKG_CACHE/gcal*
ls: /var/pkg_cache/gcal*: No such file or directory



[patch v2] xlocale part 12: add xlocale functions

2015-07-14 Thread Sebastien Marie
On Sun, Jul 12, 2015 at 05:51:13PM +0200, Sebastien Marie wrote:
 The patch add the following functions:
   - newlocale(3)
   - duplocale(3)
   - freelocale(3)
   - uselocale(3)
 
 Documentation is missing for now. A separate patch will be provided.
 

Updated patch:
  - add stubs for xlocale functions in libstubs (for release(8)
process).

  - move uselocale() from xlocale.c to setlocale.c as it simplifies
libstubs modification

-- 
Sebastien Marie


Index: b/include/locale.h
===
--- a/include/locale.h  2015-07-14 08:53:01.626366226 +0200
+++ b/include/locale.h  2015-07-14 09:00:05.039158777 +0200
@@ -95,6 +95,20 @@
 extern struct _locale_t _lc_global_locale;
 #define LC_GLOBAL_LOCALE (_lc_global_locale)
 
+#defineLC_CTYPE_MASK   (1  0)
+#defineLC_NUMERIC_MASK (1  1)
+#defineLC_TIME_MASK(1  2)
+#defineLC_COLLATE_MASK (1  3)
+#defineLC_MONETARY_MASK(1  4)
+#defineLC_MESSAGES_MASK(1  5)
+
+#defineLC_ALL_MASK (0xff)
+
+locale_t   newlocale(int, const char *, locale_t);
+locale_t   duplocale(locale_t);
+void   freelocale(locale_t);
+locale_t   uselocale(locale_t);
+
 #endif /* __POSIX_VISIBLE = 200809 */
 __END_DECLS
 
Index: b/lib/libc/locale/setlocale.c
===
--- a/lib/libc/locale/setlocale.c   2015-07-14 09:00:04.939159279 +0200
+++ b/lib/libc/locale/setlocale.c   2015-07-14 10:04:40.055055572 +0200
@@ -32,6 +32,7 @@
  */
 
 #include sys/localedef.h
+#include errno.h
 #include locale.h
 #include limits.h
 #include paths.h
@@ -300,3 +301,141 @@
 
return env;
 }
+
+
+struct _locale_t *
+newlocale(int category_mask, const char *locale, struct _locale_t *base)
+{
+   int i, loadlocale_success;
+   struct _locale_t *newloc = NULL;
+
+   /* default value for base */
+   if (base == NULL)
+   base = _lc_global_locale;
+
+   if ((newloc = malloc(sizeof(struct _locale_t))) == NULL)
+   /* errno from malloc */
+   return (NULL);
+
+   /* flags (not installed, no cache) */
+   newloc-flags = 0;
+
+   /* load the locale for each categories */
+   loadlocale_success = 0;
+   for (i=1; i  _LC_LAST; i++)
+   if (((i == LC_COLLATE)  (category_mask  LC_COLLATE_MASK))
+   || ((i == LC_CTYPE)  (category_mask  LC_CTYPE_MASK))
+   || ((i == LC_MONETARY)  (category_mask LC_MONETARY_MASK))
+   || ((i == LC_NUMERIC)  (category_mask  LC_NUMERIC_MASK))
+   || ((i == LC_TIME)  (category_mask  LC_MESSAGES_MASK))) {
+
+   if (loadlocale(i, locale, newloc) != NULL)
+   loadlocale_success = 1;
+
+   } else {
+   if (loadlocale(i, base-categories[i], newloc) != NULL)
+   loadlocale_success = 1;
+   }
+
+/* failed if all categories failed */
+   if (loadlocale_success == 0) {
+   free(newloc);
+   return (NULL);
+   }
+
+   /* free base (_lc_global_locale is discarded by freelocale) */
+   freelocale(base);
+
+   return (newloc);
+}
+
+
+struct _locale_t *
+duplocale(struct _locale_t *loc)
+{
+   int i, loadlocale_success;
+   struct _locale_t *newloc = NULL;
+
+   /* check argument */
+   if (loc == NULL) {
+   errno = EINVAL;
+   return (NULL);
+   }
+
+   /* alloc */
+   if ((newloc = malloc(sizeof(struct _locale_t))) == NULL)
+   /* errno from malloc */
+   return (NULL);
+
+   /* flags */
+   newloc-flags = 0;
+
+   /* load the locale for each categories */
+   loadlocale_success = 0;
+   for (i=1; i  _LC_LAST; i++)
+   if (loadlocale(i, loc-categories[i], newloc) != NULL)
+   loadlocale_success = 1;
+
+   /* failed if all categories failed */
+   if (loadlocale_success == 0) {
+   free(newloc);
+   newloc = NULL;
+   }
+
+   return (newloc);
+}
+
+
+void
+freelocale(struct _locale_t *loc)
+{
+   int i;
+
+   /*
+* discard on:
+* - NULL
+* - attempt to free global locale
+* - attempt to free an currently installed locale
+*/
+   if ((loc == NULL)
+   || (loc == _lc_global_locale)
+   || xlocale_is_installed(loc-flags))
+   return;
+
+   /* reset to default values */
+   for (i=1; i  _LC_LAST; i++)
+   loadlocale(i, C, loc);
+
+   free(loc);
+}
+
+
+struct _locale_t *
+uselocale(struct _locale_t * newloc)
+{
+   struct _locale_t * oldloc = NULL;
+
+   /* query mode */
+   if (newloc == NULL)
+   return (_current_locale());
+
+   /* reset 

[patch v2] xlocale part 5: Switch __mb_cur_max from global variable to per-thread function

2015-07-14 Thread Sebastien Marie
On Sun, Jul 12, 2015 at 03:51:14PM +0200, Sebastien Marie wrote:
 ctype.h header define MB_CUR_MAX macro to be the maximum number of bytes
 in a character specified by the current locale (category LC_CTYPE).
 
 Switch the implementation from global variable to function, in order to
 get the value from the current locale state (global or per-thread).
 

Updated patch:
 - as __mb_cur_max is now a function, it should be between __BEGIN_DECLS
   and __END_DECLS else C++ don't see it.

-- 
Sebastien Marie


Index: b/include/stdlib.h
===
--- a/include/stdlib.h  2015-07-09 09:38:57.743213873 +0200
+++ b/include/stdlib.h  2015-07-14 11:47:29.235163404 +0200
@@ -92,8 +92,7 @@
 
 #defineRAND_MAX0x7fff
 
-extern size_t  __mb_cur_max;
-#defineMB_CUR_MAX  __mb_cur_max
+#defineMB_CUR_MAX  __mb_cur_max()
 
 #include sys/cdefs.h
 
@@ -107,6 +106,7 @@
 #endif
 
 __BEGIN_DECLS
+size_t  __mb_cur_max(void);
 __dead void abort(void);
 int abs(int);
 int atexit(void (*)(void));
Index: b/lib/libc/locale/__mb_cur_max.c
===
--- a/lib/libc/locale/__mb_cur_max.c2015-07-09 09:38:57.743213873 +0200
+++ b/lib/libc/locale/__mb_cur_max.c2015-07-09 09:50:46.178175455 +0200
@@ -30,6 +30,19 @@
 #include sys/types.h
 #include limits.h
 
-size_t __mb_cur_max = 1;
+#include rune.h
+#include citrus/citrus_ctype_local.h
+#include xlocale_private.h
+
 size_t __mb_len_max_runtime = MB_LEN_MAX;
 
+size_t
+__mb_cur_max()
+{
+   locale_t loc = _current_locale();
+
+   if (loc-lc_ctype-rl_citrus_ctype != NULL)
+   return (loc-lc_ctype-rl_citrus_ctype-cc_mb_cur_max);
+   else
+   return (1);
+}
Index: b/lib/libc/locale/setrunelocale.c
===
--- a/lib/libc/locale/setrunelocale.c   2015-07-09 09:48:35.757157373 +0200
+++ b/lib/libc/locale/setrunelocale.c   2015-07-09 09:50:46.178175455 +0200
@@ -218,7 +218,6 @@
 
 found:
locale-lc_ctype = rl;
-   __mb_cur_max = rl-rl_citrus_ctype-cc_mb_cur_max;
 
return 0;
 }



Re: [PATCH] Slight clarification in iked.conf(5)

2015-07-14 Thread Jason McIntyre
On Sat, Jul 04, 2015 at 09:44:10PM -0400, trondd wrote:
 The from and to values for iked seemed backwords to me and the man page
 example description didn't clarify it.
 
 Make it a little more specific which end the example is talking about.
 
 Tim.
 

fixed, thanks.
jmc

 
 Index: iked.conf.5
 ===
 RCS file: /cvs/src/sbin/iked/iked.conf.5,v
 retrieving revision 1.38
 diff -u -p -r1.38 iked.conf.5
 --- iked.conf.5 28 Feb 2015 21:51:57 -  1.38
 +++ iked.conf.5 5 Jul 2015 00:17:49 -
 @@ -831,7 +831,7 @@ or the non-standard Curve25519.
  Please note that the EC2N groups are considered as insecure and only
  provided for backwards compatibility.
  .Sh EXAMPLES
 -The first example is intended for clients connecting to
 +The first example is intended for a server with clients connecting to
  .Xr iked 8
  as an IPsec gateway, or IKEv2 responder, using mutual public key
  authentication and additional challenge-based EAP-MSCHAPv2 password
 



Re: Fix for segfault in find(1)

2015-07-14 Thread Todd C. Miller
On Tue, 14 Jul 2015 17:52:52 +0200, Gregor Best wrote:

Comments inline:

 Index: misc.c
 ===
 RCS file: /mnt/media/cvs/src/usr.bin/find/misc.c,v
 retrieving revision 1.12
 diff -u -p -u -r1.12 misc.c
 --- misc.c18 May 2014 08:10:00 -  1.12
 +++ misc.c14 Jul 2015 15:41:20 -
 @@ -66,6 +66,7 @@ brace_subst(char *orig, char **store, ch
   if (!(newstore = realloc(*store, newlen)))
   err(1, NULL);
   *store = newstore;
 + p = newstore;

Shouldn't this be:

p = (p - *store) + newstore;

   len = newlen;
   }
   memmove(p, path, plen);
 



find(1): replace remaining realloc()

2015-07-14 Thread Todd C. Miller
Use reallocarray() to replace the one remaining realloc() in find.

 - todd

Index: usr.bin/find/misc.c
===
RCS file: /cvs/src/usr.bin/find/misc.c,v
retrieving revision 1.13
diff -u -p -u -r1.13 misc.c
--- usr.bin/find/misc.c 14 Jul 2015 16:16:07 -  1.13
+++ usr.bin/find/misc.c 14 Jul 2015 16:21:18 -
@@ -60,14 +60,14 @@ brace_subst(char *orig, char **store, ch
for (p = *store; (ch = *orig); ++orig)
if (ch == '{'  orig[1] == '}') {
while ((p - *store) + plen  len) {
-   int newlen = len * 2;
char *newstore;
 
-   if (!(newstore = realloc(*store, newlen)))
+   newstore = reallocarray(*store, len, 2);
+   if (newstore == NULL)
err(1, NULL);
p = (p - *store) + newstore;
*store = newstore;
-   len = newlen;
+   len *= 2;
}
memmove(p, path, plen);
p += plen;



Re: Fix for segfault in find(1)

2015-07-14 Thread Gregor Best
On Tue, Jul 14, 2015 at 09:57:45AM -0600, Todd C. Miller wrote:
 [...]
 Shouldn't this be:
 
   p = (p - *store) + newstore;
 [...]

Of course, that makes way more sense. An amended patch is attached.

-- 
Gregor

Index: misc.c
===
RCS file: /mnt/media/cvs/src/usr.bin/find/misc.c,v
retrieving revision 1.12
diff -u -p -u -r1.12 misc.c
--- misc.c  18 May 2014 08:10:00 -  1.12
+++ misc.c  14 Jul 2015 16:07:28 -
@@ -65,6 +65,7 @@ brace_subst(char *orig, char **store, ch
 
if (!(newstore = realloc(*store, newlen)))
err(1, NULL);
+   p = (p - *store) + newstore;
*store = newstore;
len = newlen;
}



Re: Fix for segfault in find(1)

2015-07-14 Thread Todd C. Miller
On Tue, 14 Jul 2015 12:55:35 -0400, Ted Unangst wrote:

 so technically i believe this is still undefined since you're not supposed to
 look at freed pointers. an even more better fix would be to save the offset
 before the realloc.

Yeah, I forgot we had to deref store.

 - todd

Index: misc.c
===
RCS file: /cvs/src/usr.bin/find/misc.c,v
retrieving revision 1.14
diff -u -p -u -r1.14 misc.c
--- misc.c  14 Jul 2015 16:58:22 -  1.14
+++ misc.c  14 Jul 2015 17:05:19 -
@@ -39,6 +39,7 @@
 #include err.h
 #include errno.h
 #include fts.h
+#include stddef.h
 #include stdio.h
 #include stdlib.h
 #include string.h
@@ -60,12 +61,14 @@ brace_subst(char *orig, char **store, ch
for (p = *store; (ch = *orig); ++orig)
if (ch == '{'  orig[1] == '}') {
while ((p - *store) + plen  len) {
+   ptrdiff_t p_off;
char *newstore;
 
+   p_off = (p - *store);
newstore = reallocarray(*store, len, 2);
if (newstore == NULL)
err(1, NULL);
-   p = (p - *store) + newstore;
+   p = newstore + p_off;
*store = newstore;
len *= 2;
}



Re: Fix for segfault in find(1)

2015-07-14 Thread Ted Unangst
Gregor Best wrote:
 On Tue, Jul 14, 2015 at 09:57:45AM -0600, Todd C. Miller wrote:
  [...]
  Shouldn't this be:
  
  p = (p - *store) + newstore;
  [...]
 
 Of course, that makes way more sense. An amended patch is attached.

so technically i believe this is still undefined since you're not supposed to
look at freed pointers. an even more better fix would be to save the offset
before the realloc.



Stalled IPI processing on octeon

2015-07-14 Thread Visa Hankala
The patch below solves stalled IPI processing on octeon. When IPIs are
finally enabled during boot, some kernel threads have already been
started. There seems to be no mechanism that would update interrupt
masks for a running thread, so the early threads run IPIs disabled.
This will lead to a deadlock quite soon after launching other cores.
The patch makes the registering of the IPI handler happen early enough
for the correct idle_mask to propagate to all threads.

With the patch, an EdgeRouter Lite boots quite nicely with two cores.
There are stability issues however. My test setup tends to panic or
hang after a while. I am trying to find out the cause. It seems
unrelated to the patch.


Index: arch/octeon/octeon/machdep.c
===
RCS file: src/sys/arch/octeon/octeon/machdep.c,v
retrieving revision 1.64
diff -u -p -r1.64 machdep.c
--- arch/octeon/octeon/machdep.c25 Jun 2015 10:56:00 -  1.64
+++ arch/octeon/octeon/machdep.c14 Jul 2015 14:11:31 -
@@ -128,6 +128,10 @@ intocteon_cpuspeed(int *);
 static voidprocess_bootargs(void);
 static uint64_tget_ncpusfound(void);
 
+#ifdef MULTIPROCESSOR
+uint32_t   ipi_intr(uint32_t, struct trap_frame *);
+#endif
+
 extern voidparse_uboot_root(void);
 
 cons_decl(cn30xxuart);
@@ -487,6 +491,10 @@ mips_init(__register_t a0, __register_t 
Debugger();
 #endif
 
+#ifdef MULTIPROCESSOR
+   set_intr(INTPRI_IPI, CR_INT_1, ipi_intr);
+#endif
+
/*
 * Return the new kernel stack pointer.
 */
@@ -770,8 +778,7 @@ is_memory_range(paddr_t pa, psize_t len,
 uint32_t cpu_spinup_mask = 0;
 uint64_t cpu_spinup_a0, cpu_spinup_sp;
 static int (*ipi_handler)(void *);
-
-uint32_t ipi_intr(uint32_t, struct trap_frame *);
+static int ipi_enabled = 0;
 
 extern bus_space_t iobus_tag;
 extern bus_space_handle_t iobus_h;
@@ -852,6 +859,9 @@ ipi_intr(uint32_t hwpend, struct trap_fr
 */
bus_space_write_8(iobus_tag, iobus_h, CIU_IP3_EN0(cpuid), 0);
 
+   if (!ipi_enabled)
+   return hwpend;
+
ipi_handler((void *)cpuid);
 
/*
@@ -865,14 +875,16 @@ ipi_intr(uint32_t hwpend, struct trap_fr
 int
 hw_ipi_intr_establish(int (*func)(void *), u_long cpuid)
 {
-   if (cpuid == 0)
+   if (cpuid == 0) {
ipi_handler = func;
+   mips_sync();
+   ipi_enabled = 1;
+   }
 
bus_space_write_8(iobus_tag, iobus_h, CIU_MBOX_CLR(cpuid),
0x);
bus_space_write_8(iobus_tag, iobus_h, CIU_IP3_EN0(cpuid),
(1ULL  CIU_INT_MBOX0)|(1ULL  CIU_INT_MBOX1));
-   set_intr(INTPRI_IPI, CR_INT_1, ipi_intr);
 
return 0;
 };



Re: ieee80211.h: update standard references

2015-07-14 Thread Todd C. Miller
On Tue, 14 Jul 2015 22:33:39 +0200, Stefan Sperling wrote:

 I'd rather have the header be consistent with the standard.
 I have no problem with implementing extensions to the standard but I don't
 see a point in declaring non-standard elements without using them.

OK, fair enough.

 - todd



Re: ieee80211.h: update standard references

2015-07-14 Thread Todd C. Miller
On Tue, 14 Jul 2015 20:47:57 +0200, Stefan Sperling wrote:

 Updates standard references to 802.11-2012 (except for crypto).
 
 Also adds some new symbols from 802.11-2012.

Some of these names are needlessly different from ieee80211.h in
Free and Net.  Also, what happened to IEEE80211_ELEMID_TPC and
IEEE80211_ELEMID_CCKM?  I don't suppose it matters much since those
two are unused it just seems odd to drop them since they are present
in Free, Net and Linux.

 - todd



[patch] (www) Outdated and unnecessary version numbers

2015-07-14 Thread Michael McConville
Also, 'or' - 'and'.



Index: faq/faq15.html
===
RCS file: /cvs/www/faq/faq15.html,v
retrieving revision 1.110
diff -u -p -r1.110 faq15.html
--- faq/faq15.html  13 Jul 2015 06:08:56 -  1.110
+++ faq/faq15.html  14 Jul 2015 20:53:22 -
@@ -1078,8 +1078,7 @@ This will call pkg_add(1) with the b-r
 p
 bNote:/b
 Large applications will require a lot of system resources to build.
-Good examples are compilers like GCC 4.0 or the Java 2 Software
-Development Kit.
+Good examples are compilers like GCC and the Java Software Development Kit.
 If you get out of memory type of errors when building such a port,
 this usually has one of two causes:
 
Index: faq/obsd-faq.txt
===
RCS file: /cvs/www/faq/obsd-faq.txt,v
retrieving revision 1.39
diff -u -p -r1.39 obsd-faq.txt
--- faq/obsd-faq.txt5 Jun 2015 12:04:13 -   1.39
+++ faq/obsd-faq.txt14 Jul 2015 20:53:23 -
@@ -13778,7 +13778,7 @@ installed on your system, you can use ma
 This will call pkg_add(1) with the -r flag.
 
 Note: Large applications will require a lot of system resources to build. Good
-examples are compilers like GCC 4.0 or the Java 2 Software Development Kit. If
+examples are compilers like GCC and the Java Software Development Kit. If
 you get out of memory type of errors when building such a port, this usually
 has one of two causes:
 
Index: faq/ports/ports.html
===
RCS file: /cvs/www/faq/ports/ports.html,v
retrieving revision 1.30
diff -u -p -r1.30 ports.html
--- faq/ports/ports.html2 Jul 2015 05:49:05 -   1.30
+++ faq/ports/ports.html14 Jul 2015 20:53:23 -
@@ -532,8 +532,7 @@ This will call pkg_add(1) with the tt-
 p
 bNote:/b
 Large applications will require a lot of system resources to build.
-Good examples are compilers like GCC 4.0 or the Java 2 Software
-Development Kit.
+Good examples are compilers like GCC and the Java Software Development Kit.
 If you get out of memory type of errors when building such a port,
 this usually has one of two causes:
 



Re: ieee80211.h: update standard references

2015-07-14 Thread Stefan Sperling
On Tue, Jul 14, 2015 at 01:18:00PM -0600, Todd C. Miller wrote:
 On Tue, 14 Jul 2015 20:47:57 +0200, Stefan Sperling wrote:
 
  Updates standard references to 802.11-2012 (except for crypto).
  
  Also adds some new symbols from 802.11-2012.
 
 Some of these names are needlessly different from ieee80211.h in
 Free and Net.

Ah, thanks. I'll check that out.

 Also, what happened to IEEE80211_ELEMID_TPC and
 IEEE80211_ELEMID_CCKM?  I don't suppose it matters much since those
 two are unused it just seems odd to drop them since they are present
 in Free, Net and Linux.

The standard doesn't list them. They are in a range marked as reserved.

It seems CCKM is a proprietary Cisco extension for roaming which we 
can't support anyway because we don't support roaming.

For TCP there are two elements in the standard using different numbers,
IEEE80211_ELEMID_TPC_REQUEST and IEEE80211_ELEMID_TPC_REPORT, which I've
added. I'm not sure where IEEE80211_ELEMID_TPC came from (exists since r1.1).

I'd rather have the header be consistent with the standard.
I have no problem with implementing extensions to the standard but I don't
see a point in declaring non-standard elements without using them.



Thinkpad active cooling

2015-07-14 Thread Tobias Ulmer
As we all know, some Thinkpads have problems with their EC fan control.
EC is not spinning up the fans to maximum speed, let alone blast mode.
They also do not offer ACPI methods to spin the fan up.

Previous diffs doing manual fan control were always rejected because
hooking into the sensors framework with fixed temp limits is crude and
there are concerns with slowing the fan down and frying the hardware.

This is an attempt to solve the problem slightly differently.
- Hook into acpitz and only speed the fan up when it is requesting active
  cooling
- Never set the fan to a mode that would endanger the hardware should we
  crash

PS: It would be nice if there was a function to add cooling methods to
acpitz eg: acpitz_add(void (*fn)(struct acpitz_softc *, void *), void *arg)
I tried but getting struct acpitz_softc into a header is a bit messy.

Index: acpithinkpad.c
===
RCS file: /home/vcs/cvs/openbsd/src/sys/dev/acpi/acpithinkpad.c,v
retrieving revision 1.44
diff -u -p -r1.44 acpithinkpad.c
--- acpithinkpad.c  24 Apr 2015 14:44:17 -  1.44
+++ acpithinkpad.c  14 Jul 2015 23:52:14 -
@@ -104,6 +104,11 @@
 #define THINKPAD_ECOFFSET_FANLO0x84
 #define THINKPAD_ECOFFSET_FANHI0x85
 
+#define THINKPAD_ECOFFSET_FANLEVEL 0x2f
+#define THINKPAD_ECFANLEVEL_MAX7
+#define THINKPAD_ECFANLEVEL_BLAST  (16)
+#define THINKPAD_ECFANLEVEL_AUTO   (17)
+
 #defineTHINKPAD_ADAPTIVE_MODE_HOME 1
 #defineTHINKPAD_ADAPTIVE_MODE_FUNCTION 3
 
@@ -119,6 +124,7 @@ struct acpithinkpad_softc {
 };
 
 extern void acpiec_read(struct acpiec_softc *, u_int8_t, int, u_int8_t *);
+extern void (*acpitz_activecool)(int, int);
 
 intthinkpad_match(struct device *, void *, void *);
 void   thinkpad_attach(struct device *, struct device *, void *);
@@ -134,6 +140,7 @@ int thinkpad_brightness_up(struct acpith
 intthinkpad_brightness_down(struct acpithinkpad_softc *);
 intthinkpad_adaptive_change(struct acpithinkpad_softc *);
 intthinkpad_activate(struct device *, int);
+voidthinkpad_activecool(int, int);
 
 voidthinkpad_sensor_attach(struct acpithinkpad_softc *sc);
 voidthinkpad_sensor_refresh(void *);
@@ -228,6 +235,7 @@ thinkpad_attach(struct device *parent, s
 {
struct acpithinkpad_softc *sc = (struct acpithinkpad_softc *)self;
struct acpi_attach_args *aa = aux;
+   u_int8_t level;
 
sc-sc_acpi = (struct acpi_softc *)parent;
sc-sc_devnode = aa-aaa_node;
@@ -241,6 +249,11 @@ thinkpad_attach(struct device *parent, s
/* Run thinkpad_hotkey on button presses */
aml_register_notify(sc-sc_devnode, aa-aaa_dev,
thinkpad_hotkey, sc, ACPIDEV_POLL);
+
+   /* Make sure fan is in auto mode, otherwise we're not sure of support */
+   acpiec_read(acpi_softc-sc_ec, THINKPAD_ECOFFSET_FANLEVEL, 1, level);
+   if (level == THINKPAD_ECFANLEVEL_AUTO)
+   acpitz_activecool = thinkpad_activecool;
 }
 
 int
@@ -546,4 +559,30 @@ thinkpad_activate(struct device *self, i
break;
}
return (0);
+}
+
+void
+thinkpad_activecool(int tmp, int psv)
+{
+   static uint8_t level = THINKPAD_ECFANLEVEL_AUTO;
+   uint8_t nlevel;
+
+   if (tmp  0 || psv  0)
+   return;
+
+   if (tmp  psv)
+   nlevel = THINKPAD_ECFANLEVEL_BLAST;
+   else if (tmp  psv-50)
+   /* EC firmware fan control is too slow in some models. When
+* we're getting within 5C of active cooling mode, turn the
+* fan to MAX. Helps with oscillation between blast and auto */
+   nlevel = THINKPAD_ECFANLEVEL_MAX;
+   else
+   nlevel = THINKPAD_ECFANLEVEL_AUTO;
+
+   if (nlevel != level) {
+   acpiec_write(acpi_softc-sc_ec, THINKPAD_ECOFFSET_FANLEVEL, 1,
+   nlevel);
+   level = nlevel;
+   }
 }
Index: acpitz.c
===
RCS file: /home/vcs/cvs/openbsd/src/sys/dev/acpi/acpitz.c,v
retrieving revision 1.49
diff -u -p -r1.49 acpitz.c
--- acpitz.c6 May 2015 01:41:55 -   1.49
+++ acpitz.c14 Jul 2015 23:52:14 -
@@ -86,6 +86,7 @@ int   acpitz_setfan(struct acpitz_softc *,
 void   acpitz_init(struct acpitz_softc *, int);
 
 void   (*acpitz_cpu_setperf)(int);
+void(*acpitz_activecool)(int, int) = NULL;
 intacpitz_perflevel = -1;
 extern void(*cpu_setperf)(int);
 extern int perflevel;
@@ -427,6 +428,11 @@ acpitz_refresh(void *arg)
acpitz_setfan(sc, i, _OFF);
}
}
+
+   /* active cooling hook */
+   if (acpitz_activecool)
+   acpitz_activecool(sc-sc_tmp, sc-sc_psv);
+
sc-sc_sens.value = sc-sc_tmp * 10 - 5;
 }
 



Re: Thinkpad active cooling

2015-07-14 Thread Paul Irofti
I am not familiar with all the fan hack specifics so please keep that in mind
if my questions and comments seem trivial.

 This is an attempt to solve the problem slightly differently.
 - Hook into acpitz and only speed the fan up when it is requesting active
   cooling
 - Never set the fan to a mode that would endanger the hardware should we
   crash

Your diff applies to all Thinkpad models. Is that okay?

 
 PS: It would be nice if there was a function to add cooling methods to
 acpitz eg: acpitz_add(void (*fn)(struct acpitz_softc *, void *), void *arg)
 I tried but getting struct acpitz_softc into a header is a bit messy.

If needed you can move the softc in the acpivar.h header file.
Nothing messy about it. What other model drivers would need this though?

thinkpad_hotkey, sc, ACPIDEV_POLL);
 +
 + /* Make sure fan is in auto mode, otherwise we're not sure of support */
 + acpiec_read(acpi_softc-sc_ec, THINKPAD_ECOFFSET_FANLEVEL, 1, level);
 + if (level == THINKPAD_ECFANLEVEL_AUTO)
 + acpitz_activecool = thinkpad_activecool;

Why is there no support if the fan is not in auto mode?

 + else if (tmp  psv-50)
 + /* EC firmware fan control is too slow in some models. When
 +  * we're getting within 5C of active cooling mode, turn the
 +  * fan to MAX. Helps with oscillation between blast and auto */

This comment does not follow KNF :-)

 + nlevel = THINKPAD_ECFANLEVEL_MAX;
 + else
 + nlevel = THINKPAD_ECFANLEVEL_AUTO;
 +
 + if (nlevel != level) {
 + acpiec_write(acpi_softc-sc_ec, THINKPAD_ECOFFSET_FANLEVEL, 1,
 + nlevel);
 + level = nlevel;
 + }
  }
 Index: acpitz.c
 ===
 RCS file: /home/vcs/cvs/openbsd/src/sys/dev/acpi/acpitz.c,v
 retrieving revision 1.49
 diff -u -p -r1.49 acpitz.c
 --- acpitz.c  6 May 2015 01:41:55 -   1.49
 +++ acpitz.c  14 Jul 2015 23:52:14 -
 @@ -86,6 +86,7 @@ int acpitz_setfan(struct acpitz_softc *,
  void acpitz_init(struct acpitz_softc *, int);
  
  void (*acpitz_cpu_setperf)(int);
 +void(*acpitz_activecool)(int, int) = NULL;
  int  acpitz_perflevel = -1;
  extern void  (*cpu_setperf)(int);
  extern int   perflevel;
 @@ -427,6 +428,11 @@ acpitz_refresh(void *arg)
   acpitz_setfan(sc, i, _OFF);
   }
   }
 +
 + /* active cooling hook */
 + if (acpitz_activecool)
 + acpitz_activecool(sc-sc_tmp, sc-sc_psv);
 +

I'm not sure, but is it ever possible for acpitz to attach BEFORE
acpithinkpad and render this check false?
Would you need to somehow tie the two together?



Re: Thinkpad active cooling

2015-07-14 Thread Tobias Ulmer
Theo is asking for affected models, so lets compile a list.
All my Thinkpads can be provoked into shutdown due to overtemp because
the fan doesn't spin up:

T60
T61
X201



Re: Thinkpad active cooling

2015-07-14 Thread Michael McConville
On Wed, Jul 15, 2015 at 03:04:07AM +0200, Tobias Ulmer wrote:
 Theo is asking for affected models, so lets compile a list.
 All my Thinkpads can be provoked into shutdown due to overtemp because
 the fan doesn't spin up:
 
 T60
 T61
 X201

I've had it happen on my X201, but only once in the ~6 months I've had
it. I was building a Coq library with all four cores in a hot lab. It's
survived many other build beatings without issue, and I've never noticed
a problem with the fans. I'm not questioning that it could be improved,
though.



Re: Thinkpad active cooling

2015-07-14 Thread Tobias Ulmer
On Wed, Jul 15, 2015 at 05:12:41AM +0300, Paul Irofti wrote:
 I am not familiar with all the fan hack specifics so please keep that in mind
 if my questions and comments seem trivial.
 
  This is an attempt to solve the problem slightly differently.
  - Hook into acpitz and only speed the fan up when it is requesting active
cooling
  - Never set the fan to a mode that would endanger the hardware should we
crash
 
 Your diff applies to all Thinkpad models. Is that okay?

It applies to all Thinkpads that have a sensible value in
THINKPAD_ECOFFSET_FANLEVEL, as you noticed. There is no flag or
documentation indicating the existence of this register as far as I
know. It's somewhat of a tradition, every TP I've owned had it.

My hope is if they drop support or move the offset, the value will
change and we won't do any damage.

I'm thinking this can be improved further by querying ACPI for _AC, so
it doesn't ever interfere with  acpitz_setfan(). I'll look into this.

 
  
  PS: It would be nice if there was a function to add cooling methods to
  acpitz eg: acpitz_add(void (*fn)(struct acpitz_softc *, void *), void *arg)
  I tried but getting struct acpitz_softc into a header is a bit messy.
 
 If needed you can move the softc in the acpivar.h header file.
 Nothing messy about it. What other model drivers would need this though?

So far none, but I imagine we will see more software controlled power
management in the future. I guess I just don't like global variables and
extern declarations :)

 
   thinkpad_hotkey, sc, ACPIDEV_POLL);
  +
  +   /* Make sure fan is in auto mode, otherwise we're not sure of support */
  +   acpiec_read(acpi_softc-sc_ec, THINKPAD_ECOFFSET_FANLEVEL, 1, level);
  +   if (level == THINKPAD_ECFANLEVEL_AUTO)
  +   acpitz_activecool = thinkpad_activecool;
 
 Why is there no support if the fan is not in auto mode?

Trying not to break future models.

 
  +   else if (tmp  psv-50)
  +   /* EC firmware fan control is too slow in some models. When
  +* we're getting within 5C of active cooling mode, turn the
  +* fan to MAX. Helps with oscillation between blast and auto */
 
 This comment does not follow KNF :-)

Heh, I'll fix that to make you happy ;)

 
  +   nlevel = THINKPAD_ECFANLEVEL_MAX;
  +   else
  +   nlevel = THINKPAD_ECFANLEVEL_AUTO;
  +
  +   if (nlevel != level) {
  +   acpiec_write(acpi_softc-sc_ec, THINKPAD_ECOFFSET_FANLEVEL, 1,
  +   nlevel);
  +   level = nlevel;
  +   }
   }
  Index: acpitz.c
  ===
  RCS file: /home/vcs/cvs/openbsd/src/sys/dev/acpi/acpitz.c,v
  retrieving revision 1.49
  diff -u -p -r1.49 acpitz.c
  --- acpitz.c6 May 2015 01:41:55 -   1.49
  +++ acpitz.c14 Jul 2015 23:52:14 -
  @@ -86,6 +86,7 @@ int   acpitz_setfan(struct acpitz_softc *,
   void   acpitz_init(struct acpitz_softc *, int);
   
   void   (*acpitz_cpu_setperf)(int);
  +void(*acpitz_activecool)(int, int) = NULL;
   intacpitz_perflevel = -1;
   extern void(*cpu_setperf)(int);
   extern int perflevel;
  @@ -427,6 +428,11 @@ acpitz_refresh(void *arg)
  acpitz_setfan(sc, i, _OFF);
  }
  }
  +
  +   /* active cooling hook */
  +   if (acpitz_activecool)
  +   acpitz_activecool(sc-sc_tmp, sc-sc_psv);
  +
 
 I'm not sure, but is it ever possible for acpitz to attach BEFORE
 acpithinkpad and render this check false?
 Would you need to somehow tie the two together?

The check evaluating to false is not a problem, it will become true in
time, it's a slow running loop. I didn't see any locking around
acpitz_cpu_setperf(), so I'm guessing it's fine



Re: Stalled IPI processing on octeon

2015-07-14 Thread Miod Vallat
 The patch below solves stalled IPI processing on octeon. When IPIs are
 finally enabled during boot, some kernel threads have already been
 started. There seems to be no mechanism that would update interrupt
 masks for a running thread, so the early threads run IPIs disabled.
 This will lead to a deadlock quite soon after launching other cores.
 The patch makes the registering of the IPI handler happen early enough
 for the correct idle_mask to propagate to all threads.

This makes sense. However, your `ipi_enabled' new variable basically
mimics an `if (ipi_handler != NULL)' test, so there is no need for an
extra variable.

Miod



Re: Thinkpad active cooling

2015-07-14 Thread Tobias Ulmer
On Wed, Jul 15, 2015 at 12:03:45AM -0400, Ted Unangst wrote:
 Tobias Ulmer wrote:
  As we all know, some Thinkpads have problems with their EC fan control.
  EC is not spinning up the fans to maximum speed, let alone blast mode.
  They also do not offer ACPI methods to spin the fan up.
  
  Previous diffs doing manual fan control were always rejected because
  hooking into the sensors framework with fixed temp limits is crude and
  there are concerns with slowing the fan down and frying the hardware.
  
  This is an attempt to solve the problem slightly differently.
  - Hook into acpitz and only speed the fan up when it is requesting active
cooling
  - Never set the fan to a mode that would endanger the hardware should we
crash
 
 Can you clarify what if any effect should be observed with this diff? Will it
 make my fans louder or quieter?
 
 (I was very happy to discover that with the C states diff, my one thinkpad now
 idles at 3000 rpm vs 3500 rpm, and that is actually a lot quieter.)
 

There should be zero change in behaviour for normal use.

Only if thermal zone temp reaches its passive cooling limit (93C on my
X201) and demands active cooling will it spin the fan up. At the same
time acpitz also reduces cpuspeed. Once temps are back to normal it
switches to automatic mode and the fans should quiet down.



urtw(4): don't panic in error paths

2015-07-14 Thread Stefan Sperling
urtw(4) contains panic calls in error paths, which are counterproductive,
if not dangerous.

I have a urtw device with a dying connector which doesn't attach
most of the time but will sometimes attach if wiggled a bit.

Without the diff below, the device triggers a panic rather quickly,
such as unsupported RF chip.
With the diff the device works fine if it happens to attach, and only
as long as it is not touched while operating.

Index: if_urtw.c
===
RCS file: /cvs/src/sys/dev/usb/if_urtw.c,v
retrieving revision 1.53
diff -u -p -r1.53 if_urtw.c
--- if_urtw.c   12 Jun 2015 15:47:31 -  1.53
+++ if_urtw.c   15 Jul 2015 05:08:25 -
@@ -1252,8 +1252,7 @@ urtw_get_rfchip(struct urtw_softc *sc)
if (sc-sc_hwrev  URTW_HWREV_8187) {
error = urtw_eprom_read32(sc, URTW_EPROM_RFCHIPID, data);
if (error != 0)
-   panic(unsupported RF chip);
-   /* NOTREACHED */
+   goto fail;
switch (data  0xff) {
case URTW_EPROM_RFCHIPID_RTL8225U:
error = urtw_8225_isv2(sc, ret);
@@ -1286,8 +1285,8 @@ urtw_get_rfchip(struct urtw_softc *sc)
return (0);
 
 fail:
-   panic(unsupported RF chip %d, data  0xff);
-   /* NOTREACHED */
+   printf(unsupported RF chip %d, data  0xff);
+   return (error);
 }
 
 usbd_status
@@ -1793,7 +1792,7 @@ fail:
 usbd_status
 urtw_led_on(struct urtw_softc *sc, int type)
 {
-   usbd_status error;
+   usbd_status error = 0;
 
if (type == URTW_LED_GPIO) {
switch (sc-sc_gpio_ledpin) {
@@ -1802,13 +1801,8 @@ urtw_led_on(struct urtw_softc *sc, int t
urtw_write8_m(sc, URTW_GP_ENABLE, 0x00);
break;
default:
-   panic(unsupported LED PIN type 0x%x,
-   sc-sc_gpio_ledpin);
-   /* NOTREACHED */
+   break;
}
-   } else {
-   panic(unsupported LED type 0x%x, type);
-   /* NOTREACHED */
}
 
sc-sc_gpio_ledon = 1;
@@ -1819,7 +1813,7 @@ fail:
 static usbd_status
 urtw_led_off(struct urtw_softc *sc, int type)
 {
-   usbd_status error;
+   usbd_status error = 0;
 
if (type == URTW_LED_GPIO) {
switch (sc-sc_gpio_ledpin) {
@@ -1828,13 +1822,8 @@ urtw_led_off(struct urtw_softc *sc, int 
urtw_write8_m(sc, URTW_GP_ENABLE, 0x01);
break;
default:
-   panic(unsupported LED PIN type 0x%x,
-   sc-sc_gpio_ledpin);
-   /* NOTREACHED */
+   break;
}
-   } else {
-   panic(unsupported LED type 0x%x, type);
-   /* NOTREACHED */
}
 
sc-sc_gpio_ledon = 0;
@@ -1863,8 +1852,7 @@ urtw_led_mode0(struct urtw_softc *sc, in
sc-sc_gpio_ledstate = URTW_LED_ON;
break;
default:
-   panic(unsupported LED mode 0x%x, mode);
-   /* NOTREACHED */
+   break;
}
 
switch (sc-sc_gpio_ledstate) {
@@ -1890,8 +1878,7 @@ urtw_led_mode0(struct urtw_softc *sc, in
urtw_led_off(sc, URTW_LED_GPIO);
break;
default:
-   panic(unknown LED status 0x%x, sc-sc_gpio_ledstate);
-   /* NOTREACHED */
+   break;
}
return (0);
 }
@@ -1920,7 +1907,7 @@ urtw_ledusbtask(void *arg)
struct urtw_softc *sc = arg;
 
if (sc-sc_strategy != URTW_SW_LED_MODE0)
-   panic(could not process a LED strategy 0x%x, sc-sc_strategy);
+   return;
 
urtw_led_blink(sc);
 }
@@ -1956,8 +1943,7 @@ urtw_led_ctl(struct urtw_softc *sc, int 
error = urtw_led_mode3(sc, mode);
break;
default:
-   panic(unsupported LED mode %d, sc-sc_strategy);
-   /* NOTREACHED */
+   break;
}
 
return (error);
@@ -2007,8 +1993,7 @@ urtw_led_blink(struct urtw_softc *sc)
timeout_add(sc-sc_led_ch, tvtohz(t));
break;
default:
-   panic(unknown LED status 0x%x, sc-sc_gpio_ledstate);
-   /* NOTREACHED */
+   break;
}
return (0);
 }
@@ -2034,9 +2019,7 @@ urtw_update_msr(struct urtw_softc *sc)
data |= URTW_MSR_LINK_STA;
break;
default:
-   panic(unsupported operation mode 0x%x,
-   ic-ic_opmode);
-   /* NOTREACHED */
+   break;
}
} else
data |= URTW_MSR_LINK_NONE;
@@ -2666,7 +2649,7 @@ urtw_tx_start(struct urtw_softc 

Re: better run(4) fix (was: run(4): fix crash in run_task())

2015-07-14 Thread Stefan Sperling
On Sun, Jul 12, 2015 at 09:11:44PM +0200, Stefan Sperling wrote:
 On Sun, Jul 12, 2015 at 05:57:14PM +0200, Martin Pieuchot wrote:
run_newstate_cb SCAN - INIT
run_newstate_cb SCAN - SCAN
  
  How is this possible?  Why it isn't INIT - SCAN?
 
 I'm not entirely sure.

This implements your suggestion to properly abort async tasks when
bringing the interface down.

Fixes the problem for me just as well.

ok?

Index: if_run.c
===
RCS file: /cvs/src/sys/dev/usb/if_run.c,v
retrieving revision 1.109
diff -u -p -r1.109 if_run.c
--- if_run.c12 Jun 2015 15:47:31 -  1.109
+++ if_run.c15 Jul 2015 03:50:08 -
@@ -358,6 +358,7 @@ struct  ieee80211_node *run_node_alloc(s
 intrun_media_change(struct ifnet *);
 void   run_next_scan(void *);
 void   run_task(void *);
+void   run_cancel_async(struct run_softc *);
 void   run_do_async(struct run_softc *, void (*)(struct run_softc *,
void *), void *, int);
 intrun_newstate(struct ieee80211com *, enum ieee80211_state, int);
@@ -685,13 +686,10 @@ run_detach(struct device *self, int flag
 
s = splusb();
 
-   if (timeout_initialized(sc-scan_to))
-   timeout_del(sc-scan_to);
if (timeout_initialized(sc-calib_to))
timeout_del(sc-calib_to);
 
-   /* wait for all queued asynchronous commands to complete */
-   usb_rem_wait_task(sc-sc_udev, sc-sc_task);
+   run_cancel_async(sc);
 
usbd_ref_wait(sc-sc_udev);
 
@@ -1740,6 +1738,28 @@ run_task(void *arg)
 }
 
 void
+run_cancel_async(struct run_softc *sc)
+{
+   struct run_host_cmd_ring *ring = sc-cmdq;
+   struct run_host_cmd *cmd;
+   int s, i;
+
+   s = splusb();
+
+   if (timeout_initialized(sc-scan_to))
+   timeout_del(sc-scan_to);
+   usb_rem_task(sc-sc_udev, sc-sc_task);
+
+   for (i = 0; i  RUN_HOST_CMD_RING_COUNT; i++) {
+   cmd = ring-cmd[i];
+   cmd-cb = NULL;
+   }
+   ring-next = ring-cur = ring-queued = 0;
+
+   splx(s);
+}
+
+void
 run_do_async(struct run_softc *sc, void (*cb)(struct run_softc *, void *),
 void *arg, int len)
 {
@@ -1751,6 +1771,11 @@ run_do_async(struct run_softc *sc, void 
return;
 
s = splusb();
+   if (ring-queued == RUN_HOST_CMD_RING_COUNT) {
+   splx(s);
+   printf(%s: host cmd queue overrun\n, sc-sc_dev.dv_xname);
+   return; /* XXX */
+   }
cmd = ring-cmd[ring-cur];
cmd-cb = cb;
KASSERT(len = sizeof (cmd-data));
@@ -4504,7 +4529,9 @@ run_init(struct ifnet *ifp)
}
 
/* init host command ring */
-   sc-cmdq.cur = sc-cmdq.next = sc-cmdq.queued = 0;
+   if (sc-cmdq.queued != 0)
+   panic(outstanding host commands queued);
+   sc-cmdq.cur = sc-cmdq.next = 0;
 
/* init Tx rings (4 EDCAs) */
for (qid = 0; qid  4; qid++) {
@@ -4735,13 +4762,16 @@ run_stop(struct ifnet *ifp, int disable)
ifp-if_timer = 0;
ifp-if_flags = ~(IFF_RUNNING | IFF_OACTIVE);
 
-   timeout_del(sc-scan_to);
timeout_del(sc-calib_to);
 
s = splusb();
+
+   /* Cancel asynchronous state transitions etc. */
+   run_cancel_async(sc);
ieee80211_new_state(ic, IEEE80211_S_INIT, -1);
-   /* wait for all queued asynchronous commands to complete */
+   /* Wait for asynchronous state transition to INIT to complete. */
usb_wait_task(sc-sc_udev, sc-sc_task);
+
splx(s);
 
/* Disable Tx/Rx DMA. */



Re: Thinkpad active cooling

2015-07-14 Thread Ted Unangst
Tobias Ulmer wrote:
 As we all know, some Thinkpads have problems with their EC fan control.
 EC is not spinning up the fans to maximum speed, let alone blast mode.
 They also do not offer ACPI methods to spin the fan up.
 
 Previous diffs doing manual fan control were always rejected because
 hooking into the sensors framework with fixed temp limits is crude and
 there are concerns with slowing the fan down and frying the hardware.
 
 This is an attempt to solve the problem slightly differently.
 - Hook into acpitz and only speed the fan up when it is requesting active
   cooling
 - Never set the fan to a mode that would endanger the hardware should we
   crash

Can you clarify what if any effect should be observed with this diff? Will it
make my fans louder or quieter?

(I was very happy to discover that with the C states diff, my one thinkpad now
idles at 3000 rpm vs 3500 rpm, and that is actually a lot quieter.)



ieee80211.h: update standard references

2015-07-14 Thread Stefan Sperling
Updates standard references to 802.11-2012 (except for crypto).

Also adds some new symbols from 802.11-2012.

Index: ieee80211.h
===
RCS file: /cvs/src/sys/net80211/ieee80211.h,v
retrieving revision 1.51
diff -u -p -r1.51 ieee80211.h
--- ieee80211.h 8 Apr 2015 21:35:57 -   1.51
+++ ieee80211.h 14 Jul 2015 18:45:57 -
@@ -167,7 +167,7 @@ struct ieee80211_htframe_addr4 {/* 11n 
\07PROTECTED\08ORDER
 
 /*
- * Sequence Control field (see 7.1.3.4).
+ * Sequence Control field (see 802.11-2012 8.2.4.4).
  */
 #defineIEEE80211_SEQ_FRAG_MASK 0x000f
 #defineIEEE80211_SEQ_FRAG_SHIFT0
@@ -178,7 +178,7 @@ struct ieee80211_htframe_addr4 {/* 11n 
 #define IEEE80211_MMIE_LEN 18  /* 11w */
 
 /*
- * QoS Control field (see 7.1.3.5).
+ * QoS Control field (see 802.11-2012 8.2.4.5).
  */
 #define IEEE80211_QOS_TXOP 0xff00
 #define IEEE80211_QOS_AMSDU0x0080  /* 11n */
@@ -287,7 +287,7 @@ ieee80211_get_qos(const struct ieee80211
 #endif /* _KERNEL */
 
 /*
- * Capability Information field (see 7.3.1.4).
+ * Capability Information field (see 802.11-2012 8.4.1.4).
  */
 #defineIEEE80211_CAPINFO_ESS   0x0001
 #defineIEEE80211_CAPINFO_IBSS  0x0002
@@ -301,7 +301,7 @@ ieee80211_get_qos(const struct ieee80211
 #define IEEE80211_CAPINFO_QOS  0x0200
 #defineIEEE80211_CAPINFO_SHORT_SLOTTIME0x0400
 #defineIEEE80211_CAPINFO_APSD  0x0800
-/* bit 12 is reserved */
+#defineIEEE80211_CAPINFO_RADIO_MEASUREMENT 0x1000
 #defineIEEE80211_CAPINFO_DSSSOFDM  0x2000
 #define IEEE80211_CAPINFO_DELAYED_B_ACK0x4000
 #define IEEE80211_CAPINFO_IMMEDIATE_B_ACK  0x8000
@@ -309,10 +309,10 @@ ieee80211_get_qos(const struct ieee80211
\10\01ESS\02IBSS\03CF_POLLABLE\04CF_POLLREQ   \
\05PRIVACY\06SHORT_PREAMBLE\07PBCC\10CHNL_AGILITY \
\11SPECTRUM_MGMT\12QOS\13SHORT_SLOTTIME\14APSD\
-   \16DSSSOFDM\17DELAYED_B_ACK\20IMMEDIATE_B_ACK
+   \15RADIO_MEASUREMENT\16DSSSOFDM\17DELAYED_B_ACK\20IMMEDIATE_B_ACK
 
 /*
- * Information elements (see Table 7-26).
+ * Information element IDs (see 802.11-2012 Table 8.4.2).
  */
 enum {
IEEE80211_ELEMID_SSID   = 0,
@@ -323,53 +323,181 @@ enum {
IEEE80211_ELEMID_TIM= 5,
IEEE80211_ELEMID_IBSSPARMS  = 6,
IEEE80211_ELEMID_COUNTRY= 7,
+   IEEE80211_ELEMID_HOPPING_PARMS  = 8,
+   IEEE80211_ELEMID_HOPPING_PATTERN= 9,
+   IEEE80211_ELEMID_REQUEST= 10,
IEEE80211_ELEMID_QBSS_LOAD  = 11,
IEEE80211_ELEMID_EDCAPARMS  = 12,
+   IEEE80211_ELEMID_TSPEC  = 13,
+   IEEE80211_ELEMID_TCLASS = 14,
+   IEEE80211_ELEMID_SCHEDULE   = 15,
IEEE80211_ELEMID_CHALLENGE  = 16,
/* 17-31 reserved for challenge text extension */
+   IEEE80211_ELEMID_POWER_CONSTRAINT   = 32,
+   IEEE80211_ELEMID_POWER_CAP  = 33,
+   IEEE80211_ELEMID_TPC_REQUEST= 34,
+   IEEE80211_ELEMID_TPC_REPORT = 35,
+   IEEE80211_ELEMID_SUPP_CHNLS = 35,
IEEE80211_ELEMID_CSA= 37,   /* 11h */
+   IEEE80211_ELEMID_MEASUREMENT_REQUEST= 38,   /* DFS */
+   IEEE80211_ELEMID_MEASUREMENT_REPORT = 39,   /* DFS */
+   IEEE80211_ELEMID_QUIET  = 40,
+   IEEE80211_ELEMID_IBSS_DFS   = 41,
IEEE80211_ELEMID_ERP= 42,
+   IEEE80211_ELEMID_TS_DELAY   = 43,
+   IEEE80211_ELEMID_TCLAS  = 44,
IEEE80211_ELEMID_HTCAPS = 45,   /* 11n */
IEEE80211_ELEMID_QOS_CAP= 46,
+   /* 47 reserved */
IEEE80211_ELEMID_RSN= 48,
+   /* 49 reserved */
IEEE80211_ELEMID_XRATES = 50,
+   IEEE80211_ELEMID_AP_CHNL_REPORT = 51,
+   IEEE80211_ELEMID_NBR_REPORT = 52,
+   IEEE80211_ELEMID_RCPI   = 53,
+   IEEE80211_ELEMID_MDE= 54,
+   IEEE80211_ELEMID_FTE= 55,
IEEE80211_ELEMID_TIE= 56,   /* 11r */
+   IEEE80211_ELEMID_RDE= 57,
+   IEEE80211_ELEMID_DSE= 58,
+   IEEE80211_ELEMID_SUPP_OPCLASS   = 59,
+   IEEE80211_ELEMID_XCSA   = 60,
IEEE80211_ELEMID_HTOP   = 61,   /* 11n */
+   IEEE80211_ELEMID_SECONDARY_CHANL_OFFSET = 62,   /* 11n */
+   IEEE80211_ELEMID_AVG_ACCESS_DELAY   = 63,
+   IEEE80211_ELEMID_ANTENNA= 

Re: Fix for segfault in find(1)

2015-07-14 Thread Ted Unangst
Todd C. Miller wrote:
 On Tue, 14 Jul 2015 12:55:35 -0400, Ted Unangst wrote:
 
  so technically i believe this is still undefined since you're not supposed 
  to
  look at freed pointers. an even more better fix would be to save the offset
  before the realloc.
 
 Yeah, I forgot we had to deref store.


looks good.

 
  - todd
 
 Index: misc.c
 ===
 RCS file: /cvs/src/usr.bin/find/misc.c,v
 retrieving revision 1.14
 diff -u -p -u -r1.14 misc.c
 --- misc.c14 Jul 2015 16:58:22 -  1.14
 +++ misc.c14 Jul 2015 17:05:19 -
 @@ -39,6 +39,7 @@
  #include err.h
  #include errno.h
  #include fts.h
 +#include stddef.h
  #include stdio.h
  #include stdlib.h
  #include string.h
 @@ -60,12 +61,14 @@ brace_subst(char *orig, char **store, ch
   for (p = *store; (ch = *orig); ++orig)
   if (ch == '{'  orig[1] == '}') {
   while ((p - *store) + plen  len) {
 + ptrdiff_t p_off;
   char *newstore;
  
 + p_off = (p - *store);
   newstore = reallocarray(*store, len, 2);
   if (newstore == NULL)
   err(1, NULL);
 - p = (p - *store) + newstore;
 + p = newstore + p_off;
   *store = newstore;
   len *= 2;
   }



Re: Kill arp_ifinit()?

2015-07-14 Thread Martin Pieuchot
On 07/07/15(Tue) 18:02, Martin Pieuchot wrote:
 Maybe not yet but at least I'd like to do the ARP request a bit later.
 
 We create a RTF_LOCAL route entry for every configured address.  So
 use this information to emit a who-has for the configured address.
 
 This also has the advantage of *not* sending an ARP request if 
 something wrong happens between the SIOCSIFADDR ioctl and the
 RTF_LOCAL route creation.

Anybody?

 Ok?
 
 Index: netinet/if_ether.c
 ===
 RCS file: /cvs/src/sys/netinet/if_ether.c,v
 retrieving revision 1.157
 diff -u -p -r1.157 if_ether.c
 --- netinet/if_ether.c7 Jul 2015 14:22:25 -   1.157
 +++ netinet/if_ether.c7 Jul 2015 15:56:15 -
 @@ -196,8 +196,11 @@ arp_rtrequest(int req, struct rtentry *r
   if ((rt-rt_flags  RTF_CLONING) != 0)
   break;
   }
 - /* Announce a new entry if requested. */
 - if (rt-rt_flags  RTF_ANNOUNCE)
 + /*
 +  * Announce a new entry if requested or warn the user
 +  * if another station has this IP address.
 +  */
 + if (rt-rt_flags  (RTF_ANNOUNCE|RTF_LOCAL))
   arprequest(ifp,
   satosin(rt_key(rt))-sin_addr.s_addr,
   satosin(rt_key(rt))-sin_addr.s_addr,
 @@ -850,12 +853,6 @@ arpproxy(struct in_addr in, u_int rdomai
  void
  arp_ifinit(struct arpcom *ac, struct ifaddr *ifa)
  {
 -
 - /* Warn the user if another station has this IP address. */
 - arprequest(ac-ac_if,
 - satosin(ifa-ifa_addr)-sin_addr.s_addr,
 - satosin(ifa-ifa_addr)-sin_addr.s_addr,
 - ac-ac_enaddr);
   ifa-ifa_rtrequest = arp_rtrequest;
  }