Some changes related to output and user interaction.

- Change some printf(...)s into fprintf(stderr,...)s
- Remove one "Press enter to continue", if it's triggered it would
  always trigger a second instance further down the code path.
- Make print_checksum print to a buffer instead of stdout

Index: resume.c
===================================================================
--- resume.c    (revision 159)
+++ resume.c    (revision 160)
@@ -359,12 +359,14 @@
        return error;
 }
 
-static inline void print_checksum(unsigned char *checksum)
+static char * print_checksum(char * buf, unsigned char *checksum)
 {
        int j;
 
        for (j = 0; j < 16; j++)
-               printf("%02hhx ", checksum[j]);
+               buf += sprintf(buf, "%02hhx ", checksum[j]);
+
+       return buf;
 }
 
 #ifdef CONFIG_ENCRYPT
@@ -529,7 +531,7 @@
        fd = open(resume_dev_name, O_RDWR);
        if (fd < 0) {
                ret = -errno;
-               printf("resume: Could not open the resume device\n");
+               fprintf(stderr,"resume: Could not open the resume device\n");
                return ret;
        }
        if (lseek(fd, shift, SEEK_SET) != shift)
@@ -546,9 +548,8 @@
        if (!error) {
                if(header->image_flags & IMAGE_CHECKSUM) {
                        memcpy(orig_checksum, header->checksum, 16);
-                       printf("resume: MD5 checksum ");
-                       print_checksum(orig_checksum);
-                       printf("\n");
+                       printf("resume: MD5 checksum %s\n",
+                               print_checksum(buffer, orig_checksum));
                        verify_checksum = 1;
                }
                splash.progress(10);
@@ -557,7 +558,7 @@
 #ifdef CONFIG_COMPRESS
                        decompress = 1;
 #else
-                       printf("resume: Compression not supported\n");
+                       fprintf(stderr,"resume: Compression not supported\n");
                        error = -EINVAL;
 #endif
                }
@@ -595,11 +596,11 @@
                                if (decrypt)
                                        gcry_cipher_close(handle.cipher_handle);
                                decrypt = 0;
-                               printf("resume: libgcrypt error: %s\n",
+                               fprintf(stderr, "resume: libgcrypt error: %s\n",
                                                gcry_strerror(error));
                        }
 #else
-                       printf("resume: Encryption not supported\n");
+                       fprintf(stderr, "resume: Encryption not supported\n");
                        error = -EINVAL;
 #endif
                }
@@ -615,7 +616,8 @@
                        error = load_image(&handle, dev, nr_pages);
        }
        if (error) {
-               printf("\nresume: The system snapshot image could not be 
read.\n\n"
+               fprintf(stderr,
+                       "\nresume: The system snapshot image could not be 
read.\n\n"
 #ifdef CONFIG_ENCRYPT
                        "\tThis might be a result of booting a wrong kernel\n"
                        "\tor typing in a wrong passphrase.\n\n"
@@ -639,11 +641,9 @@
                if (!error && verify_checksum) {
                        md5_finish_ctx(&handle.ctx, checksum);
                        if (memcmp(orig_checksum, checksum, 16)) {
-                               printf("resume: MD5 checksum does not match\n");
-                               printf("resume: Computed MD5 checksum ");
-                               print_checksum(checksum);
-                               printf("\nPress ENTER to continue ");
-                               getchar();
+                               fprintf(stderr,"resume: MD5 checksum does not 
match\n");
+                               fprintf(stderr,"resume: Computed MD5 checksum 
%s\n",
+                                       print_checksum(buffer, checksum));
                                error = -EINVAL;
                        }
                }
@@ -686,7 +683,7 @@
 
        if (stat(procname, &stat_buf) && errno == ENOENT) {
                if (mount("none", "/proc", "proc", 0, NULL)) {
-                       printf("resume: Could not mount proc\n");
+                       fprintf(stderr, "resume: Could not mount proc\n");
                        return;
                } else
                        proc_mounted = 1;
@@ -731,7 +728,8 @@
                splash_param = 0;
 
        while (stat(resume_dev_name, &stat_buf)) {
-               printf("resume: Could not stat the resume device file.\n"
+               fprintf(stderr, 
+                       "resume: Could not stat the resume device file.\n"
                        "\tPlease type in the file name to try again"
                        "\tor press ENTER to boot the system: ");
                fgets(resume_dev_name, MAX_STR_LEN - 1, stdin);
Index: suspend.c
===================================================================
--- suspend.c   (revision 159)
+++ suspend.c   (revision 160)
@@ -502,7 +502,7 @@
                return error < 0 ? error : -EFAULT;
        printf("suspend: Image size: %lu kilobytes\n", header->size / 1024);
        if (!enough_swap(snapshot_fd, header->size) && !compress) {
-               printf("suspend: Not enough free swap\n");
+               fprintf(stderr, "suspend: Not enough free swap\n");
                return -ENOSPC;
        }
        error = init_swap_writer(&handle, snapshot_fd, resume_fd,
@@ -560,7 +560,7 @@
                                        header->image_flags |= IMAGE_ENCRYPTED;
                        }
                        if (error)
-                               printf("suspend: libgcrypt error: %s\n",
+                               fprintf(stderr,"suspend: libgcrypt error: %s\n",
                                                gcry_strerror(error));
                }
 #endif
@@ -625,10 +625,11 @@
        }
        fsync(fd);
        if (error) {
-               printf("reset_signature: Error %d resetting the image.\n"
-                      "There should be valid image on disk. Powerdown and do 
normal resume.\n"
-                      "Continuing with this booted system will lead to data 
corruption.\n", 
-                      error);
+               fprintf(stderr,
+                       "reset_signature: Error %d resetting the image.\n"
+                       "There should be valid image on disk. Powerdown and do 
normal resume.\n"
+                       "Continuing with this booted system will lead to data 
corruption.\n", 
+                       error);
                while(1);
        }
        return error;
@@ -640,7 +641,7 @@
        power_off();
        /* Signature is on disk, it is very dangerous to continue now.
         * We'd do resume with stale caches on next boot. */
-       printf("Powerdown failed. That's impossible.\n");
+       fprintf(stderr,"Powerdown failed. That's impossible.\n");
        while(1);
 }
 


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Suspend-devel mailing list
Suspend-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/suspend-devel

Reply via email to