[sheepdog] [PATCH] dog: log dog operation in syslog
Hitoshi Mitake
mitake.hitoshi at lab.ntt.co.jp
Fri Dec 27 03:01:40 CET 2013
This patch is based on a request from our internal team. Currently,
sheepdog doesn't provide a way of logging admin's operation. The lack
of this feature is serious because we cannot find any evidence of
operation.
This patch adds the logging feature in dog command. If the environment
variable, SHEEPDOG_DOG_LOG, has value, dog command logs its command
line argument with syslog.
Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
dog/dog.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/dog/dog.c b/dog/dog.c
index b092e62..14e9fa0 100644
--- a/dog/dog.c
+++ b/dog/dog.c
@@ -351,6 +351,33 @@ static size_t get_nr_nodes(void)
return sd_nodes_nr;
}
+static void log_dog_operation(int argc, char **argv)
+{
+ int length = 0, printed = 0;
+ char *msg;
+
+ if (!getenv("SHEEPDOG_DOG_LOG"))
+ /* don't log operation of dog */
+ return;
+
+ openlog("sheepdog admin operation", LOG_PID, LOG_USER);
+
+ for (int i = 0; i < argc; i++)
+ length += 1 + strlen(argv[i]); /* 1 is for space */
+
+ length++; /* 1 is for '\0' */
+ msg = xcalloc(length, sizeof(char));
+
+ for (int i = 0; i < argc; i++)
+ printed += snprintf(msg + printed, length - printed,
+ " %s", argv[i]);
+
+ syslog(LOG_INFO, "%s\n", msg);
+
+ free(msg);
+ closelog();
+}
+
int main(int argc, char **argv)
{
int ch, longindex, ret;
@@ -363,6 +390,8 @@ int main(int argc, char **argv)
uint8_t sdhost[16];
int sdport;
+ log_dog_operation(argc, argv);
+
install_crash_handler(crash_handler);
init_commands(&commands);
--
1.7.10.4
More information about the sheepdog
mailing list