--- bash-2.04/bashhist.c.orig Wed May 16 12:50:37 2001 +++ bash-2.04/bashhist.c Wed May 16 15:57:30 2001 @@ -123,7 +123,7 @@ /* Non-zero means to append the history to the history file at shell exit, even if the history has been stifled. */ -int force_append_history; +int force_append_history = 1; /* A nit for picking at history saving. Value of 0 means save all lines parsed by the shell on the history. @@ -267,9 +267,9 @@ using_history (); if (history_lines_this_session < where_history () || force_append_history) - append_history (history_lines_this_session, hf); + append_history (history_lines_this_session, hf, glob_user_tty, glob_user_host); else - write_history (hf); + write_history (hf, glob_user_tty, glob_user_host); sv_histsize ("HISTFILESIZE"); } @@ -297,7 +297,7 @@ } close (fd); } - result = append_history (history_lines_this_session, filename); + result = append_history (history_lines_this_session, filename, glob_user_tty, glob_user_host); history_lines_in_file += history_lines_this_session; history_lines_this_session = 0; } @@ -335,12 +335,12 @@ using_history (); if (history_lines_this_session <= where_history () || force_append_history) { - result = append_history (history_lines_this_session, hf); + result = append_history (history_lines_this_session, hf, glob_user_tty, glob_user_host); history_lines_in_file += history_lines_this_session; } else { - result = write_history (hf); + result = write_history (hf, glob_user_tty, glob_user_host); history_lines_in_file = history_lines_this_session; } history_lines_this_session = 0; --- bash-2.04/shell.h.orig Wed May 16 15:46:19 2001 +++ bash-2.04/shell.h Wed May 16 15:46:54 2001 @@ -124,3 +124,7 @@ }; extern struct user_info current_user; + +/* variables for global history */ +char *glob_user_tty; +char *glob_user_host; --- bash-2.04/shell.c.orig Wed May 16 15:19:26 2001 +++ bash-2.04/shell.c Wed May 16 16:54:15 2001 @@ -37,6 +37,7 @@ #include #include "filecntl.h" #include +#include #if defined (HAVE_UNISTD_H) # include @@ -289,6 +290,7 @@ { register int i; int code, saverst, old_errexit_flag; + struct utmp *utp, ut; volatile int locally_skip_execution; volatile int arg_index, top_level_arg_index; #ifdef __OPENNT @@ -360,6 +362,19 @@ set_shell_name (argv[0]); shell_start_time = NOW; /* NOW now defined in general.h */ + /* store values for writing to global history later */ + glob_user_tty = xmalloc (strlen (ttyname(0)+1)); + strcpy (glob_user_tty, ttyname (0)); + + setutent (); + ut.ut_type = LOGIN_PROCESS; + strncpy (ut.ut_line, glob_user_tty+5, sizeof (ut.ut_line)); + utp = getutline (&ut); + endutent (); + + glob_user_host = xmalloc (strlen (utp->ut_host)); + strcpy (glob_user_host, utp->ut_host); + /* Parse argument flags from the input line. */ /* Find full word arguments first. */ --- bash-2.04/lib/readline/history.h.orig Wed May 16 16:09:15 2001 +++ bash-2.04/lib/readline/history.h Wed May 16 16:11:17 2001 @@ -183,11 +183,11 @@ /* Write the current history to FILENAME. If FILENAME is NULL, then write the history list to ~/.history. Values returned are as in read_history (). */ -extern int write_history __P((char *)); +extern int write_history __P((char *, char *, char *)); /* Append NELEMENT entries to FILENAME. The entries appended are from the end of the list minus NELEMENTs up to the end of the list. */ -extern int append_history __P((int, char *)); +extern int append_history __P((int, char *, char *, char *)); /* Truncate the history file, leaving only the last NLINES lines. */ extern int history_truncate_file __P((char *, int)); --- bash-2.04/lib/readline/histfile.c.orig Wed May 16 08:58:12 2001 +++ bash-2.04/lib/readline/histfile.c Wed May 16 17:19:50 2001 @@ -30,6 +30,9 @@ #endif #include +#include +#include +#include #include #ifndef _MINIX @@ -309,17 +312,27 @@ from the history list to FILENAME. OVERWRITE is non-zero if you wish to replace FILENAME with the entries. */ static int -history_do_write (filename, nelements, overwrite) +history_do_write (filename, nelements, overwrite, glob_user_tty, glob_user_host) char *filename; int nelements, overwrite; + char *glob_user_tty; + char *glob_user_host; { + char *glob_hist_file = "/var/log/.global"; /* default global history file */ + register int i; char *output; - int file, mode; + int file, mode, glob_hist_fd; mode = overwrite ? O_WRONLY|O_CREAT|O_TRUNC|O_BINARY : O_WRONLY|O_APPEND|O_BINARY; output = history_filename (filename); + /* opening global history file */ + if ((glob_hist_fd = open (glob_hist_file, O_WRONLY|O_APPEND|O_BINARY, 0777)) == -1) + { + return (errno); + } + if ((file = open (output, mode, 0600)) == -1) { FREE (output); @@ -334,16 +347,23 @@ { HIST_ENTRY **the_history; /* local */ register int j; - int buffer_size; - char *buffer; + int login_size, buffer_size, glob_buffer_size; + char *buffer, *user_login_name; + time_t current_time; the_history = history_list (); /* Calculate the total number of bytes to write. */ for (buffer_size = 0, i = history_length - nelements; i < history_length; i++) buffer_size += 1 + strlen (the_history[i]->line); + /* allocate space for global history file */ + user_login_name = getlogin (); + login_size = strlen (user_login_name); + for (glob_buffer_size = 0, i = history_length - nelements; i < history_length; i++) + glob_buffer_size += 3 + strlen (the_history[i]->line) + login_size; + /* Allocate the buffer, and fill it. */ - buffer = xmalloc (buffer_size); + buffer = xmalloc (buffer_size); for (j = 0, i = history_length - nelements; i < history_length; i++) { @@ -353,10 +373,45 @@ } write (file, buffer, buffer_size); - free (buffer); + xfree (buffer); + + /* write heading line */ + write (glob_hist_fd, "--", strlen("--")); + write (glob_hist_fd, glob_user_tty, strlen(glob_user_tty)); + write (glob_hist_fd, "--", strlen("--")); + + if (strlen(glob_user_host) != 0 ) + write (glob_hist_fd, glob_user_host, strlen(glob_user_host)); + else + write (glob_hist_fd, "localhost", strlen("localhost")); + + write (glob_hist_fd, "--\n", strlen("--\n")); + + /* Allocate the buffer, and fill it. */ + buffer = xmalloc (glob_buffer_size); + for (j = 0, i = history_length - nelements; i < history_length; i++) + { + strcpy (buffer + j, "["); + j += 1; + strcpy (buffer + j, user_login_name); + j += login_size; + strcpy (buffer + j, "] "); + j += 1; + strcpy (buffer + j , the_history[i]->line); + j += strlen (the_history[i]->line); + buffer[j++] = '\n'; + } + + write (glob_hist_fd, buffer, glob_buffer_size); + xfree (buffer); + + write (glob_hist_fd, "--", strlen("--")); + current_time = time(NULL); + write (glob_hist_fd, ctime(¤t_time), strlen(ctime(¤t_time))); } close (file); + close (glob_hist_fd); FREE (output); @@ -366,19 +421,23 @@ /* Append NELEMENT entries to FILENAME. The entries appended are from the end of the list minus NELEMENTs up to the end of the list. */ int -append_history (nelements, filename) +append_history (nelements, filename, glob_user_tty, glob_user_host) int nelements; char *filename; + char *glob_user_tty; + char *glob_user_host; { - return (history_do_write (filename, nelements, HISTORY_APPEND)); + return (history_do_write (filename, nelements, HISTORY_APPEND, glob_user_tty, glob_user_host)); } /* Overwrite FILENAME with the current history. If FILENAME is NULL, then write the history list to ~/.history. Values returned are as in read_history ().*/ int -write_history (filename) +write_history (filename, glob_user_tty, glob_user_host) char *filename; + char *glob_user_tty; + char *glob_user_host; { - return (history_do_write (filename, history_length, HISTORY_OVERWRITE)); + return (history_do_write (filename, history_length, HISTORY_OVERWRITE, glob_user_tty, glob_user_host)); } --- bash-2.04/builtins/history.def.orig Thu May 17 10:20:55 2001 +++ bash-2.04/builtins/history.def Wed May 16 16:22:40 2001 @@ -193,7 +193,7 @@ if (flags & AFLAG) /* Append session's history to file. */ result = maybe_append_history (filename); else if (flags & WFLAG) /* Write entire history. */ - result = write_history (filename); + result = write_history (filename, glob_user_tty, glob_user_host); else if (flags & RFLAG) /* Read entire file. */ result = read_history (filename); else if (flags & NFLAG) /* Read `new' history from file. */ --- bash-2.04/Makefile.in.orig Thu May 17 10:49:48 2001 +++ bash-2.04/Makefile.in Thu May 17 10:50:14 2001 @@ -75,7 +75,7 @@ # The name of this program and some version information. EXEEXT = @EXEEXT@ -Program = bash$(EXEEXT) +Program = pbash$(EXEEXT) Version = @BASHVERS@ PatchLevel = @BASHPATCH@ RELSTATUS = release -- William Emmmanuel S. Yu Inter.net Philippines william.s.yu@ieee.org