diff options
author | dimitri staessens <[email protected]> | 2016-07-06 19:14:42 +0200 |
---|---|---|
committer | dimitri staessens <[email protected]> | 2016-07-06 19:14:42 +0200 |
commit | 4fb0d2bfb7486936ef05721667f03eccf664d56e (patch) | |
tree | c3753f440085a2126e399cb8667d99eb91a8ad6a /src/irmd | |
parent | 90c3c96b5c9b1e4db6bb6d1894a21aec54a965b1 (diff) | |
parent | bb85e730783ae34808e42c3107759f43106a9b1d (diff) | |
download | ouroboros-4fb0d2bfb7486936ef05721667f03eccf664d56e.tar.gz ouroboros-4fb0d2bfb7486936ef05721667f03eccf664d56e.zip |
Merged in sandervrijders/ouroboros/be (pull request #161)
lib, irmd, ipcpd: Provide the feature to write to logs
Diffstat (limited to 'src/irmd')
-rw-r--r-- | src/irmd/main.c | 67 |
1 files changed, 66 insertions, 1 deletions
diff --git a/src/irmd/main.c b/src/irmd/main.c index ab6d5167..ff129b71 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -50,6 +50,7 @@ #include <limits.h> #include <pthread.h> #include <sys/stat.h> +#include <dirent.h> #include <sys/wait.h> #define IRMD_CLEANUP_TIMER ((IRMD_FLOW_TIMEOUT / 20) * MILLION) /* ns */ @@ -1781,17 +1782,81 @@ static struct irm * irm_create() return instance; } -int main() +static void usage() +{ + LOG_ERR("Usage: irmd \n\n" + " [--stdout (Print to stdout instead of logs)]\n"); +} + +int main(int argc, char ** argv) { struct sigaction sig_act; int t = 0; + char * log_file = INSTALL_PREFIX LOG_DIR "irmd.log"; + DIR * log_dir; + struct dirent * ent; + char * point; + char * log_path; + size_t len = 0; + bool use_stdout = false; + if (geteuid() != 0) { LOG_ERR("IPC Resource Manager must be run as root."); exit(EXIT_FAILURE); } + argc--; + argv++; + while (argc > 0) { + if (strcmp(*argv, "--stdout") == 0) { + use_stdout = true; + argc--; + argv++; + } else { + usage(); + exit(EXIT_FAILURE); + } + } + + + if (!use_stdout && + (log_dir = opendir(INSTALL_PREFIX LOG_DIR)) != NULL) { + while ((ent = readdir(log_dir)) != NULL) { + point = strrchr(ent->d_name,'.'); + if (point == NULL || + strcmp(point, ".log") != 0) + continue; + + len += strlen(INSTALL_PREFIX); + len += strlen(LOG_DIR); + len += strlen(ent->d_name); + + log_path = malloc(len + 1); + if (log_path == NULL) { + LOG_ERR("Failed to malloc"); + exit(EXIT_FAILURE); + } + + strcpy(log_path, INSTALL_PREFIX); + strcat(log_path, LOG_DIR); + strcat(log_path, ent->d_name); + + unlink(log_path); + + free(log_path); + len = 0; + } + closedir(log_dir); + } + + if (!use_stdout) + if (set_logfile(log_file)) + LOG_ERR("Cannot open %s, falling back to " + "stdout for logs.", + log_file); + /* init sig_act */ memset(&sig_act, 0, sizeof sig_act); |