clean up lprintf statements - we have link.c and network.c left.
This commit is contained in:
parent
7813487c50
commit
2a4c61477a
97
src/cache.c
97
src/cache.c
|
@ -719,8 +719,6 @@ Cache *Cache_open(const char *fn)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------- Cache_open() critical section -----------------*/
|
|
||||||
|
|
||||||
lprintf(cache_lock_debug, "Cache_open(): thread %x: locking cf_lock;\n",
|
lprintf(cache_lock_debug, "Cache_open(): thread %x: locking cf_lock;\n",
|
||||||
pthread_self());
|
pthread_self());
|
||||||
PTHREAD_MUTEX_LOCK(&cf_lock);
|
PTHREAD_MUTEX_LOCK(&cf_lock);
|
||||||
|
@ -733,11 +731,6 @@ Cache *Cache_open(const char *fn)
|
||||||
return link->cache_ptr;
|
return link->cache_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
lprintf(cache_lock_debug, "Cache_open(): thread %x: unlocking cf_lock;\n",
|
|
||||||
pthread_self());
|
|
||||||
PTHREAD_MUTEX_UNLOCK(&cf_lock);
|
|
||||||
/*----------------------------------------------------------------*/
|
|
||||||
|
|
||||||
/* Check if both metadata and data file exist */
|
/* Check if both metadata and data file exist */
|
||||||
if (CONFIG.mode == NORMAL) {
|
if (CONFIG.mode == NORMAL) {
|
||||||
if (Cache_exist(fn)) {
|
if (Cache_exist(fn)) {
|
||||||
|
@ -809,13 +802,15 @@ cf->content_length: %ld, Data_size(fn): %ld.\n", fn, cf->content_length,
|
||||||
/* Yup, we just created a circular loop. ;) */
|
/* Yup, we just created a circular loop. ;) */
|
||||||
cf->link->cache_ptr = cf;
|
cf->link->cache_ptr = cf;
|
||||||
|
|
||||||
|
lprintf(cache_lock_debug, "Cache_open(): thread %x: unlocking cf_lock;\n",
|
||||||
|
pthread_self());
|
||||||
|
PTHREAD_MUTEX_UNLOCK(&cf_lock);
|
||||||
|
|
||||||
return cf;
|
return cf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cache_close(Cache *cf)
|
void Cache_close(Cache *cf)
|
||||||
{
|
{
|
||||||
/*--------------- Cache_close() critical section -----------------*/
|
|
||||||
|
|
||||||
lprintf(cache_lock_debug, "Cache_close(): thread %x: locking cf_lock;\n",
|
lprintf(cache_lock_debug, "Cache_close(): thread %x: locking cf_lock;\n",
|
||||||
pthread_self());
|
pthread_self());
|
||||||
PTHREAD_MUTEX_LOCK(&cf_lock);
|
PTHREAD_MUTEX_LOCK(&cf_lock);
|
||||||
|
@ -829,26 +824,24 @@ void Cache_close(Cache *cf)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
lprintf(cache_lock_debug, "Cache_close(): thread %x: unlocking cf_lock;\n",
|
|
||||||
pthread_self());
|
|
||||||
PTHREAD_MUTEX_UNLOCK(&cf_lock);
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------*/
|
|
||||||
|
|
||||||
if (Meta_write(cf)) {
|
if (Meta_write(cf)) {
|
||||||
lprintf(debug, "Cache_close(): Meta_write() error.");
|
lprintf(error, "Cache_close(): Meta_write() error.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fclose(cf->mfp)) {
|
if (fclose(cf->mfp)) {
|
||||||
lprintf(debug, "Cache_close(): cannot close metadata: %s.\n",
|
lprintf(error, "Cache_close(): cannot close metadata: %s.\n",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fclose(cf->dfp)) {
|
if (fclose(cf->dfp)) {
|
||||||
lprintf(debug, "Cache_close(): cannot close data file %s.\n",
|
lprintf(error, "Cache_close(): cannot close data file %s.\n",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lprintf(cache_lock_debug, "Cache_close(): thread %x: unlocking cf_lock;\n",
|
||||||
|
pthread_self());
|
||||||
|
PTHREAD_MUTEX_UNLOCK(&cf_lock);
|
||||||
|
|
||||||
return Cache_free(cf);
|
return Cache_free(cf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -884,19 +877,18 @@ static void Seg_set(Cache *cf, off_t offset, int i)
|
||||||
static void *Cache_bgdl(void *arg)
|
static void *Cache_bgdl(void *arg)
|
||||||
{
|
{
|
||||||
Cache *cf = (Cache *) arg;
|
Cache *cf = (Cache *) arg;
|
||||||
#ifdef CACHE_LOCK_DEBUG
|
|
||||||
lprintf(debug, "Cache_bgdl(): thread %x: locking w_lock;\n",
|
lprintf(cache_lock_debug, "Cache_bgdl(): thread %x: locking w_lock;\n",
|
||||||
pthread_self());
|
pthread_self());
|
||||||
#endif
|
|
||||||
PTHREAD_MUTEX_LOCK(&cf->w_lock);
|
PTHREAD_MUTEX_LOCK(&cf->w_lock);
|
||||||
|
|
||||||
uint8_t *recv_buf = CALLOC(cf->blksz, sizeof(uint8_t));
|
uint8_t *recv_buf = CALLOC(cf->blksz, sizeof(uint8_t));
|
||||||
lprintf(debug, "Cache_bgdl(): thread %x: ", pthread_self());
|
lprintf(debug, "Cache_bgdl(): thread %x spawned.\n ", pthread_self());
|
||||||
long recv = path_download(cf->fs_path, (char *) recv_buf, cf->blksz,
|
long recv = path_download(cf->fs_path, (char *) recv_buf, cf->blksz,
|
||||||
cf->next_dl_offset);
|
cf->next_dl_offset);
|
||||||
if (recv < 0) {
|
if (recv < 0) {
|
||||||
lprintf(debug, "\nCache_bgdl(): received %lu bytes, \
|
lprintf(error, "Cache_bgdl(): thread %x received %ld bytes, \
|
||||||
which does't make sense\n", recv);
|
which does't make sense\n", pthread_self(), recv);
|
||||||
exit_failure();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( (recv == cf->blksz) ||
|
if ( (recv == cf->blksz) ||
|
||||||
|
@ -905,20 +897,21 @@ which does't make sense\n", recv);
|
||||||
Data_write(cf, recv_buf, recv, cf->next_dl_offset);
|
Data_write(cf, recv_buf, recv, cf->next_dl_offset);
|
||||||
Seg_set(cf, cf->next_dl_offset, 1);
|
Seg_set(cf, cf->next_dl_offset, 1);
|
||||||
} else {
|
} else {
|
||||||
lprintf(debug,
|
lprintf(error,
|
||||||
"Cache_bgdl(): received %ld, possible network error.\n", recv);
|
"Cache_bgdl(): received %ld rather than %ld, possible network \
|
||||||
|
error.\n", recv, cf->blksz);
|
||||||
}
|
}
|
||||||
|
|
||||||
FREE(recv_buf);
|
FREE(recv_buf);
|
||||||
#ifdef CACHE_LOCK_DEBUG
|
|
||||||
lprintf(debug, "Cache_bgdl(): thread %x: unlocking bgt_lock;\n",
|
lprintf(cache_lock_debug, "Cache_bgdl(): thread %x: unlocking bgt_lock;\n",
|
||||||
pthread_self());
|
pthread_self());
|
||||||
#endif
|
|
||||||
PTHREAD_MUTEX_UNLOCK(&cf->bgt_lock);
|
PTHREAD_MUTEX_UNLOCK(&cf->bgt_lock);
|
||||||
#ifdef CACHE_LOCK_DEBUG
|
|
||||||
lprintf(debug, "Cache_bgdl(): thread %x: unlocking w_lock;\n",
|
lprintf(cache_lock_debug, "Cache_bgdl(): thread %x: unlocking w_lock;\n",
|
||||||
pthread_self());
|
pthread_self());
|
||||||
#endif
|
|
||||||
PTHREAD_MUTEX_UNLOCK(&cf->w_lock);
|
PTHREAD_MUTEX_UNLOCK(&cf->w_lock);
|
||||||
|
|
||||||
pthread_detach(pthread_self());
|
pthread_detach(pthread_self());
|
||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
}
|
}
|
||||||
|
@ -937,20 +930,21 @@ long Cache_read(Cache *cf, char * const output_buf, const off_t len,
|
||||||
goto bgdl;
|
goto bgdl;
|
||||||
} else {
|
} else {
|
||||||
/* Wait for any other download thread to finish*/
|
/* Wait for any other download thread to finish*/
|
||||||
#ifdef CACHE_LOCK_DEBUG
|
|
||||||
lprintf(debug, "Cache_read(): thread %ld: locking w_lock;\n",
|
lprintf(cache_lock_debug, "Cache_read(): thread %ld: locking w_lock;\n",
|
||||||
pthread_self());
|
pthread_self());
|
||||||
#endif
|
|
||||||
PTHREAD_MUTEX_LOCK(&cf->w_lock);
|
PTHREAD_MUTEX_LOCK(&cf->w_lock);
|
||||||
|
|
||||||
if (Seg_exist(cf, dl_offset)) {
|
if (Seg_exist(cf, dl_offset)) {
|
||||||
/* The segment now exists - it was downloaded by another
|
/* The segment now exists - it was downloaded by another
|
||||||
* download thread. Send it off and unlock the I/O */
|
* download thread. Send it off and unlock the I/O */
|
||||||
send = Data_read(cf, (uint8_t *) output_buf, len, offset_start);
|
send = Data_read(cf, (uint8_t *) output_buf, len, offset_start);
|
||||||
#ifdef CACHE_LOCK_DEBUG
|
|
||||||
lprintf(debug, "Cache_read(): thread %x: unlocking w_lock;\n",
|
lprintf(cache_lock_debug,
|
||||||
|
"Cache_read(): thread %x: unlocking w_lock;\n",
|
||||||
pthread_self());
|
pthread_self());
|
||||||
#endif
|
|
||||||
PTHREAD_MUTEX_UNLOCK(&cf->w_lock);
|
PTHREAD_MUTEX_UNLOCK(&cf->w_lock);
|
||||||
|
|
||||||
goto bgdl;
|
goto bgdl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -958,13 +952,12 @@ long Cache_read(Cache *cf, char * const output_buf, const off_t len,
|
||||||
/* ------------------------Download the segment -------------------------*/
|
/* ------------------------Download the segment -------------------------*/
|
||||||
|
|
||||||
uint8_t *recv_buf = CALLOC(cf->blksz, sizeof(uint8_t));
|
uint8_t *recv_buf = CALLOC(cf->blksz, sizeof(uint8_t));
|
||||||
lprintf(debug, "Cache_read(): thread %x: ", pthread_self());
|
lprintf(debug, "Cache_read(): thread %x: spawned.\n ", pthread_self());
|
||||||
long recv = path_download(cf->fs_path, (char *) recv_buf, cf->blksz,
|
long recv = path_download(cf->fs_path, (char *) recv_buf, cf->blksz,
|
||||||
dl_offset);
|
dl_offset);
|
||||||
if (recv < 0) {
|
if (recv < 0) {
|
||||||
lprintf(debug, "\nCache_read(): received %ld bytes, \
|
lprintf(error, "Cache_read(): thread %x received %ld bytes, \
|
||||||
which does't make sense\n", recv);
|
which does't make sense\n", pthread_self(), recv);
|
||||||
exit_failure();
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* check if we have received enough data, write it to the disk
|
* check if we have received enough data, write it to the disk
|
||||||
|
@ -978,34 +971,32 @@ which does't make sense\n", recv);
|
||||||
Data_write(cf, recv_buf, recv, dl_offset);
|
Data_write(cf, recv_buf, recv, dl_offset);
|
||||||
Seg_set(cf, dl_offset, 1);
|
Seg_set(cf, dl_offset, 1);
|
||||||
} else {
|
} else {
|
||||||
lprintf(debug,
|
lprintf(error,
|
||||||
"Cache_read(): received %ld, possible network error.\n", recv);
|
"Cache_read(): received %ld rather than %ld, possible network \
|
||||||
|
error.\n", recv, cf->blksz);
|
||||||
}
|
}
|
||||||
FREE(recv_buf);
|
FREE(recv_buf);
|
||||||
send = Data_read(cf, (uint8_t *) output_buf, len, offset_start);
|
send = Data_read(cf, (uint8_t *) output_buf, len, offset_start);
|
||||||
|
|
||||||
#ifdef CACHE_LOCK_DEBUG
|
lprintf(cache_lock_debug, "Cache_read(): thread %x: unlocking w_lock;\n",
|
||||||
lprintf(debug, "Cache_read(): thread %x: unlocking w_lock;\n",
|
|
||||||
pthread_self());
|
pthread_self());
|
||||||
#endif
|
|
||||||
PTHREAD_MUTEX_UNLOCK(&cf->w_lock);
|
PTHREAD_MUTEX_UNLOCK(&cf->w_lock);
|
||||||
|
|
||||||
/* -----------Download the next segment in background -------------------*/
|
/* -----------Download the next segment in background -------------------*/
|
||||||
bgdl:
|
bgdl:
|
||||||
;
|
{}
|
||||||
off_t next_dl_offset = round_div(offset_start, cf->blksz) * cf->blksz;
|
off_t next_dl_offset = round_div(offset_start, cf->blksz) * cf->blksz;
|
||||||
if ( (next_dl_offset > dl_offset) &&
|
if ( (next_dl_offset > dl_offset) &&
|
||||||
!Seg_exist(cf, next_dl_offset) &&
|
!Seg_exist(cf, next_dl_offset) &&
|
||||||
next_dl_offset < cf->content_length ){
|
next_dl_offset < cf->content_length ){
|
||||||
/* Stop the spawning of multiple background pthreads */
|
/* Stop the spawning of multiple background pthreads */
|
||||||
if(!pthread_mutex_trylock(&cf->bgt_lock)) {
|
if(!pthread_mutex_trylock(&cf->bgt_lock)) {
|
||||||
#ifdef CACHE_LOCK_DEBUG
|
lprintf(cache_lock_debug,
|
||||||
lprintf(debug, "Cache_read(): thread %x: trylocked bgt_lock;\n",
|
"Cache_read(): thread %x: trylocked bgt_lock;\n",
|
||||||
pthread_self());
|
pthread_self());
|
||||||
#endif
|
|
||||||
cf->next_dl_offset = next_dl_offset;
|
cf->next_dl_offset = next_dl_offset;
|
||||||
if (pthread_create(&cf->bgt, NULL, Cache_bgdl, cf)) {
|
if (pthread_create(&cf->bgt, NULL, Cache_bgdl, cf)) {
|
||||||
lprintf(debug,
|
lprintf(error,
|
||||||
"Cache_read(): Error creating background download thread\n"
|
"Cache_read(): Error creating background download thread\n"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -761,9 +761,8 @@ long path_download(const char *path, char *output_buf, size_t size,
|
||||||
/* Check for range seek support */
|
/* Check for range seek support */
|
||||||
if (!CONFIG.no_range_check) {
|
if (!CONFIG.no_range_check) {
|
||||||
if (!strcasestr((header.data), "Accept-Ranges: bytes")) {
|
if (!strcasestr((header.data), "Accept-Ranges: bytes")) {
|
||||||
lprintf(debug, "Error: This web server does not support HTTP \
|
lprintf(fatal, "This web server does not support HTTP \
|
||||||
range requests\n");
|
range requests\n");
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,6 @@ void log_printf(LogType type, const char *file, const char *func, int line,
|
||||||
fprintf(out, "(%s:%s:%d): ", file, func, line);
|
fprintf(out, "(%s:%s:%d): ", file, func, line);
|
||||||
|
|
||||||
print_actual_message:
|
print_actual_message:
|
||||||
/* A label can only be part of a statement, this is a statement. lol*/
|
|
||||||
{}
|
{}
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
|
|
13
src/main.c
13
src/main.c
|
@ -23,7 +23,7 @@ int main(int argc, char **argv)
|
||||||
/* Automatically print help if not enough arguments are supplied */
|
/* Automatically print help if not enough arguments are supplied */
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
print_help(argv[0], 0);
|
print_help(argv[0], 0);
|
||||||
lprintf(debug, "For more information, run \"%s --help.\"\n", argv[0]);
|
fprintf(stderr, "For more information, run \"%s --help.\"\n", argv[0]);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,21 +71,20 @@ int main(int argc, char **argv)
|
||||||
/* The second last remaining argument is the URL */
|
/* The second last remaining argument is the URL */
|
||||||
char *base_url = argv[argc-2];
|
char *base_url = argv[argc-2];
|
||||||
if (strncmp(base_url, "http://", 7) && strncmp(base_url, "https://", 8)) {
|
if (strncmp(base_url, "http://", 7) && strncmp(base_url, "https://", 8)) {
|
||||||
lprintf(debug, "Error: Please supply a valid URL.\n");
|
fprintf(stderr, "Error: Please supply a valid URL.\n");
|
||||||
print_help(argv[0], 0);
|
print_help(argv[0], 0);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
} else {
|
} else {
|
||||||
if (CONFIG.sonic_username && CONFIG.sonic_password) {
|
if (CONFIG.sonic_username && CONFIG.sonic_password) {
|
||||||
CONFIG.mode = SONIC;
|
CONFIG.mode = SONIC;
|
||||||
} else if (CONFIG.sonic_username || CONFIG.sonic_password) {
|
} else if (CONFIG.sonic_username || CONFIG.sonic_password) {
|
||||||
lprintf(debug,
|
fprintf(stderr,
|
||||||
"Error: You have to supply both username and password to \
|
"Error: You have to supply both username and password to \
|
||||||
activate Sonic mode.\n");
|
activate Sonic mode.\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
if(!LinkSystem_init(base_url)) {
|
if(!LinkSystem_init(base_url)) {
|
||||||
lprintf(debug, "Error: Network initialisation failed.\n");
|
lprintf(fatal, "Network initialisation failed.\n");
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,12 +261,12 @@ parse_arg_list(int argc, char **argv, char ***fuse_argv, int *fuse_argc)
|
||||||
CONFIG.mode = SINGLE_FILE;
|
CONFIG.mode = SINGLE_FILE;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
lprintf(debug, "see httpdirfs -h for usage\n");
|
fprintf(stderr, "see httpdirfs -h for usage\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
lprintf(debug, "see httpdirfs -h for usage\n");
|
fprintf(stderr, "see httpdirfs -h for usage\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
17
src/sonic.c
17
src/sonic.c
|
@ -167,11 +167,11 @@ static void XMLCALL XML_parser_general(void *data, const char *elem,
|
||||||
{
|
{
|
||||||
/* Error checking */
|
/* Error checking */
|
||||||
if (!strcmp(elem, "error")) {
|
if (!strcmp(elem, "error")) {
|
||||||
lprintf(debug, "XML_parser_general() error:\n");
|
lprintf(error, "XML_parser_general() error:\n");
|
||||||
for (int i = 0; attr[i]; i += 2) {
|
for (int i = 0; attr[i]; i += 2) {
|
||||||
lprintf(debug, "%s: %s\n", attr[i], attr[i+1]);
|
lprintf(error, "%s: %s\n", attr[i], attr[i+1]);
|
||||||
}
|
}
|
||||||
exit(EXIT_FAILURE);
|
exit_failure();
|
||||||
}
|
}
|
||||||
|
|
||||||
LinkTable *linktbl = (LinkTable *) data;
|
LinkTable *linktbl = (LinkTable *) data;
|
||||||
|
@ -322,7 +322,7 @@ static LinkTable *sonic_url_to_LinkTable(const char *url,
|
||||||
XML_SetStartElementHandler(parser, handler);
|
XML_SetStartElementHandler(parser, handler);
|
||||||
|
|
||||||
if (XML_Parse(parser, xml.data, xml.size, 1) == XML_STATUS_ERROR) {
|
if (XML_Parse(parser, xml.data, xml.size, 1) == XML_STATUS_ERROR) {
|
||||||
lprintf(debug,
|
lprintf(error,
|
||||||
"sonic_XML_to_LinkTable(): Parse error at line %lu: %s\n",
|
"sonic_XML_to_LinkTable(): Parse error at line %lu: %s\n",
|
||||||
XML_GetCurrentLineNumber(parser),
|
XML_GetCurrentLineNumber(parser),
|
||||||
XML_ErrorString(XML_GetErrorCode(parser)));
|
XML_ErrorString(XML_GetErrorCode(parser)));
|
||||||
|
@ -356,11 +356,11 @@ static void XMLCALL XML_parser_id3_root(void *data, const char *elem,
|
||||||
const char **attr)
|
const char **attr)
|
||||||
{
|
{
|
||||||
if (!strcmp(elem, "error")) {
|
if (!strcmp(elem, "error")) {
|
||||||
lprintf(debug, "XML_parser_id3_root() error:\n");
|
lprintf(error, "XML_parser_id3_root():\n");
|
||||||
for (int i = 0; attr[i]; i += 2) {
|
for (int i = 0; attr[i]; i += 2) {
|
||||||
lprintf(debug, "%s: %s\n", attr[i], attr[i+1]);
|
lprintf(error, "%s: %s\n", attr[i], attr[i+1]);
|
||||||
}
|
}
|
||||||
exit(EXIT_FAILURE);
|
exit_failure();
|
||||||
}
|
}
|
||||||
|
|
||||||
LinkTable *root_linktbl = (LinkTable *) data;
|
LinkTable *root_linktbl = (LinkTable *) data;
|
||||||
|
@ -454,8 +454,7 @@ LinkTable *sonic_LinkTable_new_id3(int depth, const char *id)
|
||||||
/*
|
/*
|
||||||
* We shouldn't reach here.
|
* We shouldn't reach here.
|
||||||
*/
|
*/
|
||||||
lprintf(debug, "sonic_LinkTable_new_id3(): case %d.\n", depth);
|
lprintf(fatal, "sonic_LinkTable_new_id3(): case %d.\n", depth);
|
||||||
exit_failure();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return linktbl;
|
return linktbl;
|
||||||
|
|
Loading…
Reference in New Issue