diff options
-rw-r--r-- | device-functions.c | 12 | ||||
-rw-r--r-- | flash.c | 41 | ||||
-rw-r--r-- | flash.h | 3 |
3 files changed, 34 insertions, 22 deletions
diff --git a/device-functions.c b/device-functions.c index 20918a8..8bca0d7 100644 --- a/device-functions.c +++ b/device-functions.c @@ -4402,7 +4402,8 @@ void Main_update_shift_registers() int IO_Setup_RS232(int baud, char hardhand) { - remount_root_as_writeable (); + printf ("start writeable: rs232 change\n"); + remount_root_as_writeable (TRUE); FILE* configfile = fopen("/tmp/instgettyopts", "w"); if(configfile) { fprintf(configfile, "OPTS=-L %s\n", hardhand ? "-h" : ""); @@ -4410,7 +4411,8 @@ int IO_Setup_RS232(int baud, char hardhand) fclose(configfile); system("systemctl --no-block restart inst-getty@ttyO5.service"); } - remount_root_as_not_writeable(); + printf ("end writeable: rs232 change\n"); + remount_root_as_writeable (FALSE); globals.Flash.baud = baud; globals.Flash.hardhand = hardhand; @@ -4497,7 +4499,8 @@ int change_password(gchar *old_password, gchar *new_password) int result; result = OK; - remount_root_as_writeable (); + printf ("start writeable: password change\n"); + remount_root_as_writeable (TRUE); ctx = lu_start(user, lu_user, NULL, NULL, lu_prompt_console_quiet, NULL, &error); @@ -4517,7 +4520,8 @@ int change_password(gchar *old_password, gchar *new_password) lu_end(ctx); - remount_root_as_not_writeable (); + printf ("end writeable: password change\n"); + remount_root_as_writeable (FALSE); return result; } else { @@ -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"); } @@ -8,8 +8,7 @@ void initFlash(FlashStruct *mem, gboolean reset_to_defaults, int starting_locati void writeUserBlock(FlashStruct *mem, int addr, int numbytes); void fixFlash(FlashStruct *mem); void stopFlashWriterThread(); -void remount_root_as_writeable(); -void remount_root_as_not_writeable(); +void remount_root_as_writeable(gboolean start); #endif |