From: Andre Noll Date: Mon, 1 Oct 2007 21:34:39 +0000 (+0200) Subject: com_add(): Always check the return value of send_va_buffer(). X-Git-Tag: v0.3.0~317^2 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=639aaf1f240adb3b328c57fc2cbdd906b44c29e0;p=paraslash.git com_add(): Always check the return value of send_va_buffer(). And abort on send errors. --- diff --git a/aft.c b/aft.c index 99b132dd..cbea5eb1 100644 --- a/aft.c +++ b/aft.c @@ -1566,8 +1566,13 @@ static int add_one_audio_file(const char *arg, const void *private_data) if (ret < 0) goto out_free; ret = guess_audio_format(path); - if (ret < 0 && !(pad->flags & ADD_FLAG_ALL)) + if (ret < 0 && !(pad->flags & ADD_FLAG_ALL)) { + if (pad->flags & ADD_FLAG_VERBOSE) + ret = send_va_buffer(pad->fd, "%s: %s\n", + PARA_STRERROR(-ret), path); + ret = 1; goto out_free; + } query.data = path; query.size = strlen(path) + 1; ret = send_callback_request(path_brother_callback, &query, &result); @@ -1618,8 +1623,11 @@ static int add_one_audio_file(const char *arg, const void *private_data) format_num = ret; afhi_ptr = &afhi; } - if (pad->flags & ADD_FLAG_VERBOSE) - send_va_buffer(pad->fd, "adding %s\n", path); + if (pad->flags & ADD_FLAG_VERBOSE) { + ret = send_va_buffer(pad->fd, "adding %s\n", path); + if (ret < 0) + goto out_unmap; + } munmap(map.data, map.size); save_audio_file_info(hash, path, afhi_ptr, pad->flags, format_num, &obj); /* Ask afs to consider this entry for adding. */ @@ -1629,14 +1637,15 @@ static int add_one_audio_file(const char *arg, const void *private_data) out_unmap: munmap(map.data, map.size); out_free: - if (ret < 0) + if (ret < 0 && ret != -E_SEND) send_va_buffer(pad->fd, "failed to add %s (%s)\n", path? path : arg, PARA_STRERROR(-ret)); free(obj.data); free(path); if (afhi_ptr) free(afhi_ptr->chunk_table); - return 1; /* it's not an error if not all files could be added */ + /* it's not an error if not all files could be added */ + return ret == -E_SEND? ret : 1; } int com_add(int fd, int argc, char * const * const argv) @@ -1681,12 +1690,18 @@ int com_add(int fd, int argc, char * const * const argv) if (ret < 0) PARA_NOTICE_LOG("failed to stat %s (%s)", path, strerror(errno)); - else + else { if (S_ISDIR(statbuf.st_mode)) - for_each_file_in_dir(path, add_one_audio_file, + ret = for_each_file_in_dir(path, add_one_audio_file, &pad); else - add_one_audio_file(path, &pad); + ret = add_one_audio_file(path, &pad); + if (ret < 0) { + send_va_buffer(fd, "%s: %s\n", path, PARA_STRERROR(-ret)); + free(path); + return ret; + } + } free(path); } ret = 1;