callit_cb() : dont return a value from avoid function
[deb_libnfs.git] / lib / libnfs.c
index 43806538d6c3cb9871f268b7a09eb604370f78ba..edaeca4df06fb3afdc6ecbc090494fe807663521 100644 (file)
@@ -144,6 +144,12 @@ struct nfs_context *nfs_init_context(void)
                return NULL;
        }
 
+       nfs->server = NULL;
+       nfs->export = NULL;
+
+       nfs->rootfh.data.data_len = 0;
+       nfs->rootfh.data.data_val = NULL;
+
        return nfs;
 }
 
@@ -470,6 +476,7 @@ static void nfs_mount_1_cb(struct rpc_context *rpc, int status, void *command_da
 int nfs_mount_async(struct nfs_context *nfs, const char *server, const char *export, nfs_cb cb, void *private_data)
 {
        struct nfs_cb_data *data;
+       char *new_server, *new_export;
 
        data = malloc(sizeof(struct nfs_cb_data));
        if (data == NULL) {
@@ -477,8 +484,18 @@ int nfs_mount_async(struct nfs_context *nfs, const char *server, const char *exp
                return -1;
        }
        bzero(data, sizeof(struct nfs_cb_data));
-       nfs->server        = strdup(server);
-       nfs->export        = strdup(export);
+       new_server = strdup(server);
+       new_export = strdup(export);
+       if (nfs->server != NULL) {
+               free(nfs->server);
+               nfs->server = NULL;
+       }
+       nfs->server        = new_server;
+       if (nfs->export != NULL) {
+               free(nfs->export);
+               nfs->export = NULL;
+       }
+       nfs->export        = new_export;
        data->nfs          = nfs;
        data->cb           = cb;
        data->private_data = private_data;
@@ -890,6 +907,7 @@ static void nfs_pread_mcb(struct rpc_context *rpc _U_, int status, void *command
 
        data->nfsfh->offset = data->max_offset;
        data->cb(data->max_offset - data->start_offset, nfs, data->buffer, data->private_data);
+
        free_nfs_cb_data(data);
        free(mdata);
 }
@@ -925,6 +943,7 @@ int nfs_pread_async(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset,
         * reads and collect into a reassembly buffer.
         * we send all reads in parallell so that performance is still good.
         */
+       data->max_offset = offset;
        data->start_offset = offset;
 
        data->buffer =  malloc(count);
@@ -2865,13 +2884,13 @@ size_t nfs_get_writemax(struct nfs_context *nfs)
 void nfs_set_error(struct nfs_context *nfs, char *error_string, ...)
 {
         va_list ap;
-       char *str;
+       char *str = NULL;
 
+        va_start(ap, error_string);
+       vasprintf(&str, error_string, ap);
        if (nfs->rpc->error_string != NULL) {
                free(nfs->rpc->error_string);
        }
-        va_start(ap, error_string);
-       vasprintf(&str, error_string, ap);
        nfs->rpc->error_string = str;
         va_end(ap);
 }
@@ -3043,3 +3062,10 @@ struct rpc_context *nfs_get_rpc_context(struct nfs_context *nfs)
        return nfs->rpc;
 }
 
+const char *nfs_get_server(struct nfs_context *nfs) {
+       return nfs->server;
+}
+
+const char *nfs_get_export(struct nfs_context *nfs) {
+       return nfs->export;
+}