summaryrefslogtreecommitdiff
path: root/flash.c
diff options
context:
space:
mode:
authorroot <root@avtech.domain.avtechpulse.com>1970-01-01 09:33:41 +0900
committerroot <root@avtech.domain.avtechpulse.com>1970-01-01 09:33:41 +0900
commit505acceba17a4987fb445cce1eed792cf41e93c6 (patch)
treec70e52da006205ef14d32547043a6e79ce7c1d9a /flash.c
parent49d90621d371d450faca9d3f5e11089d1e30eb24 (diff)
add mutex around remounting, and add debug messagesINSTRUMENT_6_2_02
Diffstat (limited to 'flash.c')
-rw-r--r--flash.c41
1 files changed, 25 insertions, 16 deletions
diff --git a/flash.c b/flash.c
index 38f42a2..ab5ebb2 100644
--- a/flash.c
+++ b/flash.c
@@ -308,23 +308,26 @@ hdrlengthok:
}
-void remount_root_as_writeable ()
+void remount_root_as_writeable (gboolean start)
{
gchar *cmd;
- cmd = g_strdup_printf ("/usr/bin/mount -o remount,rw %s /", globals.HWDetect.remount_point);
- printf ("%s\n",cmd);
- system(cmd);
- g_free (cmd);
-}
+ static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
+
+ if (start) {
+ g_static_mutex_lock (&mutex);
+ cmd = g_strdup_printf ("/usr/bin/mount -o remount,rw %s /", globals.HWDetect.remount_point);
+ } else {
+ cmd = g_strdup_printf ("/usr/bin/mount -o remount,ro %s /", globals.HWDetect.remount_point);
+ }
-void remount_root_as_not_writeable ()
-{
- gchar *cmd;
- cmd = g_strdup_printf ("/usr/bin/mount -o remount,ro %s /", globals.HWDetect.remount_point);
printf ("%s\n",cmd);
system(cmd);
g_free (cmd);
+
+ if (!start) {
+ g_static_mutex_unlock (&mutex);
+ }
}
@@ -350,12 +353,14 @@ static int readUserBlock(FlashStruct *mem)
// if the backup was good overwrite the main file
if (!globals.Sys.shutdown_started) {
globals.Sys.flash_write_in_progress = TRUE;
- remount_root_as_writeable ();
+ printf ("start writeable: copy from backup\n");
+ remount_root_as_writeable (TRUE);
persistence_copyfile(BACKUPFILE, MAINFILE);
globals.Sys.flash_write_in_progress = FALSE;
- remount_root_as_not_writeable ();
+ printf ("end writeable: copy from backup\n");
+ remount_root_as_writeable (FALSE);
}
return sizeof(*mem);
}
@@ -384,17 +389,20 @@ void writeUserBlockNow(FlashStruct *mem, int addr, int numbytes)
if (!globals.Sys.shutdown_started) {
globals.Sys.flash_write_in_progress = TRUE;
- remount_root_as_writeable ();
+ printf ("start writeable: make backup\n");
+ remount_root_as_writeable (TRUE);
bool backup_ok = persistence_copyfile(MAINFILE, BACKUPFILE);
globals.Sys.flash_write_in_progress = FALSE;
- remount_root_as_not_writeable ();
+ printf ("end writeable: make backup\n");
+ remount_root_as_writeable (FALSE);
if (backup_ok && !globals.Sys.shutdown_started) {
globals.Sys.flash_write_in_progress = TRUE;
- remount_root_as_writeable ();
+ printf ("start writeable: write to main config file\n");
+ remount_root_as_writeable (TRUE);
if (!persistence_freeze(MAINFILE, mem, addr, numbytes, sizeof(*mem), 0)) {
if (errno != PERSIST_ERR_COULDNTWRITE) {
@@ -404,7 +412,8 @@ void writeUserBlockNow(FlashStruct *mem, int addr, int numbytes)
}
}
globals.Sys.flash_write_in_progress = FALSE;
- remount_root_as_not_writeable ();
+ printf ("end writeable: write to main config file\n");
+ remount_root_as_writeable (FALSE);
} else {
printf("Could not backup current file. **Write did not happen!!!**\n");
}