pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnf41client: Patch for nfsd help options, release build infrastructure, tests+misc, 2024-08-31
Posted by Anonymous on Sat 31st Aug 2024 15:54
raw | new post

  1. From 5a7044ec5b517a74f52c2cb442a6b67d9680f23a Mon Sep 17 00:00:00 2001
  2. From: Roland Mainz <roland.mainz@nrubsig.org>
  3. Date: Sat, 31 Aug 2024 13:47:54 +0200
  4. Subject: [PATCH 1/5] daemon: nfsd_debug should support --help+/? and reject
  5.  unknown options
  6.  
  7. nfsd_debug.exe should support --help and /? options, and reject
  8. unknown options.
  9.  
  10. Reported-by: Martin Wege <martin.l.wege@gmail.com>
  11. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  12. ---
  13. daemon/nfs41_daemon.c | 74 ++++++++++++++++++++++++-------------------
  14.  1 file changed, 41 insertions(+), 33 deletions(-)
  15.  
  16. diff --git a/daemon/nfs41_daemon.c b/daemon/nfs41_daemon.c
  17. index 8f30607..8904afc 100644
  18. --- a/daemon/nfs41_daemon.c
  19. +++ b/daemon/nfs41_daemon.c
  20. @@ -259,18 +259,20 @@ static bool_t check_for_files()
  21.      return TRUE;
  22.  }
  23.  
  24. -static void PrintUsage()
  25. +static void PrintUsage(const wchar_t *argv0)
  26.  {
  27. -    (void)fprintf(stderr, "Usage: nfsd.exe -d <debug_level> "
  28. -        "--noldap "
  29. -        "--uid <non-zero value> "
  30. -        "--gid <non-zero value> "
  31. -        "--numworkerthreads <value-between 16 and %d> "
  32. +    (void)fprintf(stderr, "Usage: %S [options]\n"
  33. +        "\t-h, --help, /?  help\n"
  34. +        "\t-d <debug_level>\n"
  35. +        "\t--noldap\n"
  36. +        "\t--uid <non-zero value>\n"
  37. +        "\t--gid <non-zero value>\n"
  38. +        "\t--numworkerthreads <value-between 16 and %d>\n"
  39.  #ifdef _DEBUG
  40. -        "--crtdbgmem <'allocmem'|'leakcheck'|'delayfree', "
  41. -            "'all', 'none' or 'default'> "
  42. +        "\t--crtdbgmem <'allocmem'|'leakcheck'|'delayfree',\n"
  43. +            "\t\t'all', 'none' or 'default'>\n"
  44.  #endif /* _DEBUG */
  45. -        "\n", MAX_NUM_THREADS);
  46. +        , argv0, MAX_NUM_THREADS);
  47.  }
  48.  
  49.  static
  50. @@ -285,15 +287,16 @@ bool_t parse_cmdlineargs(int argc, wchar_t *argv[], nfsd_args *out)
  51.      /* parse command line */
  52.      for (i = 1; i < argc; i++) {
  53.          if (argv[i][0] == L'-') {
  54. -            if (!wcscmp(argv[i], L"-h")) { /* help */
  55. -                PrintUsage();
  56. +            if ((!wcscmp(argv[i], L"-h")) ||
  57. +                (!wcscmp(argv[i], L"--help"))) { /* help */
  58. +                PrintUsage(argv[0]);
  59.                  return FALSE;
  60.              }
  61.              else if (!wcscmp(argv[i], L"-d")) { /* debug level */
  62.                  ++i;
  63.                  if (i >= argc) {
  64. -                    fprintf(stderr, "Missing debug level value\n");
  65. -                    PrintUsage();
  66. +                    (void)fprintf(stderr,
  67. +                        "%S: Missing debug level value\n", argv[0]);
  68.                      return FALSE;
  69.                  }
  70.                  out->debug_level = wcstol(argv[i], NULL, 0);
  71. @@ -303,8 +306,9 @@ bool_t parse_cmdlineargs(int argc, wchar_t *argv[], nfsd_args *out)
  72.                  ++i;
  73.                  const wchar_t *memdbgoptions = argv[i];
  74.                  if (i >= argc) {
  75. -                    fprintf(stderr, "Missing options\n");
  76. -                    PrintUsage();
  77. +                    (void)fprintf(stderr,
  78. +                        "%S: Missing options for --crtdbgmem\n",
  79. +                        argv[0]);
  80.                      return FALSE;
  81.                  }
  82.  
  83. @@ -341,22 +345,15 @@ bool_t parse_cmdlineargs(int argc, wchar_t *argv[], nfsd_args *out)
  84.              else if (!wcscmp(argv[i], L"--uid")) { /* no LDAP, setting default uid */
  85.                  ++i;
  86.                  if (i >= argc) {
  87. -                    fprintf(stderr, "Missing uid value\n");
  88. -                    PrintUsage();
  89. +                    (void)fprintf(stderr, "%S: Missing uid value\n", argv[0]);
  90.                      return FALSE;
  91.                  }
  92.                  nfs41_dg.default_uid = wcstol(argv[i], NULL, 0);
  93. -                if (!nfs41_dg.default_uid) {
  94. -                    fprintf(stderr, "Invalid (or missing) anonymous uid value of %d\n",
  95. -                        nfs41_dg.default_uid);
  96. -                    return FALSE;
  97. -                }
  98.              }
  99.              else if (!wcscmp(argv[i], L"--gid")) { /* no LDAP, setting default gid */
  100.                  ++i;
  101.                  if (i >= argc) {
  102. -                    fprintf(stderr, "Missing gid value\n");
  103. -                    PrintUsage();
  104. +                    (void)fprintf(stderr, "%S: Missing gid value\n", argv[0]);
  105.                      return FALSE;
  106.                  }
  107.                  nfs41_dg.default_gid = wcstol(argv[i], NULL, 0);
  108. @@ -364,27 +361,38 @@ bool_t parse_cmdlineargs(int argc, wchar_t *argv[], nfsd_args *out)
  109.              else if (!wcscmp(argv[i], L"--numworkerthreads")) {
  110.                  ++i;
  111.                  if (i >= argc) {
  112. -                    fprintf(stderr, "Missing value for num_worker_threads\n");
  113. -                    PrintUsage();
  114. +                    (void)fprintf(stderr,
  115. +                        "%S: Missing value for num_worker_threads\n",
  116. +                        argv[0]);
  117.                      return FALSE;
  118.                  }
  119.                  nfs41_dg.num_worker_threads = wcstol(argv[i], NULL, 0);
  120.                  if (nfs41_dg.num_worker_threads < 16) {
  121. -                    fprintf(stderr, "--numworkerthreads requires at least 16 worker threads\n");
  122. -                    PrintUsage();
  123. +                    (void)fprintf(stderr,
  124. +                        "%S: --numworkerthreads requires at least "
  125. +                        "16 worker threads\n", argv[0]);
  126.                      return FALSE;
  127.                  }
  128.                  if (nfs41_dg.num_worker_threads >= MAX_NUM_THREADS) {
  129. -                    fprintf(stderr,
  130. +                    (void)fprintf(stderr, "%S: "
  131.                          "--numworkerthreads supports a maximum of "
  132.                          "%d worker threads\n",
  133. -                        MAX_NUM_THREADS);
  134. -                    PrintUsage();
  135. +                        argv[0], MAX_NUM_THREADS);
  136.                      return FALSE;
  137.                  }
  138.              }
  139. -            else
  140. -                fprintf(stderr, "Unrecognized option '%S', disregarding.\n", argv[i]);
  141. +            else {
  142. +                (void)fprintf(stderr,
  143. +                    "%S: Unrecognized option '%S'\n",
  144. +                    argv[0], argv[i]);
  145. +                return FALSE;
  146. +            }
  147. +        }
  148. +        else {
  149. +            if (!wcscmp(argv[i], L"/?")) { /* help */
  150. +                PrintUsage(argv[0]);
  151. +                return FALSE;
  152. +            }
  153.          }
  154.      }
  155.  
  156. --
  157. 2.45.1
  158.  
  159. From c456405672085766643256a45fea28bcebc4b03f Mon Sep 17 00:00:00 2001
  160. From: Roland Mainz <roland.mainz@nrubsig.org>
  161. Date: Sat, 31 Aug 2024 14:03:39 +0200
  162. Subject: [PATCH 2/5] daemon: Release/nfsd -debug prints warning about -debug
  163.  not recognized
  164.  
  165. Running Release/nfsd in debug mode with $ ./nfsd -debug # prints
  166. warning a about -debug not recognized, which in this case
  167. is a valid option.
  168.  
  169. Reported-by: Martin Wege <martin.l.wege@gmail.com>
  170. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  171. ---
  172. daemon/nfs41_daemon.c | 12 ++++++++++++
  173.  1 file changed, 12 insertions(+)
  174.  
  175. diff --git a/daemon/nfs41_daemon.c b/daemon/nfs41_daemon.c
  176. index 8904afc..258889d 100644
  177. --- a/daemon/nfs41_daemon.c
  178. +++ b/daemon/nfs41_daemon.c
  179. @@ -285,7 +285,12 @@ bool_t parse_cmdlineargs(int argc, wchar_t *argv[], nfsd_args *out)
  180.      out->ldap_enable = TRUE;
  181.  
  182.      /* parse command line */
  183. +#ifdef STANDALONE_NFSD
  184. +    /* Options from |CmdDebugService()| start at index 0 ... */
  185. +    for (i = 0; i < argc; i++) {
  186. +#else
  187.      for (i = 1; i < argc; i++) {
  188. +#endif
  189.          if (argv[i][0] == L'-') {
  190.              if ((!wcscmp(argv[i], L"-h")) ||
  191.                  (!wcscmp(argv[i], L"--help"))) { /* help */
  192. @@ -381,6 +386,13 @@ bool_t parse_cmdlineargs(int argc, wchar_t *argv[], nfsd_args *out)
  193.                      return FALSE;
  194.                  }
  195.              }
  196. +            /*
  197. +             * -Debug/-debug might be passed as first option in a
  198. +             * Release build to switch nfsd to debug mode
  199. +             */
  200. +            else if (!_wcsicmp(argv[i], L"-debug")) {
  201. +                /* ignored, nothing to do here */
  202. +            }
  203.              else {
  204.                  (void)fprintf(stderr,
  205.                      "%S: Unrecognized option '%S'\n",
  206. --
  207. 2.45.1
  208.  
  209. From 5a34b4f1062b54a9e5c7ccf2263e5473f53463c8 Mon Sep 17 00:00:00 2001
  210. From: Roland Mainz <roland.mainz@nrubsig.org>
  211. Date: Sat, 31 Aug 2024 15:15:49 +0200
  212. Subject: [PATCH 3/5] cygwin,daemon: Add infratructure to run Release builds
  213.  from msnfs41client
  214.  
  215. Add infratructure to run Release builds from msnfs41client.
  216.  
  217. Reported-by: Martin Wege <martin.l.wege@gmail.com>
  218. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  219. ---
  220. cygwin/Makefile                 |  6 ++++--
  221.  cygwin/devel/msnfs41client.bash | 22 ++++++++++++----------
  222.  daemon/nfs41_daemon.c           |  6 +++++-
  223.  3 files changed, 21 insertions(+), 13 deletions(-)
  224.  
  225. diff --git a/cygwin/Makefile b/cygwin/Makefile
  226. index 8a2a7b5..e7125bb 100644
  227. --- a/cygwin/Makefile
  228. +++ b/cygwin/Makefile
  229. @@ -15,6 +15,8 @@ DESTDIR:=$(PROJECT_BASEDIR_DIR)/destdir
  230.  
  231.  VS_BUILD_DIR32:=$(PROJECT_BASEDIR_DIR)/build.vc19/Debug/
  232.  VS_BUILD_DIR64:=$(PROJECT_BASEDIR_DIR)/build.vc19/x64/Debug/
  233. +#VS_BUILD_DIR32:=$(PROJECT_BASEDIR_DIR)/build.vc19/Release/
  234. +#VS_BUILD_DIR64:=$(PROJECT_BASEDIR_DIR)/build.vc19/x64/Release/
  235.  
  236.  # trigger "build" target when these binaries are needed
  237.  $(VS_BUILD_DIR32)/nfsd.exe \
  238. @@ -98,12 +100,12 @@ installdest: \
  239.         # installdest 32bit Windows
  240.         make -f $(CYGWIN_MAKEFILE_DIR)/Makefile.install \
  241.                 installdest \
  242. -               VS_BUILD_DIR="$(PROJECT_BASEDIR_DIR)/build.vc19/Debug/" \
  243. +               VS_BUILD_DIR="$(VS_BUILD_DIR32)" \
  244.                 CYGWIN_BASEPATH=/cygdrive/c/cygwin/
  245.         # installdest 64bit Windows
  246.         make -f $(CYGWIN_MAKEFILE_DIR)/Makefile.install \
  247.                 installdest \
  248. -               VS_BUILD_DIR="$(PROJECT_BASEDIR_DIR)/build.vc19/x64/Debug/" \
  249. +               VS_BUILD_DIR="$(VS_BUILD_DIR64)" \
  250.                 CYGWIN_BASEPATH=/cygdrive/c/cygwin64/
  251.  
  252.  bintarball: installdest
  253. diff --git a/cygwin/devel/msnfs41client.bash b/cygwin/devel/msnfs41client.bash
  254. index 7895e9f..352344a 100644
  255. --- a/cygwin/devel/msnfs41client.bash
  256. +++ b/cygwin/devel/msnfs41client.bash
  257. @@ -271,7 +271,8 @@ function nfsclient_rundeamon
  258.         set -o xtrace
  259.  
  260.         typeset -a nfsd_args=(
  261. -               'nfsd_debug.exe'
  262. +               'nfsd.exe'
  263. +               '-debug'
  264.                 '-d' '0'
  265.                 '--noldap'
  266.                 #'--numworkerthreads' '512'
  267. @@ -310,7 +311,7 @@ function nfsclient_rundeamon
  268.                 "${nfsd_args[@]}"
  269.         elif false ; then
  270.                 #
  271. -               # test nfsd_debug.exe with Dr. Memory (version 2.6.0 -- build 0)
  272. +               # test nfsd.exe with Dr. Memory (version 2.6.0 -- build 0)
  273.                 #
  274.                 export _NT_ALT_SYMBOL_PATH="$(cygpath -w "$PWD")"
  275.                 nfsd_args=(
  276. @@ -336,19 +337,19 @@ function nfsclient_rundeamon
  277.  
  278.                 # Killing DrMemory with <CTRL-C> does not terminate nfsd,
  279.                 # so we have to do it ourselves
  280. -               trap 'taskkill /F /IM nfsd_debug.exe' SIGINT SIGTERM
  281. +               trap 'taskkill /F /IM nfsd.exe' SIGINT SIGTERM
  282.  
  283.                 "${nfsd_args[@]}"
  284.         elif false ; then
  285.                 typeset -i vsdiagnostics_id=50
  286.                 VSDiagnostics \
  287.                         start ${vsdiagnostics_id} \
  288. -                       "/launch:$(cygpath -w "$PWD/nfsd_debug.exe")" \
  289. +                       "/launch:$(cygpath -w "$PWD/nfsd.exe")" \
  290.                         "/launchArgs:${nfsd_args[*]:1}" \
  291.                         "/loadConfig:$(cygpath -w "${vsdiagnostics_path}/AgentConfigs/CpuUsageHigh.json")"
  292.                 printf '#\n'
  293.                 printf '# use\n'
  294. -               printf '# $ "%s" stop %d /output:nfsd_debug%d # to collect profiling data\n#\n' \
  295. +               printf '# $ "%s" stop %d /output:nfsd%d # to collect profiling data\n#\n' \
  296.                         "$(which -a 'VSDiagnostics.exe')" \
  297.                         "${vsdiagnostics_id}" "$$"
  298.         else
  299. @@ -374,7 +375,8 @@ function nfsclient_system_rundeamon
  300.         set -o xtrace
  301.  
  302.         typeset -a nfsd_args=(
  303. -               'nfsd_debug.exe'
  304. +               'nfsd.exe'
  305. +               '-debug'
  306.                 '-d' '0'
  307.                 '--noldap'
  308.                 #'--numworkerthreads' '512'
  309. @@ -427,7 +429,7 @@ function nfsclient_system_rundeamon
  310.                 "${nfsd_args[@]}"
  311.         elif false ; then
  312.                 #
  313. -               # test nfsd_debug.exe with Dr. Memory (version 2.6.0 -- build 0)
  314. +               # test nfsd.exe with Dr. Memory (version 2.6.0 -- build 0)
  315.                 #
  316.                 export _NT_ALT_SYMBOL_PATH="$(cygpath -w "$PWD")"
  317.                 nfsd_args=(
  318. @@ -459,7 +461,7 @@ function nfsclient_system_rundeamon
  319.  
  320.                 # Killing DrMemory with <CTRL-C> does not terminate nfsd,
  321.                 # so we have to do it ourselves
  322. -               trap 'taskkill /F /IM nfsd_debug.exe' SIGINT SIGTERM
  323. +               trap 'taskkill /F /IM nfsd.exe' SIGINT SIGTERM
  324.  
  325.                 "${nfsd_args[@]}"
  326.         elif false ; then
  327. @@ -467,12 +469,12 @@ function nfsclient_system_rundeamon
  328.                 # run everything as su_system
  329.                 su_system VSDiagnostics \
  330.                         start ${vsdiagnostics_id} \
  331. -                       "/launch:$(cygpath -w "$PWD/nfsd_debug.exe")" \
  332. +                       "/launch:$(cygpath -w "$PWD/nfsd.exe")" \
  333.                         "/launchArgs:${nfsd_args[*]:1}" \
  334.                         "/loadConfig:$(cygpath -w "${vsdiagnostics_path}/AgentConfigs/CpuUsageHigh.json")"
  335.                 printf '#\n'
  336.                 printf '# use\n'
  337. -               printf '# $ "%s" stop %d /output:nfsd_debug%d # to collect profiling data\n#\n' \
  338. +               printf '# $ "%s" stop %d /output:nfsd%d # to collect profiling data\n#\n' \
  339.                         "$(which -a 'VSDiagnostics.exe')" \
  340.                         "${vsdiagnostics_id}" "$$"
  341.         else
  342. diff --git a/daemon/nfs41_daemon.c b/daemon/nfs41_daemon.c
  343. index 258889d..06730c3 100644
  344. --- a/daemon/nfs41_daemon.c
  345. +++ b/daemon/nfs41_daemon.c
  346. @@ -752,7 +752,11 @@ VOID ServiceStart(DWORD argc, LPTSTR *argv)
  347.      DPRINTF(0, ("SID cache disabled\n"));
  348.  #endif /* NFS41_DRIVER_SID_CACHE */
  349.  
  350. -    logprintf("NFS client daemon starting...\n");
  351. +#ifdef _DEBUG
  352. +    logprintf("NFS client daemon (DEBUG build) starting...\n");
  353. +#else
  354. +    logprintf("NFS client daemon (Release build) starting...\n");
  355. +#endif
  356.  
  357.      /* Enable Win32 privileges */
  358.      set_nfs_daemon_privileges();
  359. --
  360. 2.45.1
  361.  
  362. From b2fd3226d3818bf81f0c373b4bed8388108c61bb Mon Sep 17 00:00:00 2001
  363. From: Roland Mainz <roland.mainz@nrubsig.org>
  364. Date: Sat, 31 Aug 2024 15:18:20 +0200
  365. Subject: [PATCH 4/5] daemon: Release build nfsd crashes without -d 1
  366.  
  367. Release build nfsd crashes without -d 1, because the log file
  368. was not opened yet.
  369.  
  370. Reported-by: Martin Wege <martin.l.wege@gmail.com>
  371. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  372. ---
  373. daemon/daemon_debug.c | 17 ++++++++++-------
  374.  1 file changed, 10 insertions(+), 7 deletions(-)
  375.  
  376. diff --git a/daemon/daemon_debug.c b/daemon/daemon_debug.c
  377. index ad685ce..77e5e97 100644
  378. --- a/daemon/daemon_debug.c
  379. +++ b/daemon/daemon_debug.c
  380. @@ -47,18 +47,21 @@ void open_log_files()
  381.      const char dfile[] = "nfsddbg.log";
  382.      const char efile[] = "nfsderr.log";
  383.      const char mode[] = "w";
  384. -    if (g_debug_level > 0) {
  385. -        dlog_file = fopen(dfile, mode);
  386. -        if (dlog_file == NULL) {
  387. -            ReportStatusToSCMgr(SERVICE_STOPPED, GetLastError(), 0);
  388. -            exit (GetLastError());
  389. -        }
  390. -    }
  391. +
  392. +    (void)remove(efile);
  393. +    (void)remove(dfile);
  394. +
  395.      elog_file = fopen(efile, mode);
  396.      if (elog_file == NULL) {
  397.          ReportStatusToSCMgr(SERVICE_STOPPED, GetLastError(), 0);
  398.          exit (GetLastError());
  399.      }
  400. +
  401. +    dlog_file = fopen(dfile, mode);
  402. +    if (dlog_file == NULL) {
  403. +        ReportStatusToSCMgr(SERVICE_STOPPED, GetLastError(), 0);
  404. +        exit (GetLastError());
  405. +    }
  406.  }
  407.  
  408.  void close_log_files()
  409. --
  410. 2.45.1
  411.  
  412. From e7f25bc0dee349708d65b1d09fb0a4a49fea2c06 Mon Sep 17 00:00:00 2001
  413. From: Roland Mainz <roland.mainz@nrubsig.org>
  414. Date: Sat, 31 Aug 2024 16:43:42 +0200
  415. Subject: [PATCH 5/5] tests: Document how to set up Windows local user mode
  416.  crash dumps
  417.  
  418. Document how to set up Windows local user mode crash dumps, see
  419. https://learn.microsoft.com/en-us/windows/win32/wer/collecting-user-mode-dumps
  420.  
  421. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  422. ---
  423. tests/manual_testing.txt | 15 +++++++++++++++
  424.  1 file changed, 15 insertions(+)
  425.  
  426. diff --git a/tests/manual_testing.txt b/tests/manual_testing.txt
  427. index 154b8d3..ec8cf17 100644
  428. --- a/tests/manual_testing.txt
  429. +++ b/tests/manual_testing.txt
  430. @@ -86,6 +86,21 @@
  431.  #     $ PATH+=':/cygdrive/c/Program Files (x86)/Windows Kits/10/Debuggers/x64/'
  432.  #     $ kd -loga kdlog.log -k net:port=50000,key=1.1.1.1,target=10.49.202.87 #
  433.  #
  434. +# - Windows local crash dumps setup (for non-Cygwin apps)
  435. +#   (see https://learn.microsoft.com/en-us/windows/win32/wer/collecting-user-mode-dumps):
  436. +#   ---- snip -----
  437. +#   # enable crash dumps globally
  438. +#   regtool add '/HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/Windows Error Reporting/LocalDumps'
  439. +#   regtool -i set '/HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/Windows Error Reporting/LocalDumps/DumpType' 2
  440. +#   mkdir -p "$(cygpath -u "$(echo $LOCALAPPDATA)")/CrashDumps"
  441. +#   # list generated crash dumps
  442. +#   ls -la "$(cygpath -u "$(echo $LOCALAPPDATA)")/CrashDumps"
  443. +#   # get stack trace for crash dump "link.exe.1640.dmp"
  444. +#   PATH+=':/cygdrive/c/Program Files (x86)/Windows Kits/10/Debuggers/x64/'
  445. +#   cdb -z "${LOCALAPPDATA}\CrashDumps\link.exe.1640.dmp" -c '!analyze -v ; q'
  446. +#   ---- snip -----
  447. +#
  448. +
  449.  
  450.  #
  451.  # Tests for cp -p/mv/chmod/chgrp
  452. --
  453. 2.45.1

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at