Commit a35c35a9 authored by 's avatar

Fixed devgroupdb_add().


git-svn-id: file:///home/svn/mapi/trunk@1233 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent 2a53d9ee
......@@ -161,10 +161,15 @@ int devgroupdb_add(struct devgroupdb *db, char *device, int groupid) {
}
item = new_devgroupdbitem(device, groupid);
if(db->first != NULL) {
db->first->next = item;
item->next = db->first;
} else db->first = item;
if(db->first == NULL) {
/* init db */
db->last = item;
}
/* insert item */
item->next = db->first;
db->first = item;
/* close circle */
db->last->next = db->first;
return 0;
}
......@@ -179,7 +184,7 @@ int devgroupdb_acquire_rw_lock(char *filename) {
fl.l_start = 0;
fl.l_len = 0;
fl.l_pid = getpid();
fd = open(filename, O_RDWR, 0660); /* write */
if(fd == -1) {
fd = open(filename, O_RDWR | O_CREAT, 0660); /* write */
......@@ -193,7 +198,7 @@ int devgroupdb_acquire_rw_lock(char *filename) {
}
}
}
if(fcntl(fd, F_SETLKW, &fl) == -1) { /* Note: BLOCKING until acquired. */
fputs("devgroupdb_acquire_rw_lock(): could not acquire.\n", stderr);
exit(EXIT_FAILURE);
......@@ -204,13 +209,13 @@ int devgroupdb_acquire_rw_lock(char *filename) {
void devgroupdb_release_rw_lock(int fd) {
struct flock fl;
fl.l_type = F_UNLCK;
fl.l_whence = SEEK_SET;
fl.l_start = 0;
fl.l_len = 0;
fl.l_pid = getpid();
if(fcntl(fd, F_SETLK, &fl) == -1) {
fputs("devgroupdb_acquire_rw_lock(): could not release.\n", stderr);
exit(EXIT_FAILURE);
......@@ -221,9 +226,9 @@ void devgroupdb_release_rw_lock(int fd) {
int devgroupdb_getdevgroupdbfd(char *filename) {
int fd;
fd = open(filename, O_RDONLY);
return fd;
}
......
......@@ -22,6 +22,7 @@ struct devgroupdbitem {
struct devgroupdb {
struct devgroupdbitem *first;
struct devgroupdbitem *last;
int defaultgroupid;
};
......
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