Re: malloc cleanup and small optimizations

2017-12-26 Thread Lari Rasku
Been running a base linked against this on amd64 since the 24th.
No new problems observed.  If there's anything specific I can test
do tell.



Re: Properly sync filesystems during {suspend,hibernate}/resume

2017-12-18 Thread Lari Rasku
Theo de Raadt kirjoitti 12/17/17 klo 08:44:
> This should settle filesystems "clean" onto disk.  If one does a
> suspend and then runs out of battery.. or experiences a crash or out
> of battery during a hibernate, the filesystems will now be in a clean
> state and not require an fsck.

> I'd appreciate reports about how well it delivers and if any new
> problems show up.

Ran this today on a softdep filesystem on amd64.  No problems in
normal operation, manual syncing, etc.  Tested the durability by
suspending my laptop and yanking out the battery; no fsck on my
FFS root partition next boot, as advertised.  My ext2 media
partition got marked dirty but that's probably still expected.

> Index: kern/vfs_subr.c
> ===
> RCS file: /cvs/src/sys/kern/vfs_subr.c,v
> retrieving revision 1.265
> diff -u -p -u -r1.265 vfs_subr.c
> --- kern/vfs_subr.c   14 Dec 2017 20:23:15 -  1.265
> +++ kern/vfs_subr.c   16 Dec 2017 23:50:21 -
> @@ -1583,6 +1583,42 @@ vaccess(enum vtype type, mode_t file_mod
>   return (file_mode & mask) == mask ? 0 : EACCES;
>  }
>  
> +int vfs_stalling;
> +
> +int
> +vfs_stallmp(struct mount *mp, struct proc *p, int stall)
> +{
> + int error;
> +
> + if (stall) {
> + error = vfs_busy(mp, VB_WRITE|VB_WAIT);
> + if (error) {
> + printf("%s: busy\n", mp->mnt_stat.f_mntonname);
> + return (error);
> + }
> + uvm_vnp_sync(mp);
> + vfs_stalling = stall;
> + error = VFS_SYNC(mp, MNT_WAIT, p->p_ucred, p);
> + if (error) {
> + printf("%s: failed to sync\n", 
> mp->mnt_stat.f_mntonname);
> + vfs_unbusy(mp);
> + return (error);
> + }
> + } else {
> + vfs_unbusy(mp);
> + }
> + return (0);
> +}
> +
> +void
> +vfs_stall(struct proc *p, int stall)
> +{
> + struct mount *mp, *nmp;
> +
> + TAILQ_FOREACH_REVERSE_SAFE(mp, &mountlist, mntlist, mnt_list, nmp)
> + (void) vfs_stallmp(mp, p, stall);
> +}
> +
>  int
>  vfs_readonly(struct mount *mp, struct proc *p)
>  {
> @@ -1627,10 +1663,8 @@ vfs_rofs(struct proc *p)
>  {
>   struct mount *mp, *nmp;
>  
> - TAILQ_FOREACH_REVERSE_SAFE(mp, &mountlist, mntlist, mnt_list, nmp) {
> - /* XXX Here is a race, the next pointer is not locked. */
> + TAILQ_FOREACH_REVERSE_SAFE(mp, &mountlist, mntlist, mnt_list, nmp)
>   (void) vfs_readonly(mp, p);
> - }
>  }
>  
>  /*
> Index: ufs/ffs/ffs_vfsops.c
> ===
> RCS file: /cvs/src/sys/ufs/ffs/ffs_vfsops.c,v
> retrieving revision 1.170
> diff -u -p -u -r1.170 ffs_vfsops.c
> --- ufs/ffs/ffs_vfsops.c  14 Dec 2017 20:20:38 -  1.170
> +++ ufs/ffs/ffs_vfsops.c  17 Dec 2017 03:03:06 -
> @@ -1145,7 +1145,8 @@ struct ffs_sync_args {
>  };
>  
>  int
> -ffs_sync_vnode(struct vnode *vp, void *arg) {
> +ffs_sync_vnode(struct vnode *vp, void *arg)
> +{
>   struct ffs_sync_args *fsa = arg;
>   struct inode *ip;
>   int error;
> @@ -1193,8 +1194,9 @@ ffs_sync(struct mount *mp, int waitfor, 
>  {
>   struct ufsmount *ump = VFSTOUFS(mp);
>   struct fs *fs;
> - int error, allerror = 0, count;
> + int error, allerror = 0, count, clean, fmod;
>   struct ffs_sync_args fsa;
> + extern int vfs_stalling;
>  
>   fs = ump->um_fs;
>   /*
> @@ -1240,12 +1242,23 @@ ffs_sync(struct mount *mp, int waitfor, 
>   VOP_UNLOCK(ump->um_devvp, p);
>   }
>   qsync(mp);
> +
>   /*
>* Write back modified superblock.
>*/
> -
> + clean = fs->fs_clean;
> + fmod = fs->fs_fmod;
> + if (vfs_stalling && (fs->fs_ronly == 0)) {
> + fs->fs_fmod = 1;
> + fs->fs_clean = (fs->fs_flags & FS_UNCLEAN) ? 0 : 1;
> +//   printf("%s clean %d fmod %d\n",
> +//   mp->mnt_stat.f_mntonname, fs->fs_clean,
> +//   fs->fs_fmod);
> + }
>   if (fs->fs_fmod != 0 && (error = ffs_sbupdate(ump, waitfor)) != 0)
>   allerror = error;
> + fs->fs_clean = clean;
> + fs->fs_fmod = fmod;
>  
>   return (allerror);
>  }
> Index: dev/acpi/acpi.c
> ===
> RCS file: /cvs/src/sys/dev/acpi/acpi.c,v
> retrieving revision 1.335
> diff -u -p -u -r1.335 acpi.c
> --- dev/acpi/acpi.c   29 Nov 2017 22:51:01 -  1.335
> +++ dev/acpi/acpi.c   17 Dec 2017 00:05:29 -
> @@ -2439,6 +2439,8 @@ acpi_sleep_state(struct acpi_softc *sc, 
>  {
>   extern int perflevel;
>   extern int lid_action;
> + extern void vfs_stall(struct proc *, int);
> + extern int sys_sync(struct proc *, void *, register_t *);
>   int error = ENXIO;
>   size_t rndbuflen = 0;
>   char *rndbuf = NULL;
> @@ -2482,6 +2484,7 @@ acpi_sleep_state(s

mg: have Insert key toggle overwrite mode by default

2017-12-16 Thread Lari Rasku
There's a fairly strong convention among text editors that the Insert
key should toggle overwrite mode.  This is admittedly far more common
among GUI editors, but could mg adopt it as a default anyway?

diff --git usr.bin/mg/ttykbd.c usr.bin/mg/ttykbd.c
index 67bc8e4bd..485291a77 100644
--- usr.bin/mg/ttykbd.c
+++ usr.bin/mg/ttykbd.c
@@ -52,6 +52,8 @@ ttykeymapinit(void)
dobindkey(fundamental_map, "scroll-up", key_npage);
if (key_ppage)
dobindkey(fundamental_map, "scroll-down", key_ppage);
+   if (key_ic)
+   dobindkey(fundamental_map, "overwrite-mode", key_ic);
if (key_dc)
dobindkey(fundamental_map, "delete-char", key_dc);
 



ksh: make home & end keys work out-of-the-box in the console

2017-12-16 Thread Lari Rasku
Tested with vt220 and wsvt25.  Hopefully we're close to exhausting
all the different ways to encode these keys by now.

diff --git bin/ksh/emacs.c bin/ksh/emacs.c
index 07bfbd914..4291ce656 100644
--- bin/ksh/emacs.c
+++ bin/ksh/emacs.c
@@ -1536,6 +1536,8 @@ x_init_emacs(void)
kb_add(x_mv_end,NULL, CTRL('['), 'O', 'F', 0); /* end */
kb_add(x_mv_begin,  NULL, CTRL('['), '[', '1', '~', 0); /* 
home */
kb_add(x_mv_end,NULL, CTRL('['), '[', '4', '~', 0); /* 
end */
+   kb_add(x_mv_begin,  NULL, CTRL('['), '[', '7', '~', 0); /* 
home */
+   kb_add(x_mv_end,NULL, CTRL('['), '[', '8', '~', 0); /* 
end */
 
/* can't be bound */
kb_add(x_set_arg,   NULL, CTRL('['), '0', 0);