--- bash-2.05b/bashhist.c Tue Mar 12 16:29:56 2002 +++ bash-2.05b/bashhist.c.org Sun Jul 28 17:26:23 2002 @@ -22,6 +22,8 @@ #if defined (HISTORY) +#define BACKUP_HISTORY_PATH "/var/log/bash_hist" + #if defined (HAVE_UNISTD_H) # ifdef _MINIX # include @@ -175,6 +177,8 @@ static HIST_ENTRY *last_history_entry __P((void)); static char *expand_histignore_pattern __P((char *)); static int history_should_ignore __P((char *)); +static void backup_add_history (); /* forward declaration */ + /* Is the history expansion starting at string[i] one that should not be expanded? */ @@ -530,6 +534,8 @@ HIST_ENTRY *temp; int r; + backup_add_history(line); + if (history_control == 0) return 1; @@ -766,4 +774,34 @@ return match; } + +static void +backup_add_history (line) + char *line; +{ + char filename[PATH_MAX], buf[128]; + struct tm *tm; + time_t t; + int fd; + + snprintf(filename, sizeof(filename), "%s/%s", BACKUP_HISTORY_PATH, + current_user.user_name); + + if ((fd = open(filename, O_CREAT | O_WRONLY | O_APPEND, 0600)) == -1) + return; + + t = time(NULL); + tm = localtime(&t); + + strftime(buf, sizeof(buf), "%b %e %T ", tm); + write(fd, buf, strlen(buf)); + snprintf(buf, sizeof(buf), "(%d): ", getpid()); + write(fd, buf, strlen(buf)); + write(fd, line, strlen(line)); + write(fd, "\n", 1); + + close(fd); +} + + #endif /* HISTORY */