summaryrefslogtreecommitdiffstats
path: root/src/libnetdata/spawn_server/spawn_library.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-11-25 14:45:37 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-11-25 14:48:03 +0000
commite55403ed71282d7bfd8b56df219de3c28a8af064 (patch)
tree524889e5becb81643bf8741e3082955dca076f09 /src/libnetdata/spawn_server/spawn_library.c
parentReleasing debian version 1.47.5-1. (diff)
downloadnetdata-e55403ed71282d7bfd8b56df219de3c28a8af064.tar.xz
netdata-e55403ed71282d7bfd8b56df219de3c28a8af064.zip
Merging upstream version 2.0.3+dfsg:
- does not include dygraphs anymore (Closes: #923993) - does not include pako anymore (Closes: #1042533) - does not include dashboard binaries anymore (Closes: #1045145) Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/libnetdata/spawn_server/spawn_library.c')
-rw-r--r--src/libnetdata/spawn_server/spawn_library.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/libnetdata/spawn_server/spawn_library.c b/src/libnetdata/spawn_server/spawn_library.c
new file mode 100644
index 000000000..bdf64544c
--- /dev/null
+++ b/src/libnetdata/spawn_server/spawn_library.c
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#include "spawn_library.h"
+
+BUFFER *argv_to_cmdline_buffer(const char **argv) {
+ BUFFER *wb = buffer_create(0, NULL);
+
+ for(size_t i = 0; argv[i] ;i++) {
+ const char *s = argv[i];
+ size_t len = strlen(s);
+ buffer_need_bytes(wb, len * 2 + 1);
+
+ bool needs_quotes = false;
+ for(const char *c = s; !needs_quotes && *c ; c++) {
+ switch(*c) {
+ case ' ':
+ case '\v':
+ case '\t':
+ case '\n':
+ case '"':
+ needs_quotes = true;
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ if(needs_quotes && buffer_strlen(wb))
+ buffer_strcat(wb, " \"");
+ else if(buffer_strlen(wb))
+ buffer_putc(wb, ' ');
+
+ for(const char *c = s; *c ; c++) {
+ switch(*c) {
+ case '"':
+ buffer_putc(wb, '\\');
+ // fall through
+
+ default:
+ buffer_putc(wb, *c);
+ break;
+ }
+ }
+
+ if(needs_quotes)
+ buffer_strcat(wb, "\"");
+ }
+
+ return wb;
+}