test-process-title.c
Go to the documentation of this file.
1 /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining a copy
4  * of this software and associated documentation files (the "Software"), to
5  * deal in the Software without restriction, including without limitation the
6  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7  * sell copies of the Software, and to permit persons to whom the Software is
8  * furnished to do so, subject to the following conditions:
9  *
10  * The above copyright notice and this permission notice shall be included in
11  * all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19  * IN THE SOFTWARE.
20  */
21 
22 #include "uv.h"
23 #include "task.h"
24 #include <string.h>
25 
26 
27 static void set_title(const char* title) {
28  char buffer[512];
29  int err;
30 
32  ASSERT(err == 0);
33 
34  err = uv_set_process_title(title);
35  ASSERT(err == 0);
36 
38  ASSERT(err == 0);
39 
40  ASSERT(strcmp(buffer, title) == 0);
41 }
42 
43 
45  char buffer[512];
46  int r;
47 
48  /* Test a NULL buffer */
49  r = uv_get_process_title(NULL, 100);
50  ASSERT(r == UV_EINVAL);
51 
52  /* Test size of zero */
54  ASSERT(r == UV_EINVAL);
55 
56  /* Test for insufficient buffer size */
58  ASSERT(r == UV_ENOBUFS);
59 }
60 
61 
63 #if defined(__sun) || defined(__CYGWIN__) || defined(__MSYS__) || \
64  defined(__PASE__)
65  RETURN_SKIP("uv_(get|set)_process_title is not implemented.");
66 #endif
67 
68  /* Check for format string vulnerabilities. */
69  set_title("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s");
70  set_title("new title");
71 
72  /* Check uv_get_process_title() edge cases */
74 
75  return 0;
76 }
77 
78 
79 static void exit_cb(uv_process_t* process, int64_t status, int signo) {
80  ASSERT(status == 0);
81  ASSERT(signo == 0);
82  uv_close((uv_handle_t*) process, NULL);
83 }
84 
85 
89  size_t exepath_size;
90  char exepath[1024];
91  char jumbo[512];
92  char* args[5];
93 
94 #ifdef _WIN32
95  /* Remove once https://github.com/libuv/libuv/issues/2667 is fixed. */
96  uv_set_process_title("run-tests");
97 #endif
98 
99  exepath_size = sizeof(exepath) - 1;
101  exepath[exepath_size] = '\0';
102 
103  memset(jumbo, 'x', sizeof(jumbo) - 1);
104  jumbo[sizeof(jumbo) - 1] = '\0';
105 
106  /* Note: need to pass three arguments, not two, otherwise
107  * run-tests.c thinks it's the name of a test to run.
108  */
109  args[0] = exepath;
110  args[1] = "process_title_big_argv_helper";
111  args[2] = jumbo;
112  args[3] = jumbo;
113  args[4] = NULL;
114 
115  memset(&options, 0, sizeof(options));
116  options.file = exepath;
117  options.args = args;
118  options.exit_cb = exit_cb;
119 
122 
124  return 0;
125 }
126 
127 
128 /* Called by process_title_big_argv_helper. */
130  char buf[256] = "fail";
131 
132  /* Return value deliberately ignored. */
133  uv_get_process_title(buf, sizeof(buf));
134  ASSERT(0 != strcmp(buf, "fail"));
135 }
uv_process_options_s
Definition: uv.h:940
uv_process_s
Definition: uv.h:1037
task.h
memset
return memset(p, 0, total)
string.h
options
double_dict options[]
Definition: capstone_test.c:55
buf
voidpf void * buf
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
error_ref_leak.err
err
Definition: error_ref_leak.py:35
ASSERT
#define ASSERT(expr)
Definition: task.h:102
status
absl::Status status
Definition: rls.cc:251
uv_run
UV_EXTERN int uv_run(uv_loop_t *, uv_run_mode mode)
Definition: unix/core.c:361
process_title_big_argv
void process_title_big_argv(void)
Definition: test-process-title.c:129
set_title
static void set_title(const char *title)
Definition: test-process-title.c:27
uv_close
UV_EXTERN void uv_close(uv_handle_t *handle, uv_close_cb close_cb)
Definition: unix/core.c:112
exepath
static char exepath[1024]
Definition: benchmark-spawn.c:34
uv_default_loop
UV_EXTERN uv_loop_t * uv_default_loop(void)
Definition: uv-common.c:733
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
process
static uv_process_t process
Definition: benchmark-spawn.c:32
int64_t
signed __int64 int64_t
Definition: stdint-msvc2008.h:89
UV_RUN_DEFAULT
@ UV_RUN_DEFAULT
Definition: uv.h:254
uv_get_process_title_edge_cases
static void uv_get_process_title_edge_cases(void)
Definition: test-process-title.c:44
uv_set_process_title
UV_EXTERN int uv_set_process_title(const char *title)
Definition: aix.c:875
buffer
char buffer[1024]
Definition: libuv/docs/code/idle-compute/main.c:8
exit_cb
static void exit_cb(uv_process_t *process, int64_t status, int signo)
Definition: test-process-title.c:79
uv_spawn
UV_EXTERN int uv_spawn(uv_loop_t *loop, uv_process_t *handle, const uv_process_options_t *options)
Definition: unix/process.c:408
uv_exepath
UV_EXTERN int uv_exepath(char *buffer, size_t *size)
Definition: aix-common.c:79
uv.h
MAKE_VALGRIND_HAPPY
#define MAKE_VALGRIND_HAPPY()
Definition: task.h:229
exepath_size
static size_t exepath_size
Definition: benchmark-spawn.c:35
fix_build_deps.r
r
Definition: fix_build_deps.py:491
RETURN_SKIP
#define RETURN_SKIP(explanation)
Definition: task.h:262
process_title
static char * process_title
Definition: bsd-proctitle.c:31
uv_handle_s
Definition: uv.h:441
TEST_IMPL
TEST_IMPL(process_title)
Definition: test-process-title.c:62
uv_get_process_title
UV_EXTERN int uv_get_process_title(char *buffer, size_t size)
Definition: aix.c:906


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:30