diff options
author | An-Cheng Huang <ancheng@vyatta.com> | 2007-10-30 10:56:58 -0700 |
---|---|---|
committer | An-Cheng Huang <ancheng@vyatta.com> | 2007-10-30 10:56:58 -0700 |
commit | 653569b3768a4ebfc7d111864f3d165977db37a6 (patch) | |
tree | df4c1ee8a7d237dcdc8cad5b2984b0e60cc430bc /src | |
parent | 5c170940c89065df4c7bbc6561cbdfd297363aad (diff) | |
download | vyatta-cfg-653569b3768a4ebfc7d111864f3d165977db37a6.tar.gz vyatta-cfg-653569b3768a4ebfc7d111864f3d165977db37a6.zip |
handle config locking
Diffstat (limited to 'src')
-rw-r--r-- | src/cli_new.c | 46 | ||||
-rw-r--r-- | src/cli_val.h | 3 | ||||
-rw-r--r-- | src/commit.c | 6 | ||||
-rw-r--r-- | src/delete.c | 1 | ||||
-rw-r--r-- | src/set.c | 1 |
5 files changed, 23 insertions, 34 deletions
diff --git a/src/cli_new.c b/src/cli_new.c index 8abdbff..52a03d3 100644 --- a/src/cli_new.c +++ b/src/cli_new.c @@ -215,35 +215,31 @@ void di(vtw_sorted *srtp) printf("%u %u\n", i, *(unsigned int *)(srtp->ptrs[i])); } -static char _lock_file_[1025] = {0}; -static int _lock_fd_=-1; +#define LOCK_FILE "/var/lock/vyatta_cfg_lock" -static void clean_lock_file(void) { - if(_lock_file_[0]) { - unlink(_lock_file_); - _lock_file_[0]=0; - } - if(_lock_fd_!=-1) { - close(_lock_fd_); - _lock_fd_=-1; - } +static void +release_config_lock() +{ + unlink(LOCK_FILE); + /* error ignored */ } -boolean get_config_lock(const char* adirp, const char* lock_name) { - - boolean ret = TRUE; - - sprintf(_lock_file_, "%s/%s", adirp, lock_name); - - _lock_fd_ = open(_lock_file_, O_WRONLY | O_CREAT | O_EXCL, 0644); - - ret = (_lock_fd_!=-1); - - if(ret) { - atexit(clean_lock_file); +int +get_config_lock() +{ + int fd = open(LOCK_FILE, O_WRONLY | O_CREAT | O_EXCL, 0660); + if (fd == -1) { + return -1; } - - return ret; + if (close(fd) == -1) { + release_config_lock(); + return -1; + } + if (atexit(release_config_lock) != 0) { + release_config_lock(); + return -1; + } + return 0; } void internal_error(int line, char *file) diff --git a/src/cli_val.h b/src/cli_val.h index 6ccfde2..7d57456 100644 --- a/src/cli_val.h +++ b/src/cli_val.h @@ -190,7 +190,7 @@ extern void touch_dir(const char *dp); void mark_paths(vtw_mark *markp); void restore_paths(vtw_mark *markp); -extern boolean get_config_lock(const char* adirp, const char* lock_name); +extern int get_config_lock(); #define VTWERR_BADPATH -2 #define VTWERR_OK 0 @@ -199,7 +199,6 @@ extern boolean get_config_lock(const char* adirp, const char* lock_name); #define VAL_NAME "node.val" #define MOD_NAME ".modified" #define OPQ_NAME ".wh.__dir_opaque" -#define LOCK_NAME ".commit.lck" #define INTERNAL internal_error(__LINE__, __FILE__) diff --git a/src/commit.c b/src/commit.c index 7cd01df..9aafedd 100644 --- a/src/commit.c +++ b/src/commit.c @@ -117,7 +117,6 @@ static boolean validate_dir_for_commit() if (strcmp(dirp->d_name, ".") == 0 || strcmp(dirp->d_name, "..") == 0 || strcmp(dirp->d_name, MOD_NAME) == 0 || - strcmp(dirp->d_name, LOCK_NAME) == 0 || strcmp(dirp->d_name, opaque_name) == 0 || strncmp(dirp->d_name, ".wh.", 4) == 0) { continue; /*ignore dot and dot-dot*/ @@ -274,7 +273,7 @@ int main(int argc, char **argv) bye("No configuration changes to commit\n"); } - if(!get_config_lock(get_adirp(), LOCK_NAME)) { + if (get_config_lock() == -1) { fprintf(out_stream, "Cannot commit: Configuration is locked\n"); bye("Configuration is locked\n"); } @@ -387,7 +386,6 @@ boolean commit_update_child(vtw_def *pdefp, char *child, if (strcmp(child, ".") == 0 || strcmp(child, "..") == 0 || strcmp(child, MOD_NAME) == 0 || - strcmp(child, LOCK_NAME) == 0 || strcmp(child, opaque_name) == 0) return TRUE; @@ -931,7 +929,6 @@ static boolean commit_delete_children(vtw_def *defp, boolean deleting, if (strcmp(child, ".") == 0 || strcmp(child, "..") == 0 || strcmp(child, MOD_NAME) == 0 || - strcmp(child, LOCK_NAME) == 0 || strcmp(child, OPQ_NAME) == 0) continue; uename = clind_unescape(child); @@ -1020,7 +1017,6 @@ static boolean commit_update_children(vtw_def *defp, boolean creating, if (strcmp(child, ".") == 0 || strcmp(child, "..") == 0 || strcmp(child, MOD_NAME) == 0 || - strcmp(child, LOCK_NAME) == 0 || strcmp(child, OPQ_NAME) == 0) continue; cp = uename = clind_unescape(child); diff --git a/src/delete.c b/src/delete.c index 0f16e7d..f048f46 100644 --- a/src/delete.c +++ b/src/delete.c @@ -144,7 +144,6 @@ int main(int argc, char **argv) if (strcmp(dirp->d_name, ".") && strcmp(dirp->d_name, "..") && strcmp(dirp->d_name, MOD_NAME) && /* XXX */ - strcmp(dirp->d_name, LOCK_NAME) && /* XXX */ strncmp(dirp->d_name, ".wh.", 4) ) break; } @@ -274,7 +274,6 @@ static void handle_defaults() if (strcmp(dirp->d_name, ".")==0 || strcmp(dirp->d_name, "..")==0 || strcmp(dirp->d_name, MOD_NAME) == 0 || - strcmp(dirp->d_name, LOCK_NAME) == 0 || strcmp(dirp->d_name, DEF_NAME)==0) continue; uename = clind_unescape(dirp->d_name); |