]> granicus.if.org Git - fcron/commitdiff
Merge branch 'log-to-file'
authorThibault Godouet <fcron@free.fr>
Tue, 1 Jan 2013 17:56:27 +0000 (17:56 +0000)
committerThibault Godouet <fcron@free.fr>
Tue, 1 Jan 2013 17:56:27 +0000 (17:56 +0000)
Conflicts:
convert-fcrontab.c
fcron.c
log.c
subs.c

14 files changed:
1  2 
Makefile.in
convert-fcrontab.c
convert-fcrontab.h
exe_list_test.c
fcron.c
fcron.h
fcrondyn.c
fcrondyn.h
fcronsighup.c
fcrontab.c
fcrontab.h
log.c
log.h
subs.c

diff --cc Makefile.in
Simple merge
index 0036c17bf7b87c8cfc01088abbc4f7d75ae3227e,f8acddf83d5eea1aeb5f36acba767e6048830e9d..d22daafebf5d4f5d590e45a945fc1c96c0b2847e
@@@ -242,35 -242,38 +241,40 @@@ main(int argc, char *argv[]
  
      /* constants and variables defined by command line */
  
-     while (1) {
-         c = getopt(argc, argv, "hV");
-         if (c == EOF)
-             break;
-         switch (c) {
+     while(1) {
+       c = getopt(argc, argv, "chV");
+       if (c == EOF) break;
+       switch (c) {
  
 -      case 'V':
 -          info(); break;
 +        case 'V':
 +            info();
 +            break;
  
 -      case 'h':
 -          usage(); break;
 +        case 'h':
 +            usage();
 +            break;
  
-         case ':':
-             fprintf(stderr, "(setopt) Missing parameter");
-             usage();
+       case 'c':
+           Set(fcronconf, optarg); break;
+       case ':':
+           fprintf(stderr, "(setopt) Missing parameter");
+           usage();
  
 -      case '?':
 -          usage();
 +        case '?':
 +            usage();
  
 -      default:
 -          fprintf(stderr, "(setopt) Warning: getopt returned %c", c);
 -      }
 +        default:
 +            fprintf(stderr, "(setopt) Warning: getopt returned %c", c);
 +        }
      }
  
      if (optind >= argc || argc != 2)
 -      usage();
 +        usage();
  
+     /* parse fcron.conf */
+     read_conf();
      user_to_update = strdup2(argv[optind]);
  
      if (chdir(cdir) != 0)
Simple merge
diff --cc exe_list_test.c
Simple merge
diff --cc fcron.c
index 391d4c3c2b362cbc317616cd19de973439c5138f,1fbb84c2e41a0bcc179e95c35261006ec696a950..842980bc600b1683895bfa6cb434e7e02a6a0ee2
+++ b/fcron.c
@@@ -305,110 -306,105 +306,105 @@@ parseopt(int argc, char *argv[]
      int i;
  
  #ifdef HAVE_GETOPT_LONG
-     static struct option opt[] = {
-         {"debug", 0, NULL, 'd'},
-         {"foreground", 0, NULL, 'f'},
-         {"background", 0, NULL, 'b'},
-         {"nosyslog", 0, NULL, 'y'},
-         {"help", 0, NULL, 'h'},
-         {"version", 0, NULL, 'V'},
-         {"once", 0, NULL, 'o'},
-         {"savetime", 1, NULL, 's'},
-         {"firstsleep", 1, NULL, 'l'},
-         {"maxserial", 1, NULL, 'm'},
-         {"configfile", 1, NULL, 'c'},
-         {"newspooldir", 1, NULL, 'n'},
-         {"queuelen", 1, NULL, 'q'},
-         {0, 0, 0, 0}
+     static struct option opt[] =
+     {
+       {"debug", 0, NULL, 'd'},
+       {"foreground", 0, NULL, 'f'},
+       {"background", 0, NULL, 'b'},
+       {"nosyslog", 0, NULL, 'y'},
+       {"logfilepath", 1, NULL, 'p'},
+       {"help", 0, NULL, 'h'},
+       {"version", 0, NULL, 'V'},
+       {"once", 0, NULL, 'o'},
+       {"savetime", 1, NULL, 's'},
+       {"firstsleep", 1, NULL, 'l'},
+       {"maxserial", 1, NULL, 'm'},
+       {"configfile", 1, NULL, 'c'},
+       {"newspooldir", 1, NULL, 'n'},
+       {"queuelen", 1, NULL, 'q'},
+       {0,0,0,0}
      };
 -#endif /* HAVE_GETOPT_LONG */
 +#endif                          /* HAVE_GETOPT_LONG */
  
      extern char *optarg;
      extern int optind, opterr, optopt;
  
      /* constants and variables defined by command line */
  
 -    while(1) {
 +    while (1) {
  #ifdef HAVE_GETOPT_LONG
-         c = getopt_long(argc, argv, "dfbyhVos:l:m:c:n:q:", opt, NULL);
+       c = getopt_long(argc, argv, "dfbyp:hVos:l:m:c:n:q:", opt, NULL);
  #else
-         c = getopt(argc, argv, "dfbyhVos:l:m:c:n:q:");
- #endif                          /* HAVE_GETOPT_LONG */
-         if (c == EOF)
-             break;
-         switch ((char)c) {
-         case 'V':
-             info();
-             break;
-         case 'h':
-             usage();
-             break;
+       c = getopt(argc, argv, "dfbyp:hVos:l:m:c:n:q:");
+ #endif /* HAVE_GETOPT_LONG */
+       if ( c == EOF ) break;
+       switch ( (char)c ) {
  
-         case 'd':
-             debug_opt = 1;
-             break;
+       case 'V':
+           info(); break;
  
-         case 'f':
-             foreground = 1;
-             break;
+       case 'h':
+           usage(); break;
  
-         case 'b':
-             foreground = 0;
-             break;
+       case 'd':
+           debug_opt = 1; break;
  
-         case 'y':
-             dosyslog = 0;
-             break;
+       case 'f':
+           foreground = 1; break;
  
-         case 'o':
-             once = 1;
-             first_sleep = 0;
-             break;
+       case 'b':
+           foreground = 0; break;
  
-         case 's':
-             if ((save_time = strtol(optarg, NULL, 10)) < 60
-                 || save_time >= LONG_MAX)
-                 die("Save time can only be set between 60 and %d.", LONG_MAX);
-             break;
+       case 'y':
+           dosyslog = 0; break;
  
-         case 'l':
-             if ((first_sleep = strtol(optarg, NULL, 10)) < 0
-                 || first_sleep >= LONG_MAX)
-                 die("First sleep can only be set between 0 and %d.", LONG_MAX);
+         case 'p':
+             logfile_path = strdup2(optarg);
              break;
-         case 'm':
-             if ((serial_max_running = strtol(optarg, NULL, 10)) <= 0
-                 || serial_max_running >= SHRT_MAX)
-                 die("Max running can only be set between 1 and %d.", SHRT_MAX);
-             break;
-         case 'c':
-             Set(fcronconf, optarg);
-             break;
-         case 'n':
-             create_spooldir(optarg);
-             break;
-         case 'q':
-             if ((lavg_queue_max = serial_queue_max =
-                  strtol(optarg, NULL, 10)) < 5 || serial_queue_max >= SHRT_MAX)
-                 die("Queue length can only be set between 5 and %d.", SHRT_MAX);
-             break;
-         case ':':
-             error("(parseopt) Missing parameter");
-             usage();
-         case '?':
-             usage();
-         default:
-             warn("(parseopt) Warning: getopt returned %c", c);
-         }
+           
+       case 'o':
+           once = 1; first_sleep = 0; break;
+       case 's':
+           if ( (save_time = strtol(optarg, NULL, 10)) < 60 || save_time >= LONG_MAX )
+               die("Save time can only be set between 60 and %d.", LONG_MAX); 
+           break;
+       case 'l':
+           if ( (first_sleep = strtol(optarg, NULL, 10)) < 0 || first_sleep >= LONG_MAX)
+               die("First sleep can only be set between 0 and %d.", LONG_MAX); 
+           break;
+           
+       case 'm':
+           if ( (serial_max_running = strtol(optarg, NULL, 10)) <= 0 
+                || serial_max_running >= SHRT_MAX )
+               die("Max running can only be set between 1 and %d.",SHRT_MAX);
+           break;
+       case 'c':
+           Set(fcronconf, optarg);
+           break;
+       case 'n':
+           create_spooldir(optarg);
+           break;
+       case 'q':
+           if ( (lavg_queue_max = serial_queue_max = strtol(optarg, NULL, 10)) < 5 
+               || serial_queue_max >= SHRT_MAX )
+               die("Queue length can only be set between 5 and %d.", SHRT_MAX);
+           break;
+       case ':':
+           error("(parseopt) Missing parameter");
+           usage();
+       case '?':
+           usage();
+       default:
+           warn("(parseopt) Warning: getopt returned %c", c);
+       }
      }
  
      if (optind < argc) {
diff --cc fcron.h
Simple merge
diff --cc fcrondyn.c
Simple merge
diff --cc fcrondyn.h
Simple merge
diff --cc fcronsighup.c
Simple merge
diff --cc fcrontab.c
Simple merge
diff --cc fcrontab.h
Simple merge
diff --cc log.c
index 46d8b50dc112289bf25cc508f226955320e4542b,06e3c723f5453281a0ccf21265dfca6302cab7e5..c1df1dbc77dc837a6d062bed7a0bdc0f20c04adc
--- 1/log.c
--- 2/log.c
+++ b/log.c
  #include <sys/socket.h>
  
  #ifdef DEBUG
 -char debug_opt = 1;       /* set to 1 if we are in debug mode */
 +char debug_opt = 1;             /* set to 1 if we are in debug mode */
  #else
 -char debug_opt = 0;       /* set to 1 if we are in debug mode */
 +char debug_opt = 0;             /* set to 1 if we are in debug mode */
  #endif
+ int dosyslog = 1;
+ char *logfile_path = NULL;
  
  
- static void xopenlog(void);
- char *make_msg(const char *append, char *fmt, va_list args);
+ char* make_msg(const char *append, char *fmt, va_list args);
  void log_syslog_str(int priority, char *msg);
- void log_console_str(char *msg);
+ void log_file_str(FILE *logfile, int priority, char *msg);
+ void log_console_str(int priority, char *msg);
  void log_fd_str(int fd, char *msg);
- static void log_syslog(int priority, int fd, char *fmt, va_list args);
- static void log_e(int priority, char *fmt, va_list args);
+ static void print_line_prefix(FILE *logfile, int priority);
+ static void xlog(int priority, int fd, char *fmt, va_list args);
+ static void xlog_e(int priority, int fd, char *fmt, va_list args);
  #ifdef HAVE_LIBPAM
 -static void log_pame(int priority, pam_handle_t *pamh, int pamerrno,
 -                   char *fmt, va_list args);
 +static void log_pame(int priority, pam_handle_t * pamh, int pamerrno,
 +                     char *fmt, va_list args);
  #endif
  
  static char truncated[] = " (truncated)";
@@@ -146,11 -206,12 +206,12 @@@ xlog(int priority, int fd, char *fmt, v
  {
      char *msg;
  
 -    if ( (msg = make_msg(NULL, fmt, args)) == NULL)
 -      return;
 +    if ((msg = make_msg(NULL, fmt, args)) == NULL)
 +        return;
  
      log_syslog_str(priority, msg);
-     log_console_str(msg);
+     log_file_str(logfile, priority, msg);
+     log_console_str(priority, msg);
      log_fd_str(fd, msg);
  
      Free_safe(msg);
@@@ -164,13 -225,15 +225,15 @@@ xlog_e(int priority, int fd, char *fmt
      int saved_errno;
      char *msg;
  
 -    saved_errno=errno;
 +    saved_errno = errno;
  
 -    if ( (msg = make_msg(strerror(saved_errno), fmt, args)) == NULL )
 -      return ;
 +    if ((msg = make_msg(strerror(saved_errno), fmt, args)) == NULL)
 +        return;
  
      log_syslog_str(priority, msg);
-     log_console_str(msg);
+     log_file_str(logfile, priority, msg);
+     log_console_str(priority, msg);
+     log_fd_str(fd, msg);
  
      Free_safe(msg);
  }
@@@ -185,11 -283,11 +284,11 @@@ log_pame(int priority, pam_handle_t * p
  {
      char *msg;
  
 -    if ( (msg = make_msg(pam_strerror(pamh, pamerrno), fmt, args)) == NULL )
 -        return ;
 +    if ((msg = make_msg(pam_strerror(pamh, pamerrno), fmt, args)) == NULL)
 +        return;
  
      log_syslog_str(priority, msg);
-     log_console_str(msg);
+     log_console_str(priority, msg);
  
      xcloselog();
  
@@@ -344,15 -442,15 +443,15 @@@ die(char *fmt, ...
  void
  die_e(char *fmt, ...)
  {
 -   va_list args;
 -   int err_no = 0;
 +    va_list args;
 +    int err_no = 0;
  
 -   err_no = errno;
 +    err_no = errno;
  
-     va_start(args, fmt);
-     log_e(COMPLAIN_LEVEL, fmt, args);
-     va_end(args);
-     if (getpid() == daemon_pid) {
+    va_start(args, fmt);
+    xlog_e(COMPLAIN_LEVEL, -1, fmt, args);
+    va_end(args);
+    if (getpid() == daemon_pid) {
          error("Aborted");
      }
      else {
diff --cc log.h
Simple merge
diff --cc subs.c
index 9936ce66f82c4d553a5554a5f87a724b76c801c8,9dd052338223d4682f127a12d7bfb66b614ac40c..7d95aed5968acc19f0b7019bf9f59cf93bcdeb0f
--- 1/subs.c
--- 2/subs.c
+++ b/subs.c
@@@ -122,20 -123,21 +125,21 @@@ open_as_user(const char *pathname, uid_
      setegid_safe(orig_egid);
  
      /* if open() didn't fail make sure we opened a 'normal' file */
 -    if ( fd >= 0 ) {
 +    if (fd >= 0) {
  
-         if (fstat(fd, &s) < 0) {
+         if ( fstat(fd, &s) < 0 ) {
+             saved_errno = errno;
              error_e("open_as_user(): could not fstat %s", pathname);
 -            if ( close(fd) < 0 )
 +            if (close(fd) < 0)
                  error_e("open_as_user: could not close() %s", pathname);
              fd = -1;
          }
  
 -        if ( ! S_ISREG(s.st_mode) || s.st_nlink != 1 ) {
 +        if (!S_ISREG(s.st_mode) || s.st_nlink != 1) {
              error_e("open_as_user(): file %s is not a regular file", pathname);
 -            if ( close(fd) < 0 )
 +            if (close(fd) < 0)
                  error_e("open_as_user: could not close() %s", pathname);
-             errno = 0;
+             saved_errno = 0;
              fd = -1;
          }
  
@@@ -217,12 -224,13 +228,12 @@@ open_as_user(const char *pathname, uid_
       * is allowed to read that file
       * We do that again as a malicious user could have replaced the file
       * by another one (e.g. a link) between the stat() and the open() earlier */
 -    if ( ! ( s.st_mode & S_IROTH
 -            || ( s.st_uid == openuid && s.st_mode & S_IRUSR )
 -            || ( s.st_gid == opengid && s.st_mode & S_IRGRP ) ) ) {
 +    if (!(s.st_mode & S_IROTH || (s.st_uid == openuid && s.st_mode & S_IRUSR)
 +          || (s.st_gid == opengid && s.st_mode & S_IRGRP))) {
          error("open_as_user(): file %s does not pass the security test: "
-               "uid=%d gid=%d mode=%lo openuid=%d opengid=%d",
-               pathname, s.st_uid, s.st_gid, s.st_mode, openuid, opengid);
-         errno = EACCES;
+                 "uid=%d gid=%d mode=%lo openuid=%d opengid=%d",
+                 pathname, s.st_uid, s.st_gid, s.st_mode, openuid, opengid);
+         saved_errno = EACCES;
          goto err;
      }
  
      /* everything went ok: return the file descriptor */
      return fd;
  
 -err:
 -    if ( fd >= 0 && close(fd) < 0 )
 + err:
 +    if (fd >= 0 && close(fd) < 0)
          error_e("open_as_user: could not close() %s", pathname);
+     errno = saved_errno;
      return -1;
  }