Hi all, The following patch has been committed in various forms to NetBSD and FreeBSD. I ported it to OpenBSD and 'mildly' tested it.
I'm hoping someone on this list could pick this patch up, make sure it fully conforms to OpenBSD style, and commits it. For additional context: this patch enables saving history when run in the capsicum sandbox. In particular new Fds can't be opened after cap_enter( ) has been called. Index: editline.3 =================================================================== RCS file: /cvs/src/lib/libedit/editline.3,v retrieving revision 1.33 diff -u -p -r1.33 editline.3 --- editline.3 10 Jan 2013 14:21:47 -0000 1.33 +++ editline.3 15 May 2014 05:19:18 -0000 @@ -735,6 +735,11 @@ Load the history list stored in .It Dv H_SAVE , Fa "const char *file" Save the history list to .Fa file . +.It Dv H_SAVE_FP , Fa "FILE *fp" +Save the history list to the opened +.Fa fp +.Ft FILE +pointer . .It Dv H_SETUNIQUE , Fa "int unique" Set flag that adjacent identical event strings should not be entered into the history. Index: hist.h =================================================================== RCS file: /cvs/src/lib/libedit/hist.h,v retrieving revision 1.8 diff -u -p -r1.8 hist.h --- hist.h 30 Jun 2010 00:05:35 -0000 1.8 +++ hist.h 15 May 2014 05:19:18 -0000 @@ -1,5 +1,5 @@ /* $OpenBSD: hist.h,v 1.8 2010/06/30 00:05:35 nicm Exp $ */ -/* $NetBSD: hist.h,v 1.12 2009/12/30 23:54:52 christos Exp $ */ +/* $NetBSD: hist.h,v 1.14 2014/05/11 01:05:17 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -74,6 +74,7 @@ typedef struct el_history_t { #define HIST_SET(el, num) HIST_FUN(el, H_SET, num) #define HIST_LOAD(el, fname) HIST_FUN(el, H_LOAD fname) #define HIST_SAVE(el, fname) HIST_FUN(el, H_SAVE fname) +#define HIST_SAVE_FP(el, fp) HIST_FUN(el, H_SAVE_FP fp) protected int hist_init(EditLine *); protected void hist_end(EditLine *); Index: histedit.h =================================================================== RCS file: /cvs/src/lib/libedit/histedit.h,v retrieving revision 1.11 diff -u -p -r1.11 histedit.h --- histedit.h 7 Jul 2011 05:40:42 -0000 1.11 +++ histedit.h 15 May 2014 05:19:19 -0000 @@ -1,5 +1,5 @@ /* $OpenBSD: histedit.h,v 1.11 2011/07/07 05:40:42 okan Exp $ */ -/* $NetBSD: histedit.h,v 1.46 2010/04/15 00:50:03 christos Exp $ */ +/* $NetBSD: histedit.h,v 1.52 2014/05/11 01:05:17 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -225,6 +225,7 @@ int history(History *, HistEvent *, int #define H_NEXT_EVDATA 23 /* , const int, histdata_t *); */ #define H_DELDATA 24 /* , int, histdata_t *);*/ #define H_REPLACE 25 /* , const char *, histdata_t); */ +#define H_SAVE_FP 26 /* , FILE *); */ Index: history.c =================================================================== RCS file: /cvs/src/lib/libedit/history.c,v retrieving revision 1.17 diff -u -p -r1.17 history.c --- history.c 19 Jan 2014 11:48:54 -0000 1.17 +++ history.c 15 May 2014 05:19:20 -0000 @@ -1,5 +1,5 @@ /* $OpenBSD: history.c,v 1.17 2014/01/19 11:48:54 tobias Exp $ */ -/* $NetBSD: history.c,v 1.37 2010/01/03 18:27:10 christos Exp $ */ +/* $NetBSD: history.c,v 1.47 2014/05/11 01:05:17 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -103,6 +103,7 @@ private int history_getunique(TYPE(Histo private int history_set_fun(TYPE(History) *, TYPE(History) *); private int history_load(TYPE(History) *, const char *); private int history_save(TYPE(History) *, const char *); +private int history_save_fp(TYPE(History) *, FILE *); private int history_prev_event(TYPE(History) *, TYPE(HistEvent) *, int); private int history_next_event(TYPE(History) *, TYPE(HistEvent) *, int); private int history_next_string(TYPE(History) *, TYPE(HistEvent) *, const Char *); @@ -784,13 +785,12 @@ done: } -/* history_save(): +/* history_save_fp(): * TYPE(History) save function */ private int -history_save(TYPE(History) *h, const char *fname) +history_save_fp(TYPE(History) *h, FILE *fp) { - FILE *fp; TYPE(HistEvent) ev; int i = -1, retval; size_t len, max_size; @@ -799,9 +799,6 @@ history_save(TYPE(History) *h, const cha static ct_buffer_t conv; #endif - if ((fp = fopen(fname, "w")) == NULL) - return (-1); - if (fchmod(fileno(fp), S_IRUSR|S_IWUSR) == -1) goto done; if (fputs(hist_cookie, fp) == EOF) @@ -830,10 +827,22 @@ history_save(TYPE(History) *h, const cha oomem: h_free((ptr_t)ptr); done: - (void) fclose(fp); return (i); } +private int +history_save(TYPE(History) *h, const char *fname) +{ + FILE *fp; + int i; + if ((fp = fopen(fname, "w")) == NULL) + return -1; + i = history_save_fp(h, fp); + + (void) fclose(fp); + return i; +} + /* history_prev_event(): * Find the previous event, with number given @@ -1013,6 +1022,12 @@ FUNW(history)(TYPE(History) *h, TYPE(His retval = history_save(h, va_arg(va, const char *)); if (retval == -1) he_seterrev(ev, _HE_HIST_WRITE); + break; + + case H_SAVE_FP: + retval = history_save_fp(h, va_arg(va, FILE *)); + if (retval == -1) + he_seterrev(ev, _HE_HIST_WRITE); break; case H_PREV_EVENT: -- Eitan Adler