Blob Blame History Raw
From b6e94e46e4a44fe0bc73f60f2993c8151b91b33a Mon Sep 17 00:00:00 2001
From: Avra Sengupta <asengupt@redhat.com>
Date: Sun, 5 Jul 2015 12:57:39 +0530
Subject: [PATCH 215/234] snapshot/scheduler: Use /var/run/gluster/shared_storage/snaps/tmp_file for writing data into tmp file and then making an atomic rename to the required filename

The reason for using this location is that it adheres to
the selinux policies.

Also moving the update of the current_scheduler file,
under the lock so as to avoid multiple writes

>Reviewed-on: http://review.gluster.org/11536
Change-Id: I61e62b5daf6f1bce2319f64f7b1dfb8b93726077
BUG: 1231647
Signed-off-by: Avra Sengupta <asengupt@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/52559
Reviewed-by: Rajesh Joseph <rjoseph@redhat.com>
Tested-by: Rajesh Joseph <rjoseph@redhat.com>
---
 extras/snap_scheduler/snap_scheduler.py |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/extras/snap_scheduler/snap_scheduler.py b/extras/snap_scheduler/snap_scheduler.py
index 09015c5..ce808cf 100755
--- a/extras/snap_scheduler/snap_scheduler.py
+++ b/extras/snap_scheduler/snap_scheduler.py
@@ -423,7 +423,7 @@ def edit_schedules(jobname, schedule, volname):
 
 def initialise_scheduler():
     try:
-        with open("/tmp/crontab", "w+", 0644) as f:
+        with open(TMP_FILE, "w+", 0644) as f:
             updater = ("* * * * * root PATH=$PATH:/usr/local/sbin:"
                        "/usr/sbin gcron.py --update\n")
             f.write("%s\n" % updater)
@@ -431,11 +431,11 @@ def initialise_scheduler():
             os.fsync(f.fileno())
             f.close()
     except IOError as (errno, strerror):
-        log.error("Failed to open /tmp/crontab. Error: %s.", strerror)
+        log.error("Failed to open %s. Error: %s.", TMP_FILE, strerror)
         ret = INIT_FAILED
         return ret
 
-    shutil.move("/tmp/crontab", GCRON_UPDATE_TASK)
+    shutil.move(TMP_FILE, GCRON_UPDATE_TASK)
 
     if not os.path.lexists(GCRON_TASKS):
         try:
@@ -491,6 +491,9 @@ def syntax_checker(args):
 
 
 def perform_operation(args):
+    if not os.path.exists(CURRENT_SCHEDULER):
+        update_current_scheduler("none")
+
     # Initialise snapshot scheduler on local node
     if args.action == "init":
         ret = initialise_scheduler()
@@ -651,9 +654,6 @@ def main(argv):
                        % (LOCK_FILE_DIR, strerror))
                 return INTERNAL_ERROR
 
-    if not os.path.exists(CURRENT_SCHEDULER):
-        update_current_scheduler("none")
-
     try:
         f = os.open(LOCK_FILE, os.O_CREAT | os.O_RDWR | os.O_NONBLOCK, 0644)
         try:
-- 
1.7.1