Rearrange the code in write_image().
---
suspend.c | 154 ++++++++++++++++++++++++++++++++------------------------------
1 file changed, 81 insertions(+), 73 deletions(-)
Index: suspend/suspend.c
===================================================================
--- suspend.orig/suspend.c 2007-08-16 15:19:49.000000000 +0200
+++ suspend/suspend.c 2007-08-16 15:33:48.000000000 +0200
@@ -611,96 +611,100 @@ int write_image(int snapshot_fd, int res
}
error = init_swap_writer(&handle, snapshot_fd, resume_fd,
(char *)mem_pool + page_size);
- if (!error) {
- header->map_start = handle.cur_swap;
- header->image_flags = 0;
- max_block_size = page_size;
- if (compute_checksum)
- header->image_flags |= IMAGE_CHECKSUM;
-
- if (compress) {
- header->image_flags |= IMAGE_COMPRESSED;
- /*
- * The formula below follows from the worst-case
- * expansion calculation for LZO1. sizeof(short) is
- * related to the size field in 'struct buf_block'
- */
- max_block_size += (page_size >> 4) + 67
- + sizeof(short);
- }
+ if (error)
+ goto Exit;
-#ifdef CONFIG_ENCRYPT
- if (do_encrypt) {
- if (use_RSA) {
- error = gcry_cipher_setkey(cipher_handle,
- key_data->key, KEY_SIZE);
- if (error)
- goto No_RSA;
+ header->map_start = handle.cur_swap;
+ header->image_flags = 0;
+ max_block_size = page_size;
+ if (compute_checksum)
+ header->image_flags |= IMAGE_CHECKSUM;
- error = gcry_cipher_setiv(cipher_handle,
- key_data->ivec, CIPHER_BLOCK);
+ if (compress) {
+ header->image_flags |= IMAGE_COMPRESSED;
+ /*
+ * The formula below follows from the worst-case expansion
+ * calculation for LZO1. sizeof(short) is due to the size field
+ * in 'struct buf_block'.
+ */
+ max_block_size += (page_size >> 4) + 67 + sizeof(short);
+ }
- if (error)
- goto No_RSA;
+#ifdef CONFIG_ENCRYPT
+ if (!do_encrypt)
+ goto Save_image;
- header->image_flags |= IMAGE_ENCRYPTED |
- IMAGE_USE_RSA;
- memcpy(&header->rsa, &key_data->rsa,
- sizeof(struct RSA_data));
- memcpy(&header->key, &key_data->encrypted_key,
+ if (use_RSA) {
+ error = gcry_cipher_setkey(cipher_handle, key_data->key,
+ KEY_SIZE);
+ if (error)
+ goto No_RSA;
+
+ error = gcry_cipher_setiv(cipher_handle, key_data->ivec,
+ CIPHER_BLOCK);
+ if (error)
+ goto No_RSA;
+
+ header->image_flags |= IMAGE_ENCRYPTED | IMAGE_USE_RSA;
+ memcpy(&header->rsa, &key_data->rsa, sizeof(struct RSA_data));
+ memcpy(&header->key, &key_data->encrypted_key,
sizeof(struct encrypted_key));
- } else {
- int j;
+ } else {
+ int j;
No_RSA:
- encrypt_init(key_data->key, key_data->ivec,
- password);
- splash.progress(20);
- get_random_salt(header->salt, CIPHER_BLOCK);
- for (j = 0; j < CIPHER_BLOCK; j++)
- key_data->ivec[j] ^= header->salt[j];
-
- error = gcry_cipher_setkey(cipher_handle,
- key_data->key, KEY_SIZE);
- if (!error)
- error = gcry_cipher_setiv(cipher_handle,
- key_data->ivec, CIPHER_BLOCK);
+ encrypt_init(key_data->key, key_data->ivec, password);
+ splash.progress(20);
+ get_random_salt(header->salt, CIPHER_BLOCK);
+ for (j = 0; j < CIPHER_BLOCK; j++)
+ key_data->ivec[j] ^= header->salt[j];
+
+ error = gcry_cipher_setkey(cipher_handle, key_data->key,
+ KEY_SIZE);
+ if (!error)
+ error = gcry_cipher_setiv(cipher_handle, key_data->ivec,
+ CIPHER_BLOCK);
+ if (!error)
+ header->image_flags |= IMAGE_ENCRYPTED;
+ }
- if (!error)
- header->image_flags |= IMAGE_ENCRYPTED;
- }
- if (error)
- fprintf(stderr,"%s: libgcrypt error: %s\n",
- my_name, gcry_strerror(error));
- }
+ if (error) {
+ fprintf(stderr,"%s: libgcrypt error: %s\n", my_name,
+ gcry_strerror(error));
+ goto Exit;
+ }
+
+Save_image:
#endif
- if (!error) {
- gettimeofday(&begin, NULL);
- error = save_image(&handle, header->pages - 1);
- }
+ gettimeofday(&begin, NULL);
- /*
- * NOTICE:
- * This should be after save_image() as
- * the user may modify the behavior
- */
- if (shutdown_method == SHUTDOWN_METHOD_PLATFORM)
- header->image_flags |= PLATFORM_SUSPEND;
- }
+ error = save_image(&handle, header->pages - 1);
+ if (error)
+ goto Exit;
+
+ /*
+ * NOTICE: This needs to go after save_image(), because the user may
+ * modify the behavior.
+ */
+ if (shutdown_method == SHUTDOWN_METHOD_PLATFORM)
+ header->image_flags |= PLATFORM_SUSPEND;
+
+ error = flush_swap_writer(&handle);
if (!error) {
- error = flush_swap_writer(&handle);
+ struct timeval end;
+
+ fsync(resume_fd);
+
if (compute_checksum)
md5_finish_ctx(&handle.ctx, header->checksum);
- }
- fsync(resume_fd);
- if (!error) {
- struct timeval end;
+
gettimeofday(&end, NULL);
timersub(&end, &begin, &end);
header->writeout_time = end.tv_usec / 1000000.0 + end.tv_sec;
- }
- if (!error)
+
error = write_area(resume_fd, header, start, page_size);
+ }
+
if (!error) {
if (compress) {
double delta = header->size - compr_diff;
@@ -711,9 +715,13 @@ No_RSA:
printf( "S" );
error = mark_swap(resume_fd, start);
}
+
fsync(resume_fd);
+
if (!error)
printf( "|" );
+
+Exit:
printf("\n");
return error;
}
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Suspend-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/suspend-devel