#include "header.h"
#include <sys/types.h>
#include <unistd.h>
#include <syslog.h>
#include <signal.h>
#define UNIX
#include "kludges.h"
#undef UNIX
void do_nothing (int seconds) {
sleep((unsigned int)(seconds+2));
}
int ftty (FILE *file) {
return isatty(fileno(file));
}
void set_lock (int lock) {
FILE *file;
long pid;
if (lockname == NULL || lockname[0] == '\0') return;
if (lock) {
errno = 0;
if ((file = fopen(lockname,"r")) != NULL &&
fscanf(file,"%ld",&pid) == 1 && kill(pid,0) == 0) {
if (verbose || isatty(STDIN_FILENO) || isatty(STDOUT_FILENO))
fatal(0,"another msntp process is currently running",NULL);
else
fatal(0,NULL,NULL);
}
if (file != NULL) fclose(file);
errno = 0;
if ((file = fopen(lockname,"w")) == NULL ||
fprintf(file,"%ld\n",(long)getpid()) <= 0 ||
ferror(file) || fclose(file) != 0)
fatal(1,"unable to write PID to %s",lockname);
adjust_time(0.0,1,0.0);
} else {
errno = 0;
if (remove(lockname) != 0)
fatal(1,"unable to remove the msntp lockname %s",lockname);
}
}
void
log_message (const char *message)
{
syslog(
#ifdef LOG_DAEMON
LOG_DAEMON |
#endif
LOG_WARNING, "%s", message);
}