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.

154 lines
4.7 KiB

  1. From 737b3b4f4d1ecdff6597f5f299bdef6873147bf8 Mon Sep 17 00:00:00 2001
  2. From: Christian Wiese <christian.wiese@securepoint.de>
  3. Date: Thu, 25 Apr 2013 16:27:56 +0200
  4. Subject: [PATCH] common: add global variable for foreground operation
  5. ---
  6. common/common.c | 1 +
  7. include/common.h | 3 +++
  8. 2 files changed, 4 insertions(+)
  9. diff --git a/common/common.c b/common/common.c
  10. index ef680b0..e02190a 100644
  11. --- a/common/common.c
  12. +++ b/common/common.c
  13. @@ -32,6 +32,7 @@
  14. #include "nut_version.h"
  15. const char *UPS_VERSION = NUT_VERSION_MACRO;
  16. + int foreground = 0;
  17. int nut_debug_level = 0;
  18. int nut_log_level = 0;
  19. static int upslog_flags = UPSLOG_STDERR;
  20. diff --git a/include/common.h b/include/common.h
  21. index d044d52..a67c176 100644
  22. --- a/include/common.h
  23. +++ b/include/common.h
  24. @@ -52,6 +52,9 @@ void open_syslog(const char *progname);
  25. /* close ttys and become a daemon */
  26. void background(void);
  27. +/* do not detach from controlling tty and run in foreground */
  28. +extern int foreground;
  29. +
  30. /* do this here to keep pwd/grp stuff out of the main files */
  31. struct passwd *get_user_pwent(const char *name);
  32. --
  33. 1.7.10.2
  34. From 7201d2536e3ca96a617d38c8c1e680200fcdf83e Mon Sep 17 00:00:00 2001
  35. From: Christian Wiese <christian.wiese@securepoint.de>
  36. Date: Thu, 25 Apr 2013 16:29:21 +0200
  37. Subject: [PATCH] drivers: add command line option to not detach from
  38. controlling tty
  39. This is needed to run the standalone driver by a supervise service like
  40. daemontools, runit, s6 etc. without getting all the noise when using
  41. the -D option for debugging.
  42. The original default behavoir, which detaches from the controlling tty
  43. and running in background has been preserved.
  44. To run a driver in foreground you have to use the -f command option.
  45. ---
  46. drivers/main.c | 8 ++++++--
  47. 1 file changed, 6 insertions(+), 2 deletions(-)
  48. diff --git a/drivers/main.c b/drivers/main.c
  49. index 7c2fc55..42f6ec9 100644
  50. --- a/drivers/main.c
  51. +++ b/drivers/main.c
  52. @@ -89,6 +89,7 @@ static void help_msg(void)
  53. printf(" -a <id> - autoconfig using ups.conf section <id>\n");
  54. printf(" - note: -x after -a overrides ups.conf settings\n\n");
  55. + printf(" -f - run in foreground\n");
  56. printf(" -V - print version, then exit\n");
  57. printf(" -L - print parseable list of driver variables\n");
  58. printf(" -D - raise debugging level\n");
  59. @@ -488,7 +489,7 @@ int main(int argc, char **argv)
  60. /* build the driver's extra (-x) variable table */
  61. upsdrv_makevartable();
  62. - while ((i = getopt(argc, argv, "+a:kDhx:Lqr:u:Vi:")) != -1) {
  63. + while ((i = getopt(argc, argv, "+a:fkDhx:Lqr:u:Vi:")) != -1) {
  64. switch (i) {
  65. case 'a':
  66. upsname = optarg;
  67. @@ -499,6 +500,9 @@ int main(int argc, char **argv)
  68. fatalx(EXIT_FAILURE, "Error: Section %s not found in ups.conf",
  69. optarg);
  70. break;
  71. + case 'f':
  72. + foreground = 1;
  73. + break;
  74. case 'D':
  75. nut_debug_level++;
  76. break;
  77. @@ -668,7 +672,7 @@ int main(int argc, char **argv)
  78. if (dstate_getinfo("ups.serial") != NULL)
  79. dstate_setinfo("device.serial", "%s", dstate_getinfo("ups.serial"));
  80. - if (nut_debug_level == 0) {
  81. + if ((nut_debug_level == 0) && (!foreground)) {
  82. background();
  83. writepid(pidfn); /* PID changes when backgrounding */
  84. }
  85. --
  86. 1.7.10.2
  87. From 285bc3c90146b24508ebbcab21c8ebab3d990f63 Mon Sep 17 00:00:00 2001
  88. From: Christian Wiese <christian.wiese@securepoint.de>
  89. Date: Thu, 25 Apr 2013 16:38:17 +0200
  90. Subject: [PATCH] upsd: add command line option to not detach from controlling
  91. tty
  92. This is needed to run upsd by a supervise service like daemontools, runit, s6
  93. etc. without getting all the noise when using the -D option for debugging.
  94. The original default behavoir, which detaches from the controlling tty and
  95. running in background has been preserved.
  96. To run upsd in foreground you have to use the -f command option.
  97. ---
  98. server/upsd.c | 7 ++++++-
  99. 1 file changed, 6 insertions(+), 1 deletion(-)
  100. diff --git a/server/upsd.c b/server/upsd.c
  101. index f8d9c7e..86964c0 100644
  102. --- a/server/upsd.c
  103. +++ b/server/upsd.c
  104. @@ -819,6 +819,7 @@ static void help(const char *progname)
  105. printf(" - reload: reread configuration files\n");
  106. printf(" - stop: stop process and exit\n");
  107. printf(" -D raise debugging level\n");
  108. + printf(" -f run in foreground\n");
  109. printf(" -h display this help\n");
  110. printf(" -r <dir> chroots to <dir>\n");
  111. printf(" -q raise log level threshold\n");
  112. @@ -936,6 +937,10 @@ int main(int argc, char **argv)
  113. nut_debug_level++;
  114. break;
  115. + case 'f':
  116. + foreground = 1;
  117. + break;
  118. +
  119. case '4':
  120. opt_af = AF_INET;
  121. break;
  122. @@ -1023,7 +1028,7 @@ int main(int argc, char **argv)
  123. /* handle upsd.users */
  124. user_load();
  125. - if (!nut_debug_level) {
  126. + if ((!nut_debug_level) && (!foreground)) {
  127. background();
  128. writepid(pidfn);
  129. } else {
  130. --
  131. 1.7.10.2