no persistent history (flock missing), no arc4random, etc. for Solaris

This commit is contained in:
tg 2005-05-23 15:36:56 +00:00
parent dc5614a091
commit 37d3bd813d
4 changed files with 37 additions and 12 deletions

@ -1,4 +1,4 @@
/** $MirOS: src/bin/mksh/histrap.c,v 1.5 2005/05/23 15:09:22 tg Exp $ */ /** $MirOS: src/bin/mksh/histrap.c,v 1.6 2005/05/23 15:36:55 tg Exp $ */
/* $OpenBSD: history.c,v 1.30 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: history.c,v 1.30 2005/03/30 17:16:37 deraadt Exp $ */
/* $OpenBSD: trap.c,v 1.22 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: trap.c,v 1.22 2005/03/30 17:16:37 deraadt Exp $ */
@ -8,18 +8,20 @@
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/stat.h> #include <sys/stat.h>
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.5 2005/05/23 15:09:22 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.6 2005/05/23 15:36:55 tg Exp $");
static int histfd; static int histfd;
static int hsize; static int hsize;
static void histinsert(Source *, int, unsigned char *);
#ifndef __sun__
static int hist_count_lines(unsigned char *, int); static int hist_count_lines(unsigned char *, int);
static int hist_shrink(unsigned char *, int); static int hist_shrink(unsigned char *, int);
static unsigned char *hist_skip_back(unsigned char *,int *,int); static unsigned char *hist_skip_back(unsigned char *,int *,int);
static void histload(Source *, unsigned char *, int); static void histload(Source *, unsigned char *, int);
static void histinsert(Source *, int, unsigned char *);
static void writehistfile(int, char *); static void writehistfile(int, char *);
static int sprinkle(int); static int sprinkle(int);
#endif
static int hist_execute(char *); static int hist_execute(char *);
static int hist_replace(char **, const char *, const char *, int); static int hist_replace(char **, const char *, const char *, int);
@ -595,8 +597,10 @@ histsave(int lno, const char *cmd, int dowrite)
if ((cp = strchr(c, '\n')) != NULL) if ((cp = strchr(c, '\n')) != NULL)
*cp = '\0'; *cp = '\0';
#ifndef __sun__
if (histfd && dowrite) if (histfd && dowrite)
writehistfile(lno, c); writehistfile(lno, c);
#endif
hp = histptr; hp = histptr;
@ -636,9 +640,11 @@ histsave(int lno, const char *cmd, int dowrite)
void void
hist_init(Source *s) hist_init(Source *s)
{ {
#ifndef __sun__
unsigned char *base; unsigned char *base;
int lines; int lines;
int fd; int fd;
#endif
if (Flag(FTALKING) == 0) if (Flag(FTALKING) == 0)
return; return;
@ -647,6 +653,10 @@ hist_init(Source *s)
hist_source = s; hist_source = s;
#ifdef __sun__
hname = NULL;
histfd = 0;
#else
hname = str_val(global("HISTFILE")); hname = str_val(global("HISTFILE"));
if (hname == NULL) if (hname == NULL)
return; return;
@ -702,6 +712,7 @@ hist_init(Source *s)
} }
(void) flock(histfd, LOCK_UN); (void) flock(histfd, LOCK_UN);
hsize = lseek(histfd, 0L, SEEK_END); hsize = lseek(histfd, 0L, SEEK_END);
#endif
} }
typedef enum state { typedef enum state {
@ -711,6 +722,7 @@ typedef enum state {
sn2, sn3, sn4 sn2, sn3, sn4
} State; } State;
#ifndef __sun__
static int static int
hist_count_lines(unsigned char *base, int bytes) hist_count_lines(unsigned char *base, int bytes)
{ {
@ -790,7 +802,6 @@ hist_shrink(unsigned char *oldbase, int oldbytes)
return 0; return 0;
} }
/* /*
* find a pointer to the data 'no' back from the end of the file * find a pointer to the data 'no' back from the end of the file
* return the pointer and the number of bytes left * return the pointer and the number of bytes left
@ -867,6 +878,7 @@ histload(Source *s, unsigned char *base, int bytes)
} }
} }
} }
#endif
/* /*
* Insert a line into the history at a specified number * Insert a line into the history at a specified number
@ -884,6 +896,7 @@ histinsert(Source *s, int lno, unsigned char *line)
} }
} }
#ifndef __sun__
/* /*
* write a command to the end of the history file * write a command to the end of the history file
* This *MAY* seem easy but it's also necessary to check * This *MAY* seem easy but it's also necessary to check
@ -947,15 +960,19 @@ writehistfile(int lno, char *cmd)
bad: bad:
hist_finish(); hist_finish();
} }
#endif
void void
hist_finish(void) hist_finish(void)
{ {
#ifndef __sun__
(void) flock(histfd, LOCK_UN); (void) flock(histfd, LOCK_UN);
(void) close(histfd); (void) close(histfd);
#endif
histfd = 0; histfd = 0;
} }
#ifndef __sun__
/* /*
* add magic to the history file * add magic to the history file
*/ */
@ -966,6 +983,7 @@ sprinkle(int fd)
return(write(fd, mag, 2) != 2); return(write(fd, mag, 2) != 2);
} }
#endif
#ifdef NEED_MKSH_SIGNAME #ifdef NEED_MKSH_SIGNAME
static const char * static const char *

6
main.c

