bsd-proctitle.c
Go to the documentation of this file.
1 /* Copyright libuv project 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 "internal.h"
24 
25 #include <sys/types.h>
26 #include <unistd.h>
27 
28 
31 static char* process_title;
32 
33 
34 static void init_process_title_mutex_once(void) {
36  abort();
37 }
38 
39 
40 char** uv_setup_args(int argc, char** argv) {
41  process_title = argc > 0 ? uv__strdup(argv[0]) : NULL;
42  return argv;
43 }
44 
45 
46 int uv_set_process_title(const char* title) {
47  char* new_title;
48 
49  new_title = uv__strdup(title);
50  if (new_title == NULL)
51  return UV_ENOMEM;
52 
55 
57  process_title = new_title;
58  setproctitle("%s", title);
59 
61 
62  return 0;
63 }
64 
65 
66 int uv_get_process_title(char* buffer, size_t size) {
67  size_t len;
68 
69  if (buffer == NULL || size == 0)
70  return UV_EINVAL;
71 
74 
75  if (process_title != NULL) {
76  len = strlen(process_title) + 1;
77 
78  if (size < len) {
80  return UV_ENOBUFS;
81  }
82 
84  } else {
85  len = 0;
86  }
87 
89 
90  buffer[len] = '\0';
91 
92  return 0;
93 }
uv_mutex_init
UV_EXTERN int uv_mutex_init(uv_mutex_t *handle)
Definition: libuv/src/unix/thread.c:281
uv_setup_args
char ** uv_setup_args(int argc, char **argv)
Definition: bsd-proctitle.c:40
uv_get_process_title
int uv_get_process_title(char *buffer, size_t size)
Definition: bsd-proctitle.c:66
init_process_title_mutex_once
static void init_process_title_mutex_once(void)
Definition: bsd-proctitle.c:34
process_title_mutex_once
static uv_once_t process_title_mutex_once
Definition: bsd-proctitle.c:30
uv_set_process_title
int uv_set_process_title(const char *title)
Definition: bsd-proctitle.c:46
memcpy
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
uv_once
UV_EXTERN void uv_once(uv_once_t *guard, void(*callback)(void))
Definition: libuv/src/unix/thread.c:418
uv__strdup
char * uv__strdup(const char *s)
Definition: uv-common.c:55
uv_once_t
pthread_once_t uv_once_t
Definition: unix.h:133
uv__free
void uv__free(void *ptr)
Definition: uv-common.c:81
uv_mutex_t
pthread_mutex_t uv_mutex_t
Definition: unix.h:135
buffer
char buffer[1024]
Definition: libuv/docs/code/idle-compute/main.c:8
uv_mutex_unlock
UV_EXTERN void uv_mutex_unlock(uv_mutex_t *handle)
Definition: libuv/src/unix/thread.c:349
uv.h
internal.h
process_title_mutex
static uv_mutex_t process_title_mutex
Definition: bsd-proctitle.c:29
uv_mutex_lock
UV_EXTERN void uv_mutex_lock(uv_mutex_t *handle)
Definition: libuv/src/unix/thread.c:329
process_title
static char * process_title
Definition: bsd-proctitle.c:31
UV_ONCE_INIT
#define UV_ONCE_INIT
Definition: unix.h:131
len
int len
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:46
size
voidpf void uLong size
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:40