Clean-up: modernize pretty_xml.cpp
[lttng-tools.git] / src / common / runas.cpp
index 667b28cb8e3ed8ccba5ff33db7701b41ca80ba01..07d9e171f0a0cf941c78cec5c928af2da9158469 100644 (file)
@@ -177,30 +177,31 @@ struct run_as_ret {
        bool _error;
 } LTTNG_PACKED;
 
-#define COMMAND_IN_FDS(data_ptr)                                                         \
-       ({                                                                               \
-               int *fds = NULL;                                                         \
-               if (command_properties[data_ptr->cmd].in_fds_offset != -1) {             \
-                       fds = (int *) ((char *) data_ptr +                               \
-                                      command_properties[data_ptr->cmd].in_fds_offset); \
-               }                                                                        \
-               fds;                                                                     \
+#define COMMAND_IN_FDS(data_ptr)                                                           \
+       ({                                                                                 \
+               int *fds = NULL;                                                           \
+               if (command_properties[(data_ptr)->cmd].in_fds_offset != -1) {             \
+                       fds = (int *) ((char *) (data_ptr) +                               \
+                                      command_properties[(data_ptr)->cmd].in_fds_offset); \
+               }                                                                          \
+               fds;                                                                       \
        })
 
-#define COMMAND_OUT_FDS(cmd, ret_ptr)                                                              \
-       ({                                                                                         \
-               int *fds = NULL;                                                                   \
-               if (command_properties[cmd].out_fds_offset != -1) {                                \
-                       fds = (int *) ((char *) ret_ptr + command_properties[cmd].out_fds_offset); \
-               }                                                                                  \
-               fds;                                                                               \
+#define COMMAND_OUT_FDS(cmd, ret_ptr)                                           \
+       ({                                                                      \
+               int *fds = NULL;                                                \
+               if (command_properties[cmd].out_fds_offset != -1) {             \
+                       fds = (int *) ((char *) (ret_ptr) +                     \
+                                      command_properties[cmd].out_fds_offset); \
+               }                                                               \
+               fds;                                                            \
        })
 
-#define COMMAND_IN_FD_COUNT(data_ptr) ({ command_properties[data_ptr->cmd].in_fd_count; })
+#define COMMAND_IN_FD_COUNT(data_ptr) ({ command_properties[(data_ptr)->cmd].in_fd_count; })
 
 #define COMMAND_OUT_FD_COUNT(cmd) ({ command_properties[cmd].out_fd_count; })
 
-#define COMMAND_USE_CWD_FD(data_ptr) command_properties[data_ptr->cmd].use_cwd_fd
+#define COMMAND_USE_CWD_FD(data_ptr) command_properties[(data_ptr)->cmd].use_cwd_fd
 
 struct run_as_command_properties {
        /* Set to -1 when not applicable. */
@@ -349,7 +350,7 @@ static int use_clone(void)
        return 0;
 }
 #else
-static int use_clone(void)
+static int use_clone()
 {
        return !lttng_secure_getenv("LTTNG_DEBUG_NOCLONE");
 }
@@ -379,7 +380,7 @@ static int _mkdirat_recursive(struct run_as_data *data, struct run_as_ret *ret_v
        /* Safe to call as we have transitioned to the requested uid/gid. */
        ret_value->u.ret = lttng_directory_handle_create_subdirectory_recursive(handle, path, mode);
        ret_value->_errno = errno;
-       ret_value->_error = (ret_value->u.ret) ? true : false;
+       ret_value->_error = (ret_value->u.ret) != 0;
        lttng_directory_handle_put(handle);
 end:
        return ret_value->u.ret;
@@ -406,7 +407,7 @@ static int _mkdirat(struct run_as_data *data, struct run_as_ret *ret_value)
        /* Safe to call as we have transitioned to the requested uid/gid. */
        ret_value->u.ret = lttng_directory_handle_create_subdirectory(handle, path, mode);
        ret_value->_errno = errno;
-       ret_value->_error = (ret_value->u.ret) ? true : false;
+       ret_value->_error = (ret_value->u.ret) != 0;
        lttng_directory_handle_put(handle);
 end:
        return ret_value->u.ret;
@@ -461,7 +462,7 @@ static int _unlink(struct run_as_data *data, struct run_as_ret *ret_value)
 
        ret_value->u.ret = lttng_directory_handle_unlink_file(handle, data->u.unlink.path);
        ret_value->_errno = errno;
-       ret_value->_error = (ret_value->u.ret) ? true : false;
+       ret_value->_error = (ret_value->u.ret) != 0;
        lttng_directory_handle_put(handle);
 end:
        return ret_value->u.ret;
@@ -484,7 +485,7 @@ static int _rmdir(struct run_as_data *data, struct run_as_ret *ret_value)
 
        ret_value->u.ret = lttng_directory_handle_remove_subdirectory(handle, data->u.rmdir.path);
        ret_value->_errno = errno;
-       ret_value->_error = (ret_value->u.ret) ? true : false;
+       ret_value->_error = (ret_value->u.ret) != 0;
        lttng_directory_handle_put(handle);
 end:
        return ret_value->u.ret;
@@ -508,7 +509,7 @@ static int _rmdir_recursive(struct run_as_data *data, struct run_as_ret *ret_val
        ret_value->u.ret = lttng_directory_handle_remove_subdirectory_recursive(
                handle, data->u.rmdir.path, data->u.rmdir.flags);
        ret_value->_errno = errno;
-       ret_value->_error = (ret_value->u.ret) ? true : false;
+       ret_value->_error = (ret_value->u.ret) != 0;
        lttng_directory_handle_put(handle);
 end:
        return ret_value->u.ret;
@@ -517,7 +518,7 @@ end:
 static int _rename(struct run_as_data *data, struct run_as_ret *ret_value)
 {
        const char *old_path, *new_path;
-       struct lttng_directory_handle *old_handle = NULL, *new_handle = NULL;
+       struct lttng_directory_handle *old_handle = nullptr, *new_handle = nullptr;
 
        old_path = data->u.rename.old_path;
        new_path = data->u.rename.new_path;
@@ -543,7 +544,7 @@ end:
        lttng_directory_handle_put(old_handle);
        lttng_directory_handle_put(new_handle);
        ret_value->_errno = errno;
-       ret_value->_error = (ret_value->u.ret) ? true : false;
+       ret_value->_error = (ret_value->u.ret) != 0;
        return ret_value->u.ret;
 }
 
@@ -569,7 +570,7 @@ static int _extract_elf_symbol_offset(struct run_as_data *data, struct run_as_re
 static int _extract_sdt_probe_offsets(struct run_as_data *data, struct run_as_ret *ret_value)
 {
        int ret = 0;
-       uint64_t *offsets = NULL;
+       uint64_t *offsets = nullptr;
        uint32_t num_offset;
 
        ret_value->_error = false;
@@ -625,8 +626,8 @@ static int _extract_sdt_probe_offsets(struct run_as_data *data __attribute__((un
 static int _generate_filter_bytecode(struct run_as_data *data, struct run_as_ret *ret_value)
 {
        int ret = 0;
-       const char *filter_expression = NULL;
-       struct filter_parser_ctx *ctx = NULL;
+       const char *filter_expression = nullptr;
+       struct filter_parser_ctx *ctx = nullptr;
 
        ret_value->_error = false;
 
@@ -694,7 +695,7 @@ static run_as_fct run_as_enum_to_fct(enum run_as_cmd cmd)
                return _generate_filter_bytecode;
        default:
                ERR("Unknown command %d", (int) cmd);
-               return NULL;
+               return nullptr;
        }
 }
 
@@ -867,11 +868,11 @@ end:
 static int get_user_infos_from_uid(uid_t uid, char **username, gid_t *primary_gid)
 {
        int ret;
-       char *buf = NULL;
+       char *buf = nullptr;
        long raw_get_pw_buf_size;
        size_t get_pw_buf_size;
        struct passwd pwd;
-       struct passwd *result = NULL;
+       struct passwd *result = nullptr;
 
        /* Fetch the max size for the temporary buffer. */
        errno = 0;
@@ -891,7 +892,7 @@ static int get_user_infos_from_uid(uid_t uid, char **username, gid_t *primary_gi
        get_pw_buf_size = (size_t) raw_get_pw_buf_size;
 
        buf = calloc<char>(get_pw_buf_size);
-       if (buf == NULL) {
+       if (buf == nullptr) {
                PERROR("Failed to allocate buffer to get password file entries");
                goto error;
        }
@@ -902,14 +903,14 @@ static int get_user_infos_from_uid(uid_t uid, char **username, gid_t *primary_gi
                goto error;
        }
 
-       if (result == NULL) {
+       if (result == nullptr) {
                ERR("Failed to find user information in password entries: uid = %d", (int) uid);
                ret = -1;
                goto error;
        }
 
        *username = strdup(result->pw_name);
-       if (*username == NULL) {
+       if (*username == nullptr) {
                PERROR("Failed to copy user name");
                goto error;
        }
@@ -920,7 +921,7 @@ end:
        free(buf);
        return ret;
 error:
-       *username = NULL;
+       *username = nullptr;
        *primary_gid = -1;
        ret = -1;
        goto end;
@@ -930,7 +931,7 @@ static int demote_creds(uid_t prev_uid, gid_t prev_gid, uid_t new_uid, gid_t new
 {
        int ret = 0;
        gid_t primary_gid;
-       char *username = NULL;
+       char *username = nullptr;
 
        /* Change the group id. */
        if (prev_gid != new_gid) {
@@ -997,7 +998,7 @@ static int promote_creds(uid_t prev_uid, gid_t prev_gid, uid_t new_uid, gid_t ne
 {
        int ret = 0;
        gid_t primary_gid;
-       char *username = NULL;
+       char *username = nullptr;
 
        /* Change the group id. */
        if (prev_gid != new_gid) {
@@ -1316,7 +1317,7 @@ end:
        return ret;
 }
 
-static int reset_sighandler(void)
+static int reset_sighandler()
 {
        int sig;
 
@@ -1345,7 +1346,7 @@ static void worker_sighandler(int sig)
                signame = "SIGTERM";
                break;
        default:
-               signame = NULL;
+               signame = nullptr;
        }
 
        if (signame) {
@@ -1355,7 +1356,7 @@ static void worker_sighandler(int sig)
        }
 }
 
-static int set_worker_sighandlers(void)
+static int set_worker_sighandlers()
 {
        int ret = 0;
        sigset_t sigset;
@@ -1369,12 +1370,12 @@ static int set_worker_sighandlers(void)
        sa.sa_handler = worker_sighandler;
        sa.sa_mask = sigset;
        sa.sa_flags = 0;
-       if ((ret = sigaction(SIGINT, &sa, NULL)) < 0) {
+       if ((ret = sigaction(SIGINT, &sa, nullptr)) < 0) {
                PERROR("sigaction SIGINT");
                goto end;
        }
 
-       if ((ret = sigaction(SIGTERM, &sa, NULL)) < 0) {
+       if ((ret = sigaction(SIGTERM, &sa, nullptr)) < 0) {
                PERROR("sigaction SIGTERM");
                goto end;
        }
@@ -1510,7 +1511,7 @@ error_procname_alloc:
        return ret;
 }
 
-static void run_as_destroy_worker_no_lock(void)
+static void run_as_destroy_worker_no_lock()
 {
        run_as_worker_data *worker = global_worker;
 
@@ -1551,13 +1552,13 @@ static void run_as_destroy_worker_no_lock(void)
        }
        free(worker->procname);
        free(worker);
-       global_worker = NULL;
+       global_worker = nullptr;
 }
 
 static int run_as_restart_worker(run_as_worker_data *worker)
 {
        int ret = 0;
-       char *procname = NULL;
+       char *procname = nullptr;
 
        procname = worker->procname;
 
@@ -1565,7 +1566,7 @@ static int run_as_restart_worker(run_as_worker_data *worker)
        run_as_destroy_worker_no_lock();
 
        /* Create a new run_as worker process*/
-       ret = run_as_create_worker_no_lock(procname, NULL, NULL);
+       ret = run_as_create_worker_no_lock(procname, nullptr, nullptr);
        if (ret < 0) {
                ERR("Restarting the worker process failed");
                ret = -1;
@@ -1957,8 +1958,8 @@ int run_as_generate_filter_bytecode(const char *filter_expression,
        int ret;
        struct run_as_data data = {};
        struct run_as_ret run_as_ret = {};
-       const struct lttng_bytecode *view_bytecode = NULL;
-       struct lttng_bytecode *local_bytecode = NULL;
+       const struct lttng_bytecode *view_bytecode = nullptr;
+       struct lttng_bytecode *local_bytecode = nullptr;
        const uid_t uid = lttng_credentials_get_uid(creds);
        const gid_t gid = lttng_credentials_get_gid(creds);
 
@@ -2010,7 +2011,7 @@ int run_as_create_worker(const char *procname,
        return ret;
 }
 
-void run_as_destroy_worker(void)
+void run_as_destroy_worker()
 {
        pthread_mutex_lock(&worker_lock);
        run_as_destroy_worker_no_lock();
This page took 0.029366 seconds and 4 git commands to generate.