X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Frunas.c;h=60e02a2bf85a4e22ff363d2a6ede3cfc1a0fd277;hp=745a6d0d13643d2333ee1bfe5c8b3e4c8fe4fb3b;hb=4c462e790c62ed5f6c5d61b3a182762fe02f7e9a;hpb=799e2c4f4ecb595fcb52c3e6affd3b4ec7b5b24e diff --git a/src/common/runas.c b/src/common/runas.c index 745a6d0d1..60e02a2bf 100644 --- a/src/common/runas.c +++ b/src/common/runas.c @@ -154,14 +154,14 @@ int child_run_as(void *_data) if (data->gid != getegid()) { ret = setegid(data->gid); if (ret < 0) { - perror("setegid"); + PERROR("setegid"); return EXIT_FAILURE; } } if (data->uid != geteuid()) { ret = seteuid(data->uid); if (ret < 0) { - perror("seteuid"); + PERROR("seteuid"); return EXIT_FAILURE; } } @@ -177,7 +177,7 @@ int child_run_as(void *_data) writelen = write(data->retval_pipe, &sendret.c[index], writeleft); if (writelen < 0) { - perror("write"); + PERROR("write"); return EXIT_FAILURE; } writeleft -= writelen; @@ -214,7 +214,7 @@ int run_as(int (*cmd)(void *data), void *data, uid_t uid, gid_t gid) ret = pipe(retval_pipe); if (ret < 0) { - perror("pipe"); + PERROR("pipe"); retval.i = ret; goto end; } @@ -228,7 +228,7 @@ int run_as(int (*cmd)(void *data), void *data, uid_t uid, gid_t gid) MAP_PRIVATE | MAP_GROWSDOWN | MAP_ANONYMOUS | MAP_STACK, -1, 0); if (child_stack == MAP_FAILED) { - perror("mmap"); + PERROR("mmap"); retval.i = -ENOMEM; goto close_pipe; } @@ -240,7 +240,7 @@ int run_as(int (*cmd)(void *data), void *data, uid_t uid, gid_t gid) CLONE_FILES | SIGCHLD, &run_as_data, NULL); if (pid < 0) { - perror("clone"); + PERROR("clone"); retval.i = pid; goto unmap_stack; } @@ -250,7 +250,7 @@ int run_as(int (*cmd)(void *data), void *data, uid_t uid, gid_t gid) do { readlen = read(retval_pipe[0], &retval.c[index], readleft); if (readlen < 0) { - perror("read"); + PERROR("read"); ret = -1; break; } @@ -264,18 +264,24 @@ int run_as(int (*cmd)(void *data), void *data, uid_t uid, gid_t gid) */ pid = waitpid(pid, &status, 0); if (pid < 0 || !WIFEXITED(status) || WEXITSTATUS(status) != 0) { - perror("wait"); + PERROR("wait"); retval.i = -1; } unmap_stack: ret = munmap(child_stack, RUNAS_CHILD_STACK_SIZE); if (ret < 0) { - perror("munmap"); + PERROR("munmap"); retval.i = ret; } close_pipe: - close(retval_pipe[0]); - close(retval_pipe[1]); + ret = close(retval_pipe[0]); + if (ret) { + PERROR("close"); + } + ret = close(retval_pipe[1]); + if (ret) { + PERROR("close"); + } end: return retval.i; }