diff options
| author | Alex Dowad <alexinbeijing@gmail.com> | 2014-04-04 16:36:30 +0200 | 
|---|---|---|
| committer | Timo Teräs <timo.teras@iki.fi> | 2014-04-25 10:16:49 +0300 | 
| commit | 751bbc05d4dd72bdbe7e57f6724de865cd7c0bd9 (patch) | |
| tree | 329a906671c9136a329e263f40fa5b6c1360e567 | |
| parent | eb5b69d278b1430750a5e1d74bd2804cbc4b14e8 (diff) | |
| download | squark-751bbc05d4dd72bdbe7e57f6724de865cd7c0bd9.tar.bz2 squark-751bbc05d4dd72bdbe7e57f6724de865cd7c0bd9.tar.xz  | |
authdb: report errors in authdb_me_open
| -rw-r--r-- | src/authdb.c | 19 | 
1 files changed, 16 insertions, 3 deletions
diff --git a/src/authdb.c b/src/authdb.c index a329d8b..c9a5dd3 100644 --- a/src/authdb.c +++ b/src/authdb.c @@ -8,12 +8,15 @@  #include <ctype.h>  #include <time.h>  #include <grp.h> +#include <errno.h> +#include <string.h>  #include "config.h"  #include "authdb.h"  #include "filterdb.h"  #include "addr.h"  #include "blob.h" +#include "reporting.h"  #define ALIGN(s,a)		(((s) + a - 1) & ~(a - 1)) @@ -38,17 +41,22 @@ static struct authdb_map_entry *authdb_me_open(sockaddr_any *addr, int create)  		oflag |= O_CREAT;  	fd = shm_open(name, oflag, 0660); -	if (fd < 0) +	if (fd < 0) { +		report_error("Couldn't create shared memory object. Error: %s\n", strerror(errno));  		return NULL; +	}  	if (ftruncate(fd, AUTHDB_SHM_SIZE) < 0) {  		close(fd); +		report_error("Couldn't truncate shared memory object. Error: %s\n", strerror(errno));  		return NULL;  	}  	getgrnam_r("squark", &grp, buf, sizeof(buf), &res);  	if (res != NULL) { -		fchown(fd, -1, res->gr_gid); +		if (fchown(fd, -1, res->gr_gid) < 0) +			report_error("Couldn't set group ownership of shared memory object. Error: %s\n", +				strerror(errno));  		fchmod(fd, 0660);  	} @@ -56,12 +64,17 @@ static struct authdb_map_entry *authdb_me_open(sockaddr_any *addr, int create)  		    PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);  	close(fd); -	if (base == MAP_FAILED) +	if (base == MAP_FAILED) { +		report_error("Couldn't map shared memory object into address space. Error: %s\n", +			strerror(errno));  		return NULL; +	}  	me = malloc(sizeof(*me));  	if (me == NULL) {  		munmap(base, AUTHDB_SHM_SIZE); +		report_error("Couldn't allocate memory for authentication database entry. Error: %s\n", +			strerror(errno));  		return NULL;  	}  | 
