summaryrefslogtreecommitdiffstats
path: root/community-scripts/rename/atomic/bug1034/gt_rename.c
diff options
context:
space:
mode:
authorLakshmipathi <lakshmipathi.g@gmail.com>2011-07-08 11:51:53 +0530
committerLakshmipathi <lakshmipathi.g@gmail.com>2011-07-08 11:51:53 +0530
commitb47528cc4bb7a308c74d4dae7c2adcf9f7392f4e (patch)
tree35742effa1325ea42a99492167d16e75feabd373 /community-scripts/rename/atomic/bug1034/gt_rename.c
parentbb2ca55002b8faac2b4687a97b611724081e601b (diff)
Added community provided scripts for lock and rename
Diffstat (limited to 'community-scripts/rename/atomic/bug1034/gt_rename.c')
-rw-r--r--community-scripts/rename/atomic/bug1034/gt_rename.c86
1 files changed, 86 insertions, 0 deletions
diff --git a/community-scripts/rename/atomic/bug1034/gt_rename.c b/community-scripts/rename/atomic/bug1034/gt_rename.c
new file mode 100644
index 0000000..96ecce0
--- /dev/null
+++ b/community-scripts/rename/atomic/bug1034/gt_rename.c
@@ -0,0 +1,86 @@
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "gt.h"
+
+static void
+usage(char *progname)
+{
+ fprintf(stderr, "usage: %s node\n", progname);
+ exit(1);
+}
+
+static void
+touch_tree(char *rootpath, int node)
+{
+ char pathbuf[PATH_MAX];
+ char databuf[PATH_MAX];
+ int fd;
+ int i;
+ int retval;
+
+ for (i = 0; i < SUBDIR_FILES; i++) {
+ char tempbuf[PATH_MAX];
+
+ snprintf(pathbuf, sizeof(pathbuf),
+ "%s/%d/WA_RC_%d", rootpath, node, i);
+ snprintf(tempbuf, sizeof(tempbuf),
+ "%s/%d/WA_RC_%d.temp", rootpath, node, i);
+ fd = open(tempbuf, O_RDWR|O_CREAT, 0644);
+ if (0 > fd) {
+ fprintf(stderr, "gt_rename: %s: open %s\n",
+ strerror(errno), tempbuf);
+ continue;
+ }
+ retval = write(fd, pathbuf, strlen(pathbuf));
+ if (0 > retval) {
+ fprintf(stderr, "gt_rename: %s: write %s\n",
+ strerror(errno), pathbuf);
+ } else if (retval != strlen(pathbuf)) {
+ fprintf(stderr, "gt_rename: incomplete write: write %s\n",
+ pathbuf);
+ }
+ close(fd);
+
+ retval = rename(tempbuf, pathbuf);
+ if (0 > retval) {
+ fprintf(stderr, "gt_rename: %s rename %s\n",
+ strerror(errno), pathbuf);
+ }
+ }
+}
+
+int
+main(int argc, char **argv)
+{
+ char *arg_ptr;
+ long node;
+
+ if (argc != 2) {
+ usage(argv[0]);
+ }
+
+ node = strtol(argv[1], &arg_ptr, 10);
+ if (*arg_ptr != '\0') {
+ usage(argv[0]);
+ }
+
+ while (1) {
+ int snooze;
+
+ touch_tree(BASE_PATH, node);
+
+ snooze = CYCLE_TIME + random()%CYCLE_JITTER;
+ usleep(1000*snooze);
+ }
+
+ exit(0);
+}