Clean up urlGetFile() return values
authorPanu Matilainen <pmatilai@redhat.com>
Mon, 18 Apr 2011 07:13:24 +0000 (10:13 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Mon, 18 Apr 2011 07:20:19 +0000 (10:20 +0300)
- Its callers only care about success vs failure, so only ever return
  0 or -1 and take waitpid() errors into account too. As a side effect
  shuts up a set-but-unused compiler warning too

rpmio/rpmurl.h
rpmio/url.c

index 3384bc4..e820e95 100644 (file)
@@ -41,7 +41,7 @@ urltype       urlPath(const char * url, const char ** pathp);
  * Copy data from URL to local file.
  * @param url          url string of source
  * @param dest         file name of destination
- * @return             0 on success, otherwise FTPERR_* code
+ * @return             0 on success, -1 on error
  */
 int urlGetFile(const char * url, const char * dest);
 
index c609fd1..fc31f36 100644 (file)
@@ -97,8 +97,8 @@ int urlGetFile(const char * url, const char * dest)
     char *cmd = NULL;
     const char *target = NULL;
     char *urlhelper = NULL;
-    int rc;
-    pid_t pid, wait;
+    int status;
+    pid_t pid;
 
     urlhelper = rpmExpand("%{?_urlhelper}", NULL);
 
@@ -119,9 +119,8 @@ int urlGetFile(const char * url, const char * dest)
         execvp(argv[0], argv);
         exit(127); /* exit with 127 for compatibility with bash(1) */
     }
-    wait = waitpid(pid, &rc, 0);
-    cmd = _free(cmd);
-
-    return rc;
+    free(cmd);
 
+    return ((waitpid(pid, &status, 0) != -1) &&
+           WIFEXITED(status) && (WEXITSTATUS(status) == 0)) ? 0 : -1;
 }