Commit 224f0dfe authored by Jon Kåre Hellan's avatar Jon Kåre Hellan

Create devgroupdb tmpfile with group mapi.


git-svn-id: file:///home/svn/mapi/trunk@1225 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent 2e2e803f
......@@ -68,6 +68,7 @@
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <grp.h>
#include "mapi.h"
#include "mapi_errors.h"
......@@ -171,6 +172,7 @@ int devgroupdb_add(struct devgroupdb *db, char *device, int groupid) {
int devgroupdb_acquire_rw_lock(char *filename) {
struct flock fl;
int fd;
struct group *mapi_group;
fl.l_type = F_WRLCK; /* write */
fl.l_whence = SEEK_SET;
......@@ -178,10 +180,18 @@ int devgroupdb_acquire_rw_lock(char *filename) {
fl.l_len = 0;
fl.l_pid = getpid();
fd = open(filename, O_RDWR | O_CREAT, 0660); /* write */
fd = open(filename, O_RDWR, 0660); /* write */
if(fd == -1) {
fprintf(stderr, "devgroupdb_acquire_rw_lock(): could not open devgroupdb %s.\n", filename);
exit(EXIT_FAILURE);
fd = open(filename, O_RDWR | O_CREAT, 0660); /* write */
if(fd == -1) {
fprintf(stderr, "devgroupdb_acquire_rw_lock(): could not open devgroupdb %s.\n", filename);
exit(EXIT_FAILURE);
} else {
mapi_group = getgrnam(MAPI_GROUP_NAME);
if (mapi_group != NULL) {
chown(filename, -1, mapi_group->gr_gid);
}
}
}
if(fcntl(fd, F_SETLKW, &fl) == -1) { /* Note: BLOCKING until acquired. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment