Listing 4: rm.c
/*
* rm.c -- C version of rm logging script
* Copyright 1994 by Steven G. Isaacson
*/
#include <stdio.h>
#include <ctype.h>
#include <sys/types.h>
#include <time.h>
/* log file name */
char *logname="/usr/spool/log/rm.log";
main(argc, argv)
int argc;
char *argv[];
{
FILE *fp;
int i;
char *cwd;
time_t now;
/*
* check for error opening the log file, but don't
* stop people from working just because there is a
* problem with the log file.
*/
if ((fp=fopen(logname, "a+")) != NULL ) {
/* log who is doing what where */
fprintf(fp, "\n" );
if (time(&now) == -1)
fprintf(fp,"time not available\n");
else
fprintf(fp,"%s", ctime(&now));
fprintf(fp,
"getlogin=%s uid=%d euid=%d gid=%d egid=%d cuserid=%s\n",
getlogin(), getuid(), geteuid(), getgid(), getegid(),
cuserid(NULL));
fprintf(fp,"%s=%s ", "HOME", getenv("HOME"));
fprintf(fp,"%s=%s\n", "NAME", getenv("NAME"));
fprintf(fp, "cwd=%s\n", getcwd((char *)NULL, 64));
for (i=0; i < argc; i++)
fprintf(fp, "%s ", argv[i]);
fprintf(fp, "\n");
fflush(fp);
close(fp);
}
/* now call the real rm program */
execvp("/bin/rrm", argv);
}
/* End of File */
|