diff options
| author | Rich Felker <dalias@aerifal.cx> | 2020-10-27 01:12:56 -0400 | 
|---|---|---|
| committer | Rich Felker <dalias@aerifal.cx> | 2020-10-27 01:15:06 -0400 | 
| commit | 613ccabeb0c10ac818e36ef53e09753d23785cbf (patch) | |
| tree | 3f17524f9d2c16c36bf89a66a5f10fbd0a0d4ca5 /src | |
| parent | ccba23459ebacc8bc6e5eeef7454c91ceb61b5b0 (diff) | |
| download | musl-613ccabeb0c10ac818e36ef53e09753d23785cbf.tar.gz | |
refactor setxid return path to use __syscall_ret
this avoids some spurious negation and duplicated errno logic, and
brings the code in line with the newly-added multithreaded setgroups.
Diffstat (limited to 'src')
| -rw-r--r-- | src/unistd/setxid.c | 23 | 
1 files changed, 9 insertions, 14 deletions
| diff --git a/src/unistd/setxid.c b/src/unistd/setxid.c index 0239f8af..487c1a16 100644 --- a/src/unistd/setxid.c +++ b/src/unistd/setxid.c @@ -1,20 +1,19 @@  #include <unistd.h> -#include <errno.h> +#include <signal.h>  #include "syscall.h"  #include "libc.h" -#include "pthread_impl.h"  struct ctx {  	int id, eid, sid; -	int nr, err; +	int nr, ret;  };  static void do_setxid(void *p)  {  	struct ctx *c = p; -	if (c->err>0) return; -	int ret = -__syscall(c->nr, c->id, c->eid, c->sid); -	if (ret && !c->err) { +	if (c->ret<0) return; +	int ret = __syscall(c->nr, c->id, c->eid, c->sid); +	if (ret && !c->ret) {  		/* If one thread fails to set ids after another has already  		 * succeeded, forcibly killing the process is the only safe  		 * thing to do. State is inconsistent and dangerous. Use @@ -22,18 +21,14 @@ static void do_setxid(void *p)  		__block_all_sigs(0);  		__syscall(SYS_kill, __syscall(SYS_getpid), SIGKILL);  	} -	c->err = ret; +	c->ret = ret;  }  int __setxid(int nr, int id, int eid, int sid)  { -	/* err is initially nonzero so that failure of the first thread does not +	/* ret is initially nonzero so that failure of the first thread does not  	 * trigger the safety kill above. */ -	struct ctx c = { .nr = nr, .id = id, .eid = eid, .sid = sid, .err = -1 }; +	struct ctx c = { .nr = nr, .id = id, .eid = eid, .sid = sid, .ret = 1 };  	__synccall(do_setxid, &c); -	if (c.err) { -		if (c.err>0) errno = c.err; -		return -1; -	} -	return 0; +	return __syscall_ret(c.ret);  } | 
