unlock bge(4)

2015-10-04 Thread Jonathan Matthew
This brings bge(4) up to about where em(4) is.  It involves a few different
changes, notably:
- per-ring refill timeouts, to ensure we don't try to refill a ring from the
timeout and an interrupt at the same time
- removing the list of tx dma maps and just assigning a map to use based
on the current ring slot number (this is why it's more - than +)
- using atomics to adjust bge_txcnt, saving those adjustments until the
end of the tx/txeof loops, and only acting on the adjusted value
- not adding any mutexes

I've tested it on amd64 with these:

bge0 at pci1 dev 0 function 0 "Broadcom BCM5721" rev 0x21, BCM5750 C1 (0x4201): 
msi, address 00:18:f3:d1:80:64

bge0 at pci2 dev 2 function 0 "Broadcom BCM5703X" rev 0x02, BCM5702/5703 A2 
(0x1002): apic 3 int 1, address 00:09:3d:00:84:d1

and on sparc64:

bge0 at pci7 dev 4 function 0 "Broadcom BCM5714" rev 0xa3, BCM5715 A3 (0x9003): 
ivec 0x795, address 00:14:4f:00:5a:5a

On the sparc64 box (a v245), with if_input_process unlocked, this gets me 10-20%
more pps or about 100mbps more in tcpbench (550, up from 450).

ok?

Index: if_bgereg.h
===
RCS file: /cvs/src/sys/dev/pci/if_bgereg.h,v
retrieving revision 1.127
diff -u -p -u -p -r1.127 if_bgereg.h
--- if_bgereg.h 11 Sep 2015 13:02:28 -  1.127
+++ if_bgereg.h 30 Sep 2015 11:14:09 -
@@ -2830,11 +2830,6 @@ struct bge_type {
 #defineBGE_TIMEOUT 10
 #defineBGE_TXCONS_UNSET0x  /* impossible value */
 
-struct txdmamap_pool_entry {
-   bus_dmamap_t dmamap;
-   SLIST_ENTRY(txdmamap_pool_entry) link;
-};
-
 #defineASF_ENABLE  1
 #defineASF_NEW_HANDSHAKE   2
 #defineASF_STACKUP 4
@@ -2934,11 +2929,11 @@ struct bge_softc {
int bge_txcnt;
struct timeout  bge_timeout;
struct timeout  bge_rxtimeout;
+   struct timeout  bge_rxtimeout_jumbo;
u_int32_t   bge_rx_discards;
u_int32_t   bge_tx_discards;
u_int32_t   bge_rx_inerrors;
u_int32_t   bge_rx_overruns;
u_int32_t   bge_tx_collisions;
-   SLIST_HEAD(, txdmamap_pool_entry) txdma_list;
-   struct txdmamap_pool_entry *txdma[BGE_TX_RING_CNT];
+   bus_dmamap_tbge_txdma[BGE_TX_RING_CNT];
 };
Index: if_bge.c
===
RCS file: /cvs/src/sys/dev/pci/if_bge.c,v
retrieving revision 1.369
diff -u -p -u -p -r1.369 if_bge.c
--- if_bge.c19 Jul 2015 06:28:12 -  1.369
+++ if_bge.c5 Oct 2015 01:06:21 -
@@ -141,7 +141,7 @@ void bge_tick(void *);
 void bge_stats_update(struct bge_softc *);
 void bge_stats_update_regs(struct bge_softc *);
 int bge_cksum_pad(struct mbuf *);
-int bge_encap(struct bge_softc *, struct mbuf *, u_int32_t *);
+int bge_encap(struct bge_softc *, struct mbuf *, int *);
 int bge_compact_dma_runt(struct mbuf *);
 
 int bge_intr(void *);
@@ -1262,20 +1262,31 @@ uncreate:
return (1);
 }
 
+/*
+ * When the refill timeout for a ring is active, that ring is so empty
+ * that no more packets can be received on it, so the interrupt handler
+ * will not attempt to refill it, meaning we don't need to protect against
+ * interrupts here.
+ */
+
 void
 bge_rxtick(void *arg)
 {
struct bge_softc *sc = arg;
-   int s;
 
-   s = splnet();
if (ISSET(sc->bge_flags, BGE_RXRING_VALID) &&
if_rxr_inuse(>bge_std_ring) <= 8)
bge_fill_rx_ring_std(sc);
+}
+
+void
+bge_rxtick_jumbo(void *arg)
+{
+   struct bge_softc *sc = arg;
+
if (ISSET(sc->bge_flags, BGE_JUMBO_RXRING_VALID) &&
if_rxr_inuse(>bge_jumbo_ring) <= 8)
bge_fill_rx_ring_jumbo(sc);
-   splx(s);
 }
 
 void
@@ -1410,7 +1421,7 @@ bge_fill_rx_ring_jumbo(struct bge_softc 
 * that now, then try again later.
 */
if (if_rxr_inuse(>bge_jumbo_ring) <= 8)
-   timeout_add(>bge_rxtimeout, 1);
+   timeout_add(>bge_rxtimeout_jumbo, 1);
 }
 
 void
@@ -1446,7 +1457,6 @@ void
 bge_free_tx_ring(struct bge_softc *sc)
 {
int i;
-   struct txdmamap_pool_entry *dma;
 
if (!(sc->bge_flags & BGE_TXRING_VALID))
return;
@@ -1455,18 +1465,12 @@ bge_free_tx_ring(struct bge_softc *sc)
if (sc->bge_cdata.bge_tx_chain[i] != NULL) {
m_freem(sc->bge_cdata.bge_tx_chain[i]);
sc->bge_cdata.bge_tx_chain[i] = NULL;
-   SLIST_INSERT_HEAD(>txdma_list, sc->txdma[i],
-   link);
-   sc->txdma[i] = 0;
+   sc->bge_cdata.bge_tx_map[i] = NULL;
}
bzero(>bge_rdata->bge_tx_ring[i],
sizeof(struct bge_tx_bd));
-   }
 
-   while ((dma = 

Re: more on tame

2015-10-04 Thread Michael Reed
perror(3) is being used instead of err(3) in a few places;  is
that on purpose?  If it's an oversight, I also noticed the same
in patch(1).

On 10/04/15 01:34, Theo de Raadt wrote:
> 42 tame calls have been commited to 28 userland programs so far.
> For instance gzip, md5, ping, traceroute, tcpdump, script, arp,
> whois, ntpd, sshd...
> 
> Below is a tree of roughly a hundred more programs.  Not all are
> fully verified yet, but they being placed in snapshots.
> 
> Some of these I did myself, but others were contributed.  I am trying
> to focus on the programs which do either file or socket behaviour, but
> not both.  Or, on the programs which do their fd setup early.
> 
> I appreciate the feedback I've received so far.
> 
> Index: bin/dd/dd.c
> ===
> RCS file: /cvs/src/bin/dd/dd.c,v
> retrieving revision 1.21
> diff -u -p -u -r1.21 dd.c
> --- bin/dd/dd.c   16 Jan 2015 06:39:31 -  1.21
> +++ bin/dd/dd.c   28 Sep 2015 20:15:11 -
> @@ -149,6 +149,9 @@ setup(void)
>   if (out.offset)
>   pos_out();
>  
> + if (tame("stdio", NULL) == -1)
> + err(1, "tame");
> +
>   /*
>* Truncate the output file; ignore errors because it fails on some
>* kinds of output files, tapes, for example.
> Index: bin/df/df.c
> ===
> RCS file: /cvs/src/bin/df/df.c,v
> retrieving revision 1.52
> diff -u -p -u -r1.52 df.c
> --- bin/df/df.c   16 Jan 2015 06:39:31 -  1.52
> +++ bin/df/df.c   2 Oct 2015 00:19:01 -
> @@ -79,6 +79,9 @@ main(int argc, char *argv[])
>   int width, maxwidth;
>   char *mntpt;
>  
> + if (tame("stdio rpath", NULL) == -1)
> + err(1, "tame");
> +
>   while ((ch = getopt(argc, argv, "hiklnPt:")) != -1)
>   switch (ch) {
>   case 'h':
> Index: bin/expr/expr.c
> ===
> RCS file: /cvs/src/bin/expr/expr.c,v
> retrieving revision 1.20
> diff -u -p -u -r1.20 expr.c
> --- bin/expr/expr.c   11 Aug 2015 17:15:46 -  1.20
> +++ bin/expr/expr.c   28 Sep 2015 20:15:11 -
> @@ -12,6 +12,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  
> @@ -499,6 +500,9 @@ main(int argc, char *argv[])
>   struct val *vp;
>  
>   (void) setlocale(LC_ALL, "");
> +
> + if (tame("stdio", NULL) == -1)
> + err(1, "tame");
>  
>   if (argc > 1 && !strcmp(argv[1], "--"))
>   argv++;
> Index: bin/ls/ls.c
> ===
> RCS file: /cvs/src/bin/ls/ls.c,v
> retrieving revision 1.41
> diff -u -p -u -r1.41 ls.c
> --- bin/ls/ls.c   25 Jun 2015 02:04:07 -  1.41
> +++ bin/ls/ls.c   28 Sep 2015 20:15:11 -
> @@ -123,6 +123,9 @@ ls_main(int argc, char *argv[])
>   termwidth = width;
>   }
>  
> + if (tame("stdio rpath", NULL) == -1)
> + err(1, "tame");
> +
>   /* Root is -A automatically. */
>   if (!getuid())
>   f_listdot = 1;
> Index: bin/mkdir/mkdir.c
> ===
> RCS file: /cvs/src/bin/mkdir/mkdir.c,v
> retrieving revision 1.25
> diff -u -p -u -r1.25 mkdir.c
> --- bin/mkdir/mkdir.c 2 Apr 2013 20:26:17 -   1.25
> +++ bin/mkdir/mkdir.c 3 Oct 2015 03:32:46 -
> @@ -55,6 +55,9 @@ main(int argc, char *argv[])
>  
>   setlocale(LC_ALL, "");
>  
> + if (tame("stdio cpath rpath fattr", NULL) == -1)
> + err(1, "tame");
> +
>   /*
>* The default file mode is a=rwx (0777) with selected permissions
>* removed in accordance with the file mode creation mask.  For
> Index: bin/pax/ar_io.c
> ===
> RCS file: /cvs/src/bin/pax/ar_io.c,v
> retrieving revision 1.50
> diff -u -p -u -r1.50 ar_io.c
> --- bin/pax/ar_io.c   22 Mar 2015 03:15:00 -  1.50
> +++ bin/pax/ar_io.c   3 Oct 2015 23:42:07 -
> @@ -75,6 +75,7 @@ static int wr_trail = 1;/* trailer was
>  static int can_unlnk = 0;/* do we unlink null archives?  */
>  const char *arcname; /* printable name of archive */
>  const char *gzip_program;/* name of gzip program */
> +const char *delayed_tame;/* tame request for after forking gzip_program 
> */
>  static pid_t zpid = -1;  /* pid of child process */
>  int force_one_volume;/* 1 if we ignore volume 
> changes */
>  
> @@ -1276,4 +1277,6 @@ ar_start_gzip(int fd, const char *path, 
>   err(1, "could not exec %s", path);
>   /* NOTREACHED */
>   }
> + if (delayed_tame != NULL && tame(delayed_tame, NULL) == -1)
> + err(1, "tame");
>  }
> Index: bin/pax/extern.h
> 

Re: tame(2) nologin(8)

2015-10-04 Thread Mike Burns
On 2015-10-04 01.33.12 +0200, Mike Burns wrote:
> I suspect that the paths argument is unused or not yet ready, but I
> include in here regardless merely so that I can ask about it.

Consolidated feedback from off-list:

The paths argument is not yet to be used. Also, it must be
NULL-terminated.



Re: tame userland diff

2015-10-04 Thread Mike Burns
On 2015-10-04 07.15.47 +0200, Sebastien Marie wrote:
> On Sat, Oct 03, 2015 at 09:52:13PM +0200, Mike Burns wrote:
> > On 2015-10-03 09.53.54 -0600, Theo de Raadt wrote:
> > > 
> > > I don't know why you added "proc".  I don't see a need for it.  Do
> > > you have a seperate test cases that prompts this?
> > 
> > This is because of the system(3) call in bcode.c, the bexec function.

To clarify: this is because system(3) uses one of the fork functions.



Re: ahci.c memory leak in error path

2015-10-04 Thread Jonathan Matthew
On Fri, Oct 02, 2015 at 02:37:18PM +0200, Benjamin Baier wrote:
> Fix memory leak in error path.
> Found by llvm/scan-build.

Thanks, I've just committed this.

> 
> Also port (sc->sc_ports[port]) was not assigned, so "goto freeport;"
> seems wrong.
> 
> Index: ahci.c
> ===
> RCS file: /cvs/src/sys/dev/ic/ahci.c,v
> retrieving revision 1.22
> diff -u -p -r1.22 ahci.c
> --- ahci.c27 Aug 2015 18:47:29 -  1.22
> +++ ahci.c26 Sep 2015 09:29:57 -
> @@ -460,7 +460,8 @@ ahci_port_alloc(struct ahci_softc *sc, u
>   if (ap->ap_err_scratch == NULL) {
>   printf("%s: unable to allocate DMA scratch buf for port %d\n",
>   DEVNAME(sc), port);
> - goto freeport;
> + free(ap, M_DEVBUF, sizeof(*ap));
> + goto reterr;
>   }
>  
>  #ifdef AHCI_DEBUG
> 



Re: acpidump(8): fix usage message

2015-10-04 Thread Jason McIntyre
On Sat, Oct 03, 2015 at 02:30:38AM -0400, Michael Reed wrote:
> This brings the usage info in line with most other programs.
> 
> 

fixed, thanks.
jmc

> 
> Index: acpidump.c
> ===
> RCS file: /cvs/src/usr.sbin/acpidump/acpidump.c,v
> retrieving revision 1.13
> diff -u -p -r1.13 acpidump.c
> --- acpidump.c3 Oct 2015 01:05:12 -   1.13
> +++ acpidump.c3 Oct 2015 06:28:57 -
> @@ -560,7 +560,7 @@ usage(void)
>  {
>   extern char *__progname;
>  
> - fprintf(stderr, "%s -o prefix_for_output\n", __progname);
> + fprintf(stderr, "usage: %s -o prefix_for_output\n", __progname);
>   exit(1);
>  }
>  
> 



Re: tame userland diff

2015-10-04 Thread Ted Unangst
Sebastien Marie wrote:
>   - if an exec'ed program starts with herited TAME flags: the
> initialisation of the program would be difficult as it would be
> already tamed.

i've been thinking about this some more. true in some cases, but i think in
many cases, what we are banning should be banned in the child as well. for
example, tar execs gzip. tar doesn't need sockets, neither does gzip. (in the
specific case of tar, guenther has done something different, but let's
consider this more abstractly.)

if i want to exec a program now, that means the entire code path up to exec()
can't use tame() anywhere. that seems bad. if i know the execed program won't
create new files or sockets, i'd like to remove those capabilities form the
parent too.

yes, maybe the parent will need to go into the exec() with a few extra
permissions in order to let the child initialize, but a few extra permissions
can still be less than *all* permissions, as required today.



Re: iwm(4) newstate task (again)

2015-10-04 Thread Vadim Zhukov
2015-10-03 22:33 GMT+02:00 Stefan Sperling :
> On Sun, Sep 27, 2015 at 08:00:19PM +0200, Stefan Sperling wrote:
>> This is yet another attempt at improving the iwm(4) newstate task.
>
> This diff has been working nicely for me, with many suspend/resume cycles.
> Never had a problem connecting to several wifis.
>
> Any objections? Any Oks?
>
>> The goal is to simplify things by only queuing one state transition
>> at a time. The newstate task now always transitions to the most
>> recently requested state, rather than hopping along with every request.
>>
>> This allows us get rid of the silly newstate generation counter, and
>> allows us to simply cancel any outstanding transition when the interface
>> goes down.
>>
>> The old code was queuing *additional* work from iwm_stop(). Which meant,
>> for example, that every time upon resume, a task ran only to discover that
>> it is no longer relevant.
>>
>> This probably needs some testing to shake out bugs.
>> Test reports are very much appreciated!
>>
>> This change might also fix semi-frequent firmware errors during association.
>> But not all -- I've found that running with IWM_DEBUG cranked up produces
>> sufficient printfs to make firmware commands time out more often.
>> It all seems very sensitive to timing which is hard to get completely
>> right with tasks involved.
>>
>> Index: if_iwm.c
>> ===
>> RCS file: /cvs/src/sys/dev/pci/if_iwm.c,v
>> retrieving revision 1.51
>> diff -u -p -r1.51 if_iwm.c
>> --- if_iwm.c  27 Sep 2015 16:53:38 -  1.51
>> +++ if_iwm.c  27 Sep 2015 17:33:58 -
>> @@ -195,14 +195,6 @@ const struct iwm_rate {
>>  #define IWM_RIDX_IS_CCK(_i_) ((_i_) < IWM_RIDX_OFDM)
>>  #define IWM_RIDX_IS_OFDM(_i_) ((_i_) >= IWM_RIDX_OFDM)
>>
>> -struct iwm_newstate_state {
>> - struct task ns_wk;
>> - struct ieee80211com *ns_ic;
>> - enum ieee80211_state ns_nstate;
>> - int ns_arg;
>> - int ns_generation;
>> -};
>> -
>>  int  iwm_store_cscheme(struct iwm_softc *, uint8_t *, size_t);
>>  int  iwm_firmware_store_section(struct iwm_softc *, enum iwm_ucode_type,
>>   uint8_t *, size_t);
>> @@ -406,7 +398,7 @@ struct ieee80211_node *iwm_node_alloc(st
>>  void iwm_calib_timeout(void *);
>>  void iwm_setrates(struct iwm_node *);
>>  int  iwm_media_change(struct ifnet *);
>> -void iwm_newstate_cb(void *);
>> +void iwm_newstate_task(void *);
>>  int  iwm_newstate(struct ieee80211com *, enum ieee80211_state, int);
>>  void iwm_endscan_cb(void *);
>>  int  iwm_init_hw(struct iwm_softc *);
>> @@ -5263,43 +5255,29 @@ iwm_media_change(struct ifnet *ifp)
>>  }
>>
>>  void
>> -iwm_newstate_cb(void *wk)
>> +iwm_newstate_task(void *psc)
>>  {
>> - struct iwm_newstate_state *iwmns = (void *)wk;
>> - struct ieee80211com *ic = iwmns->ns_ic;
>> - enum ieee80211_state nstate = iwmns->ns_nstate;
>> - int generation = iwmns->ns_generation;
>> + struct iwm_softc *sc = (struct iwm_softc *)psc;
>> + struct ieee80211com *ic = >sc_ic;
>> + enum ieee80211_state nstate = sc->ns_nstate;
>> + enum ieee80211_state ostate = ic->ic_state;
>>   struct iwm_node *in;
>> - int arg = iwmns->ns_arg;
>> - struct ifnet *ifp = IC2IFP(ic);
>> - struct iwm_softc *sc = ifp->if_softc;
>> + int arg = sc->ns_arg;
>>   int error;
>>
>> - free(iwmns, M_DEVBUF, sizeof(*iwmns));
>> -
>> - DPRINTF(("Prepare to switch state %s->%s\n",
>> - ieee80211_state_name[ic->ic_state],
>> - ieee80211_state_name[nstate]));
>> - if (sc->sc_generation != generation) {
>> - DPRINTF(("newstate_cb: someone pulled the plug meanwhile\n"));
>> - if (nstate == IEEE80211_S_INIT) {
>> - DPRINTF(("newstate_cb: nstate == IEEE80211_S_INIT: 
>> calling sc_newstate()\n"));
>> - sc->sc_newstate(ic, nstate, arg);
>> - }
>> - return;
>> - }
>> -
>>   DPRINTF(("switching state %s->%s\n",
>> - ieee80211_state_name[ic->ic_state],
>> + ieee80211_state_name[ostate],
>>   ieee80211_state_name[nstate]));
>>
>> - if (ic->ic_state == IEEE80211_S_SCAN && nstate != ic->ic_state)
>> + if (ostate == IEEE80211_S_SCAN && nstate != ostate)
>>   iwm_led_blink_stop(sc);
>>
>>   /* disable beacon filtering if we're hopping out of RUN */
>> - if (ic->ic_state == IEEE80211_S_RUN && nstate != ic->ic_state) {
>> + if (ostate == IEEE80211_S_RUN && nstate != ostate)
>>   iwm_mvm_disable_beacon_filter(sc, (void *)ic->ic_bss);
>>
>> + /* Reset the device if moving out of AUTH, ASSOC, or RUN. */
>> + if (ostate > IEEE80211_S_SCAN && nstate < ostate) {
>>   if (((in = (void *)ic->ic_bss) != NULL))
>>   in->in_assoc = 0;
>>   iwm_release(sc, NULL);
>> @@ -5393,25 +5371,15 @@ iwm_newstate_cb(void *wk)
>>  int
>>  

ftpd popen

2015-10-04 Thread Ted Unangst
as seen in cron, make the popen replacement nicer. this also repairs two
abuses of comma operators and an unnecessary function pointer.


Index: extern.h
===
RCS file: /cvs/src/libexec/ftpd/extern.h,v
retrieving revision 1.18
diff -u -p -r1.18 extern.h
--- extern.h4 Mar 2012 04:05:15 -   1.18
+++ extern.h4 Oct 2015 09:35:33 -
@@ -67,8 +67,8 @@ void  cwd(char *);
 void   delete(char *);
 void   dologout(int);
 void   fatal(char *);
-intftpd_pclose(FILE *);
-FILE   *ftpd_popen(char *, char *);
+intftpd_pclose(FILE *, pid_t);
+FILE   *ftpd_popen(char *, char *, pid_t *);
 int get_line(char *, int, FILE *);
 void   ftpdlogwtmp(char *, char *, char *);
 void   lreply(int, const char *, ...);
Index: ftpd.c
===
RCS file: /cvs/src/libexec/ftpd/ftpd.c,v
retrieving revision 1.208
diff -u -p -r1.208 ftpd.c
--- ftpd.c  1 Sep 2015 06:50:53 -   1.208
+++ ftpd.c  4 Oct 2015 09:38:41 -
@@ -1160,18 +1160,18 @@ retrieve(char *cmd, char *name)
 {
FILE *fin, *dout;
struct stat st;
-   int (*closefunc)(FILE *);
+   pid_t pid;
time_t start;
 
if (cmd == 0) {
-   fin = fopen(name, "r"), closefunc = fclose;
+   fin = fopen(name, "r");
st.st_size = 0;
} else {
char line[BUFSIZ];
 
(void) snprintf(line, sizeof(line), cmd, name);
name = line;
-   fin = ftpd_popen(line, "r"), closefunc = ftpd_pclose;
+   fin = ftpd_popen(line, "r", );
st.st_size = -1;
st.st_blksize = BUFSIZ;
}
@@ -1226,9 +1226,12 @@ done:
if (pdata >= 0)
(void) close(pdata);
pdata = -1;
-   if (cmd == 0)
+   if (cmd == 0) {
LOGBYTES("get", name, byte_count);
-   (*closefunc)(fin);
+   fclose(fin);
+   } else {
+   ftpd_pclose(fin, pid);
+   }
 }
 
 void
@@ -1771,10 +1774,11 @@ statfilecmd(char *filename)
FILE *fin;
int c;
int atstart;
+   pid_t pid;
char line[LINE_MAX];
 
(void)snprintf(line, sizeof(line), "/bin/ls -lgA %s", filename);
-   fin = ftpd_popen(line, "r");
+   fin = ftpd_popen(line, "r", );
if (fin == NULL) {
reply(451, "Local resource failure");
return;
@@ -1785,13 +1789,13 @@ statfilecmd(char *filename)
if (c == '\n') {
if (ferror(stdout)){
perror_reply(421, "control connection");
-   (void) ftpd_pclose(fin);
+   (void) ftpd_pclose(fin, pid);
dologout(1);
/* NOTREACHED */
}
if (ferror(fin)) {
perror_reply(551, filename);
-   (void) ftpd_pclose(fin);
+   (void) ftpd_pclose(fin, pid);
return;
}
(void) putc('\r', stdout);
@@ -1801,7 +1805,7 @@ statfilecmd(char *filename)
(void) putc(c, stdout);
atstart = (c == '\n');
}
-   (void) ftpd_pclose(fin);
+   (void) ftpd_pclose(fin, pid);
reply(211, "End of Status");
 }
 
Index: popen.c
===
RCS file: /cvs/src/libexec/ftpd/popen.c,v
retrieving revision 1.24
diff -u -p -r1.24 popen.c
--- popen.c 8 Mar 2010 19:34:44 -   1.24
+++ popen.c 4 Oct 2015 09:35:03 -
@@ -56,14 +56,11 @@
  * may create a pipe to a hidden program as a side effect of a list or dir
  * command.
  */
-static pid_t *pids;
-static int fds;
-
 #define MAX_ARGV   100
 #define MAX_GARGV  1000
 
 FILE *
-ftpd_popen(char *program, char *type)
+ftpd_popen(char *program, char *type, pid_t *pidptr)
 {
char *cp;
FILE *iop;
@@ -74,12 +71,6 @@ ftpd_popen(char *program, char *type)
if ((*type != 'r' && *type != 'w') || type[1])
return (NULL);
 
-   if (!pids) {
-   if ((fds = getdtablesize()) <= 0)
-   return (NULL);
-   if ((pids = calloc(fds, sizeof(pid_t))) == NULL)
-   return (NULL);
-   }
if (pipe(pdes) < 0)
return (NULL);
 
@@ -160,7 +151,7 @@ ftpd_popen(char *program, char *type)
iop = fdopen(pdes[1], type);
(void)close(pdes[0]);
}
-   pids[fileno(iop)] = pid;
+   *pidptr = pid;
 
 pfree: for (argc = 1; gargv[argc] != NULL; argc++)
free(gargv[argc]);
@@ -169,29 +160,22 @@ pfree:for (argc = 1; gargv[argc] != NUL
 }
 
 int
-ftpd_pclose(FILE *iop)

Re: CVS: cvs.openbsd.org: src

2015-10-04 Thread Joerg Jung
On Wed, Sep 30, 2015 at 06:07:54PM +0200, Joerg Jung wrote:
> On Wed, Sep 30, 2015 at 05:13:31PM +0200, Martijn van Duren wrote:
> > 
> > What I find somewhat strange is that although the dmesg says it has "2
> > lights", it only shows one illuminance sensor in my sysctl. 
> 
> This is expected. In newer models the SMC shows up with two sensor keys,
> but only *one* provides useful/valid values (with 10bit instead of 6bit
> in older models). I probably should remove the number from the initial
> message to avoid confusion.

I committed a fix to -current, so that it should show now the correct
number of light sensors on initialization.



Re: more on tame

2015-10-04 Thread Theo de Raadt
> perror(3) is being used instead of err(3) in a few places;  is
> that on purpose?  If it's an oversight, I also noticed the same
> in patch(1).

I am using perror in older programs.



Re: CVS: cvs.openbsd.org: src

2015-10-04 Thread Joerg Jung
On Sun, Oct 04, 2015 at 09:20:06PM +0200, Mark Kettenis wrote:
> 
> Here is what I get on the Macmini 1,1 now:
> 
> asmc0 at isa0 port 0x300/32
> asmc0: rev 1.3f503, 137 keys, 5 temperatures, 1 fan, 0 lights, kbdled

Thanks for testing! I think printing "0 lights" is not very useful,
so I will tweak the output a bit further.
 
> hw.sensors.cpu0.temp0=54.00 degC
> hw.sensors.asmc0.temp0=56.00 degC (TC0D CPU0 Die Core)
> hw.sensors.asmc0.temp1=51.00 degC (TC0H CPU0 Heatsink)
> hw.sensors.asmc0.temp2=55.00 degC (TC0P CPU0 Proximity)
> hw.sensors.asmc0.temp3=54.00 degC (TN0P Northbridge Proximity)
> hw.sensors.asmc0.temp4=55.00 degC (TN1P Northbridge 2)
> hw.sensors.asmc0.fan0=1538 RPM (Master)
> 
> To answer your earlier question: I think having asmc(4) provide the
> Die Core temperature is good even though it is redundant.  This allows
> us to verify that cpu(4) is providing the right temperature/

Ok, fair enough.



pkg_(add|delete|info): fix synopses

2015-10-04 Thread Michael Reed
The use of an ellipsis in manuals usually seems to already imply
optional arguments, e.g., `.Op Ar file ...', so constructs like
`Ar pkg-name Op Ar ...' seem redundant to me.

While here, also denote the `pkg-name' argument to pkg_delete
as optional, since you can do things like `pkg_delete -nX'.



Index: pkg_add.1
===
RCS file: /cvs/src/usr.sbin/pkg_add/pkg_add.1,v
retrieving revision 1.132
diff -u -p -r1.132 pkg_add.1
--- pkg_add.1   16 Apr 2015 20:01:39 -  1.132
+++ pkg_add.1   4 Oct 2015 17:54:40 -
@@ -31,7 +31,7 @@
 .Op Fl L Ar localbase
 .Op Fl l Ar file
 .Op Fl P Ar type
-.Ar pkg-name Op Ar ...
+.Ar pkg-name ...
 .Ek
 .Sh DESCRIPTION
 The
Index: pkg_delete.1
===
RCS file: /cvs/src/usr.sbin/pkg_add/pkg_delete.1,v
retrieving revision 1.50
diff -u -p -r1.50 pkg_delete.1
--- pkg_delete.18 Apr 2015 17:25:58 -   1.50
+++ pkg_delete.14 Oct 2015 17:54:40 -
@@ -26,7 +26,7 @@
 .Op Fl acIimnqsvXx
 .Op Fl B Ar pkg-destdir
 .Op Fl D Ar name Ns Op = Ns Ar value
-.Ar pkg-name Op Ar ...
+.Op Ar pkg-name ...
 .Sh DESCRIPTION
 The
 .Nm
Index: pkg_info.1
===
RCS file: /cvs/src/usr.sbin/pkg_add/pkg_info.1,v
retrieving revision 1.50
diff -u -p -r1.50 pkg_info.1
--- pkg_info.1  8 Sep 2014 01:27:55 -   1.50
+++ pkg_info.1  4 Oct 2015 17:54:40 -
@@ -30,8 +30,7 @@
 .Op Fl l Ar str
 .Op Fl Q Ar query
 .Op Fl r Ar pkgspec
-.Op Ar pkg-name
-.Op Ar ...
+.Op Ar pkg-name ...
 .Ek
 .Sh DESCRIPTION
 The
Index: OpenBSD/PkgAdd.pm
===
RCS file: /cvs/src/usr.sbin/pkg_add/OpenBSD/PkgAdd.pm,v
retrieving revision 1.87
diff -u -p -r1.87 PkgAdd.pm
--- OpenBSD/PkgAdd.pm   30 Jun 2015 19:20:08 -  1.87
+++ OpenBSD/PkgAdd.pm   4 Oct 2015 17:54:40 -
@@ -107,7 +107,7 @@ sub handle_options
my $state = shift;
$state->SUPER::handle_options('ruUzl:A:P:',
'[-acinqrsUuvxz] [-A arch] [-B pkg-destdir] [-D name[=value]]',
-   '[-L localbase] [-l file] [-P type] pkg-name [...]');
+   '[-L localbase] [-l file] [-P type] pkg-name ...');
 
$state->{arch} = $state->opt('A');
 
Index: OpenBSD/PkgDelete.pm
===
RCS file: /cvs/src/usr.sbin/pkg_add/OpenBSD/PkgDelete.pm,v
retrieving revision 1.34
diff -u -p -r1.34 PkgDelete.pm
--- OpenBSD/PkgDelete.pm29 Nov 2014 10:42:51 -  1.34
+++ OpenBSD/PkgDelete.pm4 Oct 2015 17:54:40 -
@@ -101,7 +101,7 @@ sub handle_options
 {
my $state = shift;
$state->SUPER::handle_options('X',
-   '[-acimnqsvXx] [-B pkg-destdir] [-D name[=value]] pkg-name [...]');
+   '[-acimnqsvXx] [-B pkg-destdir] [-D name[=value]] [pkg-name ...]');
 
my $base = $state->opt('B') // $ENV{'PKG_DESTDIR'} // '';
if ($base ne '') {
Index: OpenBSD/PkgInfo.pm
===
RCS file: /cvs/src/usr.sbin/pkg_add/OpenBSD/PkgInfo.pm,v
retrieving revision 1.35
diff -u -p -r1.35 PkgInfo.pm
--- OpenBSD/PkgInfo.pm  6 Apr 2015 12:19:35 -   1.35
+++ OpenBSD/PkgInfo.pm  4 Oct 2015 17:54:40 -
@@ -559,7 +559,7 @@ sub parse_and_run
$state->{no_exports} = 1;
$state->handle_options('cCdfF:hIKLmPQ:qr:RsSUe:E:Ml:aAt',
'[-AaCcdfIKLMmPqRSstUv] [-D nolock][-E filename] [-e pkg-name] ',
-   '[-l str] [-Q query] [-r pkgspec] [pkg-name] [...]');
+   '[-l str] [-Q query] [-r pkgspec] [pkg-name ...]');
 
if ($state->opt('r')) {
 



Re: CVS: cvs.openbsd.org: src

2015-10-04 Thread Mark Kettenis
> Date: Sun, 4 Oct 2015 14:10:18 +0200
> From: Joerg Jung 
> 
> On Wed, Sep 30, 2015 at 06:07:54PM +0200, Joerg Jung wrote:
> > On Wed, Sep 30, 2015 at 05:13:31PM +0200, Martijn van Duren wrote:
> > > 
> > > What I find somewhat strange is that although the dmesg says it has "2
> > > lights", it only shows one illuminance sensor in my sysctl. 
> > 
> > This is expected. In newer models the SMC shows up with two sensor keys,
> > but only *one* provides useful/valid values (with 10bit instead of 6bit
> > in older models). I probably should remove the number from the initial
> > message to avoid confusion.
> 
> I committed a fix to -current, so that it should show now the correct
> number of light sensors on initialization.

Here is what I get on the Macmini 1,1 now:

asmc0 at isa0 port 0x300/32
asmc0: rev 1.3f503, 137 keys, 5 temperatures, 1 fan, 0 lights, kbdled

hw.sensors.cpu0.temp0=54.00 degC
hw.sensors.asmc0.temp0=56.00 degC (TC0D CPU0 Die Core)
hw.sensors.asmc0.temp1=51.00 degC (TC0H CPU0 Heatsink)
hw.sensors.asmc0.temp2=55.00 degC (TC0P CPU0 Proximity)
hw.sensors.asmc0.temp3=54.00 degC (TN0P Northbridge Proximity)
hw.sensors.asmc0.temp4=55.00 degC (TN1P Northbridge 2)
hw.sensors.asmc0.fan0=1538 RPM (Master)

To answer your earlier question: I think having asmc(4) provide the
Die Core temperature is good even though it is redundant.  This allows
us to verify that cpu(4) is providing the right temperature/



Re: Happy Birthday OpenBSD!

2015-10-04 Thread Bob Beck

On Sun, Oct 04, 2015 at 05:27:51PM -0600, Bob Beck wrote:
> 
>   ** OpenBSD is turning 20, on January 18th 2015 ** 

Ok, and I'm an idiot.. OCTOBER 18th, 2015  I.E. coming up in two weeks 
from today :) 

> 
> There will be an informal Birthday Party upstairs at the Hose and Hound pub 
> in Calgary (http://www.thehose.ca/)
> 
> At the very least, Theo de Raadt and I will be there starting from about 5 
> PM. 
> 
> Any and all are welcome to stop by and say hi, and to have a beer or 
> thirteen. 
> 
>   Cheers, 
> 
>   -Bob



Happy Birthday OpenBSD!

2015-10-04 Thread Bob Beck

** OpenBSD is turning 20, on January 18th 2015 ** 

There will be an informal Birthday Party upstairs at the Hose and Hound pub in 
Calgary (http://www.thehose.ca/)

At the very least, Theo de Raadt and I will be there starting from about 5 PM. 

Any and all are welcome to stop by and say hi, and to have a beer or thirteen. 

Cheers, 

-Bob



style.9 references "user land"

2015-10-04 Thread Rob Pierce
When I read "user land" in style.9 it seemed weird. I checked and all other
man pages refer to "userland". I also checked the source tree and found well
over 400 instances of userland, and only 3 other instances of "user land":

share/man/man9/style.9
lib/libc/rpc/svc.c
sys/arch/m88k/include/pcb.h
sys/netinet6/in6_var.h

Rob

Index: style.9
===
RCS file: /cvs/src/share/man/man9/style.9,v
retrieving revision 1.61
diff -u -p -r1.61 style.9
--- style.9 26 Sep 2015 15:40:28 -  1.61
+++ style.9 4 Oct 2015 23:10:01 -
@@ -34,7 +34,7 @@
 This file specifies the preferred style for kernel source files in the
 .Ox
 source tree.
-It is also a guide for preferred user land code style.
+It is also a guide for preferred userland code style.
 These guidelines should be followed for all new code.
 In general, code can be considered
 .Dq new code
@@ -110,7 +110,7 @@ All functions are prototyped somewhere.
 .Pp
 Function prototypes for private functions (i.e., functions not used
 elsewhere) go at the top of the first source module.
-In user land, functions local to one source module should be declared
+In userland, functions local to one source module should be declared
 .Ql static .
 This should not be done in kernel land since it makes it impossible
 to use the kernel debugger.

Index: svc.c
===
RCS file: /cvs/src/lib/libc/rpc/svc.c,v
retrieving revision 1.28
diff -u -p -r1.28 svc.c
--- svc.c   13 Sep 2015 15:36:56 -  1.28
+++ svc.c   4 Oct 2015 23:13:09 -
@@ -500,7 +500,7 @@ DEF_WEAK(svcerr_progvers);
  *   a) the structure is contiguous (no pointers), and
  *   b) the cred structure size does not exceed RQCRED_SIZE bytes. 
  * In all events, all three parameters are freed upon exit from this routine.
- * The storage is trivially management on the call stack in user land, but
+ * The storage is trivially management on the call stack in userland, but
  * is mallocated in kernel land.
  */
 
Index: pcb.h
===
RCS file: /cvs/src/sys/arch/m88k/include/pcb.h,v
retrieving revision 1.7
diff -u -p -r1.7 pcb.h
--- pcb.h   5 May 2015 02:13:46 -   1.7
+++ pcb.h   4 Oct 2015 23:13:39 -
@@ -38,7 +38,7 @@
 
 /*
  * Our PCB is the regular PCB+Save area for kernel frame.
- * Upon entering kernel mode from user land, save the user context
+ * Upon entering kernel mode from userland, save the user context
  * in the saved_state area - this is passed as the exception frame.
  * On a context switch, only registers that need to be saved by the
  * C calling convention and few other regs (pc, psr etc) are saved

Index: in6_var.h
===
RCS file: /cvs/src/sys/netinet6/in6_var.h,v
retrieving revision 1.56
diff -u -p -r1.56 in6_var.h
--- in6_var.h   10 Sep 2015 16:39:39 -  1.56
+++ in6_var.h   4 Oct 2015 23:14:19 -
@@ -275,7 +275,7 @@ struct  in6_aliasreq {
 
 /*
  * prefix related flags passed between kernel(NDP related part) and
- * user land command(ifconfig) and daemon(rtadvd).
+ * userland command(ifconfig) and daemon(rtadvd).
  */
 struct prf_ra {
u_int onlink : 1;



update lex to use __progname

2015-10-04 Thread Rob Pierce
Lex is currently using progam_name = argv[0].

Change to __progname?

Regards,

Index: flexdef.h
===
RCS file: /cvs/src/usr.bin/lex/flexdef.h,v
retrieving revision 1.7
diff -u -p -r1.7 flexdef.h
--- flexdef.h   3 Feb 2004 21:20:17 -   1.7
+++ flexdef.h   4 Oct 2015 23:36:52 -
@@ -423,7 +423,7 @@ extern int yymore_really_used, reject_re
  * use_stdout - the -t flag
  * input_files - array holding names of input files
  * num_input_files - size of input_files array
- * program_name - name with which program was invoked 
+ * __progname - name with which program was invoked 
  *
  * action_array - array to hold the rule actions
  * action_size - size of action_array
@@ -445,7 +445,7 @@ extern char *prefix, *yyclass;
 extern int do_stdinit, use_stdout;
 extern char **input_files;
 extern int num_input_files;
-extern char *program_name;
+extern char *__progname;
 
 extern char *action_array;
 extern int action_size;

Index: main.c
===
RCS file: /cvs/src/usr.bin/lex/main.c,v
retrieving revision 1.14
diff -u -p -r1.14 main.c
--- main.c  16 Mar 2014 18:38:30 -  1.14
+++ main.c  4 Oct 2015 23:36:53 -
@@ -104,11 +104,6 @@ int end_of_buffer_state;
 char **input_files;
 int num_input_files;
 
-/* Make sure program_name is initialized so we don't crash if writing
- * out an error message before getting the program name from argv[0].
- */
-char *program_name = "flex";
-
 #ifndef SHORT_FILE_NAMES
 static const char outfile_template[] = "lex.%s.%s";
 static const char backing_name[] = "lex.backup";
@@ -406,7 +401,7 @@ int exit_status;
if ( printstats )
{
fprintf( stderr, _( "%s version %s usage statistics:\n" ),
-   program_name, flex_version );
+   __progname, flex_version );
 
fprintf( stderr, _( "  scanner options: -" ) );
 
@@ -609,10 +604,8 @@ char **argv;
defs1_offset = prolog_offset = action_offset = action_index = 0;
action_array[0] = '\0';
 
-   program_name = argv[0];
-
-   if ( program_name[0] != '\0' &&
-program_name[strlen( program_name ) - 1] == '+' )
+   if ( __progname[0] != '\0' &&
+__progname[strlen( __progname ) - 1] == '+' )
C_plus_plus = true;
 
/* read flags */
@@ -795,7 +788,7 @@ char **argv;
 
case 'V':
printf( _( "%s version %s\n" ),
-   program_name, flex_version );
+   __progname, flex_version );
exit( 0 );
 
case 'w':
@@ -813,8 +806,8 @@ char **argv;
default:
fprintf( stderr,
_( "%s: unknown flag '%c'.  For usage, try\n\t%s --help\n" ),
-   program_name, (int) arg[i],
-   program_name );
+   __progname, (int) arg[i],
+   __progname );
exit( 1 );
}
 
@@ -1116,7 +1109,7 @@ void usage()
 
fprintf( f,
 _( "%s [-bdfhilnpstvwBFILTV78+? -C[aefFmr] -ooutput -Pprefix -Sskeleton]\n" ),
-   program_name );
+   __progname );
fprintf( f, _( "\t[--help --version] [file ...]\n" ) );
 
fprintf( f, _( "\t-b  generate backing-up information to %s\n" ),
@@ -1151,8 +1144,8 @@ _( "%s [-bdfhilnpstvwBFILTV78+? -C[aefFm
fprintf( f,
_( "\t-I  generate interactive scanner (opposite of -B)\n" ) );
fprintf( f, _( "\t-L  suppress #line directives in scanner\n" ) );
-   fprintf( f, _( "\t-T  %s should run in trace mode\n" ), program_name );
-   fprintf( f, _( "\t-V  report %s version\n" ), program_name );
+   fprintf( f, _( "\t-T  %s should run in trace mode\n" ), __progname );
+   fprintf( f, _( "\t-V  report %s version\n" ), __progname );
fprintf( f, _( "\t-7  generate 7-bit scanner\n" ) );
fprintf( f, _( "\t-8  generate 8-bit scanner\n" ) );
fprintf( f, _( "\t-+  generate C++ scanner class\n" ) );
@@ -1173,5 +1166,5 @@ _( "\t\t-CF  do not compress scanner tab
fprintf( f, _( "\t-P  specify scanner prefix other than \"yy\"\n" ) );
fprintf( f, _( "\t-S  specify skeleton file\n" ) );
fprintf( f, _( "\t--help produce this help message\n" ) );
-   fprintf( f, _( "\t--version  report %s version\n" ), program_name );
+   fprintf( f, _( "\t--version  report %s version\n" ), __progname );
}

Index: misc.c
===
RCS file: 

Re: ftpd popen

2015-10-04 Thread Todd C. Miller
On Sun, 04 Oct 2015 05:40:39 -0400, "Ted Unangst" wrote:

> as seen in cron, make the popen replacement nicer. this also repairs two
> abuses of comma operators and an unnecessary function pointer.

OK millert@

 - todd