OpenSDE Packages Database (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.7 KiB

  1. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # Filename: package/.../nut/nut-2.6.5-upsd-foreground.patch
  5. # Copyright (C) 2012 The OpenSDE Project
  6. #
  7. # More information can be found in the files COPYING and README.
  8. #
  9. # This patch file is dual-licensed. It is available under the license the
  10. # patched project is licensed under, as long as it is an OpenSource license
  11. # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
  12. # of the GNU General Public License as published by the Free Software
  13. # Foundation; either version 2 of the License, or (at your option) any later
  14. # version.
  15. # --- SDE-COPYRIGHT-NOTE-END ---
  16. Description: Add option upsd to not detach from the controlling tty
  17. This is needed to run upsd by a supervise service like daemontools,
  18. runit.
  19. The original default behavoir, which detaches from the controlling tty
  20. and running in background has been preserved.
  21. To run upsd in foreground you have to use the -f command option.
  22. diff -ruN nut-2.6.5-orig/common/common.c nut-2.6.5/common/common.c
  23. --- nut-2.6.5-orig/common/common.c 2012-07-31 19:38:58.000000000 +0200
  24. +++ nut-2.6.5/common/common.c 2012-08-15 09:07:43.949002650 +0200
  25. @@ -32,6 +32,7 @@
  26. #include "nut_version.h"
  27. const char *UPS_VERSION = NUT_VERSION_MACRO;
  28. + int foreground = 0;
  29. int nut_debug_level = 0;
  30. int nut_log_level = 0;
  31. static int upslog_flags = UPSLOG_STDERR;
  32. diff -ruN nut-2.6.5-orig/include/common.h nut-2.6.5/include/common.h
  33. --- nut-2.6.5-orig/include/common.h 2012-07-31 19:38:56.000000000 +0200
  34. +++ nut-2.6.5/include/common.h 2012-08-15 09:14:10.999949407 +0200
  35. @@ -52,6 +52,9 @@
  36. /* close ttys and become a daemon */
  37. void background(void);
  38. +/* do not detach from controlling tty and run in foreground */
  39. +extern int foreground;
  40. +
  41. /* do this here to keep pwd/grp stuff out of the main files */
  42. struct passwd *get_user_pwent(const char *name);
  43. diff -ruN nut-2.6.5-orig/server/upsd.c nut-2.6.5/server/upsd.c
  44. --- nut-2.6.5-orig/server/upsd.c 2012-07-31 19:38:58.000000000 +0200
  45. +++ nut-2.6.5/server/upsd.c 2012-08-15 09:07:43.949002650 +0200
  46. @@ -819,6 +819,7 @@
  47. printf(" - reload: reread configuration files\n");
  48. printf(" - stop: stop process and exit\n");
  49. printf(" -D raise debugging level\n");
  50. + printf(" -f run in foreground\n");
  51. printf(" -h display this help\n");
  52. printf(" -r <dir> chroots to <dir>\n");
  53. printf(" -q raise log level threshold\n");
  54. @@ -936,6 +937,10 @@
  55. nut_debug_level++;
  56. break;
  57. + case 'f':
  58. + foreground = 1;
  59. + break;
  60. +
  61. case '4':
  62. opt_af = AF_INET;
  63. break;
  64. @@ -1023,7 +1028,7 @@
  65. /* handle upsd.users */
  66. user_load();
  67. - if (!nut_debug_level) {
  68. + if ((!nut_debug_level) && (!foreground)) {
  69. background();
  70. writepid(pidfn);
  71. } else {