cronolog-1.6.2-umask.patch 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. Add umask support to cronolog.
  2. Patch-by: Mike Doty <kingtaco@gentoo.org>
  3. Signed-off-By: Robin H. Johnson <robbat2@gentoo.org>
  4. --- a/src/cronolog.c.orig 2010-01-22 16:49:41.000000000 -0800
  5. +++ b/src/cronolog.c 2010-01-22 17:31:50.000000000 -0800
  6. @@ -106,7 +106,8 @@
  7. #ifndef _WIN32
  8. #define SETUGID_USAGE " -u USER, --set-uid=USER change to USER before doing anything (name or UID)\n" \
  9. - " -g GROUP, --set-gid=GROUP change to GROUP before doing anything (name or GID)\n"
  10. + " -g GROUP, --set-gid=GROUP change to GROUP before doing anything (name or GID)\n" \
  11. + " -U OCTAL, --umask=OCTAL sets umask of file/directory creation\n"
  12. #else
  13. #define SETUGID_USAGE ""
  14. #endif
  15. @@ -134,7 +135,7 @@
  16. /* Definition of the short and long program options */
  17. #ifndef _WIN32
  18. -char *short_options = "ad:eop:s:z:H:P:S:l:hVx:u:g:";
  19. +char *short_options = "ad:eop:s:z:H:P:S:l:hVx:u:g:U:";
  20. #else
  21. char *short_options = "ad:eop:s:z:H:P:S:l:hVx:";
  22. #endif
  23. @@ -157,10 +158,16 @@
  24. { "once-only", no_argument, NULL, 'o' },
  25. { "help", no_argument, NULL, 'h' },
  26. { "version", no_argument, NULL, 'V' },
  27. + { "umask", required_argument, NULL, 'U' },
  28. { NULL, 0, NULL, 0 }
  29. };
  30. #endif
  31. +#ifndef _WIN32
  32. +static mode_t saved_umask = 0;
  33. +static mode_t new_umask = 0;
  34. +#endif
  35. +
  36. /* Main function.
  37. */
  38. int
  39. @@ -193,6 +200,11 @@
  40. int log_fd = -1;
  41. #ifndef _WIN32
  42. + new_umask=umask(0);
  43. + umask(new_umask);
  44. +#endif
  45. +
  46. +#ifndef _WIN32
  47. while ((ch = getopt_long(argc, argv, short_options, long_options, NULL)) != EOF)
  48. #else
  49. while ((ch = getopt(argc, argv, short_options)) != EOF)
  50. @@ -267,6 +279,9 @@
  51. new_gid = parse_gid(optarg, argv[0]);
  52. change_gid = 1;
  53. break;
  54. + case 'U':
  55. + new_umask = (mode_t)strtol(optarg, NULL, 8);
  56. + break;
  57. #endif
  58. case 'o':
  59. periodicity = ONCE_ONLY;
  60. @@ -443,6 +458,9 @@
  61. timestamp(*pnext_period), *pnext_period,
  62. *pnext_period - time_now));
  63. +#ifndef _WIN32
  64. + saved_umask=umask(new_umask);
  65. +#endif
  66. log_fd = open(pfilename, O_WRONLY|O_CREAT|O_APPEND|O_LARGEFILE, FILE_MODE);
  67. #ifndef DONT_CREATE_SUBDIRS
  68. @@ -459,6 +477,10 @@
  69. exit(2);
  70. }
  71. +#ifndef _WIN32
  72. + umask(saved_umask);
  73. +#endif
  74. +
  75. if (linkname)
  76. {
  77. create_link(pfilename, linkname, linktype, prevlinkname);