Commit 136c3fa7 authored by Kirk Webb's avatar Kirk Webb
Browse files

Changed slothd to report build time/date on startup (syslog).

Also moved pidfile location to /var/run (was /tmp)
parent 64eab53c
......@@ -27,11 +27,14 @@ linux: islinux slothd
fbsd: isfbsd slothd
$(CP) slothd fbsd/slothd
slothd: slothd.o slothd.h
$(CC) $(CFLAGS) $(LDFLAGS) -static -o $@ slothd.o $(LIBS)
slothd: slothd.o slothd.h version.o
$(CC) $(CFLAGS) $(LDFLAGS) -static -o $@ slothd.o version.o $(LIBS)
sdcollectd: sdcollectd.o sdcollectd.h
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ sdcollectd.o $(SDLIBS)
sdcollectd: sdcollectd.o sdcollectd.h version.o
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ sdcollectd.o version.o $(SDLIBS)
version.c: slothd.c slothd.h sdcollectd.c sdcollectd.h
echo >$@ "char build_info[] = \"Built `date +%d-%b-%Y` by `id -nu`@`hostname | sed 's/\..*//'`:`pwd`\";"
islinux:
@uname -s | grep inux > /dev/null
......@@ -42,5 +45,5 @@ isfbsd:
install: $(addprefix $(INSTALL_SBINDIR)/, $(SBIN_SCRIPTS))
clean:
rm -f *.o $(PROGS) *~ core *.core
rm -f *.o $(PROGS) *~ core *.core version.c
......@@ -71,6 +71,8 @@ int main(int argc, char **argv) {
static IDLE_DATA iddata;
static SDCOLLECTD_OPTS gopts;
extern char build_info[];
opts = &gopts;
/* Foo on SIGPIPE & SIGHUP. */
......@@ -122,7 +124,8 @@ int main(int argc, char **argv) {
lerror("Couldn't become daemon");
exit(1);
}
lnotice("Daemon started successfully");
lnotice("sdcollectd started successfully");
lnotice(build_info);
}
/* do our thing - just loop collecting data from clients, and insert into
......
......@@ -51,7 +51,7 @@ void usage(void) {
printf("\tslothd [-a] [-d] [-i <interval>] [-p <port>] [-s <server>]\n");
printf("\t -h\t This message.\n");
printf("\t -a\t Only scan active terminal special files.\n");
printf("\t -f\t Send first idle data report immediately on startup.\n");
printf("\t -f\t Do not send idle data report immediately on startup.\n");
printf("\t -d\t Debug mode; do not fork into background.\n");
printf("\t -i <interval>\t Run interval, in seconds. (default is 10 min.)\n");
printf("\t -p <port>\t Send on port <port> (default is %d).\n", SLOTHD_DEF_PORT);
......@@ -67,6 +67,8 @@ int main(int argc, char **argv) {
static SLOTHD_OPTS mopts;
static SLOTHD_PACKET mpkt;
extern char build_info[];
/* pre-init */
bzero(&mopts, sizeof(SLOTHD_OPTS));
bzero(&mpkt, sizeof(SLOTHD_PACKET));
......@@ -75,6 +77,7 @@ int main(int argc, char **argv) {
/* Try to get lock. If can't, then bail out. */
if ((pfd = open(PIDFILE, O_EXCL | O_CREAT | O_RDWR)) < 0) {
lerror("Can't create lock file, quiting.");
exit(1);
}
fchmod(pfd, S_IRUSR | S_IRGRP | S_IROTH);
......@@ -92,6 +95,7 @@ int main(int argc, char **argv) {
else {
exitcode = 0;
lnotice("Slothd started");
lnotice(build_info);
for (;;) {
if (!opts->first) {
sleep(mopts.interval);
......@@ -120,7 +124,7 @@ int parse_args(int argc, char **argv) {
opts->interval = DEF_INTVL;
opts->port = SLOTHD_DEF_PORT;
opts->servname = SLOTHD_DEF_SERV;
opts->first = 0;
opts->first = 1;
while ((ch = getopt(argc, argv, "ai:dp:s:hf")) != -1) {
switch (ch) {
......@@ -143,7 +147,7 @@ int parse_args(int argc, char **argv) {
break;
case 'f':
opts->first = 1;
opts->first = 0;
break;
case 'p':
......@@ -208,6 +212,15 @@ int init_slothd(void) {
}
opts->ttys[opts->numttys] = strdup("/dev/console");
opts->numttys++;
#ifdef __linux__
/*
Include the pts mux device to check for activity on
dynamically allocated linux pts devices:
(/dev/pts/<num>)
*/
opts->ttys[opts->numttys] = strdup("/dev/ptmx");
opts->numttys++;
#endif
while (opts->numttys < MAXTTYS && (dptr = readdir(devs))) {
if (strstr(dptr->d_name, "tty") || strstr(dptr->d_name, "pty")) {
snprintf(bufstr, MAXDEVLEN, "/dev/%s", dptr->d_name);
......@@ -260,7 +273,8 @@ void get_min_tty_idle(void) {
mintime = wtmp_get_last();
}
}
#ifdef __linux__
#ifdef COMMENT
/* Linux uses dynamically allocated UNIX98 ptys */
else {
DIR *ptsdir;
......
......@@ -34,7 +34,7 @@
#define SLOTHD_PATH_ENV "/bin:/usr/bin:/sbin:/usr/sbin:/etc/testbed"
#define UTMP_PATH "/var/run/utmp"
#define WTMP_PATH "/var/log/wtmp"
#define PIDFILE "/tmp/.sdpid"
#define PIDFILE "/var/run/slothd"
#define MACADDRLEN 18
#define MAXNUMIFACES 10
#define MAXIFNAMELEN 10
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment