2 * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
3 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 * Copyright (C) 2019 Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 * SPDX-License-Identifier: GPL-2.0-only
17 #include <sys/types.h>
26 #include <common/lttng-kernel.h>
27 #include <common/common.h>
28 #include <common/utils.h>
29 #include <common/compat/getenv.h>
30 #include <common/compat/prctl.h>
31 #include <common/compat/string.h>
32 #include <common/unix.h>
33 #include <common/defaults.h>
34 #include <common/lttng-elf.h>
36 #include <lttng/constant.h>
38 #include <common/sessiond-comm/sessiond-comm.h>
39 #include <common/filter/filter-ast.h>
40 #include <common/filter/filter-bytecode.h>
46 typedef int (*run_as_fct
)(struct run_as_data
*data
, struct run_as_ret
*ret_value
);
51 RUN_AS_MKDIR_RECURSIVE
,
52 RUN_AS_MKDIRAT_RECURSIVE
,
59 RUN_AS_RMDIR_RECURSIVE
,
60 RUN_AS_RMDIRAT_RECURSIVE
,
63 RUN_AS_EXTRACT_ELF_SYMBOL_OFFSET
,
64 RUN_AS_EXTRACT_SDT_PROBE_OFFSETS
,
65 RUN_AS_GENERATE_FILTER_BYTECODE
,
68 struct run_as_mkdir_data
{
70 char path
[LTTNG_PATH_MAX
];
74 struct run_as_open_data
{
76 char path
[LTTNG_PATH_MAX
];
81 struct run_as_unlink_data
{
83 char path
[LTTNG_PATH_MAX
];
86 struct run_as_rmdir_data
{
88 char path
[LTTNG_PATH_MAX
];
89 int flags
; /* enum lttng_directory_handle_rmdir_recursive_flags */
92 struct run_as_extract_elf_symbol_offset_data
{
94 char function
[LTTNG_SYMBOL_NAME_LEN
];
97 struct run_as_extract_sdt_probe_offsets_data
{
99 char probe_name
[LTTNG_SYMBOL_NAME_LEN
];
100 char provider_name
[LTTNG_SYMBOL_NAME_LEN
];
103 struct run_as_generate_filter_bytecode_data
{
104 char filter_expression
[LTTNG_FILTER_MAX_LEN
];
107 struct run_as_rename_data
{
113 char old_path
[LTTNG_PATH_MAX
];
114 char new_path
[LTTNG_PATH_MAX
];
117 struct run_as_open_ret
{
121 struct run_as_extract_elf_symbol_offset_ret
{
125 struct run_as_extract_sdt_probe_offsets_ret
{
127 uint64_t offsets
[LTTNG_KERNEL_MAX_UPROBE_NUM
];
130 struct run_as_generate_filter_bytecode_ret
{
131 /* A lttng_bytecode_filter strcut with "dynamic" payload */
132 char bytecode
[LTTNG_FILTER_MAX_LEN
];
138 struct run_as_mkdir_data mkdir
;
139 struct run_as_open_data open
;
140 struct run_as_unlink_data unlink
;
141 struct run_as_rmdir_data rmdir
;
142 struct run_as_rename_data rename
;
143 struct run_as_extract_elf_symbol_offset_data extract_elf_symbol_offset
;
144 struct run_as_extract_sdt_probe_offsets_data extract_sdt_probe_offsets
;
145 struct run_as_generate_filter_bytecode_data generate_filter_bytecode
;
152 * The run_as_ret structure holds the returned value and status of the command.
154 * The `u` union field holds the return value of the command; in most cases it
155 * represents the success or the failure of the command. In more complex
156 * commands, it holds a computed value.
158 * The _errno field is the errno recorded after the execution of the command.
160 * The _error fields is used the signify that return status of the command. For
161 * simple commands returning `int` the _error field will be the same as the
162 * ret_int field. In complex commands, it signify the success or failure of the
169 struct run_as_open_ret open
;
170 struct run_as_extract_elf_symbol_offset_ret extract_elf_symbol_offset
;
171 struct run_as_extract_sdt_probe_offsets_ret extract_sdt_probe_offsets
;
172 struct run_as_generate_filter_bytecode_ret generate_filter_bytecode
;
178 #define COMMAND_IN_FDS(data_ptr) ({ \
180 if (command_properties[data_ptr->cmd].in_fds_offset != -1) { \
181 fds = (int *) ((char *) data_ptr + command_properties[data_ptr->cmd].in_fds_offset); \
186 #define COMMAND_OUT_FDS(cmd, ret_ptr) ({ \
188 if (command_properties[cmd].out_fds_offset != -1) { \
189 fds = (int *) ((char *) ret_ptr + command_properties[cmd].out_fds_offset); \
194 #define COMMAND_IN_FD_COUNT(data_ptr) ({ \
195 command_properties[data_ptr->cmd].in_fd_count; \
198 #define COMMAND_OUT_FD_COUNT(cmd) ({ \
199 command_properties[cmd].out_fd_count; \
202 #define COMMAND_USE_CWD_FD(data_ptr) command_properties[data_ptr->cmd].use_cwd_fd
204 struct run_as_command_properties
{
205 /* Set to -1 when not applicable. */
206 ptrdiff_t in_fds_offset
, out_fds_offset
;
207 unsigned int in_fd_count
, out_fd_count
;
211 static const struct run_as_command_properties command_properties
[] = {
213 .in_fds_offset
= offsetof(struct run_as_data
, u
.mkdir
.dirfd
),
215 .out_fds_offset
= -1,
220 .in_fds_offset
= offsetof(struct run_as_data
, u
.mkdir
.dirfd
),
222 .out_fds_offset
= -1,
226 [RUN_AS_MKDIR_RECURSIVE
] = {
227 .in_fds_offset
= offsetof(struct run_as_data
, u
.mkdir
.dirfd
),
229 .out_fds_offset
= -1,
233 [RUN_AS_MKDIRAT_RECURSIVE
] = {
234 .in_fds_offset
= offsetof(struct run_as_data
, u
.mkdir
.dirfd
),
236 .out_fds_offset
= -1,
241 .in_fds_offset
= offsetof(struct run_as_data
, u
.open
.dirfd
),
243 .out_fds_offset
= offsetof(struct run_as_ret
, u
.open
.fd
),
248 .in_fds_offset
= offsetof(struct run_as_data
, u
.open
.dirfd
),
250 .out_fds_offset
= offsetof(struct run_as_ret
, u
.open
.fd
),
255 .in_fds_offset
= offsetof(struct run_as_data
, u
.unlink
.dirfd
),
257 .out_fds_offset
= -1,
261 [RUN_AS_UNLINKAT
] = {
262 .in_fds_offset
= offsetof(struct run_as_data
, u
.unlink
.dirfd
),
264 .out_fds_offset
= -1,
268 [RUN_AS_RMDIR_RECURSIVE
] = {
269 .in_fds_offset
= offsetof(struct run_as_data
, u
.rmdir
.dirfd
),
271 .out_fds_offset
= -1,
275 [RUN_AS_RMDIRAT_RECURSIVE
] = {
276 .in_fds_offset
= offsetof(struct run_as_data
, u
.rmdir
.dirfd
),
278 .out_fds_offset
= -1,
283 .in_fds_offset
= offsetof(struct run_as_data
, u
.rmdir
.dirfd
),
285 .out_fds_offset
= -1,
290 .in_fds_offset
= offsetof(struct run_as_data
, u
.rmdir
.dirfd
),
292 .out_fds_offset
= -1,
297 .in_fds_offset
= offsetof(struct run_as_data
, u
.rename
.dirfds
),
299 .out_fds_offset
= -1,
303 [RUN_AS_RENAMEAT
] = {
304 .in_fds_offset
= offsetof(struct run_as_data
, u
.rename
.dirfds
),
306 .out_fds_offset
= -1,
310 [RUN_AS_EXTRACT_ELF_SYMBOL_OFFSET
] = {
311 .in_fds_offset
= offsetof(struct run_as_data
,
312 u
.extract_elf_symbol_offset
.fd
),
314 .out_fds_offset
= -1,
318 [RUN_AS_EXTRACT_SDT_PROBE_OFFSETS
] = {
319 .in_fds_offset
= offsetof(struct run_as_data
,
320 u
.extract_sdt_probe_offsets
.fd
),
322 .out_fds_offset
= -1,
326 [RUN_AS_GENERATE_FILTER_BYTECODE
] = {
329 .out_fds_offset
= -1,
335 struct run_as_worker
{
336 pid_t pid
; /* Worker PID. */
341 /* Single global worker per process (for now). */
342 static struct run_as_worker
*global_worker
;
343 /* Lock protecting the worker. */
344 static pthread_mutex_t worker_lock
= PTHREAD_MUTEX_INITIALIZER
;
356 return !lttng_secure_getenv("LTTNG_DEBUG_NOCLONE");
361 * Create recursively directory using the FULL path.
364 int _mkdirat_recursive(struct run_as_data
*data
, struct run_as_ret
*ret_value
)
368 struct lttng_directory_handle
*handle
;
370 path
= data
->u
.mkdir
.path
;
371 mode
= data
->u
.mkdir
.mode
;
373 handle
= lttng_directory_handle_create_from_dirfd(data
->u
.mkdir
.dirfd
);
375 ret_value
->_errno
= errno
;
376 ret_value
->_error
= true;
377 ret_value
->u
.ret
= -1;
380 /* Ownership of dirfd is transferred to the handle. */
381 data
->u
.mkdir
.dirfd
= -1;
382 /* Safe to call as we have transitioned to the requested uid/gid. */
383 ret_value
->u
.ret
= lttng_directory_handle_create_subdirectory_recursive(
385 ret_value
->_errno
= errno
;
386 ret_value
->_error
= (ret_value
->u
.ret
) ? true : false;
387 lttng_directory_handle_put(handle
);
389 return ret_value
->u
.ret
;
393 int _mkdirat(struct run_as_data
*data
, struct run_as_ret
*ret_value
)
397 struct lttng_directory_handle
*handle
;
399 path
= data
->u
.mkdir
.path
;
400 mode
= data
->u
.mkdir
.mode
;
402 handle
= lttng_directory_handle_create_from_dirfd(data
->u
.mkdir
.dirfd
);
404 ret_value
->u
.ret
= -1;
405 ret_value
->_errno
= errno
;
406 ret_value
->_error
= true;
409 /* Ownership of dirfd is transferred to the handle. */
410 data
->u
.mkdir
.dirfd
= -1;
411 /* Safe to call as we have transitioned to the requested uid/gid. */
412 ret_value
->u
.ret
= lttng_directory_handle_create_subdirectory(
414 ret_value
->_errno
= errno
;
415 ret_value
->_error
= (ret_value
->u
.ret
) ? true : false;
416 lttng_directory_handle_put(handle
);
418 return ret_value
->u
.ret
;
422 int _open(struct run_as_data
*data
, struct run_as_ret
*ret_value
)
425 struct lttng_directory_handle
*handle
;
427 handle
= lttng_directory_handle_create_from_dirfd(data
->u
.open
.dirfd
);
429 ret_value
->_errno
= errno
;
430 ret_value
->_error
= true;
431 ret_value
->u
.ret
= -1;
434 /* Ownership of dirfd is transferred to the handle. */
435 data
->u
.open
.dirfd
= -1;
437 fd
= lttng_directory_handle_open_file(handle
,
438 data
->u
.open
.path
, data
->u
.open
.flags
,
441 ret_value
->u
.ret
= -1;
442 ret_value
->u
.open
.fd
= -1;
444 ret_value
->u
.ret
= 0;
445 ret_value
->u
.open
.fd
= fd
;
448 ret_value
->_errno
= errno
;
449 ret_value
->_error
= fd
< 0;
450 lttng_directory_handle_put(handle
);
452 return ret_value
->u
.ret
;
456 int _unlink(struct run_as_data
*data
, struct run_as_ret
*ret_value
)
458 struct lttng_directory_handle
*handle
;
460 handle
= lttng_directory_handle_create_from_dirfd(data
->u
.unlink
.dirfd
);
462 ret_value
->u
.ret
= -1;
463 ret_value
->_errno
= errno
;
464 ret_value
->_error
= true;
468 /* Ownership of dirfd is transferred to the handle. */
469 data
->u
.unlink
.dirfd
= -1;
471 ret_value
->u
.ret
= lttng_directory_handle_unlink_file(handle
,
472 data
->u
.unlink
.path
);
473 ret_value
->_errno
= errno
;
474 ret_value
->_error
= (ret_value
->u
.ret
) ? true : false;
475 lttng_directory_handle_put(handle
);
477 return ret_value
->u
.ret
;
481 int _rmdir(struct run_as_data
*data
, struct run_as_ret
*ret_value
)
483 struct lttng_directory_handle
*handle
;
485 handle
= lttng_directory_handle_create_from_dirfd(data
->u
.rmdir
.dirfd
);
487 ret_value
->u
.ret
= -1;
488 ret_value
->_errno
= errno
;
489 ret_value
->_error
= true;
493 /* Ownership of dirfd is transferred to the handle. */
494 data
->u
.rmdir
.dirfd
= -1;
496 ret_value
->u
.ret
= lttng_directory_handle_remove_subdirectory(
497 handle
, data
->u
.rmdir
.path
);
498 ret_value
->_errno
= errno
;
499 ret_value
->_error
= (ret_value
->u
.ret
) ? true : false;
500 lttng_directory_handle_put(handle
);
502 return ret_value
->u
.ret
;
506 int _rmdir_recursive(struct run_as_data
*data
, struct run_as_ret
*ret_value
)
508 struct lttng_directory_handle
*handle
;
510 handle
= lttng_directory_handle_create_from_dirfd(data
->u
.rmdir
.dirfd
);
512 ret_value
->u
.ret
= -1;
513 ret_value
->_errno
= errno
;
514 ret_value
->_error
= true;
518 /* Ownership of dirfd is transferred to the handle. */
519 data
->u
.rmdir
.dirfd
= -1;
521 ret_value
->u
.ret
= lttng_directory_handle_remove_subdirectory_recursive(
522 handle
, data
->u
.rmdir
.path
, data
->u
.rmdir
.flags
);
523 ret_value
->_errno
= errno
;
524 ret_value
->_error
= (ret_value
->u
.ret
) ? true : false;
525 lttng_directory_handle_put(handle
);
527 return ret_value
->u
.ret
;
531 int _rename(struct run_as_data
*data
, struct run_as_ret
*ret_value
)
533 const char *old_path
, *new_path
;
534 struct lttng_directory_handle
*old_handle
= NULL
, *new_handle
= NULL
;
536 old_path
= data
->u
.rename
.old_path
;
537 new_path
= data
->u
.rename
.new_path
;
539 old_handle
= lttng_directory_handle_create_from_dirfd(
540 data
->u
.rename
.dirfds
[0]);
542 ret_value
->u
.ret
= -1;
545 new_handle
= lttng_directory_handle_create_from_dirfd(
546 data
->u
.rename
.dirfds
[1]);
548 ret_value
->u
.ret
= -1;
552 /* Ownership of dirfds are transferred to the handles. */
553 data
->u
.rename
.dirfds
[0] = data
->u
.rename
.dirfds
[1] = -1;
555 /* Safe to call as we have transitioned to the requested uid/gid. */
556 ret_value
->u
.ret
= lttng_directory_handle_rename(
557 old_handle
, old_path
, new_handle
, new_path
);
559 lttng_directory_handle_put(old_handle
);
560 lttng_directory_handle_put(new_handle
);
561 ret_value
->_errno
= errno
;
562 ret_value
->_error
= (ret_value
->u
.ret
) ? true : false;
563 return ret_value
->u
.ret
;
568 int _extract_elf_symbol_offset(struct run_as_data
*data
,
569 struct run_as_ret
*ret_value
)
574 ret_value
->_error
= false;
575 ret
= lttng_elf_get_symbol_offset(data
->u
.extract_elf_symbol_offset
.fd
,
576 data
->u
.extract_elf_symbol_offset
.function
,
579 DBG("Failed to extract ELF function offset");
580 ret_value
->_error
= true;
582 ret_value
->u
.extract_elf_symbol_offset
.offset
= offset
;
588 int _extract_sdt_probe_offsets(struct run_as_data
*data
,
589 struct run_as_ret
*ret_value
)
592 uint64_t *offsets
= NULL
;
595 ret_value
->_error
= false;
597 /* On success, this call allocates the offsets paramater. */
598 ret
= lttng_elf_get_sdt_probe_offsets(
599 data
->u
.extract_sdt_probe_offsets
.fd
,
600 data
->u
.extract_sdt_probe_offsets
.provider_name
,
601 data
->u
.extract_sdt_probe_offsets
.probe_name
,
602 &offsets
, &num_offset
);
605 DBG("Failed to extract SDT probe offsets");
606 ret_value
->_error
= true;
610 if (num_offset
<= 0 || num_offset
> LTTNG_KERNEL_MAX_UPROBE_NUM
) {
611 DBG("Wrong number of probes.");
613 ret_value
->_error
= true;
617 /* Copy the content of the offsets array to the ret struct. */
618 memcpy(ret_value
->u
.extract_sdt_probe_offsets
.offsets
,
619 offsets
, num_offset
* sizeof(uint64_t));
621 ret_value
->u
.extract_sdt_probe_offsets
.num_offset
= num_offset
;
630 int _extract_elf_symbol_offset(struct run_as_data
*data
,
631 struct run_as_ret
*ret_value
)
633 ERR("Unimplemented runas command RUN_AS_EXTRACT_ELF_SYMBOL_OFFSET");
638 int _extract_sdt_probe_offsets(struct run_as_data
*data
,
639 struct run_as_ret
*ret_value
)
641 ERR("Unimplemented runas command RUN_AS_EXTRACT_SDT_PROBE_OFFSETS");
647 int _generate_filter_bytecode(struct run_as_data
*data
,
648 struct run_as_ret
*ret_value
) {
650 const char *filter_expression
= NULL
;
651 struct filter_parser_ctx
*ctx
= NULL
;
653 ret_value
->_error
= false;
655 filter_expression
= data
->u
.generate_filter_bytecode
.filter_expression
;
657 if (lttng_strnlen(filter_expression
, LTTNG_FILTER_MAX_LEN
- 1) == LTTNG_FILTER_MAX_LEN
- 1) {
658 ret_value
->_error
= true;
663 ret
= filter_parser_ctx_create_from_filter_expression(filter_expression
, &ctx
);
665 ret_value
->_error
= true;
670 DBG("Size of bytecode generated: %u bytes.",
671 bytecode_get_len(&ctx
->bytecode
->b
));
673 /* Copy the lttng_bytecode_filter object to the return structure */
674 memcpy(ret_value
->u
.generate_filter_bytecode
.bytecode
,
676 sizeof(ctx
->bytecode
->b
) +
677 bytecode_get_len(&ctx
->bytecode
->b
));
681 filter_bytecode_free(ctx
);
683 filter_parser_ctx_free(ctx
);
688 run_as_fct
run_as_enum_to_fct(enum run_as_cmd cmd
)
694 case RUN_AS_MKDIR_RECURSIVE
:
695 case RUN_AS_MKDIRAT_RECURSIVE
:
696 return _mkdirat_recursive
;
701 case RUN_AS_UNLINKAT
:
706 case RUN_AS_RMDIR_RECURSIVE
:
707 case RUN_AS_RMDIRAT_RECURSIVE
:
708 return _rmdir_recursive
;
710 case RUN_AS_RENAMEAT
:
712 case RUN_AS_EXTRACT_ELF_SYMBOL_OFFSET
:
713 return _extract_elf_symbol_offset
;
714 case RUN_AS_EXTRACT_SDT_PROBE_OFFSETS
:
715 return _extract_sdt_probe_offsets
;
716 case RUN_AS_GENERATE_FILTER_BYTECODE
:
717 return _generate_filter_bytecode
;
719 ERR("Unknown command %d", (int) cmd
);
725 int do_send_fds(int sock
, const int *fds
, unsigned int fd_count
)
731 /* Nothing to send */
735 for (i
= 0; i
< fd_count
; i
++) {
737 ERR("Attempt to send invalid file descriptor to master (fd = %i)",
739 /* Return 0 as this is not a fatal error. */
744 len
= lttcomm_send_fds_unix_sock(sock
, fds
, fd_count
);
745 return len
< 0 ? -1 : 0;
749 int do_recv_fds(int sock
, int *fds
, unsigned int fd_count
)
756 /* Nothing to receive */
760 len
= lttcomm_recv_fds_unix_sock(sock
, fds
, fd_count
);
764 } else if (len
< 0) {
765 PERROR("Failed to receive file descriptors from socket");
770 for (i
= 0; i
< fd_count
; i
++) {
772 ERR("Invalid file descriptor received from worker (fd = %i)", fds
[i
]);
773 /* Return 0 as this is not a fatal error. */
781 int send_fds_to_worker(const struct run_as_worker
*worker
,
782 const struct run_as_data
*data
)
787 if (COMMAND_USE_CWD_FD(data
) || COMMAND_IN_FD_COUNT(data
) == 0) {
791 for (i
= 0; i
< COMMAND_IN_FD_COUNT(data
); i
++) {
792 if (COMMAND_IN_FDS(data
)[i
] < 0) {
793 ERR("Refusing to send invalid fd to worker (fd = %i)",
794 COMMAND_IN_FDS(data
)[i
]);
800 ret
= do_send_fds(worker
->sockpair
[0], COMMAND_IN_FDS(data
),
801 COMMAND_IN_FD_COUNT(data
));
803 PERROR("Failed to send file descriptor to run-as worker");
812 int send_fds_to_master(struct run_as_worker
*worker
, enum run_as_cmd cmd
,
813 struct run_as_ret
*run_as_ret
)
818 if (COMMAND_OUT_FD_COUNT(cmd
) == 0) {
822 ret
= do_send_fds(worker
->sockpair
[1], COMMAND_OUT_FDS(cmd
, run_as_ret
),
823 COMMAND_OUT_FD_COUNT(cmd
));
825 PERROR("Failed to send file descriptor to master process");
829 for (i
= 0; i
< COMMAND_OUT_FD_COUNT(cmd
); i
++) {
830 int ret_close
= close(COMMAND_OUT_FDS(cmd
, run_as_ret
)[i
]);
833 PERROR("Failed to close result file descriptor");
841 int recv_fds_from_worker(const struct run_as_worker
*worker
, enum run_as_cmd cmd
,
842 struct run_as_ret
*run_as_ret
)
846 if (COMMAND_OUT_FD_COUNT(cmd
) == 0) {
850 ret
= do_recv_fds(worker
->sockpair
[0], COMMAND_OUT_FDS(cmd
, run_as_ret
),
851 COMMAND_OUT_FD_COUNT(cmd
));
853 PERROR("Failed to receive file descriptor from run-as worker");
861 int recv_fds_from_master(struct run_as_worker
*worker
, struct run_as_data
*data
)
865 if (COMMAND_USE_CWD_FD(data
)) {
868 for (i
= 0; i
< COMMAND_IN_FD_COUNT(data
); i
++) {
869 COMMAND_IN_FDS(data
)[i
] = AT_FDCWD
;
874 ret
= do_recv_fds(worker
->sockpair
[1], COMMAND_IN_FDS(data
),
875 COMMAND_IN_FD_COUNT(data
));
877 PERROR("Failed to receive file descriptors from master process");
885 int cleanup_received_fds(struct run_as_data
*data
)
889 for (i
= 0; i
< COMMAND_IN_FD_COUNT(data
); i
++) {
890 if (COMMAND_IN_FDS(data
)[i
] == -1) {
893 ret
= close(COMMAND_IN_FDS(data
)[i
]);
895 PERROR("Failed to close file descriptor received fd in run-as worker");
904 * Return < 0 on error, 0 if OK, 1 on hangup.
907 int handle_one_cmd(struct run_as_worker
*worker
)
910 struct run_as_data data
= {};
911 ssize_t readlen
, writelen
;
912 struct run_as_ret sendret
= {};
917 * Stage 1: Receive run_as_data struct from the master.
918 * The structure contains the command type and all the parameters needed for
921 readlen
= lttcomm_recv_unix_sock(worker
->sockpair
[1], &data
,
928 if (readlen
< sizeof(data
)) {
929 PERROR("lttcomm_recv_unix_sock error");
934 cmd
= run_as_enum_to_fct(data
.cmd
);
941 * Stage 2: Receive file descriptor from master.
942 * Some commands need a file descriptor as input so if it's needed we
943 * receive the fd using the Unix socket.
945 ret
= recv_fds_from_master(worker
, &data
);
947 PERROR("recv_fd_from_master error");
952 prev_euid
= getuid();
953 if (data
.gid
!= getegid()) {
954 ret
= setegid(data
.gid
);
956 sendret
._error
= true;
957 sendret
._errno
= errno
;
962 if (data
.uid
!= prev_euid
) {
963 ret
= seteuid(data
.uid
);
965 sendret
._error
= true;
966 sendret
._errno
= errno
;
973 * Also set umask to 0 for mkdir executable bit.
978 * Stage 3: Execute the command
980 ret
= (*cmd
)(&data
, &sendret
);
982 DBG("Execution of command returned an error");
986 ret
= cleanup_received_fds(&data
);
988 ERR("Error cleaning up FD");
993 * Stage 4: Send run_as_ret structure to the master.
994 * This structure contain the return value of the command and the errno.
996 writelen
= lttcomm_send_unix_sock(worker
->sockpair
[1], &sendret
,
998 if (writelen
< sizeof(sendret
)) {
999 PERROR("lttcomm_send_unix_sock error");
1005 * Stage 5: Send resulting file descriptors to the master.
1007 ret
= send_fds_to_master(worker
, data
.cmd
, &sendret
);
1009 DBG("Sending FD to master returned an error");
1013 if (seteuid(prev_euid
) < 0) {
1024 int run_as_worker(struct run_as_worker
*worker
)
1028 struct run_as_ret sendret
;
1029 size_t proc_orig_len
;
1032 * Initialize worker. Set a different process cmdline.
1034 proc_orig_len
= strlen(worker
->procname
);
1035 memset(worker
->procname
, 0, proc_orig_len
);
1036 strncpy(worker
->procname
, DEFAULT_RUN_AS_WORKER_NAME
, proc_orig_len
);
1038 ret
= lttng_prctl(PR_SET_NAME
,
1039 (unsigned long) DEFAULT_RUN_AS_WORKER_NAME
, 0, 0, 0);
1040 if (ret
&& ret
!= -ENOSYS
) {
1041 /* Don't fail as this is not essential. */
1042 PERROR("prctl PR_SET_NAME");
1045 memset(&sendret
, 0, sizeof(sendret
));
1047 writelen
= lttcomm_send_unix_sock(worker
->sockpair
[1], &sendret
,
1049 if (writelen
< sizeof(sendret
)) {
1050 PERROR("lttcomm_send_unix_sock error");
1056 ret
= handle_one_cmd(worker
);
1060 } else if (ret
> 0) {
1063 continue; /* Next command. */
1072 int run_as_cmd(struct run_as_worker
*worker
,
1073 enum run_as_cmd cmd
,
1074 struct run_as_data
*data
,
1075 struct run_as_ret
*ret_value
,
1076 uid_t uid
, gid_t gid
)
1079 ssize_t readlen
, writelen
;
1082 * If we are non-root, we can only deal with our own uid.
1084 if (geteuid() != 0) {
1085 if (uid
!= geteuid()) {
1087 ret_value
->_errno
= EPERM
;
1088 ERR("Client (%d)/Server (%d) UID mismatch (and sessiond is not root)",
1089 (int) uid
, (int) geteuid());
1099 * Stage 1: Send the run_as_data struct to the worker process
1101 writelen
= lttcomm_send_unix_sock(worker
->sockpair
[0], data
,
1103 if (writelen
< sizeof(*data
)) {
1104 PERROR("Error writing message to run_as");
1106 ret_value
->_errno
= EIO
;
1111 * Stage 2: Send file descriptor to the worker process if needed
1113 ret
= send_fds_to_worker(worker
, data
);
1115 PERROR("do_send_fd error");
1117 ret_value
->_errno
= EIO
;
1122 * Stage 3: Wait for the execution of the command
1126 * Stage 4: Receive the run_as_ret struct containing the return value and
1129 readlen
= lttcomm_recv_unix_sock(worker
->sockpair
[0], ret_value
,
1130 sizeof(*ret_value
));
1132 ERR("Run-as worker has hung-up during run_as_cmd");
1134 ret_value
->_errno
= EIO
;
1136 } else if (readlen
< sizeof(*ret_value
)) {
1137 PERROR("Error reading response from run_as");
1139 ret_value
->_errno
= errno
;
1143 if (ret_value
->_error
) {
1144 /* Skip stage 5 on error as there will be no fd to receive. */
1149 * Stage 5: Receive file descriptor if needed
1151 ret
= recv_fds_from_worker(worker
, cmd
, ret_value
);
1153 ERR("Error receiving fd");
1155 ret_value
->_errno
= EIO
;
1163 * This is for debugging ONLY and should not be considered secure.
1166 int run_as_noworker(enum run_as_cmd cmd
,
1167 struct run_as_data
*data
, struct run_as_ret
*ret_value
,
1168 uid_t uid
, gid_t gid
)
1170 int ret
, saved_errno
;
1174 fct
= run_as_enum_to_fct(cmd
);
1180 old_mask
= umask(0);
1181 ret
= fct(data
, ret_value
);
1182 saved_errno
= ret_value
->_errno
;
1184 errno
= saved_errno
;
1190 int reset_sighandler(void)
1194 DBG("Resetting run_as worker signal handlers to default");
1195 for (sig
= 1; sig
<= 31; sig
++) {
1196 (void) signal(sig
, SIG_DFL
);
1202 void worker_sighandler(int sig
)
1204 const char *signame
;
1207 * The worker will inherit its parent's signals since they are part of
1208 * the same process group. However, in the case of SIGINT and SIGTERM,
1209 * we want to give the worker a chance to teardown gracefully when its
1210 * parent closes the command socket.
1217 signame
= "SIGTERM";
1224 DBG("run_as worker received signal %s", signame
);
1226 DBG("run_as_worker received signal %d", sig
);
1231 int set_worker_sighandlers(void)
1235 struct sigaction sa
;
1237 if ((ret
= sigemptyset(&sigset
)) < 0) {
1238 PERROR("sigemptyset");
1242 sa
.sa_handler
= worker_sighandler
;
1243 sa
.sa_mask
= sigset
;
1245 if ((ret
= sigaction(SIGINT
, &sa
, NULL
)) < 0) {
1246 PERROR("sigaction SIGINT");
1250 if ((ret
= sigaction(SIGTERM
, &sa
, NULL
)) < 0) {
1251 PERROR("sigaction SIGTERM");
1255 DBG("run_as signal handler set for SIGTERM and SIGINT");
1261 int run_as_create_worker_no_lock(const char *procname
,
1262 post_fork_cleanup_cb clean_up_func
,
1263 void *clean_up_user_data
)
1268 struct run_as_ret recvret
;
1269 struct run_as_worker
*worker
;
1271 assert(!global_worker
);
1274 * Don't initialize a worker, all run_as tasks will be performed
1275 * in the current process.
1280 worker
= zmalloc(sizeof(*worker
));
1285 worker
->procname
= strdup(procname
);
1286 if (!worker
->procname
) {
1288 goto error_procname_alloc
;
1290 /* Create unix socket. */
1291 if (lttcomm_create_anon_unix_socketpair(worker
->sockpair
) < 0) {
1302 } else if (pid
== 0) {
1307 set_worker_sighandlers();
1308 if (clean_up_func
) {
1309 if (clean_up_func(clean_up_user_data
) < 0) {
1310 ERR("Run-as post-fork clean-up failed, exiting.");
1315 /* Just close, no shutdown. */
1316 if (close(worker
->sockpair
[0])) {
1322 * Close all FDs aside from STDIN, STDOUT, STDERR and sockpair[1]
1323 * Sockpair[1] is used as a control channel with the master
1325 for (i
= 3; i
< sysconf(_SC_OPEN_MAX
); i
++) {
1326 if (i
!= worker
->sockpair
[1]) {
1331 worker
->sockpair
[0] = -1;
1332 ret
= run_as_worker(worker
);
1333 if (lttcomm_close_unix_sock(worker
->sockpair
[1])) {
1337 worker
->sockpair
[1] = -1;
1338 free(worker
->procname
);
1340 LOG(ret
? PRINT_ERR
: PRINT_DBG
, "run_as worker exiting (ret = %d)", ret
);
1341 exit(ret
? EXIT_FAILURE
: EXIT_SUCCESS
);
1345 /* Just close, no shutdown. */
1346 if (close(worker
->sockpair
[1])) {
1351 worker
->sockpair
[1] = -1;
1353 /* Wait for worker to become ready. */
1354 readlen
= lttcomm_recv_unix_sock(worker
->sockpair
[0],
1355 &recvret
, sizeof(recvret
));
1356 if (readlen
< sizeof(recvret
)) {
1357 ERR("readlen: %zd", readlen
);
1358 PERROR("Error reading response from run_as at creation");
1362 global_worker
= worker
;
1367 /* Error handling. */
1369 for (i
= 0; i
< 2; i
++) {
1370 if (worker
->sockpair
[i
] < 0) {
1373 if (lttcomm_close_unix_sock(worker
->sockpair
[i
])) {
1376 worker
->sockpair
[i
] = -1;
1379 free(worker
->procname
);
1380 error_procname_alloc
:
1386 void run_as_destroy_worker_no_lock(void)
1388 struct run_as_worker
*worker
= global_worker
;
1390 DBG("Destroying run_as worker");
1394 /* Close unix socket */
1395 DBG("Closing run_as worker socket");
1396 if (lttcomm_close_unix_sock(worker
->sockpair
[0])) {
1399 worker
->sockpair
[0] = -1;
1400 /* Wait for worker. */
1405 wait_ret
= waitpid(worker
->pid
, &status
, 0);
1407 if (errno
== EINTR
) {
1414 if (WIFEXITED(status
)) {
1415 LOG(WEXITSTATUS(status
) == 0 ? PRINT_DBG
: PRINT_ERR
,
1416 DEFAULT_RUN_AS_WORKER_NAME
" terminated with status code %d",
1417 WEXITSTATUS(status
));
1419 } else if (WIFSIGNALED(status
)) {
1420 ERR(DEFAULT_RUN_AS_WORKER_NAME
" was killed by signal %d",
1425 free(worker
->procname
);
1427 global_worker
= NULL
;
1431 int run_as_restart_worker(struct run_as_worker
*worker
)
1434 char *procname
= NULL
;
1436 procname
= worker
->procname
;
1438 /* Close socket to run_as worker process and clean up the zombie process */
1439 run_as_destroy_worker_no_lock();
1441 /* Create a new run_as worker process*/
1442 ret
= run_as_create_worker_no_lock(procname
, NULL
, NULL
);
1444 ERR("Restarting the worker process failed");
1453 int run_as(enum run_as_cmd cmd
, struct run_as_data
*data
,
1454 struct run_as_ret
*ret_value
, uid_t uid
, gid_t gid
)
1456 int ret
, saved_errno
;
1458 pthread_mutex_lock(&worker_lock
);
1460 DBG("Using run_as worker");
1462 assert(global_worker
);
1464 ret
= run_as_cmd(global_worker
, cmd
, data
, ret_value
, uid
, gid
);
1465 saved_errno
= ret_value
->_errno
;
1468 * If the worker thread crashed the errno is set to EIO. we log
1469 * the error and start a new worker process.
1471 if (ret
== -1 && saved_errno
== EIO
) {
1472 DBG("Socket closed unexpectedly... "
1473 "Restarting the worker process");
1474 ret
= run_as_restart_worker(global_worker
);
1476 ERR("Failed to restart worker process.");
1481 DBG("Using run_as without worker");
1482 ret
= run_as_noworker(cmd
, data
, ret_value
, uid
, gid
);
1485 pthread_mutex_unlock(&worker_lock
);
1490 int run_as_mkdir_recursive(const char *path
, mode_t mode
, uid_t uid
, gid_t gid
)
1492 return run_as_mkdirat_recursive(AT_FDCWD
, path
, mode
, uid
, gid
);
1496 int run_as_mkdirat_recursive(int dirfd
, const char *path
, mode_t mode
,
1497 uid_t uid
, gid_t gid
)
1500 struct run_as_data data
= {};
1501 struct run_as_ret run_as_ret
= {};
1503 DBG3("mkdirat() recursive fd = %d%s, path = %s, mode = %d, uid = %d, gid = %d",
1504 dirfd
, dirfd
== AT_FDCWD
? " (AT_FDCWD)" : "",
1505 path
, (int) mode
, (int) uid
, (int) gid
);
1506 ret
= lttng_strncpy(data
.u
.mkdir
.path
, path
,
1507 sizeof(data
.u
.mkdir
.path
));
1509 ERR("Failed to copy path argument of mkdirat recursive command");
1512 data
.u
.mkdir
.path
[sizeof(data
.u
.mkdir
.path
) - 1] = '\0';
1513 data
.u
.mkdir
.mode
= mode
;
1514 data
.u
.mkdir
.dirfd
= dirfd
;
1515 run_as(dirfd
== AT_FDCWD
? RUN_AS_MKDIR_RECURSIVE
: RUN_AS_MKDIRAT_RECURSIVE
,
1516 &data
, &run_as_ret
, uid
, gid
);
1517 errno
= run_as_ret
._errno
;
1518 ret
= run_as_ret
.u
.ret
;
1524 int run_as_mkdir(const char *path
, mode_t mode
, uid_t uid
, gid_t gid
)
1526 return run_as_mkdirat(AT_FDCWD
, path
, mode
, uid
, gid
);
1530 int run_as_mkdirat(int dirfd
, const char *path
, mode_t mode
,
1531 uid_t uid
, gid_t gid
)
1534 struct run_as_data data
= {};
1535 struct run_as_ret run_as_ret
= {};
1537 DBG3("mkdirat() recursive fd = %d%s, path = %s, mode = %d, uid = %d, gid = %d",
1538 dirfd
, dirfd
== AT_FDCWD
? " (AT_FDCWD)" : "",
1539 path
, (int) mode
, (int) uid
, (int) gid
);
1540 ret
= lttng_strncpy(data
.u
.mkdir
.path
, path
,
1541 sizeof(data
.u
.mkdir
.path
));
1543 ERR("Failed to copy path argument of mkdirat command");
1546 data
.u
.mkdir
.path
[sizeof(data
.u
.mkdir
.path
) - 1] = '\0';
1547 data
.u
.mkdir
.mode
= mode
;
1548 data
.u
.mkdir
.dirfd
= dirfd
;
1549 run_as(dirfd
== AT_FDCWD
? RUN_AS_MKDIR
: RUN_AS_MKDIRAT
,
1550 &data
, &run_as_ret
, uid
, gid
);
1551 errno
= run_as_ret
._errno
;
1552 ret
= run_as_ret
.u
.ret
;
1558 int run_as_open(const char *path
, int flags
, mode_t mode
, uid_t uid
,
1561 return run_as_openat(AT_FDCWD
, path
, flags
, mode
, uid
, gid
);
1565 int run_as_openat(int dirfd
, const char *path
, int flags
, mode_t mode
,
1566 uid_t uid
, gid_t gid
)
1569 struct run_as_data data
= {};
1570 struct run_as_ret run_as_ret
= {};
1572 DBG3("openat() fd = %d%s, path = %s, flags = %X, mode = %d, uid %d, gid %d",
1573 dirfd
, dirfd
== AT_FDCWD
? " (AT_FDCWD)" : "",
1574 path
, flags
, (int) mode
, (int) uid
, (int) gid
);
1575 ret
= lttng_strncpy(data
.u
.open
.path
, path
, sizeof(data
.u
.open
.path
));
1577 ERR("Failed to copy path argument of open command");
1580 data
.u
.open
.flags
= flags
;
1581 data
.u
.open
.mode
= mode
;
1582 data
.u
.open
.dirfd
= dirfd
;
1583 run_as(dirfd
== AT_FDCWD
? RUN_AS_OPEN
: RUN_AS_OPENAT
,
1584 &data
, &run_as_ret
, uid
, gid
);
1585 errno
= run_as_ret
._errno
;
1586 ret
= run_as_ret
.u
.ret
< 0 ? run_as_ret
.u
.ret
:
1587 run_as_ret
.u
.open
.fd
;
1593 int run_as_unlink(const char *path
, uid_t uid
, gid_t gid
)
1595 return run_as_unlinkat(AT_FDCWD
, path
, uid
, gid
);
1599 int run_as_unlinkat(int dirfd
, const char *path
, uid_t uid
, gid_t gid
)
1602 struct run_as_data data
= {};
1603 struct run_as_ret run_as_ret
= {};
1605 DBG3("unlinkat() fd = %d%s, path = %s, uid = %d, gid = %d",
1606 dirfd
, dirfd
== AT_FDCWD
? " (AT_FDCWD)" : "",
1607 path
, (int) uid
, (int) gid
);
1608 ret
= lttng_strncpy(data
.u
.unlink
.path
, path
,
1609 sizeof(data
.u
.unlink
.path
));
1613 data
.u
.unlink
.dirfd
= dirfd
;
1614 run_as(dirfd
== AT_FDCWD
? RUN_AS_UNLINK
: RUN_AS_UNLINKAT
, &data
,
1615 &run_as_ret
, uid
, gid
);
1616 errno
= run_as_ret
._errno
;
1617 ret
= run_as_ret
.u
.ret
;
1623 int run_as_rmdir(const char *path
, uid_t uid
, gid_t gid
)
1625 return run_as_rmdirat(AT_FDCWD
, path
, uid
, gid
);
1629 int run_as_rmdirat(int dirfd
, const char *path
, uid_t uid
, gid_t gid
)
1632 struct run_as_data data
= {};
1633 struct run_as_ret run_as_ret
= {};
1635 DBG3("rmdirat() fd = %d%s, path = %s, uid = %d, gid = %d",
1636 dirfd
, dirfd
== AT_FDCWD
? " (AT_FDCWD)" : "",
1637 path
, (int) uid
, (int) gid
);
1638 ret
= lttng_strncpy(data
.u
.rmdir
.path
, path
,
1639 sizeof(data
.u
.rmdir
.path
));
1643 data
.u
.rmdir
.dirfd
= dirfd
;
1644 run_as(dirfd
== AT_FDCWD
? RUN_AS_RMDIR
: RUN_AS_RMDIRAT
, &data
,
1645 &run_as_ret
, uid
, gid
);
1646 errno
= run_as_ret
._errno
;
1647 ret
= run_as_ret
.u
.ret
;
1653 int run_as_rmdir_recursive(const char *path
, uid_t uid
, gid_t gid
, int flags
)
1655 return run_as_rmdirat_recursive(AT_FDCWD
, path
, uid
, gid
, flags
);
1659 int run_as_rmdirat_recursive(int dirfd
, const char *path
, uid_t uid
, gid_t gid
, int flags
)
1662 struct run_as_data data
= {};
1663 struct run_as_ret run_as_ret
= {};
1665 DBG3("rmdirat() recursive fd = %d%s, path = %s, uid = %d, gid = %d",
1666 dirfd
, dirfd
== AT_FDCWD
? " (AT_FDCWD)" : "",
1667 path
, (int) uid
, (int) gid
);
1668 ret
= lttng_strncpy(data
.u
.rmdir
.path
, path
,
1669 sizeof(data
.u
.rmdir
.path
));
1673 data
.u
.rmdir
.dirfd
= dirfd
;
1674 data
.u
.rmdir
.flags
= flags
;
1675 run_as(dirfd
== AT_FDCWD
? RUN_AS_RMDIR_RECURSIVE
: RUN_AS_RMDIRAT_RECURSIVE
,
1676 &data
, &run_as_ret
, uid
, gid
);
1677 errno
= run_as_ret
._errno
;
1678 ret
= run_as_ret
.u
.ret
;
1684 int run_as_rename(const char *old
, const char *new, uid_t uid
, gid_t gid
)
1686 return run_as_renameat(AT_FDCWD
, old
, AT_FDCWD
, new, uid
, gid
);
1690 int run_as_renameat(int old_dirfd
, const char *old_name
,
1691 int new_dirfd
, const char *new_name
, uid_t uid
, gid_t gid
)
1694 struct run_as_data data
= {};
1695 struct run_as_ret run_as_ret
= {};
1697 DBG3("renameat() old_dirfd = %d%s, old_name = %s, new_dirfd = %d%s, new_name = %s, uid = %d, gid = %d",
1698 old_dirfd
, old_dirfd
== AT_FDCWD
? " (AT_FDCWD)" : "",
1700 new_dirfd
, new_dirfd
== AT_FDCWD
? " (AT_FDCWD)" : "",
1701 new_name
, (int) uid
, (int) gid
);
1702 ret
= lttng_strncpy(data
.u
.rename
.old_path
, old_name
,
1703 sizeof(data
.u
.rename
.old_path
));
1707 ret
= lttng_strncpy(data
.u
.rename
.new_path
, new_name
,
1708 sizeof(data
.u
.rename
.new_path
));
1713 data
.u
.rename
.dirfds
[0] = old_dirfd
;
1714 data
.u
.rename
.dirfds
[1] = new_dirfd
;
1715 run_as(old_dirfd
== AT_FDCWD
&& new_dirfd
== AT_FDCWD
?
1716 RUN_AS_RENAME
: RUN_AS_RENAMEAT
,
1717 &data
, &run_as_ret
, uid
, gid
);
1718 errno
= run_as_ret
._errno
;
1719 ret
= run_as_ret
.u
.ret
;
1725 int run_as_extract_elf_symbol_offset(int fd
, const char* function
,
1726 uid_t uid
, gid_t gid
, uint64_t *offset
)
1729 struct run_as_data data
= {};
1730 struct run_as_ret run_as_ret
= {};
1732 DBG3("extract_elf_symbol_offset() on fd=%d and function=%s "
1733 "with for uid %d and gid %d", fd
, function
,
1734 (int) uid
, (int) gid
);
1736 data
.u
.extract_elf_symbol_offset
.fd
= fd
;
1738 strncpy(data
.u
.extract_elf_symbol_offset
.function
, function
, LTTNG_SYMBOL_NAME_LEN
- 1);
1739 data
.u
.extract_elf_symbol_offset
.function
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
1740 ret
= lttng_strncpy(data
.u
.extract_elf_symbol_offset
.function
,
1742 sizeof(data
.u
.extract_elf_symbol_offset
.function
));
1747 run_as(RUN_AS_EXTRACT_ELF_SYMBOL_OFFSET
, &data
, &run_as_ret
, uid
, gid
);
1748 errno
= run_as_ret
._errno
;
1749 if (run_as_ret
._error
) {
1754 *offset
= run_as_ret
.u
.extract_elf_symbol_offset
.offset
;
1760 int run_as_extract_sdt_probe_offsets(int fd
, const char* provider_name
,
1761 const char* probe_name
, uid_t uid
, gid_t gid
,
1762 uint64_t **offsets
, uint32_t *num_offset
)
1765 struct run_as_data data
= {};
1766 struct run_as_ret run_as_ret
= {};
1768 DBG3("extract_sdt_probe_offsets() on fd=%d, probe_name=%s and "
1769 "provider_name=%s with for uid %d and gid %d", fd
,
1770 probe_name
, provider_name
, (int) uid
, (int) gid
);
1772 data
.u
.extract_sdt_probe_offsets
.fd
= fd
;
1774 ret
= lttng_strncpy(data
.u
.extract_sdt_probe_offsets
.probe_name
, probe_name
,
1775 sizeof(data
.u
.extract_sdt_probe_offsets
.probe_name
));
1779 ret
= lttng_strncpy(data
.u
.extract_sdt_probe_offsets
.provider_name
,
1781 sizeof(data
.u
.extract_sdt_probe_offsets
.provider_name
));
1786 run_as(RUN_AS_EXTRACT_SDT_PROBE_OFFSETS
, &data
, &run_as_ret
, uid
, gid
);
1787 errno
= run_as_ret
._errno
;
1788 if (run_as_ret
._error
) {
1793 *num_offset
= run_as_ret
.u
.extract_sdt_probe_offsets
.num_offset
;
1794 *offsets
= zmalloc(*num_offset
* sizeof(uint64_t));
1800 memcpy(*offsets
, run_as_ret
.u
.extract_sdt_probe_offsets
.offsets
,
1801 *num_offset
* sizeof(uint64_t));
1807 int run_as_generate_filter_bytecode(const char *filter_expression
,
1810 struct lttng_filter_bytecode
**bytecode
)
1813 struct run_as_data data
= {};
1814 struct run_as_ret run_as_ret
= {};
1815 const struct lttng_filter_bytecode
*view_bytecode
= NULL
;
1816 struct lttng_filter_bytecode
*local_bytecode
= NULL
;
1818 DBG3("generate_filter_bytecode() from expression=\"%s\" for uid %d and gid %d",
1819 filter_expression
, (int) uid
, (int) gid
);
1821 ret
= lttng_strncpy(data
.u
.generate_filter_bytecode
.filter_expression
, filter_expression
,
1822 sizeof(data
.u
.generate_filter_bytecode
.filter_expression
));
1827 run_as(RUN_AS_GENERATE_FILTER_BYTECODE
, &data
, &run_as_ret
, uid
, gid
);
1828 errno
= run_as_ret
._errno
;
1829 if (run_as_ret
._error
) {
1834 view_bytecode
= (const struct lttng_filter_bytecode
*) run_as_ret
.u
.generate_filter_bytecode
.bytecode
;
1836 local_bytecode
= zmalloc(sizeof(*local_bytecode
) + view_bytecode
->len
);
1837 if (!local_bytecode
) {
1842 memcpy(local_bytecode
, run_as_ret
.u
.generate_filter_bytecode
.bytecode
,
1843 sizeof(*local_bytecode
) + view_bytecode
->len
);
1844 *bytecode
= local_bytecode
;
1851 int run_as_create_worker(const char *procname
,
1852 post_fork_cleanup_cb clean_up_func
,
1853 void *clean_up_user_data
)
1857 pthread_mutex_lock(&worker_lock
);
1858 ret
= run_as_create_worker_no_lock(procname
, clean_up_func
,
1859 clean_up_user_data
);
1860 pthread_mutex_unlock(&worker_lock
);
1865 void run_as_destroy_worker(void)
1867 pthread_mutex_lock(&worker_lock
);
1868 run_as_destroy_worker_no_lock();
1869 pthread_mutex_unlock(&worker_lock
);