summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Linehan <patientulysses@gmail.com>2012-06-14 17:46:28 -0400
committerJason Linehan <patientulysses@gmail.com>2012-06-14 17:46:28 -0400
commit045b94f8fadd9d66b038741be78f2ed4b0528272 (patch)
tree98b5ea9ff93c14cef8a1a28de275fa748143a62e
parent00e7bc097a5cfe09fba0d75dbd8eeaa662cdf721 (diff)
downloadcloth-045b94f8fadd9d66b038741be78f2ed4b0528272.tar.gz
cloth-045b94f8fadd9d66b038741be78f2ed4b0528272.tar.bz2
cloth-045b94f8fadd9d66b038741be78f2ed4b0528272.zip
Info file for a watcher/console process to parse
-rw-r--r--cloth.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/cloth.c b/cloth.c
index a125be6..29cb58b 100644
--- a/cloth.c
+++ b/cloth.c
@@ -26,6 +26,8 @@
#define BUFSIZE 8096
/* Default path of the log file (relative to -d) */
#define LOG_PATH "cloth.log"
+/* Default path of procinfo file (relative to -d) */
+#define INFO_PATH "cloth.info"
/* The strftime() format string for common log time. */
#define COMMON_LOG_TIME "%d/%b/%Y:%H:%M:%S %z"
/* Message printed on illegal argument usage. */
@@ -161,6 +163,29 @@ void log(enum log_genre genre, char *msg, char *raw, int socket)
if (genre == OOPS || genre == WARN)
exit(3);
}
+
+/**
+ * procinfo -- record the process information so it can be read by watcher
+ */
+void procinfo(pid_t pid, int socket, int hit, struct sockaddr_in *client)
+{
+ char buf[BUFSIZE];
+ char *ip;
+ int port;
+ int fd;
+
+ ip = inet_ntoa(client->sin_addr);
+ port = (int)client->sin_port;
+
+ sprintf(buf, "%d:%d:%d:%s:%d", pid, socket, hit, ip, port);
+
+ /* Write the procinfo to the log file */
+ if ((fd = open(INFO_PATH, O_CREAT| O_WRONLY | O_APPEND, 0644)) >= 0) {
+ write(fd, buf, strlen(buf));
+ write(fd, "\n", 1);
+ close(fd);
+ }
+}
/******************************************************************************
@@ -305,6 +330,7 @@ void cloth(int port)
log(INFO, "cloth is starting up...", "", getpid());
+
/**********************************************
* Establish the server side of the socket *
**********************************************/
@@ -347,6 +373,7 @@ void cloth(int port)
} else {
close(fd_socket);
}
+ procinfo(pid, fd_socket, hit, &client_addr);
}
}