remove errant ifstated whitespace

2017-06-27 Thread Rob Pierce

Index: ifstated.c
===
RCS file: /cvs/src/usr.sbin/ifstated/ifstated.c,v
retrieving revision 1.43
diff -u -p -r1.43 ifstated.c
--- ifstated.c  27 Jun 2017 20:46:34 -  1.43
+++ ifstated.c  28 Jun 2017 01:30:02 -
@@ -151,12 +151,12 @@ main(int argc, char *argv[])
 
rtfilter = ROUTE_FILTER(RTM_IFINFO);
if (setsockopt(rt_fd, PF_ROUTE, ROUTE_MSGFILTER,
-   , sizeof(rtfilter)) == -1) /* not fatal */
+   , sizeof(rtfilter)) == -1) /* not fatal */
log_warn("%s: setsockopt msgfilter", __func__);
 
rtfilter = RTABLE_ANY;
if (setsockopt(rt_fd, PF_ROUTE, ROUTE_TABLEFILTER,
-   , sizeof(rtfilter)) == -1) /* not fatal */
+   , sizeof(rtfilter)) == -1) /* not fatal */
log_warn("%s: setsockopt tablefilter", __func__);
 
signal_set(_ev, SIGCHLD, sigchld_handler, NULL);
@@ -605,7 +605,7 @@ fetch_state(void)
 
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
struct ifreq ifr;
-   struct if_data  ifrdat;
+   struct if_data ifrdat;
 
if (oname && !strcmp(oname, ifa->ifa_name))
continue;
@@ -623,8 +623,6 @@ fetch_state(void)
freeifaddrs(ifap);
close(sock);
 }
