Comment is inline

thanks
Avantika

Eric B Munson wrote:

> The return value from the system() call in add_temp_swap() was
> being ignored, generating compile time warnings.  This patch adds
> a check of the return value to make sure that all is well.  It also
> changes the ERROR reporting in add_temp_swap to WARNING in the cases
> where execution is not stopped.
>
> Signed-off-by: Eric B Munson <[email protected]>
> ---
>  hugeadm.c |   23 +++++++++++++++++++----
>  1 files changed, 19 insertions(+), 4 deletions(-)
>
> diff --git a/hugeadm.c b/hugeadm.c
> index 7c8170d..8147463 100644
> --- a/hugeadm.c
> +++ b/hugeadm.c
> @@ -37,6 +37,7 @@
>  #include <sys/types.h>
>  #include <sys/mount.h>
>  #include <sys/swap.h>
> +#include <sys/wait.h>
>
>  #define _GNU_SOURCE /* for getopt_long */
>  #include <unistd.h>
> @@ -602,16 +603,20 @@ void add_temp_swap()
>       FILE *f;
>       char *buf;
>       long swap_size;
> +     long pid;
> +     int ret;
> +
>       if (geteuid() != 0) {
>               ERROR("Swap can only be manipulated by root\n");
>               exit(EXIT_FAILURE);
>       }
>
> +     pid = getpid();
>       snprintf(path, PATH_MAX, "%s/swap/temp", MOUNT_DIR);
> -     snprintf(file, PATH_MAX, "%s/swapfile", path);
> +     snprintf(file, PATH_MAX, "%s/swapfile-%ld", path, pid);
>   
the pid needs needs to be appended to the filename in rem_temp_swap() as well
otherwise the swapoff and rem will fail.  

> -     if (ensure_dir(path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH, 
> 0, 0))
> +     if (ensure_dir(path, S_IRWXU | S_IRGRP | S_IXGRP, 0, 0))
>               exit(EXIT_FAILURE);
>
>       f = fopen(file, "w");
> @@ -629,11 +634,21 @@ void add_temp_swap()
>       fclose(f);
>
>       snprintf(mkswap_cmd, PATH_MAX, "mkswap %s", file);
> -     system(mkswap_cmd);
> +     ret = system(mkswap_cmd);
> +     if (WIFSIGNALED(ret)) {
> +             WARNING("Call to mkswap failed\n");
> +             return;
> +     } else if (WIFEXITED(ret)) {
> +             ret = WEXITSTATUS(ret);
> +             if (ret) {
> +                     WARNING("Call to mkswap failed\n");
> +                     return;
> +             }
> +     }
>
>       INFO("swapon %s\n", file);
>       if (swapon(file, 0))
> -             ERROR("swapon on %s failed: %s\n", file, strerror(errno));
> +             WARNING("swapon on %s failed: %s\n", file, strerror(errno));
>  }
>
>  void rem_temp_swap() {
>   


------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT 
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, & 
iPhoneDevCamp as they present alongside digital heavyweights like Barbarian 
Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com 
_______________________________________________
Libhugetlbfs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel

Reply via email to