Re: tetris: remove unused vars
On Sun, May 19, 2019 at 02:39:20PM -0400, Jake Champlin wrote: > Revision 1.23 added unveil to tetris, yet left two unused variables in > scores.c > Removes unused vars in scores.c, that were added to tetris.c in v1.23 Fixed, thanks! > Index: scores.c > === > RCS file: /cvs/src/games/tetris/scores.c,v > retrieving revision 1.23 > diff -u -p -r1.23 scores.c > --- scores.c 18 May 2019 19:38:25 - 1.23 > +++ scores.c 19 May 2019 18:42:35 - > @@ -91,8 +91,8 @@ static char *thisuser(void); > static void > getscores(FILE **fpp) > { > - int sd, mint, i, ret; > - char *mstr, *human, *home; > + int sd, mint, i; > + char *mstr, *human; > FILE *sf; > > if (fpp != NULL) { >
[PATCH] Add swich to enable/disable re-link the kernel at startup
Hi all, As exists the variable "library_aslr" to disable library randomization on rc, it would be helpful to have the same option for the kernel. Here is the patch to add the "kernel_aslr" swich. Regards, Ricardo F. diff --git etc/rc etc/rc index 9a3917986cc..df2abbaa652 100644 --- etc/rc +++ etc/rc @@ -615,7 +615,9 @@ echo '.' # Re-link the kernel, placing the objects in a random order. # Replace current with relinked kernel and inform root about it. -/usr/libexec/reorder_kernel & +if [[ $kernel_aslr == YES ]]; then + /usr/libexec/reorder_kernel & +fi date exit 0 diff --git etc/rc.conf etc/rc.conf index a513b7575d4..30d1ca8953b 100644 --- etc/rc.conf +++ etc/rc.conf @@ -101,6 +101,7 @@ multicast=NO # Reject IPv4 multicast packets by default # miscellaneous other flags amd_master=/etc/amd/master # AMD 'master' map library_aslr=YES # set to NO to disable library randomization +kernel_aslr=YES# set to NO to disable kernel randomization savecore_flags=# "-z" to compress spamd_black=NO # set to YES to run spamd without greylisting shlib_dirs=# extra directories for ldconfig, separated diff --git etc/rc.d/rc.subr etc/rc.d/rc.subr index 6a8e05e3b3e..3dafbba3e7e 100644 --- etc/rc.d/rc.subr +++ etc/rc.d/rc.subr @@ -140,8 +140,9 @@ _rc_parse_conf() { typeset -l _key local _l _rcfile _val set -A _allowed_keys -- \ - accounting amd_master check_quotas ipsec library_aslr \ - multicast nfs_server pexp pf pkg_scripts shlib_dirs spamd_black + accounting amd_master check_quotas ipsec kernel_aslr \ + library_aslr multicast nfs_server pexp pf pkg_scripts \ + shlib_dirs spamd_black [ $# -gt 0 ] || set -- /etc/rc.conf /etc/rc.conf.local for _rcfile; do
Re: mdoc.7: fix Dd example
On Sun, May 19, 2019 at 09:52:39PM +0200, Klemens Nanni wrote: > On Sun, May 19, 2019 at 07:31:19PM +0100, Jason McIntyre wrote: > > no. just use $Mdocdate$ and it gets expanded on commit. just like when > > you add $OpenBSD$: you don;t fill that in, right? > OK, will do so. No, I'll just wite `$OpenBSD$'. > > > use $Mdocdate$ and let expansion happen, or just use the > > old format of "month day, year". > > > > is that clear, or did the docs mislead you somehow? > Now it is, thanks. I had no idea of old vs. new, so it confused me to > see warnings in both variations. > > To be clear: what is the "new" format? > originally we wrote the date every time we bumped the page, in the format: month day, year now you just add an Mdocdate id before *first* commit, and thereafter there's no need to touch it. it updates every commit. like any other rcsid. > I think I also misunderstood the `$Mdocdate$ | month day, year' syntax. > This means either `$Mdocdate$' *or* `May 19, 2019`, not both together > like I did. > correct. jmc
snake: unveil + pledge earlier
Unveils snake and pledges earlier during execution. Index: snake.c === RCS file: /cvs/src/games/snake/snake.c,v retrieving revision 1.33 diff -u -p -r1.33 snake.c --- snake.c 20 Jan 2019 04:14:19 - 1.33 +++ snake.c 19 May 2019 19:51:33 - @@ -135,17 +135,23 @@ int main(int argc, char *argv[]) { struct sigaction sa; - int ch, i; + int ch, i, ret; + const char *home; -#ifdef LOGGING - const char *home; + if (pledge("stdio tty rpath wpath cpath unveil", NULL) == -1) + err(1, "pledge"); home = getenv("HOME"); if (home == NULL || *home == '\0') err(1, "getenv"); + ret = snprintf(scorepath, sizeof(scorepath), "%s/%s", home, + ".snake.scores"); + if (ret < 0 || ret >= PATH_MAX) + errc(1, ENAMETOOLONG, "%s/%s", home, ".snake.scores"); + +#ifdef LOGGING snprintf(logpath, sizeof(logpath), "%s/%s", home, ".snake.log"); - logfile = fopen(logpath, "a"); #endif while ((ch = getopt(argc, argv, "hl:stw:")) != -1) @@ -173,11 +179,18 @@ main(int argc, char *argv[]) return 1; } - readscores(1); penalty = loot = 0; initscr(); + if (unveil(scorepath, "rwc") == -1) + err(1, "unveil"); +#ifdef LOGGING + if (unveil(logpath, "rwc") == -1) + err(1, "unveil"); + logfile = fopen(logpath, "a"); +#endif + readscores(1); - if (pledge("stdio tty", NULL) == -1) + if (pledge("stdio tty rpath wpath cpath", NULL) == -1) err(1, "pledge"); #ifdef KEY_LEFT @@ -947,11 +960,9 @@ logit(char *msg) int readscores(int create) { - const char *home; const char *name; const char *modstr; int modint; - int ret; if (create == 0) { modint = O_RDONLY; @@ -960,15 +971,6 @@ readscores(int create) modint = O_RDWR | O_CREAT; modstr = "r+"; } - - home = getenv("HOME"); - if (home == NULL || *home == '\0') - err(1, "getenv"); - - ret = snprintf(scorepath, sizeof(scorepath), "%s/%s", home, - ".snake.scores"); - if (ret < 0 || ret >= PATH_MAX) - errc(1, ENAMETOOLONG, "%s/%s", home, ".snake.scores"); rawscores = open(scorepath, modint, 0666); if (rawscores < 0) {
Re: mdoc.7: fix Dd example
On Sun, May 19, 2019 at 07:31:19PM +0100, Jason McIntyre wrote: > no. just use $Mdocdate$ and it gets expanded on commit. just like when > you add $OpenBSD$: you don;t fill that in, right? OK, will do so. No, I'll just wite `$OpenBSD$'. > use $Mdocdate$ and let expansion happen, or just use the > old format of "month day, year". > > is that clear, or did the docs mislead you somehow? Now it is, thanks. I had no idea of old vs. new, so it confused me to see warnings in both variations. To be clear: what is the "new" format? I think I also misunderstood the `$Mdocdate$ | month day, year' syntax. This means either `$Mdocdate$' *or* `May 19, 2019`, not both together like I did.
tetris: remove unused vars
Revision 1.23 added unveil to tetris, yet left two unused variables in scores.c Removes unused vars in scores.c, that were added to tetris.c in v1.23 Index: scores.c === RCS file: /cvs/src/games/tetris/scores.c,v retrieving revision 1.23 diff -u -p -r1.23 scores.c --- scores.c18 May 2019 19:38:25 - 1.23 +++ scores.c19 May 2019 18:42:35 - @@ -91,8 +91,8 @@ static char *thisuser(void); static void getscores(FILE **fpp) { - int sd, mint, i, ret; - char *mstr, *human, *home; + int sd, mint, i; + char *mstr, *human; FILE *sf; if (fpp != NULL) {
Re: mdoc.7: fix Dd example
On Sun, May 19, 2019 at 08:19:09PM +0200, Klemens Nanni wrote: > jmc noted that I didn't include my actual line, so here it is. > ah! > First I was using only > > .Dd $Mdocdate$ > > but that warned me > > mandoc: ./files/varnishreload.1:2:2: WARNING: missing date, using > today's date > yes. this will happen until an initial commit. then the date gets expanded. > so I did what I was told, according to mdoc(7) > > .Dd $Mdocdate: May 19, 2019 $ > no. just use $Mdocdate$ and it gets expanded on commit. just like when you add $OpenBSD$: you don;t fill that in, right? > but it still warned me > > mandoc: ./files/varnishreload.1:2:2: WARNING: cannot parse date, using > it verbatim: $Mdocdate: May 19, 2019 $ > > So I removed the comma and mandoc(1) was happy. > > .Dd $Mdocdate: May 19 2019 $ > > > What should be used here? Either I'm warned or I'm using undocumented > syntax, both seems wrong to me. > use $Mdocdate$ and let expansion happen, or just use the old format of "month day, year". is that clear, or did the docs mislead you somehow? jmc
Re: mdoc.7: fix Dd example
jmc noted that I didn't include my actual line, so here it is. First I was using only .Dd $Mdocdate$ but that warned me mandoc: ./files/varnishreload.1:2:2: WARNING: missing date, using today's date so I did what I was told, according to mdoc(7) .Dd $Mdocdate: May 19, 2019 $ but it still warned me mandoc: ./files/varnishreload.1:2:2: WARNING: cannot parse date, using it verbatim: $Mdocdate: May 19, 2019 $ So I removed the comma and mandoc(1) was happy. .Dd $Mdocdate: May 19 2019 $ What should be used here? Either I'm warned or I'm using undocumented syntax, both seems wrong to me.
Re: amd64: i8254_delay(): simpler microsecond->ticks conversion
On Sun, May 19, 2019 at 01:23:17AM -0500, Scott Cheloha wrote: > On Sat, May 18, 2019 at 10:57:32PM -0700, Mike Larkin wrote: > > On Sun, May 19, 2019 at 12:47:11AM -0500, Scott Cheloha wrote: > > > This code is really fidgety and I think we can do better. > > > > > > If we use a 64-bit value here for microseconds the compiler arranges > > > for all the math to be done with 64-bit quantites. I'm pretty sure > > > this is standard C numeric type upconversion. As noted in the comment > > > for the assembly, use of the 64-bit intermediate avoids overflow for > > > most plausible inputs. > > > > > > So with one line of code we get the same result as we do with the > > > __GNUC__ assembly and the nigh incomprehensible default computation. > > > > > > [...] > > > > What bug or problem is this fixing? > > The code is more complicated than it needs to be. > > There are two different ways to convert microseconds to i8254 ticks > in this function. One is assembly, the other is a non-obvious method > that avoids overflowing an int while using ints for partial sums. > > You can replace both of them with legible, plain C that does exactly > what it looks like it is doing by using a larger intermediate type. guenther@ has pointed out in a separate mail that I can make the diff smaller with a cast and that it's acceptable here. As with the code it's replacing I've left a comment explaining what we're doing. ok? Index: arch/amd64/isa/clock.c === RCS file: /cvs/src/sys/arch/amd64/isa/clock.c,v retrieving revision 1.28 diff -u -p -r1.28 clock.c --- arch/amd64/isa/clock.c 27 Jul 2018 21:11:31 - 1.28 +++ arch/amd64/isa/clock.c 19 May 2019 17:11:15 - @@ -242,31 +242,8 @@ i8254_delay(int n) if (n <= 25) n = delaytab[n]; else { -#ifdef __GNUC__ - /* -* Calculate ((n * TIMER_FREQ) / 1e6) using explicit assembler -* code so we can take advantage of the intermediate 64-bit -* quantity to prevent loss of significance. -*/ - int m; - __asm volatile("mul %3" -: "=a" (n), "=d" (m) -: "0" (n), "r" (TIMER_FREQ)); - __asm volatile("div %4" -: "=a" (n), "=d" (m) -: "0" (n), "1" (m), "r" (100)); -#else - /* -* Calculate ((n * TIMER_FREQ) / 1e6) without using floating -* point and without any avoidable overflows. -*/ - int sec = n / 100, - usec = n % 100; - n = sec * TIMER_FREQ + - usec * (TIMER_FREQ / 100) + - usec * ((TIMER_FREQ % 100) / 1000) / 1000 + - usec * (TIMER_FREQ % 1000) / 100; -#endif + /* Force 64-bit math to avoid 32-bit overflow if possible. */ + n = (int64_t)n * TIMER_FREQ / 100; } limit = TIMER_FREQ / hz;
mdoc.7: fix Dd example
The example seems to have an extranous comma, which mandoc(1)'s `-T lint' warns about: $ man mdoc | col -b | grep 'document date' Dd document date: $Mdocdate$ | month day, year $ mandoc -Tlint ./files/varnishreload.1 mandoc: ./files/varnishreload.1:2:2: WARNING: cannot parse date, using it verbatim: $Mdocdate: May 19, 2019 $ All installed manuals ship without a comma and the linter is happy if I remove it, so diff below adjusts the example. Am I missing something? OK? Index: mdoc.7 === RCS file: /cvs/src/share/man/man7/mdoc.7,v retrieving revision 1.167 diff -u -p -r1.167 mdoc.7 --- mdoc.7 11 May 2019 07:18:15 - 1.167 +++ mdoc.7 19 May 2019 16:41:25 - @@ -437,7 +437,7 @@ in the alphabetical .Sx MACRO REFERENCE . .Ss Document preamble and NAME section macros .Bl -column "Brq, Bro, Brc" description -.It Ic \&Dd Ta document date: Cm $\&Mdocdate$ | Ar month day , year +.It Ic \&Dd Ta document date: Cm $\&Mdocdate$ | Ar month day year .It Ic \&Dt Ta document title: Ar TITLE section Op Ar arch .It Ic \&Os Ta operating system version: Op Ar system Op Ar version .It Ic \&Nm Ta document name (one argument)