summaryrefslogtreecommitdiffstats
path: root/src/librcc.c
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@dside.dyndns.org>2006-11-24 20:23:09 +0000
committerSuren A. Chilingaryan <csa@dside.dyndns.org>2006-11-24 20:23:09 +0000
commitb91203daf1a2b5865bfd284821c0c0b103f5b8e7 (patch)
tree60949a1c16c1ce22c897393ab4534dab5e8acc0c /src/librcc.c
parent0e5da4d706fa83d29999d9d90976fa4822c3e2e1 (diff)
downloadlibrcc-b91203daf1a2b5865bfd284821c0c0b103f5b8e7.tar.gz
librcc-b91203daf1a2b5865bfd284821c0c0b103f5b8e7.tar.bz2
librcc-b91203daf1a2b5865bfd284821c0c0b103f5b8e7.tar.xz
librcc-b91203daf1a2b5865bfd284821c0c0b103f5b8e7.zip
DB4 Recovery
- RCC Subsystem Locking (per user) - DB4 Recovery (automatically restores environment in the case of db4 upgrades)
Diffstat (limited to 'src/librcc.c')
-rw-r--r--src/librcc.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/src/librcc.c b/src/librcc.c
index 1ffe00b..6d3ce24 100644
--- a/src/librcc.c
+++ b/src/librcc.c
@@ -1,6 +1,8 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#include <time.h>
+#include <errno.h>
#include "../config.h"
@@ -19,6 +21,11 @@
# include <pwd.h>
#endif /* HAVE_PWD_H */
+#ifdef HAVE_SYS_FILE_H
+# include <sys/file.h>
+#endif /* HAVE_SYS_FILE_H */
+
+
#include "internal.h"
#include "rccconfig.h"
#include "rccenca.h"
@@ -135,6 +142,89 @@ void rccFree() {
initialized = 0;
}
+static int lockfd = -1;
+
+int rccLock() {
+# ifdef HAVE_SYS_FILE_H
+ int err, i;
+ int size;
+ char *stmp;
+ struct timespec wait = { 0, 10000000 };
+
+ if (lockfd>=0) return -1;
+
+ size = strlen(rcc_home_dir) + 32;
+ stmp = (char*)malloc(size*sizeof(char));
+ if (!stmp) return -1;
+
+ sprintf(stmp,"%s/.rcc/", rcc_home_dir);
+ mkdir(stmp, 00755);
+
+ sprintf(stmp,"%s/.rcc/locks/", rcc_home_dir);
+ mkdir(stmp, 00700);
+
+ sprintf(stmp,"%s/.rcc/locks/rcc.lock", rcc_home_dir);
+
+ lockfd = open(stmp, O_RDWR|O_CREAT, 0644);
+ if (lockfd >= 0) {
+ for (err = -1, i = 0; i < (LIBRCC_LOCK_WAIT/10); i++) {
+ err = flock(lockfd, LOCK_EX|LOCK_NB);
+ if ((err)&&(errno == EWOULDBLOCK)) nanosleep(&wait, NULL);
+ else break;
+ }
+
+ if (err) {
+ close(lockfd);
+
+ // Removing invalid lock
+ if (i == (LIBRCC_LOCK_WAIT/10)) {
+ remove(stmp);
+
+ lockfd = open(stmp, O_RDWR|O_CREAT, 0644);
+ if (lockfd >= 0) {
+ for (err = -1, i = 0; i < (LIBRCC_LOCK_WAIT/10); i++) {
+ err = flock(lockfd, LOCK_EX|LOCK_NB);
+ if ((err)&&(errno == EWOULDBLOCK)) nanosleep(&wait, NULL);
+ else break;
+ }
+
+ if (err) close(lockfd);
+ else return 0;
+ }
+ }
+
+ lockfd = -1;
+ return -1;
+ }
+
+ return 0;
+ }
+
+ return -1;
+# else /* HAVE_SYS_FILE_H */
+ return 0;
+# endif /* HAVE_SYS_FILE_H */
+}
+
+void rccUnLock() {
+#ifdef HAVE_SYS_FILE_H
+ int size;
+ char *stmp;
+
+ if (lockfd<0) return;
+
+ size = strlen(rcc_home_dir) + 32;
+ stmp = (char*)malloc(size*sizeof(char));
+ if (!stmp) return;
+
+ sprintf(stmp,"%s/.rcc/locks/rcc.lock", rcc_home_dir);
+
+ flock(lockfd, LOCK_UN);
+ close(lockfd);
+ lockfd = -1;
+#endif /* HAVE_SYS_FILE_H */
+}
+
rcc_context rccCreateContext(const char *locale_variable, unsigned int max_languages, unsigned int max_classes, rcc_class_ptr defclasses, rcc_init_flags flags) {
unsigned int i;