]> git.ipfire.org Git - ipfire-2.x.git/blobdiff - src/misc-progs/syslogdctrl.c
openvpn: Properly remove all RRDs after a connection is removed
[ipfire-2.x.git] / src / misc-progs / syslogdctrl.c
index bb9c4d083d247ee663abe37b4b0e0289ad688262..8111c84c56ac696084ff7af046e8db866c16fa1c 100644 (file)
 #include <fcntl.h>
 #include <signal.h>
 #include <errno.h>
+
 #include "libsmooth.h"
 #include "setuid.h"
+#include "netutil.h"
 
 #define ERR_ANY 1
 #define ERR_SETTINGS 2    /* error in settings file */
 
 int main(void)
 {
-   char buffer[STRING_SIZE], hostname[STRING_SIZE], varmessages[STRING_SIZE];
+   char buffer[STRING_SIZE], command[STRING_SIZE], hostname[STRING_SIZE];
+   char varmessages[STRING_SIZE], asynclog[STRING_SIZE];
    int config_fd,rc,fd,pid;
    struct stat st;
    struct keyvalue *kv = NULL;
    memset(buffer, 0, STRING_SIZE);
    memset(hostname, 0, STRING_SIZE);
    memset(varmessages, 0, STRING_SIZE);
+   memset(asynclog, 0, STRING_SIZE);
 
    if (!(initsetuid()))
       exit(1);
@@ -45,7 +49,7 @@ int main(void)
    /* Read in and verify config */
    kv=initkeyvalues();
 
-   if (!readkeyvalues(kv, "/logging/settings"))
+   if (!readkeyvalues(kv, "/var/ipfire/logging/settings"))
    {
       fprintf(stderr, "Cannot read syslog settings\n");
       exit(ERR_SETTINGS);
@@ -62,6 +66,13 @@ int main(void)
       fprintf(stderr, "Cannot read REMOTELOG_ADDR\n");
       exit(ERR_SETTINGS);
    }
+
+   if (!findkey(kv, "ENABLE_ASYNCLOG", asynclog))
+   {
+      fprintf(stderr, "Cannot read ENABLE_ASYNCLOG\n");
+      exit(ERR_SETTINGS);
+   }
+
    
    if (!findkey(kv, "VARMESSAGES", varmessages))
    {
@@ -111,10 +122,8 @@ int main(void)
       snprintf(buffer, STRING_SIZE - 1, "/bin/sed -e 's/^#\\?\\(\\*\\.\\*[[:blank:]]\\+@\\).\\+$/\\1%s/' /etc/syslog.conf >&%d", hostname, config_fd );
    else
       snprintf(buffer, STRING_SIZE - 1, "/bin/sed -e 's/^#\\?\\(\\*\\.\\*[[:blank:]]\\+@.\\+\\)$/#\\1/' /etc/syslog.conf >&%d", config_fd );
-      
-      snprintf(buffer, STRING_SIZE - 1, "&& /bin/sed -e 's/*.\/var\/log\/messages/%s \/var\/log\/messages/' /etc/syslog.conf >&%d", varmessages, config_fd );
 
-   /* if the return code isn't 0 failsafe */
+     /* if the return code isn't 0 failsafe */
    if ((rc = unpriv_system(buffer,99,99)) != 0)
    {
       fprintf(stderr, "sed returned bad exit code: %d\n", rc);
@@ -123,6 +132,17 @@ int main(void)
       exit(ERR_CONFIG);
    }
    close(config_fd);
+   
+   /* Replace the logging option*/
+     safe_system("grep -v '/var/log/messages' < /etc/syslog.conf.new > /etc/syslog.conf.tmp && mv /etc/syslog.conf.tmp /etc/syslog.conf.new");
+   
+   if (!strcmp(asynclog,"on"))
+     snprintf(command, STRING_SIZE - 1, "printf '%s     -/var/log/messages' >> /etc/syslog.conf.new", varmessages );
+   else
+     snprintf(command, STRING_SIZE - 1, "printf '%s     /var/log/messages' >> /etc/syslog.conf.new", varmessages );
+
+     safe_system(command);
+
    if (rename("/etc/syslog.conf.new", "/etc/syslog.conf") == -1)
    {
       perror("Unable to replace old config file");