Portable build framework for OpenNTPD
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.

59 lines
1.5 KiB

3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
8 years ago
3 years ago
  1. From 549bec923b5cdbd6baa83a67b7e625f1fa824539 Mon Sep 17 00:00:00 2001
  2. From: Brent Cook <busterb@gmail.com>
  3. Date: Mon, 12 Jan 2015 06:18:31 -0600
  4. Subject: [PATCH 08/18] initialize setproctitle where needed
  5. We need to save a copy of argv and __progname to avoid setproctitle
  6. clobbering them.
  7. ---
  8. src/usr.sbin/ntpd/ntpd.c | 20 ++++++++++++++++++++
  9. 1 file changed, 20 insertions(+)
  10. diff --git a/src/usr.sbin/ntpd/ntpd.c b/src/usr.sbin/ntpd/ntpd.c
  11. index a0da39adf7..7259bb6236 100644
  12. --- a/src/usr.sbin/ntpd/ntpd.c
  13. +++ b/src/usr.sbin/ntpd/ntpd.c
  14. @@ -134,6 +134,13 @@ auto_preconditions(const struct ntpd_conf *cnf)
  15. #define PFD_PIPE 0
  16. #define PFD_MAX 1
  17. +/* Saves a copy of argv for setproctitle emulation */
  18. +#ifndef HAVE_SETPROCTITLE
  19. +static char **saved_argv;
  20. +#endif
  21. +
  22. +char *get_progname(char *argv0);
  23. +
  24. int
  25. main(int argc, char *argv[])
  26. {
  27. @@ -154,6 +161,8 @@ main(int argc, char *argv[])
  28. time_t settime_deadline;
  29. int sopt = 0;
  30. + __progname = get_progname(argv[0]);
  31. +
  32. if (strcmp(__progname, "ntpctl") == 0) {
  33. ctl_main(argc, argv);
  34. /* NOTREACHED */
  35. @@ -163,6 +172,17 @@ main(int argc, char *argv[])
  36. memset(&lconf, 0, sizeof(lconf));
  37. +#ifndef HAVE_SETPROCTITLE
  38. + /* Prepare for later setproctitle emulation */
  39. + saved_argv = calloc(argc + 1, sizeof(*saved_argv));
  40. + for (i = 0; i < argc; i++)
  41. + saved_argv[i] = strdup(argv[i]);
  42. + saved_argv[i] = NULL;
  43. + compat_init_setproctitle(argc, argv);
  44. + argv = saved_argv;
  45. + argv0 = argv;
  46. +#endif
  47. +
  48. while ((ch = getopt(argc, argv, "df:np:P:sSv")) != -1) {
  49. switch (ch) {
  50. case 'd':
  51. --
  52. 2.27.0