projects
/
lttng-tools.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix: consumer race: should allow reuse of FD key
[lttng-tools.git]
/
src
/
common
/
runas.c
diff --git
a/src/common/runas.c
b/src/common/runas.c
index cc503412689f55f48524ef515d608a9f1a4cdf4b..60e02a2bf85a4e22ff363d2a6ede3cfc1a0fd277 100644
(file)
--- a/
src/common/runas.c
+++ b/
src/common/runas.c
@@
-30,12
+30,16
@@
#include <sched.h>
#include <sys/mman.h>
#include <sched.h>
#include <sys/mman.h>
-#include <common/
lttnger
r.h>
+#include <common/
erro
r.h>
#include "runas.h"
#define RUNAS_CHILD_STACK_SIZE 10485760
#include "runas.h"
#define RUNAS_CHILD_STACK_SIZE 10485760
+#ifndef MAP_STACK
+#define MAP_STACK 0
+#endif
+
struct run_as_data {
int (*cmd)(void *data);
void *data;
struct run_as_data {
int (*cmd)(void *data);
void *data;
@@
-150,14
+154,14
@@
int child_run_as(void *_data)
if (data->gid != getegid()) {
ret = setegid(data->gid);
if (ret < 0) {
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) {
return EXIT_FAILURE;
}
}
if (data->uid != geteuid()) {
ret = seteuid(data->uid);
if (ret < 0) {
-
perror
("seteuid");
+
PERROR
("seteuid");
return EXIT_FAILURE;
}
}
return EXIT_FAILURE;
}
}
@@
-173,7
+177,7
@@
int child_run_as(void *_data)
writelen = write(data->retval_pipe, &sendret.c[index],
writeleft);
if (writelen < 0) {
writelen = write(data->retval_pipe, &sendret.c[index],
writeleft);
if (writelen < 0) {
-
perror
("write");
+
PERROR
("write");
return EXIT_FAILURE;
}
writeleft -= writelen;
return EXIT_FAILURE;
}
writeleft -= writelen;
@@
-210,7
+214,8
@@
int run_as(int (*cmd)(void *data), void *data, uid_t uid, gid_t gid)
ret = pipe(retval_pipe);
if (ret < 0) {
ret = pipe(retval_pipe);
if (ret < 0) {
- perror("pipe");
+ PERROR("pipe");
+ retval.i = ret;
goto end;
}
run_as_data.data = data;
goto end;
}
run_as_data.data = data;
@@
-223,8
+228,8
@@
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) {
MAP_PRIVATE | MAP_GROWSDOWN | MAP_ANONYMOUS | MAP_STACK,
-1, 0);
if (child_stack == MAP_FAILED) {
-
perror
("mmap");
- ret = -ENOMEM;
+
PERROR
("mmap");
+ ret
val.i
= -ENOMEM;
goto close_pipe;
}
/*
goto close_pipe;
}
/*
@@
-235,8
+240,8
@@
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) {
CLONE_FILES | SIGCHLD,
&run_as_data, NULL);
if (pid < 0) {
-
perror
("clone");
- ret = pid;
+
PERROR
("clone");
+ ret
val.i
= pid;
goto unmap_stack;
}
/* receive return value */
goto unmap_stack;
}
/* receive return value */
@@
-245,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) {
do {
readlen = read(retval_pipe[0], &retval.c[index], readleft);
if (readlen < 0) {
-
perror
("read");
+
PERROR
("read");
ret = -1;
break;
}
ret = -1;
break;
}
@@
-259,17
+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) {
*/
pid = waitpid(pid, &status, 0);
if (pid < 0 || !WIFEXITED(status) || WEXITSTATUS(status) != 0) {
-
perror
("wait");
- ret = -1;
+
PERROR
("wait");
+ ret
val.i
= -1;
}
unmap_stack:
ret = munmap(child_stack, RUNAS_CHILD_STACK_SIZE);
if (ret < 0) {
}
unmap_stack:
ret = munmap(child_stack, RUNAS_CHILD_STACK_SIZE);
if (ret < 0) {
- perror("munmap");
+ PERROR("munmap");
+ retval.i = ret;
}
close_pipe:
}
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;
}
end:
return retval.i;
}
This page took
0.02561 seconds
and
4
git commands to generate.