--- src/install.orig.c Mon Dec 25 12:07:36 2000 +++ src/install.c Fri Sep 28 17:12:47 2001 @@ -23,6 +23,9 @@ #include #include +#include +#include +#include #include #include #include @@ -141,6 +144,58 @@ {NULL, 0, NULL, 0} }; +int installlog (const char *file0,const char *file1) +{ +/* The enviroment variable ILOGFILE specifies where to put the logfile. + i.e. /var/log/ilog */ + char *ilogfile = (char *) getenv("ILOGFILE"); +/* if ILOGFILE is set -> continue, else forget everything... */ + if (ilogfile != NULL) { + int fd = open (ilogfile, O_CREAT|O_APPEND|O_WRONLY, 0644); + if (fd<0) { + fprintf (stderr,"%s :",ilogfile); + perror ("open"); + return (1); + } + struct timeval tv; + struct timezone tz; + gettimeofday (&tv, &tz); + + char datestring[255]; +/* this forges the first part of the logstring, the date */ + strftime (datestring, 255, "%Y-%m-%d-%H:%M:%S ", localtime (&tv.tv_sec)); +/* and this tries to extract the packagename from PWD. Assume you installed the + sources to /usr/src/fileutils-4.1 then the extracted packagename will be + PWD minus /usr/src/ = fileutils-4.1 .Any following tree will be cutted away + also. */ + char *pathstring= (char *) getenv("PWD"); + int matches = strspn(pathstring,"/usr/src/"); + if (matches != 9) { + fprintf (stderr,"if you want loging, you have to install from /usr/src/* !\n"); + return (1); + } + char *startptr = &pathstring[matches]; + char *endptr = strchr(startptr, '/'); + char packstring[255]; + if (endptr != NULL) + strncpy (packstring, startptr, endptr-startptr); + else + strcpy (packstring, startptr); +/* this one forges the complete logstring, */ + strcat (datestring, packstring); + strcat (datestring, ": "); + strcat (datestring, file0); + strcat (datestring, " -> "); + strcat (datestring, file1); + strcat (datestring, "\n"); +/* which is finally written... */ + write(fd, datestring, strlen(datestring)); + + close (fd); + } + return (0); +} + static void cp_option_init (struct cp_options *x) { @@ -326,6 +381,8 @@ errors = install_file_in_file (file[0], file[1], &x); else errors = install_file_in_dir (file[0], file[1], &x); + if (errors == 0) + installlog (file[0], file[1]); } else { @@ -342,6 +399,8 @@ for (i = 0; i < n_files - 1; i++) { errors |= install_file_in_dir (file[i], dest, &x); + if (errors == 0) + installlog (file[i], dest); } } }