X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=src%2Flib%2Flttng-ust-ctl%2Fustctl.c;h=bcbd9c66c2a2b01da949e7f85a6a3628a34c49dc;hb=8449a229b6adf4ed87d34ef4d6f128e2177c3354;hp=784cb75db0b46a7c42a9b506199a3e10e2baf343;hpb=2722f20cbda88b5f6250213a7be8412c19a11e8a;p=lttng-ust.git diff --git a/src/lib/lttng-ust-ctl/ustctl.c b/src/lib/lttng-ust-ctl/ustctl.c index 784cb75d..bcbd9c66 100644 --- a/src/lib/lttng-ust-ctl/ustctl.c +++ b/src/lib/lttng-ust-ctl/ustctl.c @@ -1,7 +1,7 @@ /* * SPDX-License-Identifier: GPL-2.0-only * - * Copyright (C) 2011 Julien Desfossez + * Copyright (C) 2011 EfficiOS Inc. * Copyright (C) 2011-2013 Mathieu Desnoyers */ @@ -1257,7 +1257,7 @@ int lttng_ust_ctl_duplicate_ust_object_data(struct lttng_ust_abi_object_data **d obj->u.channel.wakeup_fd = dup(src->u.channel.wakeup_fd); if (obj->u.channel.wakeup_fd < 0) { - ret = errno; + ret = -errno; goto chan_error_wakeup_fd; } } else { @@ -1293,7 +1293,7 @@ int lttng_ust_ctl_duplicate_ust_object_data(struct lttng_ust_abi_object_data **d obj->u.stream.wakeup_fd = dup(src->u.stream.wakeup_fd); if (obj->u.stream.wakeup_fd < 0) { - ret = errno; + ret = -errno; goto stream_error_wakeup_fd; } } else { @@ -1305,7 +1305,7 @@ int lttng_ust_ctl_duplicate_ust_object_data(struct lttng_ust_abi_object_data **d obj->u.stream.shm_fd = dup(src->u.stream.shm_fd); if (obj->u.stream.shm_fd < 0) { - ret = errno; + ret = -errno; goto stream_error_shm_fd; } } else { @@ -1344,7 +1344,7 @@ int lttng_ust_ctl_duplicate_ust_object_data(struct lttng_ust_abi_object_data **d obj->u.counter_global.shm_fd = dup(src->u.counter_global.shm_fd); if (obj->u.counter_global.shm_fd < 0) { - ret = errno; + ret = -errno; goto error_type; } } @@ -1358,7 +1358,7 @@ int lttng_ust_ctl_duplicate_ust_object_data(struct lttng_ust_abi_object_data **d obj->u.counter_cpu.shm_fd = dup(src->u.counter_cpu.shm_fd); if (obj->u.counter_cpu.shm_fd < 0) { - ret = errno; + ret = -errno; goto error_type; } } @@ -2408,7 +2408,6 @@ int get_cred(int sock, /* * Override application uid/gid with unix socket credentials. Use the * first group of the cr_groups. - * Use the pid and ppid provided by the application on registration. */ static int get_cred(int sock, @@ -2422,21 +2421,25 @@ int get_cred(int sock, socklen_t xucred_len = sizeof(struct xucred); int ret; - ret = getsockopt(sock, SOL_SOCKET, LOCAL_PEERCRED, &xucred, &xucred_len); + ret = getsockopt(sock, SOL_LOCAL, LOCAL_PEERCRED, &xucred, &xucred_len); if (ret) { return -LTTNG_UST_ERR_PEERCRED; } if (xucred.cr_version != XUCRED_VERSION || xucred.cr_ngroups < 1) { return -LTTNG_UST_ERR_PEERCRED; } - DBG("Unix socket peercred [ uid: %u, gid: %u ], " - "application registered claiming [ pid: %d, ppid: %d, uid: %u, gid: %u ]", - xucred.cr_uid, xucred.cr_groups[0], + DBG("Unix socket peercred [ pid: %u, uid: %u, gid: %u ], " + "application registered claiming [ pid: %u, ppid: %u, uid: %u, gid: %u ]", + xucred.cr_pid, xucred.cr_uid, xucred.cr_groups[0], reg_msg->pid, reg_msg->ppid, reg_msg->uid, reg_msg->gid); - *pid = reg_msg->pid; - *ppid = reg_msg->ppid; + *pid = xucred.cr_pid; *uid = xucred.cr_uid; *gid = xucred.cr_groups[0]; + if (xucred.cr_pid == reg_msg->pid) { + *ppid = reg_msg->ppid; + } else { + *ppid = 0; + } return 0; } #else