@ -1,4 +1,4 @@
/** $MirOS: src/bin/mksh/main.c,v 1.2 2005/05/23 14:22:03 tg Exp $ */ /** $MirOS: src/bin/mksh/main.c,v 1.3 2005/05/23 15:36:55 tg Exp $ */
/* $OpenBSD: main.c,v 1.38 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: main.c,v 1.38 2005/03/30 17:16:37 deraadt Exp $ */
/* $OpenBSD: tty.c,v 1.8 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: tty.c,v 1.8 2005/03/30 17:16:37 deraadt Exp $ */
/* $OpenBSD: io.c,v 1.21 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: io.c,v 1.21 2005/03/30 17:16:37 deraadt Exp $ */
@ -10,7 +10,7 @@
#include <ctype.h> #include <ctype.h>
#include <pwd.h> #include <pwd.h>
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.2 2005/05/23 14:22:03 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/main.c,v 1.3 2005/05/23 15:36:55 tg Exp $");
extern char **environ; extern char **environ;
@ -201,7 +201,7 @@ main(int argc, char *argv[])
setstr(pwd_v, current_wd, KSH_RETURN_ERROR); setstr(pwd_v, current_wd, KSH_RETURN_ERROR);
} }
ppid = getppid(); ppid = getppid();
#if !defined(__gnu_linux__) && !defined(__INTERIX) #if !defined(__gnu_linux__) && !defined(__INTERIX) && !defined(__sun__)
srand((*((long *)kshname)) ^ ((long)time(NULL) * kshpid * ppid)); srand((*((long *)kshname)) ^ ((long)time(NULL) * kshpid * ppid));
#endif #endif
setint(global("PPID"), (long) ppid); setint(global("PPID"), (long) ppid);

9
sh.h

@ -1,4 +1,4 @@
/** $MirOS: src/bin/mksh/sh.h,v 1.4 2005/05/23 15:24:43 tg Exp $ */ /** $MirOS: src/bin/mksh/sh.h,v 1.5 2005/05/23 15:36:55 tg Exp $ */
/* $OpenBSD: sh.h,v 1.27 2005/03/28 21:33:04 deraadt Exp $ */ /* $OpenBSD: sh.h,v 1.27 2005/03/28 21:33:04 deraadt Exp $ */
/* $OpenBSD: shf.h,v 1.5 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: shf.h,v 1.5 2005/03/30 17:16:37 deraadt Exp $ */
/* $OpenBSD: table.h,v 1.6 2004/12/18 20:55:52 millert Exp $ */ /* $OpenBSD: table.h,v 1.6 2004/12/18 20:55:52 millert Exp $ */
@ -100,6 +100,9 @@ typedef int32_t Tflag;
#ifndef PATH_MAX #ifndef PATH_MAX
#define PATH_MAX 1024 /* pathname size (todo: PATH_MAX/pathconf()) */ #define PATH_MAX 1024 /* pathname size (todo: PATH_MAX/pathconf()) */
#endif #endif
#ifndef _PATH_DEFPATH
#define _PATH_DEFPATH "/bin:/usr/bin:/sbin:/usr/sbin"
#endif
EXTERN char * kshname; /* $0 */ EXTERN char * kshname; /* $0 */
EXTERN pid_t kshpid; /* $$, shell pid */ EXTERN pid_t kshpid; /* $$, shell pid */
@ -1301,6 +1304,10 @@ size_t strlcat(char *, const char *, size_t);
size_t strlcpy(char *, const char *, size_t); size_t strlcpy(char *, const char *, size_t);
#endif #endif
#if defined(__sun__)
size_t confstr(int, char *, size_t);
#endif
#ifndef timeradd #ifndef timeradd
#define timeradd(tvp, uvp, vvp) \ #define timeradd(tvp, uvp, vvp) \
do { \ do { \

8
var.c

@ -1,4 +1,4 @@
/** $MirOS: src/bin/mksh/var.c,v 1.2 2005/05/23 14:22:03 tg Exp $ */ /** $MirOS: src/bin/mksh/var.c,v 1.3 2005/05/23 15:36:56 tg Exp $ */
/* $OpenBSD: var.c,v 1.26 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: var.c,v 1.26 2005/03/30 17:16:37 deraadt Exp $ */
#include "sh.h" #include "sh.h"
@ -6,7 +6,7 @@
#include <ctype.h> #include <ctype.h>
#include <time.h> #include <time.h>
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.2 2005/05/23 14:22:03 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/var.c,v 1.3 2005/05/23 15:36:56 tg Exp $");
/* /*
* Variables * Variables
@ -855,7 +855,7 @@ makenv(void)
* Someone has set the srand() value, therefore from now on * Someone has set the srand() value, therefore from now on
* we return values from rand() instead of arc4random() * we return values from rand() instead of arc4random()
*/ */
#if !defined(__gnu_linux__) && !defined(__INTERIX) #if !defined(__gnu_linux__) && !defined(__INTERIX) && !defined(__sun__)
int use_rand = 0; int use_rand = 0;
#else #else
int use_rand = 1; int use_rand = 1;
@ -919,7 +919,7 @@ getspec(struct tbl *vp)
vp->flag &= ~SPECIAL; vp->flag &= ~SPECIAL;
if (use_rand) if (use_rand)
setint(vp, (long) (rand() & 0x7fff)); setint(vp, (long) (rand() & 0x7fff));
#if !defined(__gnu_linux__) && !defined(__INTERIX) #if !defined(__gnu_linux__) && !defined(__INTERIX) && !defined(__sun__)
else else
setint(vp, (long) (arc4random() & 0x7fff)); setint(vp, (long) (arc4random() & 0x7fff));
#endif #endif