-
-
 
 /*
  * Clear the config.
Index: ifstated.h
===
RCS file: /cvs/src/usr.sbin/ifstated/ifstated.h,v
retrieving revision 1.11
diff -u -p -r1.11 ifstated.h
--- ifstated.h  18 Jun 2017 12:03:47 -  1.11
+++ ifstated.h  28 Jun 2017 01:30:02 -
@@ -29,7 +29,6 @@
 #include 
 #include 
 
-
 struct ifsd_expression;
 TAILQ_HEAD(ifsd_expression_list, ifsd_expression);
 
@@ -80,7 +79,6 @@ struct ifsd_action {
 #define IFSD_ACTION_CHANGESTATE2
 #define IFSD_ACTION_CONDITION  3
 };
-
 
 struct ifsd_expression {
TAILQ_ENTRY(ifsd_expression) entries;



Re: Attempt to simplify file(1)

2017-06-27 Thread Bryan Steele
On Tue, Jun 27, 2017 at 11:40:49PM +0100, Nicholas Marriott wrote:
> Thanks. Comments inline.
> 
> > [..]
>
> One member per line in structs please. Also you could reduce the amount
> of space here now to one tab.
>
> > [..]
>
> magic_load (which parses the magic file) is now before pledge and
> privdrop which is wrong. You need to drop privs and pledge before
> magic_load - if needed you can reduce the pledge further after
> magic_load, but I think it only needs stdio anyway.
> 
> > [..]
> 
> The privdrop was easier to see inline than in a separate function. I
> think it should all be up front in main() not hidden away.
> 
> > [..]
> 
> This fclose() is pointless here but it can be done much earlier (after
> magic_load).
> 
> And you need to exit(0) rather than dropping out of the bottom of main.
>
> > [..]
>
> This comment needs to be edited now we are not passing the file
> descriptors anywhere.
> 
> > [..]
> 
> I'd assign this in the loop which calls test_file? Everything else in
> input_file is set up outside this function.
>

Here's another stab at it with your suggestions, seems to work. Thanks!

Index: Makefile
===
RCS file: /cvs/src/usr.bin/file/Makefile,v
retrieving revision 1.16
diff -u -p -u -r1.16 Makefile
--- Makefile4 Oct 2015 07:25:59 -   1.16
+++ Makefile27 Jun 2017 23:19:35 -
@@ -5,9 +5,6 @@ SRCS=   file.c magic-dump.c magic-load.c
text.c xmalloc.c
 MAN=   file.1 magic.5
 
-LDADD= -lutil
-DPADD= ${LIBUTIL}
-
 CDIAGFLAGS+= -Wno-long-long -Wall -W -Wnested-externs -Wformat=2
 CDIAGFLAGS+= -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations
 CDIAGFLAGS+= -Wwrite-strings -Wshadow -Wpointer-arith -Wsign-compare
Index: file.c
===
RCS file: /cvs/src/usr.bin/file/file.c,v
retrieving revision 1.59
diff -u -p -u -r1.59 file.c
--- file.c  18 Apr 2017 14:16:48 -  1.59
+++ file.c  27 Jun 2017 23:19:35 -
@@ -29,12 +29,10 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -43,45 +41,31 @@
 #include "magic.h"
 #include "xmalloc.h"
 
-struct input_msg {
-   int idx;
-
-   struct stat sb;
-   int error;
-
-   charlink_path[PATH_MAX];
-   int link_error;
-   int link_target;
-};
-
-struct input_ack {
-   int idx;
-};
-
 struct input_file {
-   struct magic*m;
-   struct input_msg*msg;
+   struct magic*m;
 
-   const char  *path;
-   int  fd;
+   const char  *path;
+   struct stat  sb;
+   int  fd;
+   int  error;
 
-   void*base;
-   size_t   size;
-   int  mapped;
-   char*result;
+   char link_path[PATH_MAX];
+   int  link_error;
+   int  link_target;
+
+   void*base;
+   size_t   size;
+   int  mapped;
+   char*result;
 };
 
 extern char*__progname;
 
 __dead void usage(void);
 
-static int  prepare_message(struct input_msg *, int, const char *);
-static void send_message(struct imsgbuf *, void *, size_t, int);
-static int  read_message(struct imsgbuf *, struct imsg *, pid_t);
-
-static void read_link(struct input_msg *, const char *);
+static void prepare_input(struct input_file *, const char *);
 
-static __dead void child(int, pid_t, int, char **);
+static void read_link(struct input_file *, const char *);
 
 static void test_file(struct input_file *, size_t);
 
@@ -120,14 +104,12 @@ usage(void)
 int
 main(int argc, char **argv)
 {
-   int  opt, pair[2], fd, idx;
+   int  opt, idx;
char*home;
struct passwd   *pw;
-   struct imsgbuf   ibuf;
-   struct imsg  imsg;
-   struct input_msg msg;
-   struct input_ack*ack;
-   pid_tpid, parent;
+   struct magic*m;
+   struct input_file   *inf;
+   size_t   len, width = 0;
 
tzset();
 
@@ -193,79 +175,75 @@ main(int argc, char **argv)
if (magicfp == NULL)
err(1, "%s", magicpath);
 
-   parent = getpid();
-   if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pair) != 0)
-   err(1, "socketpair");
-   switch (pid = fork()) {
-   case -1:
-   err(1, "fork");
-   case 0:
-   close(pair[0]);
-   child(pair[1], parent, argc, argv);
+   if (!cflag) {
+   inf = xcalloc(argc, sizeof *inf);
+   for (idx = 0; idx < argc; idx++) {
+   len = strlen(argv[idx]) + 1;
+ 

Re: Attempt to simplify file(1)

2017-06-27 Thread Nicholas Marriott
Thanks. Comments inline.

On Tue, Jun 27, 2017 at 06:28:57AM -0400, Bryan Steele wrote:
> On Tue, Jun 27, 2017 at 01:20:59AM -0400, Bryan Steele wrote:
> > On Tue, Jun 27, 2017 at 12:26:08AM -0400, Bryan Steele wrote:
> > Some unintentional changes crept in, here's another diff..
> 
> Sorry, last diff broke width calculation.. 3rd times the charm.
> 
> Index: Makefile
> ===
> RCS file: /cvs/src/usr.bin/file/Makefile,v
> retrieving revision 1.16
> diff -u -p -u -r1.16 Makefile
> --- Makefile  4 Oct 2015 07:25:59 -   1.16
> +++ Makefile  27 Jun 2017 10:05:39 -
> @@ -5,9 +5,6 @@ SRCS=   file.c magic-dump.c magic-load.c
>   text.c xmalloc.c
>  MAN= file.1 magic.5
>  
> -LDADD=   -lutil
> -DPADD=   ${LIBUTIL}
> -
>  CDIAGFLAGS+= -Wno-long-long -Wall -W -Wnested-externs -Wformat=2
>  CDIAGFLAGS+= -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations
>  CDIAGFLAGS+= -Wwrite-strings -Wshadow -Wpointer-arith -Wsign-compare
> Index: file.c
> ===
> RCS file: /cvs/src/usr.bin/file/file.c,v
> retrieving revision 1.59
> diff -u -p -u -r1.59 file.c
> --- file.c18 Apr 2017 14:16:48 -  1.59
> +++ file.c27 Jun 2017 10:05:39 -
> @@ -29,12 +29,10 @@
>  #include 
>  #include 
>  #include 
> -#include 
>  #include 
>  #include 
>  #include 
>  #include 
> -#include 
>  #include 
>  #include 
>  #include 
> @@ -43,27 +41,16 @@
>  #include "magic.h"
>  #include "xmalloc.h"
>  
> -struct input_msg {
> - int idx;
> -
> - struct stat sb;
> - int error;
> -
> - charlink_path[PATH_MAX];
> - int link_error;
> - int link_target;
> -};
> -
> -struct input_ack {
> - int idx;
> -};
> -
>  struct input_file {
>   struct magic*m;
> - struct input_msg*msg;
>  
>   const char  *path;
> - int  fd;
> + struct stat  sb;
> + int  fd, error;

One member per line in structs please. Also you could reduce the amount
of space here now to one tab.

> +
> + char link_path[PATH_MAX];
> + int  link_error;
> + int  link_target;
>  
>   void*base;
>   size_t   size;
> @@ -75,15 +62,13 @@ extern char   *__progname;
>  
>  __dead void   usage(void);
>  
> -static intprepare_message(struct input_msg *, int, const char *);
> -static void   send_message(struct imsgbuf *, void *, size_t, int);
> -static intread_message(struct imsgbuf *, struct imsg *, pid_t);
> +static void   prepare_input(struct input_file *, const char *);
>  
> -static void   read_link(struct input_msg *, const char *);
> +static void   read_link(struct input_file *, const char *);
>  
> -static __dead void child(int, pid_t, int, char **);
> +static void   privdrop(void);
>  
> -static void   test_file(struct input_file *, size_t);
> +static void   test_file(struct input_file *, struct magic *, size_t);
>  
>  static inttry_stat(struct input_file *);
>  static inttry_empty(struct input_file *);
> @@ -120,14 +105,12 @@ usage(void)
>  int
>  main(int argc, char **argv)
>  {
> - int  opt, pair[2], fd, idx;
> + int  opt, idx;
>   char*home;
>   struct passwd   *pw;
> - struct imsgbuf   ibuf;
> - struct imsg  imsg;
> - struct input_msg msg;
> - struct input_ack*ack;
> - pid_tpid, parent;
> + struct magic*m;
> + struct input_file   *inf;
> + size_t   len, width = 0;
>  
>   tzset();
>  
> @@ -193,71 +176,48 @@ main(int argc, char **argv)
>   if (magicfp == NULL)
>   err(1, "%s", magicpath);
>  
> - parent = getpid();
> - if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pair) != 0)
> - err(1, "socketpair");
> - switch (pid = fork()) {
> - case -1:
> - err(1, "fork");
> - case 0:
> - close(pair[0]);
> - child(pair[1], parent, argc, argv);
> + m = magic_load(magicfp, magicpath, cflag || Wflag);
> + if (cflag) {
> + magic_dump(m);
> + exit(0);

magic_load (which parses the magic file) is now before pledge and
privdrop which is wrong. You need to drop privs and pledge before
magic_load - if needed you can reduce the pledge further after
magic_load, but I think it only needs stdio anyway.

>   }
> - close(pair[1]);
> -
> - fclose(magicfp);
> - magicfp = NULL;
>  
> - if (cflag)
> - goto wait_for_child;
> -
> - imsg_init(, pair[0]);
> + inf = xcalloc(argc, sizeof *inf);
>   for (idx = 0; idx < argc; idx++) {
> - fd 

Re: Attempt to simplify file(1)

2017-06-27 Thread Theo de Raadt
> OpenBSD's file(1) implementation was written by nicm@, first introduced
> in 5.8, the inital design included a privileged parent process which
> forked an unprivileged child which would handle potentially unsafe
> file parsing.
> 
> It also had 'sandboxing' using systrace(4), which required complex
> parent/child monitoring (SIGSTOP/START) to attach a policy to the
> child process.
> 
> The goal was to make running file(1) safter, as it is often blindly
> run as root by users and build scripts alike.
> 
> Today, file(1) uses pledge(2) in the unprivileged child, and the
> parent handles the initial opening and passing of fds using imsg, but
> otherwise it just wait(4)'s until the process exits.
> 
> The diff below attempts to simplify the design, removing the
> parent/child abstractions entirely and dropping privs in the parent
> after opening the magic(5) patterns and input.

BTW, there is a piece of the story missing.

I started work on pledge due to conversations about file with nicm.
It was I who pushed him to write our file replacement.  As he and I
pivoted through various privsep design considerations, and the
side-adventure to use systrace, I remembered all my misgivings about
the way systrace is used, and ("tame") pledge was born.

The 2nd program that was considered during pledge design was the
ntpd privsep.  The 3rd program was the sshd pre-auth sandbox.

The direction seems sound.  It is even tighter.  This didn't work
in early pledge, but it does now.

However that diff contained other unrelated changes, which should not
be included.



Re: Attempt to simplify file(1)

2017-06-27 Thread Ted Unangst
Bryan Steele wrote:
> OpenBSD's file(1) implementation was written by nicm@, first introduced
> in 5.8, the inital design included a privileged parent process which
> forked an unprivileged child which would handle potentially unsafe
> file parsing.
> 
> It also had 'sandboxing' using systrace(4), which required complex
> parent/child monitoring (SIGSTOP/START) to attach a policy to the
> child process.
> 
> The goal was to make running file(1) safter, as it is often blindly
> run as root by users and build scripts alike.
> 
> Today, file(1) uses pledge(2) in the unprivileged child, and the
> parent handles the initial opening and passing of fds using imsg, but
> otherwise it just wait(4)'s until the process exits.
> 
> The diff below attempts to simplify the design, removing the
> parent/child abstractions entirely and dropping privs in the parent
> after opening the magic(5) patterns and input.
> 
> This was brought up during awolk@'s #openbsd-daily readthrough.
> 
> Make sense, or unnecessary churn? :-)

No, this makes a lot of sense to me. pledge is supposed to make this stuff
easier. i didn't read the whole diff, but i believe the idea is sound.




Re: no depends for perl

2017-06-27 Thread Andrew Fresh
On Tue, Jun 27, 2017 at 02:13:12PM -0600, Todd C. Miller wrote:
> On Mon, 26 Jun 2017 19:49:18 +0200, Marc Espie wrote:
> 
> > Probably the most intricate yet.
> > 
> > This is not entirely new, since I had to split manpages already a long
> > time ago.  The trick is to keep the "Configure stuff" in the main 
> > Makefile.bsd-wrapper, and put everything else in Makefile.bsd-wrapper1...
> > 
> > I hope I haven't forgotten any small piece, but it seems okay to me.
> 
> Looks good to me and appears to work as expected.

I was going to say the same.  My tests worked, I built a release, was
going to install the release and try that, but ran out of time.

l8rZ,
-- 
andrew - http://afresh1.com

A hacker does for love what others would not do for money.



Re: [PATCH] bin: Add -v option to cp(1), mv(1), rm(1)

2017-06-27 Thread Sebastian Benoit
3 lines are longer than 80 chars.

otherwise ok benno@

Job Snijders(j...@instituut.net) on 2017.06.27 11:00:55 +0200:
> Dear all,
> 
> This patch adds a '-v' option to cp(1), mv(1), and rm(1). If the '-v'
> option is used, the utility will display the name of each file after it
> has been successfully copied, moved or removed.
> 
> This patch rolls in feedback from recent discussion. The manpage updates
> are specific as to what the -v option does for each utility and the
> messages written to the standard output are now minimalistic in nature.
> 
> example use:
> 
>   $ touch a
>   $ mv -v a b
>   a -> b
>   $ cp -v b c
>   b -> c
>   $ rm -v b c
>   b
>   c
> 
> Hat tip to Paul de Weerd for helping with testing.
> 
> Kind regards,
> 
> Job
> 
> diff --git bin/cp/cp.1 bin/cp/cp.1
> index 8573d801ca5..2896406498c 100644
> --- bin/cp/cp.1
> +++ bin/cp/cp.1
> @@ -41,14 +41,14 @@
>  .Nd copy files
>  .Sh SYNOPSIS
>  .Nm cp
> -.Op Fl fip
> +.Op Fl fipv
>  .Oo
>  .Fl R
>  .Op Fl H | L | P
>  .Oc
>  .Ar source target
>  .Nm cp
> -.Op Fl fip
> +.Op Fl fipv
>  .Oo
>  .Fl R
>  .Op Fl H | L | P
> @@ -145,6 +145,8 @@ use a utility such as
>  or
>  .Xr tar 1
>  instead.
> +.It Fl v
> +Display the source and destination after each copy.
>  .El
>  .Pp
>  For each destination file that already exists, its contents are
> diff --git bin/cp/cp.c bin/cp/cp.c
> index 643d82ed9fa..480f18b0ff1 100644
> --- bin/cp/cp.c
> +++ bin/cp/cp.c
> @@ -71,7 +71,7 @@
>  PATH_T to = { to.p_path, "" };
>  
>  uid_t myuid;
> -int Rflag, fflag, iflag, pflag, rflag;
> +int Rflag, fflag, iflag, pflag, rflag, vflag;
>  mode_t myumask;
>  
>  enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
> @@ -88,7 +88,7 @@ main(int argc, char *argv[])
>   char *target;
>  
>   Hflag = Lflag = Pflag = Rflag = 0;
> - while ((ch = getopt(argc, argv, "HLPRfipr")) != -1)
> + while ((ch = getopt(argc, argv, "HLPRfiprv")) != -1)
>   switch (ch) {
>   case 'H':
>   Hflag = 1;
> @@ -119,6 +119,9 @@ main(int argc, char *argv[])
>   case 'r':
>   rflag = 1;
>   break;
> + case 'v':
> + vflag = 1;
> + break;
>   default:
>   usage();
>   break;
> @@ -394,6 +397,9 @@ copy(char *argv[], enum op type, int fts_options)
>   case S_IFLNK:
>   if (copy_link(curr, !fts_dne(curr)))
>   rval = 1;
> + else if (vflag)
> + (void)fprintf(stdout, "%s -> %s\n",
> + curr->fts_path, to.p_path);
>   break;
>   case S_IFDIR:
>   if (!Rflag && !rflag) {
> @@ -415,6 +421,9 @@ copy(char *argv[], enum op type, int fts_options)
>   if (mkdir(to.p_path,
>   curr->fts_statp->st_mode | S_IRWXU) < 0)
>   err(1, "%s", to.p_path);
> + else if (vflag)
> + (void)fprintf(stdout, "%s -> %s\n",
> + curr->fts_path, to.p_path);
>   } else if (!S_ISDIR(to_stat.st_mode))
>   errc(1, ENOTDIR, "%s", to.p_path);
>   break;
> @@ -426,6 +435,9 @@ copy(char *argv[], enum op type, int fts_options)
>   } else
>   if (copy_file(curr, fts_dne(curr)))
>   rval = 1;
> + if (!rval && vflag)
> + (void)fprintf(stdout, "%s -> %s\n",
> + curr->fts_path, to.p_path);
>   break;
>   case S_IFIFO:
>   if (Rflag) {
> @@ -434,6 +446,9 @@ copy(char *argv[], enum op type, int fts_options)
>   } else
>   if (copy_file(curr, fts_dne(curr)))
>   rval = 1;
> + if (!rval && vflag)
> + (void)fprintf(stdout, "%s -> %s\n",
> + curr->fts_path, to.p_path);
>   break;
>   case S_IFSOCK:
>   warnc(EOPNOTSUPP, "%s", curr->fts_path);
> @@ -441,6 +456,9 @@ copy(char *argv[], enum op type, int fts_options)
>   default:
>   if (copy_file(curr, fts_dne(curr)))
>   rval = 1;
> + else if (vflag)
> + (void)fprintf(stdout, "%s -> %s\n",
> + curr->fts_path, to.p_path);
>   break;
>   }
>   }
> diff --git bin/cp/utils.c bin/cp/utils.c
> index 

Re: ifstated.c hoist code in prep for future work

2017-06-27 Thread Sebastian Benoit
commited with the (int)(long)arg cast.

Thanks!

(waiting for more...) /Benno

Rob Pierce(r...@2keys.ca) on 2017.06.27 12:45:43 -0400:
> Hoist some privileged code in preparation for future work.
> 
> Is this the correct use of intptr_t?
> 
> Based on an approach in vmd with mc146818/ns8250.
> 
> No intended functional change.
> 
> Rob
> 
> Index: ifstated.c
> ===
> RCS file: /cvs/src/usr.sbin/ifstated/ifstated.c,v
> retrieving revision 1.42
> diff -u -p -r1.42 ifstated.c
> --- ifstated.c18 Jun 2017 12:03:47 -  1.42
> +++ ifstated.c27 Jun 2017 16:44:16 -
> @@ -36,6 +36,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -87,8 +88,9 @@ int
>  main(int argc, char *argv[])
>  {
>   struct timeval tv;
> - int ch;
> + int ch, rt_fd;
>   int debug = 0;
> + unsigned int rtfilter;
>  
>   log_init(1, LOG_DAEMON);/* log to stderr until daemonized */
>   log_setverbose(1);
> @@ -144,12 +146,25 @@ main(int argc, char *argv[])
>   log_init(debug, LOG_DAEMON);
>   log_setverbose(opts & IFSD_OPT_VERBOSE);
>  
> + if ((rt_fd = socket(PF_ROUTE, SOCK_RAW, 0)) < 0)
> + err(1, "no routing socket");
> +
> + rtfilter = ROUTE_FILTER(RTM_IFINFO);
> + if (setsockopt(rt_fd, PF_ROUTE, ROUTE_MSGFILTER,
> + , sizeof(rtfilter)) == -1) /* not fatal */
> + log_warn("%s: setsockopt msgfilter", __func__);
> +
> + rtfilter = RTABLE_ANY;
> + if (setsockopt(rt_fd, PF_ROUTE, ROUTE_TABLEFILTER,
> + , sizeof(rtfilter)) == -1) /* not fatal */
> + log_warn("%s: setsockopt tablefilter", __func__);
> +
>   signal_set(_ev, SIGCHLD, sigchld_handler, NULL);
>   signal_add(_ev, NULL);
>  
>   /* Loading the config needs to happen in the event loop */
>   timerclear();
> - evtimer_set(_ev, startup_handler, NULL);
> + evtimer_set(_ev, startup_handler, (void *)(intptr_t)rt_fd);
>   evtimer_add(_ev, );
>  
>   event_loop(0);
> @@ -159,28 +174,14 @@ main(int argc, char *argv[])
>  void
>  startup_handler(int fd, short event, void *arg)
>  {
> - int rt_fd;
> - unsigned int rtfilter;
> -
> - if ((rt_fd = socket(PF_ROUTE, SOCK_RAW, 0)) < 0)
> - err(1, "no routing socket");
> + int rfd = (intptr_t)arg;
>  
>   if (load_config() != 0) {
>   log_warnx("unable to load config");
>   exit(1);
>   }
> -
> - rtfilter = ROUTE_FILTER(RTM_IFINFO);
> - if (setsockopt(rt_fd, PF_ROUTE, ROUTE_MSGFILTER,
> - , sizeof(rtfilter)) == -1) /* not fatal */
> - log_warn("%s: setsockopt msgfilter", __func__);
> -
> - rtfilter = RTABLE_ANY;
> - if (setsockopt(rt_fd, PF_ROUTE, ROUTE_TABLEFILTER,
> - , sizeof(rtfilter)) == -1) /* not fatal */
> - log_warn("%s: setsockopt tablefilter", __func__);
>   
> - event_set(_msg_ev, rt_fd, EV_READ|EV_PERSIST, rt_msg_handler, NULL);
> + event_set(_msg_ev, rfd, EV_READ|EV_PERSIST, rt_msg_handler, NULL);
>   event_add(_msg_ev, NULL);
>  
>   signal_set(_ev, SIGHUP, sighup_handler, NULL);
> 



Re: no depends for perl

2017-06-27 Thread Todd C. Miller
On Mon, 26 Jun 2017 19:49:18 +0200, Marc Espie wrote:

> Probably the most intricate yet.
> 
> This is not entirely new, since I had to split manpages already a long
> time ago.  The trick is to keep the "Configure stuff" in the main 
> Makefile.bsd-wrapper, and put everything else in Makefile.bsd-wrapper1...
> 
> I hope I haven't forgotten any small piece, but it seems okay to me.

Looks good to me and appears to work as expected.

 - todd



OpenBSD Errata: June 27th, 2017 (icmp6_linklocal)

2017-06-27 Thread Alexander Bluhm
An errata patch for icmp6_linklocal has been released for OpenBSD 6.1.

When pinging an IPv6 link-local address, the reflected packet had ::1
as source address. The echo reply was ignored as it must be from the
link-local address.

Binary updates for the amd64 and i386 platforms are available via the
syspatch utility. A source code patch can be found on the respective
errata page:

  https://www.openbsd.org/errata61.html

As this affects the kernel, a reboot will be needed after patching.

If IPv6 is not configured on your system, this issue does not affect you.



ifstated.c hoist code in prep for future work

2017-06-27 Thread Rob Pierce
Hoist some privileged code in preparation for future work.

Is this the correct use of intptr_t?

Based on an approach in vmd with mc146818/ns8250.

No intended functional change.

Rob

Index: ifstated.c
===
RCS file: /cvs/src/usr.sbin/ifstated/ifstated.c,v
retrieving revision 1.42
diff -u -p -r1.42 ifstated.c
--- ifstated.c  18 Jun 2017 12:03:47 -  1.42
+++ ifstated.c  27 Jun 2017 16:44:16 -
@@ -36,6 +36,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -87,8 +88,9 @@ int
 main(int argc, char *argv[])
 {
struct timeval tv;
-   int ch;
+   int ch, rt_fd;
int debug = 0;
+   unsigned int rtfilter;
 
log_init(1, LOG_DAEMON);/* log to stderr until daemonized */
log_setverbose(1);
@@ -144,12 +146,25 @@ main(int argc, char *argv[])
log_init(debug, LOG_DAEMON);
log_setverbose(opts & IFSD_OPT_VERBOSE);
 
+   if ((rt_fd = socket(PF_ROUTE, SOCK_RAW, 0)) < 0)
+   err(1, "no routing socket");
+
+   rtfilter = ROUTE_FILTER(RTM_IFINFO);
+   if (setsockopt(rt_fd, PF_ROUTE, ROUTE_MSGFILTER,
+   , sizeof(rtfilter)) == -1) /* not fatal */
+   log_warn("%s: setsockopt msgfilter", __func__);
+
+   rtfilter = RTABLE_ANY;
+   if (setsockopt(rt_fd, PF_ROUTE, ROUTE_TABLEFILTER,
+   , sizeof(rtfilter)) == -1) /* not fatal */
+   log_warn("%s: setsockopt tablefilter", __func__);
+
signal_set(_ev, SIGCHLD, sigchld_handler, NULL);
signal_add(_ev, NULL);
 
/* Loading the config needs to happen in the event loop */
timerclear();
-   evtimer_set(_ev, startup_handler, NULL);
+   evtimer_set(_ev, startup_handler, (void *)(intptr_t)rt_fd);
evtimer_add(_ev, );
 
event_loop(0);
@@ -159,28 +174,14 @@ main(int argc, char *argv[])
 void
 startup_handler(int fd, short event, void *arg)
 {
-   int rt_fd;
-   unsigned int rtfilter;
-
-   if ((rt_fd = socket(PF_ROUTE, SOCK_RAW, 0)) < 0)
-   err(1, "no routing socket");
+   int rfd = (intptr_t)arg;
 
if (load_config() != 0) {
log_warnx("unable to load config");
exit(1);
}
-
-   rtfilter = ROUTE_FILTER(RTM_IFINFO);
-   if (setsockopt(rt_fd, PF_ROUTE, ROUTE_MSGFILTER,
-   , sizeof(rtfilter)) == -1) /* not fatal */
-   log_warn("%s: setsockopt msgfilter", __func__);
-
-   rtfilter = RTABLE_ANY;
-   if (setsockopt(rt_fd, PF_ROUTE, ROUTE_TABLEFILTER,
-   , sizeof(rtfilter)) == -1) /* not fatal */
-   log_warn("%s: setsockopt tablefilter", __func__);

-   event_set(_msg_ev, rt_fd, EV_READ|EV_PERSIST, rt_msg_handler, NULL);
+   event_set(_msg_ev, rfd, EV_READ|EV_PERSIST, rt_msg_handler, NULL);
event_add(_msg_ev, NULL);
 
signal_set(_ev, SIGHUP, sighup_handler, NULL);



minor bgpd.c diff

2017-06-27 Thread Rob Pierce
rfd does not need to be global.

Rob

Index: bgpd.c
===
RCS file: /cvs/src/usr.sbin/bgpd/bgpd.c,v
retrieving revision 1.189
diff -u -p -r1.189 bgpd.c
--- bgpd.c  28 May 2017 15:16:33 -  1.189
+++ bgpd.c  27 Jun 2017 15:52:02 -
@@ -48,7 +48,6 @@ int   dispatch_imsg(struct imsgbuf *, int
 intcontrol_setup(struct bgpd_config *);
 intimsg_send_sockets(struct imsgbuf *, struct imsgbuf *);
 
-int rfd = -1;
 int cflags;
 volatile sig_atomic_t   mrtdump;
 volatile sig_atomic_t   quit;
@@ -108,6 +107,7 @@ main(int argc, char *argv[])
char*saved_argv0;
int  debug = 0;
int  rflag = 0, sflag = 0;
+   int  rfd = -1;
int  ch, timeout, status;
int  pipe_m2s[2];
int  pipe_m2r[2];



Re: IP in IP header chain input

2017-06-27 Thread Alexander Bluhm
On Tue, May 23, 2017 at 01:36:00PM +0200, Alexander Bluhm wrote:
> The IP in IP input function strips the outer header and reinserts
> the inner IP packet into the internet queue.  The IPv6 local delivery
> code has a loop to deal with header chains.  My idea is to use this
> loop and avoid the queueing and rescheduling.  The packet could be
> processed in a single flow.

After commiting parts of it and merging with mpi@'s unlocking of
the forwarding path, the current diff looks like this.

The main idea is to have a single ip_deliver() loop that can handle
both addresss families.  This allows to process an IP in IP header
like a normal extension header.

If af != AF_UNSPEC we are already in a deliver loop and have the
kernel look.  Then we can just return the next protocol.  Otherwise
we enqueue.  The dequeue thread has the kernel lock and starts an
ip delivery loop.

ok?

bluhm

Index: netinet/ip_input.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/ip_input.c,v
retrieving revision 1.313
diff -u -p -r1.313 ip_input.c
--- netinet/ip_input.c  26 Jun 2017 19:06:12 -  1.313
+++ netinet/ip_input.c  27 Jun 2017 13:29:20 -
@@ -61,6 +61,11 @@
 #include 
 #include 
 
+#ifdef INET6
+#include 
+#include 
+#endif
+
 #if NPF > 0
 #include 
 #endif
@@ -216,6 +221,10 @@ ip_init(void)
 int
 ip_ours(struct mbuf **mp, int *offp, int nxt, int af)
 {
+   /* We are already in a IPv4/IPv6 local deliver loop. */
+   if (af != AF_UNSPEC)
+   return ip_local(mp, offp, nxt, af);
+
niq_enqueue(, *mp);
*mp = NULL;
return IPPROTO_DONE;
@@ -595,36 +604,118 @@ found:
}
 
*offp = hlen;
-   return ip_deliver(mp, offp, ip->ip_p, AF_INET);
+   nxt = ip->ip_p;
+   /* Check wheter we are already in a IPv4/IPv6 local deliver loop. */
+   if (af == AF_UNSPEC)
+   nxt = ip_deliver(mp, offp, nxt, AF_INET);
+   return nxt;
  bad:
m_freemp(mp);
return IPPROTO_DONE;
 }
 
+#ifndef INET6
+#define IPSTAT_INC(name)   ipstat_inc(ips_##name)
+#else
+#define IPSTAT_INC(name)   (af == AF_INET ?\
+ipstat_inc(ips_##name) : ip6stat_inc(ip6s_##name))
+#endif
+
 int
 ip_deliver(struct mbuf **mp, int *offp, int nxt, int af)
 {
+   struct protosw *psw;
+   int naf = af;
+#ifdef INET6
+   int nest = 0;
+#endif /* INET6 */
+
KERNEL_ASSERT_LOCKED();
 
/* pf might have modified stuff, might have to chksum */
-   in_proto_cksum_out(*mp, NULL);
+   switch (af) {
+   case AF_INET:
+   in_proto_cksum_out(*mp, NULL);
+   break;
+#ifdef INET6
+   case AF_INET6:
+   in6_proto_cksum_out(*mp, NULL);
+   break;
+#endif /* INET6 */
+   }
 
-#ifdef IPSEC
-   if (ipsec_in_use) {
-   if (ipsec_local_check(*mp, *offp, nxt, af) != 0) {
-   ipstat_inc(ips_cantforward);
+   /*
+* Tell launch routine the next header
+*/
+   IPSTAT_INC(delivered);
+
+   while (nxt != IPPROTO_DONE) {
+#ifdef INET6
+   if (af == AF_INET6 &&
+   ip6_hdrnestlimit && (++nest > ip6_hdrnestlimit)) {
+   ip6stat_inc(ip6s_toomanyhdr);
goto bad;
}
-   }
-   /* Otherwise, just fall through and deliver the packet */
+#endif /* INET6 */
+
+   /*
+* protection against faulty packet - there should be
+* more sanity checks in header chain processing.
+*/
+   if ((*mp)->m_pkthdr.len < *offp) {
+   IPSTAT_INC(tooshort);
+   goto bad;
+   }
+
+#ifdef INET6
+   /* draft-itojun-ipv6-tcp-to-anycast */
+   if (af == AF_INET6 &&
+   ISSET((*mp)->m_flags, M_ACAST) && (nxt == IPPROTO_TCP)) {
+   if ((*mp)->m_len >= sizeof(struct ip6_hdr)) {
+   icmp6_error(*mp, ICMP6_DST_UNREACH,
+   ICMP6_DST_UNREACH_ADDR,
+   offsetof(struct ip6_hdr, ip6_dst));
+   *mp = NULL;
+   }
+   goto bad;
+   }
+#endif /* INET6 */
+
+#ifdef IPSEC
+   if (ipsec_in_use) {
+   if (ipsec_local_check(*mp, *offp, nxt, af) != 0) {
+   IPSTAT_INC(cantforward);
+   goto bad;
+   }
+   }
+   /* Otherwise, just fall through and deliver the packet */
 #endif /* IPSEC */
 
-   /*
-* Switch out to protocol's input routine.
-*/
-   ipstat_inc(ips_delivered);
-   nxt = (*inetsw[ip_protox[nxt]].pr_input)(mp, offp, nxt, af);
-   KASSERT(nxt == IPPROTO_DONE);
+   switch (nxt) {
+ 

Additional media options for ix(4)

2017-06-27 Thread Mike Belopuhov
Hi,

I won't mind some broad testing of the following diff
which adds some additional media options to ix(4) from
FreeBSD and includes a fix for changing media from
Masanobu SAITOH.

The fix makes sure that when the media operation speed
is selected manually, the device doesn't additionally
advertise other (slower) modes.


diff --git sys/dev/pci/if_ix.c sys/dev/pci/if_ix.c
index 339ba2bc4f1..8fca8742f7f 100644
--- sys/dev/pci/if_ix.c
+++ sys/dev/pci/if_ix.c
@@ -1028,62 +1028,115 @@ ixgbe_intr(void *arg)
  *  This routine is called whenever the user queries the status of
  *  the interface using ifconfig.
  *
  **/
 void
-ixgbe_media_status(struct ifnet * ifp, struct ifmediareq *ifmr)
+ixgbe_media_status(struct ifnet *ifp, struct ifmediareq *ifmr)
 {
struct ix_softc *sc = ifp->if_softc;
+   int layer;
+
+   layer = sc->hw.mac.ops.get_supported_physical_layer(>hw);
 
ifmr->ifm_active = IFM_ETHER;
ifmr->ifm_status = IFM_AVALID;
 
INIT_DEBUGOUT("ixgbe_media_status: begin");
ixgbe_update_link_status(sc);
 
-   if (LINK_STATE_IS_UP(ifp->if_link_state)) {
-   ifmr->ifm_status |= IFM_ACTIVE;
+   if (!LINK_STATE_IS_UP(ifp->if_link_state))
+   return;
+
+   ifmr->ifm_status |= IFM_ACTIVE;
 
+   if (layer & IXGBE_PHYSICAL_LAYER_10GBASE_T ||
+   layer & IXGBE_PHYSICAL_LAYER_1000BASE_T ||
+   layer & IXGBE_PHYSICAL_LAYER_100BASE_TX)
switch (sc->link_speed) {
+   case IXGBE_LINK_SPEED_10GB_FULL:
+   ifmr->ifm_active |= IFM_10G_T | IFM_FDX;
+   break;
+   case IXGBE_LINK_SPEED_1GB_FULL:
+   ifmr->ifm_active |= IFM_1000_T | IFM_FDX;
+   break;
case IXGBE_LINK_SPEED_100_FULL:
ifmr->ifm_active |= IFM_100_TX | IFM_FDX;
break;
+   }
+   if (layer & IXGBE_PHYSICAL_LAYER_SFP_PLUS_CU ||
+   layer & IXGBE_PHYSICAL_LAYER_SFP_ACTIVE_DA)
+   switch (sc->link_speed) {
+   case IXGBE_LINK_SPEED_10GB_FULL:
+   ifmr->ifm_active |= IFM_10G_SFP_CU | IFM_FDX;
+   break;
+   }
+   if (layer & IXGBE_PHYSICAL_LAYER_10GBASE_LR)
+   switch (sc->link_speed) {
+   case IXGBE_LINK_SPEED_10GB_FULL:
+   ifmr->ifm_active |= IFM_10G_LR | IFM_FDX;
+   break;
case IXGBE_LINK_SPEED_1GB_FULL:
-   switch (sc->optics) {
-   case IFM_10G_SR: /* multi-speed fiber */
-   ifmr->ifm_active |= IFM_1000_SX | IFM_FDX;
-   break;
-   case IFM_10G_LR: /* multi-speed fiber */
-   ifmr->ifm_active |= IFM_1000_LX | IFM_FDX;
-   break;
-   default:
-   ifmr->ifm_active |= sc->optics | IFM_FDX;
-   break;
-   }
+   ifmr->ifm_active |= IFM_1000_LX | IFM_FDX;
break;
+   }
+   if (layer & IXGBE_PHYSICAL_LAYER_10GBASE_LRM)
+   switch (sc->link_speed) {
case IXGBE_LINK_SPEED_10GB_FULL:
-   ifmr->ifm_active |= sc->optics | IFM_FDX;
+   ifmr->ifm_active |= IFM_10G_LRM | IFM_FDX;
+   break;
+   case IXGBE_LINK_SPEED_1GB_FULL:
+   ifmr->ifm_active |= IFM_1000_LX | IFM_FDX;
break;
}
-
-   switch (sc->hw.fc.current_mode) {
-   case ixgbe_fc_tx_pause:
-   ifmr->ifm_active |= IFM_FLOW | IFM_ETH_TXPAUSE;
+   if (layer & IXGBE_PHYSICAL_LAYER_10GBASE_SR ||
+   layer & IXGBE_PHYSICAL_LAYER_1000BASE_SX)
+   switch (sc->link_speed) {
+   case IXGBE_LINK_SPEED_10GB_FULL:
+   ifmr->ifm_active |= IFM_10G_SR | IFM_FDX;
+   break;
+   case IXGBE_LINK_SPEED_1GB_FULL:
+   ifmr->ifm_active |= IFM_1000_SX | IFM_FDX;
break;
-   case ixgbe_fc_rx_pause:
-   ifmr->ifm_active |= IFM_FLOW | IFM_ETH_RXPAUSE;
+   }
+   if (layer & IXGBE_PHYSICAL_LAYER_10GBASE_CX4)
+   switch (sc->link_speed) {
+   case IXGBE_LINK_SPEED_10GB_FULL:
+   ifmr->ifm_active |= IFM_10G_CX4 | IFM_FDX;
break;
-   case ixgbe_fc_full:
-   ifmr->ifm_active |= IFM_FLOW | IFM_ETH_RXPAUSE |
-   IFM_ETH_TXPAUSE;
+   }
+   if (layer & 

unbound 1.6.4

2017-06-27 Thread Stuart Henderson
If anyone's interested in newer unbound, I have an initial diff, it's
750K all-in (we are currently on 1.6.1 so there are a few releases worth
of changes) so I won't send it inline, it's at
https://junkpile.org/unbound-1.6.4.diff



clang integrated asm crash while building mozilla/firefox

2017-06-27 Thread Marc Espie
I've attached the files that clang gives to reproduce the crash.

I also got a similar crash in firefox-esr.

Funnily enough, it happened after the recent update to both, BUT the crashes
seem to be unrelated ?

The sysv crash is consistent, I got it during both builds.
# 1 ""
# 1 "/pobj/firefox-54.0/build-amd64/mozilla-config.h" 1
/* List of defines generated by configure. Included with preprocessor flag,
 * -include, to avoid long list of -D defines on the compile command-line.
 * Do not edit.
 */

#ifndef MOZILLA_CONFIG_H
#define MOZILLA_CONFIG_H

#if defined(__clang__)
#pragma clang diagnostic push
#if __has_warning("-Wreserved-id-macro")
#pragma clang diagnostic ignored "-Wreserved-id-macro"
#endif
# 14 "/pobj/firefox-54.0/build-amd64/mozilla-config.h"
#endif
# 15 "/pobj/firefox-54.0/build-amd64/mozilla-config.h"

// Expands to all the defines from configure.
#define A11Y_LOG 1
#define ACCESSIBILITY 1
#define ATK_MAJOR_VERSION 2
#define ATK_MINOR_VERSION 24
#define ATK_REV_VERSION 0
#define BUILD_CTYPES 1
#define CROSS_COMPILE 
#define D_INO d_ino
#define ENABLE_INTL_API 1
#define ENABLE_SYSTEM_EXTENSION_DIRS 1
#define EXPOSE_INTL_API 1
#define FIREFOX_VERSION 54.0
#define FORCE_PR_LOG 1
#define FUNCPROTO 15
#define GDK_VERSION_MAX_ALLOWED GDK_VERSION_3_4
#define GLIB_VERSION_MAX_ALLOWED GLIB_VERSION_2_32
#define GLIB_VERSION_MIN_REQUIRED GLIB_VERSION_2_26
#define GL_PROVIDER_GLX 1
#define HAVE_64BIT_BUILD 1
#define HAVE_ARC4RANDOM 1
#define HAVE_ARC4RANDOM_BUF 1
#define HAVE_CLOCK_MONOTONIC 1
#define HAVE_CPUID_H 1
#define HAVE_DIRENT_H 1
#define HAVE_DLADDR 1
#define HAVE_DLOPEN 1
#define HAVE_FONTCONFIG_FCFREETYPE_H 1
#define HAVE_FT_BITMAP_SIZE_Y_PPEM 1
#define HAVE_FT_GLYPHSLOT_EMBOLDEN 1
#define HAVE_FT_LOAD_SFNT_TABLE 1
#define HAVE_GETOPT_H 1
#define HAVE_GMTIME_R 1
#define HAVE_I18N_LC_MESSAGES 1
#define HAVE_INTTYPES_H 1
#define HAVE_LANGINFO_CODESET 1
#define HAVE_LCHOWN 1
#define HAVE_LIBXSS 1
#define HAVE_LOCALECONV 1
#define HAVE_LOCALTIME_R 1
#define HAVE_MEMMEM 1
#define HAVE_NETINET_IN_H 1
#define HAVE_NL_TYPES_H 1
#define HAVE_POSIX_MEMALIGN 1
#define HAVE_PTHREAD_H 1
#define HAVE_SA_LEN 1
#define HAVE_SCONN_LEN 1
#define HAVE_SETPRIORITY 1
#define HAVE_SIN6_LEN 1
#define HAVE_SIN_LEN 1
#define HAVE_STDINT_H 1
#define HAVE_STRERROR 1
#define HAVE_STRNDUP 1
#define HAVE_SYSCALL 1
#define HAVE_SYS_QUEUE_H 1
#define HAVE_SYS_TYPES_H 1
#define HAVE_UNISTD_H 1
#define HAVE_VA_COPY 1
#define HAVE_VA_LIST_AS_ARRAY 1
#define HAVE_VISIBILITY_ATTRIBUTE 1
#define HAVE_VISIBILITY_HIDDEN_ATTRIBUTE 1
#define HAVE__UNWIND_BACKTRACE 1
#define HAVE___CXA_DEMANGLE 1
#define JS_DEFAULT_JITREPORT_GRANULARITY 3
#define MALLOC_USABLE_SIZE_CONST_PTR const
#define MOZILLA_OFFICIAL 1
#define MOZILLA_UAVERSION "54.0"
#define MOZILLA_VERSION "54.0"
#define MOZILLA_VERSION_U 54.0
#define MOZ_ACCESSIBILITY_ATK 1
#define MOZ_ADDON_SIGNING 1
#define MOZ_APP_UA_NAME ""
#define MOZ_APP_UA_VERSION "54.0"
#define MOZ_B2G_OS_NAME ""
#define MOZ_B2G_VERSION "1.0.0"
#define MOZ_BUILD_APP browser
#define MOZ_CRASHREPORTER_ENABLE_PERCENT 100
#define MOZ_DATA_REPORTING 1
#define MOZ_DISTRIBUTION_ID "org.mozilla"
#define MOZ_DLL_SUFFIX ".so.72.0"
#define MOZ_ENABLE_GIO 1
#define MOZ_ENABLE_MASK_AS_SHORTHAND 1
#define MOZ_ENABLE_SIGNMAR 1
#define MOZ_ENABLE_SKIA 1
#define MOZ_ENABLE_XREMOTE 1
#define MOZ_FEEDS 1
#define MOZ_FFMPEG 1
#define MOZ_FFVPX 1
#define MOZ_FMP4 1
#define MOZ_GLUE_IN_PROGRAM 1
#define MOZ_INSTRUMENT_EVENT_LOOP 1
#define MOZ_JSDOWNLOADS 1
#define MOZ_LIBAV_FFT 1
#define MOZ_LOGGING 1
#define MOZ_MACBUNDLE_ID org.mozilla.firefox
#define MOZ_OFFICIAL_BRANDING 1
#define MOZ_PEERCONNECTION 1
#define MOZ_PERMISSIONS 1
#define MOZ_PHOENIX 1
#define MOZ_PLACES 1
#define MOZ_RAW 1
#define MOZ_SAMPLE_TYPE_FLOAT32 1
#define MOZ_SCTP 1
#define MOZ_SECUREELEMENT 1
#define MOZ_SERVICES_HEALTHREPORT 1
#define MOZ_SRTP 1
#define MOZ_STATIC_JS 1
#define MOZ_SYSTEM_SQLITE 1
#define MOZ_UPDATE_CHANNEL default
#define MOZ_USER_DIR ".mozilla"
#define MOZ_VORBIS 1
#define MOZ_VPX_NO_MEM_REPORTING 1
#define MOZ_WEBM_ENCODER 1
#define MOZ_WEBRTC 1
#define MOZ_WEBRTC_ASSERT_ALWAYS 1
#define MOZ_WEBRTC_SIGNALING 1
#define MOZ_WEBSPEECH 1
#define MOZ_WEBSPEECH_TEST_BACKEND 1
#define MOZ_WIDGET_GTK 3
#define MOZ_X11 1
#define MOZ_XUL 1
#define NO_NSPR_10_SUPPORT 1
#define NS_PRINTING 1
#define NS_PRINT_PREVIEW 1
#define RELEASE_OR_BETA 1
#define STATIC_JS_API 1
#define STDC_HEADERS 1
#define TARGET_XPCOM_ABI "x86_64-gcc3"
#define USE_SKIA 1
#define U_USING_ICU_NAMESPACE 0
#define VA_COPY va_copy
#define VPX_X86_ASM 1
#define XP_UNIX 1
#define _REENTRANT 1
#define _THREAD_SAFE 1

/*
 * The c99 defining the limit macros (UINT32_MAX for example), says:
 *
 *   C++ implementations should define these macros only when
 *   __STDC_LIMIT_MACROS is defined before  is included.
 *
 * The same also occurs with __STDC_CONSTANT_MACROS for the constant macros
 * (INT8_C for example) used to specify a literal constant of the proper type,
 * 

Re: Attempt to simplify file(1)

2017-06-27 Thread Bryan Steele
On Tue, Jun 27, 2017 at 01:20:59AM -0400, Bryan Steele wrote:
> On Tue, Jun 27, 2017 at 12:26:08AM -0400, Bryan Steele wrote:
> Some unintentional changes crept in, here's another diff..

Sorry, last diff broke width calculation.. 3rd times the charm.

Index: Makefile
===
RCS file: /cvs/src/usr.bin/file/Makefile,v
retrieving revision 1.16
diff -u -p -u -r1.16 Makefile
--- Makefile4 Oct 2015 07:25:59 -   1.16
+++ Makefile27 Jun 2017 10:05:39 -
@@ -5,9 +5,6 @@ SRCS=   file.c magic-dump.c magic-load.c
text.c xmalloc.c
 MAN=   file.1 magic.5
 
-LDADD= -lutil
-DPADD= ${LIBUTIL}
-
 CDIAGFLAGS+= -Wno-long-long -Wall -W -Wnested-externs -Wformat=2
 CDIAGFLAGS+= -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations
 CDIAGFLAGS+= -Wwrite-strings -Wshadow -Wpointer-arith -Wsign-compare
Index: file.c
===
RCS file: /cvs/src/usr.bin/file/file.c,v
retrieving revision 1.59
diff -u -p -u -r1.59 file.c
--- file.c  18 Apr 2017 14:16:48 -  1.59
+++ file.c  27 Jun 2017 10:05:39 -
@@ -29,12 +29,10 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -43,27 +41,16 @@
 #include "magic.h"
 #include "xmalloc.h"
 
-struct input_msg {
-   int idx;
-
-   struct stat sb;
-   int error;
-
-   charlink_path[PATH_MAX];
-   int link_error;
-   int link_target;
-};
-
-struct input_ack {
-   int idx;
-};
-
 struct input_file {
struct magic*m;
-   struct input_msg*msg;
 
const char  *path;
-   int  fd;
+   struct stat  sb;
+   int  fd, error;
+
+   char link_path[PATH_MAX];
+   int  link_error;
+   int  link_target;
 
void*base;
size_t   size;
@@ -75,15 +62,13 @@ extern char *__progname;
 
 __dead void usage(void);
 
-static int  prepare_message(struct input_msg *, int, const char *);
-static void send_message(struct imsgbuf *, void *, size_t, int);
-static int  read_message(struct imsgbuf *, struct imsg *, pid_t);
+static void prepare_input(struct input_file *, const char *);
 
-static void read_link(struct input_msg *, const char *);
+static void read_link(struct input_file *, const char *);
 
-static __dead void child(int, pid_t, int, char **);
+static void privdrop(void);
 
-static void test_file(struct input_file *, size_t);
+static void test_file(struct input_file *, struct magic *, size_t);
 
 static int  try_stat(struct input_file *);
 static int  try_empty(struct input_file *);
@@ -120,14 +105,12 @@ usage(void)
 int
 main(int argc, char **argv)
 {
-   int  opt, pair[2], fd, idx;
+   int  opt, idx;
char*home;
struct passwd   *pw;
-   struct imsgbuf   ibuf;
-   struct imsg  imsg;
-   struct input_msg msg;
-   struct input_ack*ack;
-   pid_tpid, parent;
+   struct magic*m;
+   struct input_file   *inf;
+   size_t   len, width = 0;
 
tzset();
 
@@ -193,71 +176,48 @@ main(int argc, char **argv)
if (magicfp == NULL)
err(1, "%s", magicpath);
 
-   parent = getpid();
-   if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pair) != 0)
-   err(1, "socketpair");
-   switch (pid = fork()) {
-   case -1:
-   err(1, "fork");
-   case 0:
-   close(pair[0]);
-   child(pair[1], parent, argc, argv);
+   m = magic_load(magicfp, magicpath, cflag || Wflag);
+   if (cflag) {
+   magic_dump(m);
+   exit(0);
}
-   close(pair[1]);
-
-   fclose(magicfp);
-   magicfp = NULL;
 
-   if (cflag)
-   goto wait_for_child;
-
-   imsg_init(, pair[0]);
+   inf = xcalloc(argc, sizeof *inf);
for (idx = 0; idx < argc; idx++) {
-   fd = prepare_message(, idx, argv[idx]);
-   send_message(, , sizeof msg, fd);
-
-   if (read_message(, , pid) == 0)
-   break;
-   if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof *ack)
-   errx(1, "message too small");
-   ack = imsg.data;
-   if (ack->idx != idx)
-   errx(1, "index not expected");
-   imsg_free();
+   len = strlen(argv[idx]) + 1;
+   if (len > width)
+   width = len;
+   prepare_input([idx], 

Re: sed(1): missing NUL in pattern space

2017-06-27 Thread Otto Moerbeek
On Thu, Jun 15, 2017 at 09:01:15AM +0200, Otto Moerbeek wrote:

at last a followup, for the original problem.

This diff incorporates your later comment. It does not cause the newly
added regress test to fail, though.

So that poses the question if this is what you meant.

-Otto

Index: process.c
===
RCS file: /cvs/src/usr.bin/sed/process.c,v
retrieving revision 1.32
diff -u -p -r1.32 process.c
--- process.c   22 Feb 2017 14:09:09 -  1.32
+++ process.c   27 Jun 2017 09:16:33 -
@@ -120,8 +120,10 @@ redirect:
cp = cp->u.c;
goto redirect;
case 'c':
+   if (pd)
+   break;
pd = 1;
-   psl = 0;
+   ps[psl = 0] = '\0';
if (cp->a2 == NULL || lastaddr || lastline())
(void)fprintf(outfile, "%s", cp->t);
break;
@@ -138,6 +140,7 @@ redirect:
} else {
psl -= (p + 1) - ps;
memmove(ps, p + 1, psl);
+   ps[psl] = '\0';
goto top;
}
case 'g':



[PATCH] bin: Add -v option to cp(1), mv(1), rm(1)

2017-06-27 Thread Job Snijders
Dear all,

This patch adds a '-v' option to cp(1), mv(1), and rm(1). If the '-v'
option is used, the utility will display the name of each file after it
has been successfully copied, moved or removed.

This patch rolls in feedback from recent discussion. The manpage updates
are specific as to what the -v option does for each utility and the
messages written to the standard output are now minimalistic in nature.

example use:

$ touch a
$ mv -v a b
a -> b
$ cp -v b c
b -> c
$ rm -v b c
b
c

Hat tip to Paul de Weerd for helping with testing.

Kind regards,

Job

diff --git bin/cp/cp.1 bin/cp/cp.1
index 8573d801ca5..2896406498c 100644
--- bin/cp/cp.1
+++ bin/cp/cp.1
@@ -41,14 +41,14 @@
 .Nd copy files
 .Sh SYNOPSIS
 .Nm cp
-.Op Fl fip
+.Op Fl fipv
 .Oo
 .Fl R
 .Op Fl H | L | P
 .Oc
 .Ar source target
 .Nm cp
-.Op Fl fip
+.Op Fl fipv
 .Oo
 .Fl R
 .Op Fl H | L | P
@@ -145,6 +145,8 @@ use a utility such as
 or
 .Xr tar 1
 instead.
+.It Fl v
+Display the source and destination after each copy.
 .El
 .Pp
 For each destination file that already exists, its contents are
diff --git bin/cp/cp.c bin/cp/cp.c
index 643d82ed9fa..480f18b0ff1 100644
--- bin/cp/cp.c
+++ bin/cp/cp.c
@@ -71,7 +71,7 @@
 PATH_T to = { to.p_path, "" };
 
 uid_t myuid;
-int Rflag, fflag, iflag, pflag, rflag;
+int Rflag, fflag, iflag, pflag, rflag, vflag;
 mode_t myumask;
 
 enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
@@ -88,7 +88,7 @@ main(int argc, char *argv[])
char *target;
 
Hflag = Lflag = Pflag = Rflag = 0;
-   while ((ch = getopt(argc, argv, "HLPRfipr")) != -1)
+   while ((ch = getopt(argc, argv, "HLPRfiprv")) != -1)
switch (ch) {
case 'H':
Hflag = 1;
@@ -119,6 +119,9 @@ main(int argc, char *argv[])
case 'r':
rflag = 1;
break;
+   case 'v':
+   vflag = 1;
+   break;
default:
usage();
break;
@@ -394,6 +397,9 @@ copy(char *argv[], enum op type, int fts_options)
case S_IFLNK:
if (copy_link(curr, !fts_dne(curr)))
rval = 1;
+   else if (vflag)
+   (void)fprintf(stdout, "%s -> %s\n",
+   curr->fts_path, to.p_path);
break;
case S_IFDIR:
if (!Rflag && !rflag) {
@@ -415,6 +421,9 @@ copy(char *argv[], enum op type, int fts_options)
if (mkdir(to.p_path,
curr->fts_statp->st_mode | S_IRWXU) < 0)
err(1, "%s", to.p_path);
+   else if (vflag)
+   (void)fprintf(stdout, "%s -> %s\n",
+   curr->fts_path, to.p_path);
} else if (!S_ISDIR(to_stat.st_mode))
errc(1, ENOTDIR, "%s", to.p_path);
break;
@@ -426,6 +435,9 @@ copy(char *argv[], enum op type, int fts_options)
} else
if (copy_file(curr, fts_dne(curr)))
rval = 1;
+   if (!rval && vflag)
+   (void)fprintf(stdout, "%s -> %s\n",
+   curr->fts_path, to.p_path);
break;
case S_IFIFO:
if (Rflag) {
@@ -434,6 +446,9 @@ copy(char *argv[], enum op type, int fts_options)
} else
if (copy_file(curr, fts_dne(curr)))
rval = 1;
+   if (!rval && vflag)
+   (void)fprintf(stdout, "%s -> %s\n",
+   curr->fts_path, to.p_path);
break;
case S_IFSOCK:
warnc(EOPNOTSUPP, "%s", curr->fts_path);
@@ -441,6 +456,9 @@ copy(char *argv[], enum op type, int fts_options)
default:
if (copy_file(curr, fts_dne(curr)))
rval = 1;
+   else if (vflag)
+   (void)fprintf(stdout, "%s -> %s\n",
+   curr->fts_path, to.p_path);
break;
}
}
diff --git bin/cp/utils.c bin/cp/utils.c
index 6a3c5178647..2189dd4be1f 100644
--- bin/cp/utils.c
+++ bin/cp/utils.c
@@ -307,9 +307,9 @@ void
 usage(void)
 {
(void)fprintf(stderr,
-   "usage: %s [-fip] [-R [-H | -L | -P]] source target\n", __progname);
+   "usage: %s [-fipv] [-R [-H | -L | -P]] source 

Re: kernel relinking at install/upgrade time

2017-06-27 Thread Theo de Raadt
> On Mon 26/06/2017 14:35, Theo de Raadt wrote:
> > There is a diff in snapshots which does kernel relinking during
> > install or upgrade.
> > 
> > Really amazing...
> 
> Works as advertised, assuming that compXX is installed. The relinking bit uses
> strip, which is part of the compiler collection.
> 
> Does it make sense to include strip in the base system?

Aha!  That is an error we need to fix.



Re: kernel relinking at install/upgrade time

2017-06-27 Thread Leighton Sheppard
On Mon, Jun 26, 2017 at 02:35:55PM -0600, Theo de Raadt wrote:
> There is a diff in snapshots which does kernel relinking during
> install or upgrade.
> 
> Really amazing...
> 

This does sound amazing!  Upgrade time



Re: kernel relinking at install/upgrade time

2017-06-27 Thread Björn Ketelaars
On Mon 26/06/2017 14:35, Theo de Raadt wrote:
> There is a diff in snapshots which does kernel relinking during
> install or upgrade.
> 
> Really amazing...

Works as advertised, assuming that compXX is installed. The relinking bit uses
strip, which is part of the compiler collection.

Does it make sense to include strip in the base system?