#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/syslog.h>

#define LOGFILE "/tmp/prog.log"  

static char cmd[128];
static char format[] = "which %s\n";

FILE *initialize () 
{
	char user[100];
	FILE *log;
	sprintf(user, "%s", getenv("USER")); 
	log = fopen(LOGFILE,"a"); 
	fprintf(log, "Started by user %s\n", user); 
	return log; 
}

int main(int argc, char *argv[]) 
{
	char buf[256];
	FILE *logfile;
	logfile = initialize();
	if ( logfile == NULL ) {
		fprintf (stderr, "Cannot use logfile\n");
		exit(1);
	}
	printf ("Which command?: ");
	gets(buf); 
	sprintf(cmd, format, buf); 
	fprintf(logfile, "Will execute: %s", cmd);
	syslog(36, cmd); 
	printf("You are looking for:\n");
	system(cmd);  
	fclose(logfile);
	exit(0);
}
