[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r22987 - Extractor/src/main
From: |
gnunet |
Subject: |
[GNUnet-SVN] r22987 - Extractor/src/main |
Date: |
Mon, 30 Jul 2012 16:46:36 +0200 |
Author: grothoff
Date: 2012-07-30 16:46:36 +0200 (Mon, 30 Jul 2012)
New Revision: 22987
Modified:
Extractor/src/main/extractor.c
Extractor/src/main/extractor_common.c
Extractor/src/main/extractor_common.h
Extractor/src/main/extractor_datasource.c
Extractor/src/main/extractor_ipc.c
Extractor/src/main/extractor_ipc_gnu.c
Extractor/src/main/extractor_logging.h
Extractor/src/main/extractor_plugin_main.c
Extractor/src/main/extractor_plugins.c
Extractor/src/main/extractor_plugpath.c
Extractor/src/main/extractor_print.c
Log:
adding logging
Modified: Extractor/src/main/extractor.c
===================================================================
--- Extractor/src/main/extractor.c 2012-07-30 14:35:34 UTC (rev 22986)
+++ Extractor/src/main/extractor.c 2012-07-30 14:46:36 UTC (rev 22987)
@@ -27,6 +27,7 @@
#include <ltdl.h>
#include "extractor_datasource.h"
#include "extractor_ipc.h"
+#include "extractor_logging.h"
#include "extractor_plugpath.h"
#include "extractor_plugins.h"
@@ -87,6 +88,7 @@
&um,
sizeof (um)) )
{
+ LOG ("Failed to send UPDATED_SHM message to plugin\n");
EXTRACTOR_IPC_channel_destroy_ (plugin->channel);
plugin->channel = NULL;
plugin->round_finished = 1;
@@ -110,6 +112,7 @@
&disc_msg,
sizeof (disc_msg)) )
{
+ LOG ("Failed to send DISCARD_STATE message to plugin\n");
EXTRACTOR_IPC_channel_destroy_ (plugin->channel);
plugin->channel = NULL;
plugin->round_finished = 1;
@@ -182,6 +185,7 @@
&cont_msg,
sizeof (cont_msg)) )
{
+ LOG ("Failed to send CONTINUE_EXTRACTING message to plugin\n");
EXTRACTOR_IPC_channel_destroy_ (plugin->channel);
plugin->channel = NULL;
plugin->round_finished = 1;
@@ -240,6 +244,7 @@
&start,
sizeof (start)) ) )
{
+ LOG ("Failed to send EXTRACT_START message to plugin\n");
EXTRACTOR_IPC_channel_destroy_ (pos->channel);
pos->channel = NULL;
}
@@ -265,6 +270,7 @@
&prp))
{
/* serious problem in IPC; reset *all* channels */
+ LOG ("Failed to receive message from channels; full reset\n");
abort_all_channels (plugins);
break;
}
@@ -298,6 +304,7 @@
min_seek,
DEFAULT_SHM_SIZE)))
{
+ LOG ("Failed to seek; full reset\n");
abort_all_channels (plugins);
break;
}
@@ -334,6 +341,7 @@
{
if (EXTRACTOR_OPTION_IN_PROCESS != pos->flags)
continue;
+ LOG ("In-process plugins not implemented\n");
// FIXME: initialize read/seek context...
// pos->extract_method (FIXME);
}
Modified: Extractor/src/main/extractor_common.c
===================================================================
--- Extractor/src/main/extractor_common.c 2012-07-30 14:35:34 UTC (rev
22986)
+++ Extractor/src/main/extractor_common.c 2012-07-30 14:46:36 UTC (rev
22987)
@@ -17,9 +17,14 @@
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
-
+/**
+ * @file main/extractor_common.c
+ * @brief commonly used functions within the library
+ * @author Christian Grothoff
+ */
#include "platform.h"
#include "extractor_common.h"
+#include "extractor_logging.h"
#include "extractor.h"
#include <sys/types.h>
#include <signal.h>
@@ -48,7 +53,11 @@
{
ret = write (fd, &data[off], size - off);
if (ret <= 0)
- return -1;
+ {
+ if (-1 == ret)
+ LOG_STRERROR ("write");
+ return -1;
+ }
off += ret;
}
return size;
@@ -76,7 +85,11 @@
{
ret = read (fd, &data[off], size - off);
if (ret <= 0)
- return -1;
+ {
+ if (-1 == ret)
+ LOG_STRERROR ("write");
+ return -1;
+ }
off += ret;
}
return size;
Modified: Extractor/src/main/extractor_common.h
===================================================================
--- Extractor/src/main/extractor_common.h 2012-07-30 14:35:34 UTC (rev
22986)
+++ Extractor/src/main/extractor_common.h 2012-07-30 14:46:36 UTC (rev
22987)
@@ -17,8 +17,12 @@
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
+/**
+ * @file main/extractor_common.h
+ * @brief commonly used functions within the library
+ * @author Christian Grothoff
+ */
-
#ifndef EXTRACTOR_COMMON_H
#define EXTRACTOR_COMMON_H
Modified: Extractor/src/main/extractor_datasource.c
===================================================================
--- Extractor/src/main/extractor_datasource.c 2012-07-30 14:35:34 UTC (rev
22986)
+++ Extractor/src/main/extractor_datasource.c 2012-07-30 14:46:36 UTC (rev
22987)
@@ -23,6 +23,7 @@
* @author Christian Grothoff
*/
#include "platform.h"
+#include "extractor_logging.h"
#include "extractor_datasource.h"
#if HAVE_LIBBZ2
@@ -218,7 +219,10 @@
ssize_t rd;
if (pos > bfds->fsize)
- return -1; /* invalid */
+ {
+ LOG ("Invalid seek operation\n");
+ return -1; /* invalid */
+ }
if (NULL == bfds->buffer)
{
bfds->buffer_pos = pos;
@@ -231,7 +235,10 @@
bfds->buffer_pos = 0;
rd = read (bfds->fd, bfds->buffer, bfds->buffer_size);
if (rd < 0)
- return -1;
+ {
+ LOG_STRERROR ("read");
+ return -1;
+ }
bfds->buffer_bytes = rd;
return 0;
}
@@ -258,13 +265,19 @@
else
xtra = (size_t) fsize;
if ( (-1 == fd) && (NULL == data) )
- return NULL;
+ {
+ LOG ("Invalid arguments\n");
+ return NULL;
+ }
if ( (-1 != fd) && (NULL != data) )
fd = -1; /* don't need fd */
if (NULL != data)
xtra = 0;
if (NULL == (result = malloc (sizeof (struct BufferedFileDataSource) +
xtra)))
- return NULL;
+ {
+ LOG_STRERROR ("malloc");
+ return NULL;
+ }
memset (result, 0, sizeof (struct BufferedFileDataSource));
result->data = (NULL != data) ? data : &result[1];
result->buffer = (NULL != data) ? NULL : &result[1];
@@ -308,9 +321,15 @@
{
case SEEK_CUR:
if (bfds->fpos + bfds->buffer_pos + pos < 0)
- return -1;
+ {
+ LOG ("Invalid seek operation\n");
+ return -1;
+ }
if (bfds->fpos + bfds->buffer_pos + pos > bfds->fsize)
- return -1;
+ {
+ LOG ("Invalid seek operation\n");
+ return -1;
+ }
if ( (NULL == bfds->buffer) ||
( (bfds->buffer_pos + pos < bfds->buffer_bytes) &&
(bfds->buffer_pos + pos >= 0) ) )
@@ -320,20 +339,35 @@
}
if (0 != bfds_pick_next_buffer_at (bfds,
bfds->fpos + bfds->buffer_pos + pos))
- return -1;
+ {
+ LOG ("seek operation failed\n");
+ return -1;
+ }
return bfds->fpos;
case SEEK_END:
if (pos > 0)
- return -1;
+ {
+ LOG ("Invalid seek operation\n");
+ return -1;
+ }
if (bfds->fsize < - pos)
- return -1;
+ {
+ LOG ("Invalid seek operation\n");
+ return -1;
+ }
pos = bfds->fsize + pos;
/* fall-through! */
case SEEK_SET:
if (pos < 0)
- return -1;
+ {
+ LOG ("Invalid seek operation\n");
+ return -1;
+ }
if (pos > bfds->fsize)
- return -1;
+ {
+ LOG ("Invalid seek operation\n");
+ return -1;
+ }
if ( (NULL == bfds->buffer) ||
( (bfds->buffer_pos <= pos) &&
(bfds->buffer_pos + bfds->buffer_bytes > pos) ) )
@@ -342,7 +376,10 @@
return bfds->buffer_pos;
}
if (0 != bfds_pick_next_buffer_at (bfds, pos))
- return -1;
+ {
+ LOG ("seek operation failed\n");
+ return -1;
+ }
return bfds->fpos;
}
return -1;
@@ -383,13 +420,13 @@
bfds->fpos = old_off;
bfds->buffer_bytes = 0;
bfds->buffer_pos = 0;
+ LOG ("read operation failed\n");
return -1; /* getting more failed */
}
avail = bfds->buffer_bytes - bfds->buffer_pos;
if (avail > count)
avail = count;
- if (0 == avail)
- abort (); /* must not happen */
+ ASSERT (0 != avail);
memcpy (&cbuf[ret], bfds->data + bfds->buffer_pos, avail);
bfds->buffer_pos += avail;
count -= avail;
@@ -433,6 +470,7 @@
#endif
))
{
+ LOG ("Failed to initialize zlib decompression\n");
return -1;
}
cfs->fpos = 0;
@@ -450,6 +488,7 @@
cfs_reset_stream_bz2 (struct CompressedFileSource *cfs)
{
/* not implemented */
+ LOG ("bz2 decompression not implemented\n");
return -1;
}
@@ -473,6 +512,7 @@
case COMP_TYPE_BZ2:
return cfs_reset_stream_bz2 (cfs);
default:
+ LOG ("invalid compression type selected\n");
return -1;
}
}
@@ -575,6 +615,7 @@
cfs_init_decompressor_bz2 (struct CompressedFileSource *cfs,
EXTRACTOR_MetaDataProcessor proc, void *proc_cls)
{
+ LOG ("bz2 decompression not implemented\n");
return -1;
}
@@ -599,6 +640,7 @@
case COMP_TYPE_BZ2:
return cfs_init_decompressor_bz2 (cfs, proc, proc_cls);
default:
+ LOG ("invalid compression type selected\n");
return -1;
}
}
@@ -627,6 +669,7 @@
static int
cfs_deinit_decompressor_bz2 (struct CompressedFileSource *cfs)
{
+ LOG ("bz2 decompression not implemented\n");
return -1;
}
@@ -647,6 +690,7 @@
case COMP_TYPE_BZ2:
return cfs_deinit_decompressor_bz2 (cfs);
default:
+ LOG ("invalid compression type selected\n");
return -1;
}
}
@@ -684,7 +728,10 @@
struct CompressedFileSource *cfs;
if (NULL == (cfs = malloc (sizeof (struct CompressedFileSource))))
- return NULL;
+ {
+ LOG_STRERROR ("malloc");
+ return NULL;
+ }
memset (cfs, 0, sizeof (struct CompressedFileSource));
cfs->compression_type = compression_type;
cfs->bfds = bfds;
@@ -784,6 +831,7 @@
void *data,
size_t size)
{
+ LOG ("bz2 decompression not implemented\n");
return -1;
}
@@ -810,6 +858,7 @@
case COMP_TYPE_BZ2:
return cfs_read_bz2 (cfs, data, size);
default:
+ LOG ("invalid compression type selected\n");
return -1;
}
}
@@ -837,33 +886,53 @@
{
case SEEK_CUR:
if (cfs->fpos + position < 0)
- return -1;
+ {
+ LOG ("Invalid seek operation\n");
+ return -1;
+ }
if ( (-1 != cfs->uncompressed_size) &&
(cfs->fpos + position > cfs->uncompressed_size) )
- return -1;
+ {
+ LOG ("Invalid seek operation\n");
+ return -1;
+ }
nposition = cfs->fpos + position;
break;
case SEEK_END:
if (-1 == cfs->uncompressed_size)
{
/* yuck, need to first find end of file! */
+ LOG ("Seeking from end-of-file in compressed files not
implemented\n");
return -1; // FIXME: not implemented
}
if (position > 0)
- return -1;
+ {
+ LOG ("Invalid seek operation\n");
+ return -1;
+ }
if (cfs->uncompressed_size < - position)
- return -1;
+ {
+ LOG ("Invalid seek operation\n");
+ return -1;
+ }
nposition = cfs->uncompressed_size + position;
break;
case SEEK_SET:
if (position < 0)
- return -1;
+ {
+ LOG ("Invalid seek operation\n");
+ return -1;
+ }
if ( (-1 != cfs->uncompressed_size) &&
(cfs->uncompressed_size < position ) )
- return -1;
+ {
+ LOG ("Invalid seek operation\n");
+ return -1;
+ }
nposition = (uint64_t) position;
break;
default:
+ LOG ("Invalid seek operation\n");
return -1;
}
@@ -878,7 +947,10 @@
else
{
if (-1 == cfs_reset_stream (cfs))
- return -1;
+ {
+ LOG ("Failed to restart compressed stream for seek operation\n");
+ return -1;
+ }
delta = nposition;
}
}
@@ -891,7 +963,10 @@
max = (sizeof (buf) > delta) ? delta : sizeof (buf);
ret = cfs_read (cfs, buf, max);
if (-1 == ret)
- return -1;
+ {
+ LOG ("Failed to read decompressed stream for seek operation\n");
+ return -1;
+ }
delta -= ret;
}
return cfs->fpos;
@@ -979,10 +1054,14 @@
int64_t fsize;
if (-1 == (fd = open (filename, O_RDONLY | O_LARGEFILE)))
- return NULL;
+ {
+ LOG_STRERROR_FILE ("open", filename);
+ return NULL;
+ }
if ( (0 != fstat (fd, &sb)) ||
(S_ISDIR (sb.st_mode)) )
{
+ LOG_STRERROR_FILE ("fstat", filename);
(void) close (fd);
return NULL;
}
@@ -1000,21 +1079,26 @@
}
if (NULL == (ds = malloc (sizeof (struct EXTRACTOR_Datasource))))
{
+ LOG_STRERROR ("malloc");
bfds_delete (bfds);
return NULL;
}
ds->bfds = bfds;
ds->fd = fd;
+ ds->cfs = NULL;
ct = get_compression_type (bfds);
if ( (COMP_TYPE_ZLIB == ct) ||
(COMP_TYPE_BZ2 == ct) )
- ds->cfs = cfs_new (bfds, fsize, ct, proc, proc_cls);
- if (NULL == ds->cfs)
{
- bfds_delete (bfds);
- free (ds);
- (void) close (fd);
- return NULL;
+ ds->cfs = cfs_new (bfds, fsize, ct, proc, proc_cls);
+ if (NULL == ds->cfs)
+ {
+ LOG ("Failed to initialize decompressor\n");
+ bfds_delete (bfds);
+ free (ds);
+ (void) close (fd);
+ return NULL;
+ }
}
return ds;
}
@@ -1041,9 +1125,13 @@
if (0 == size)
return NULL;
if (NULL == (bfds = bfds_new (buf, -1, size)))
- return NULL;
+ {
+ LOG ("Failed to initialize buffer data source\n");
+ return NULL;
+ }
if (NULL == (ds = malloc (sizeof (struct EXTRACTOR_Datasource))))
{
+ LOG_STRERROR ("malloc");
bfds_delete (bfds);
return NULL;
}
@@ -1052,12 +1140,15 @@
ct = get_compression_type (bfds);
if ( (COMP_TYPE_ZLIB == ct) ||
(COMP_TYPE_BZ2 == ct) )
- ds->cfs = cfs_new (bfds, size, ct, proc, proc_cls);
- if (NULL == ds->cfs)
{
- bfds_delete (bfds);
- free (ds);
- return NULL;
+ ds->cfs = cfs_new (bfds, size, ct, proc, proc_cls);
+ if (NULL == ds->cfs)
+ {
+ LOG ("Failed to initialize decompressor\n");
+ bfds_delete (bfds);
+ free (ds);
+ return NULL;
+ }
}
return ds;
}
Modified: Extractor/src/main/extractor_ipc.c
===================================================================
--- Extractor/src/main/extractor_ipc.c 2012-07-30 14:35:34 UTC (rev 22986)
+++ Extractor/src/main/extractor_ipc.c 2012-07-30 14:46:36 UTC (rev 22987)
@@ -23,6 +23,7 @@
* @author Christian Grothoff
*/
#include "platform.h"
+#include "extractor_logging.h"
#include "extractor_ipc.h"
#include "extractor_plugins.h"
@@ -78,7 +79,10 @@
memcpy (&meta, cdata, sizeof (meta));
/* check hdr for sanity */
if (meta.value_size > MAX_META_DATA)
- return -1; /* not allowing more than MAX_META_DATA meta data */
+ {
+ LOG ("Meta data exceeds size limit\n");
+ return -1; /* not allowing more than MAX_META_DATA meta data */
+ }
if (size < sizeof (meta) + meta.mime_length + meta.value_size)
{
plugin->seek_request = -1;
@@ -92,7 +96,10 @@
{
mime_type = &cdata[sizeof (struct MetaMessage)];
if ('\0' != mime_type[meta.mime_length - 1])
- return -1;
+ {
+ LOG ("Mime type not 0-terminated\n");
+ return -1;
+ }
}
if (0 == meta.value_size)
value = NULL;
@@ -106,6 +113,7 @@
mime_type, value);
return sizeof (struct MetaMessage) + meta.mime_length +
meta.value_size;
default:
+ LOG ("Invalid message type %d\n", (int) code);
return -1;
}
}
Modified: Extractor/src/main/extractor_ipc_gnu.c
===================================================================
--- Extractor/src/main/extractor_ipc_gnu.c 2012-07-30 14:35:34 UTC (rev
22986)
+++ Extractor/src/main/extractor_ipc_gnu.c 2012-07-30 14:46:36 UTC (rev
22987)
@@ -26,6 +26,7 @@
#include "plibc.h"
#include "extractor.h"
#include "extractor_datasource.h"
+#include "extractor_logging.h"
#include "extractor_plugin_main.h"
#include "extractor_ipc.h"
#include <dirent.h>
@@ -136,7 +137,10 @@
const char *tpath;
if (NULL == (shm = malloc (sizeof (struct EXTRACTOR_SharedMemory))))
- return NULL;
+ {
+ LOG_STRERROR ("malloc");
+ return NULL;
+ }
#if SOMEBSD
/* this works on FreeBSD, not sure about others... */
tpath = getenv ("TMPDIR");
@@ -153,6 +157,7 @@
if (-1 == (shm->shm_id = shm_open (shm->shm_name,
O_RDWR | O_CREAT, S_IRUSR | S_IWUSR)))
{
+ LOG_STRERROR_FILE ("shm_open", shm->shm_name);
free (shm);
return NULL;
}
@@ -162,6 +167,7 @@
shm->shm_id, 0))) ||
(((void*) -1) == shm->shm_ptr) )
{
+ LOG_STRERROR ("ftruncate/mmap");
(void) close (shm->shm_id);
(void) shm_unlink (shm->shm_name);
free (shm);
@@ -251,16 +257,21 @@
size_t slen;
if (NULL == (channel = malloc (sizeof (struct EXTRACTOR_Channel))))
- return NULL;
+ {
+ LOG_STRERROR ("malloc");
+ return NULL;
+ }
channel->shm = shm;
channel->plugin = plugin;
if (0 != pipe (p1))
{
+ LOG_STRERROR ("pipe");
free (channel);
return NULL;
}
if (0 != pipe (p2))
{
+ LOG_STRERROR ("pipe");
(void) close (p1[0]);
(void) close (p1[1]);
free (channel);
@@ -269,6 +280,7 @@
pid = fork ();
if (pid == -1)
{
+ LOG_STRERROR ("fork");
(void) close (p1[0]);
(void) close (p1[1]);
(void) close (p2[0]);
@@ -291,6 +303,7 @@
slen = strlen (shm->shm_name) + 1;
if (NULL == (init = malloc (sizeof (struct InitMessage) + slen)))
{
+ LOG_STRERROR ("malloc");
EXTRACTOR_IPC_channel_destroy_ (channel);
return NULL;
}
@@ -304,6 +317,7 @@
init,
sizeof (init) + slen) )
{
+ LOG ("Failed to send INIT_STATE message to plugin\n");
EXTRACTOR_IPC_channel_destroy_ (channel);
return NULL;
}
@@ -322,10 +336,14 @@
{
int status;
- (void) kill (channel->cpid, SIGKILL);
- (void) waitpid (channel->cpid, &status, 0);
- (void) close (channel->cpipe_out);
- (void) close (channel->cpipe_in);
+ if (0 != kill (channel->cpid, SIGKILL))
+ LOG_STRERROR ("kill");
+ if (-1 == waitpid (channel->cpid, &status, 0))
+ LOG_STRERROR ("waitpid");
+ if (0 != close (channel->cpipe_out))
+ LOG_STRERROR ("close");
+ if (0 != close (channel->cpipe_in))
+ LOG_STRERROR ("close");
free (channel);
}
@@ -352,7 +370,11 @@
{
ret = write (channel->cpipe_in, &cdata[off], size - off);
if (ret <= 0)
- return -1;
+ {
+ if (-1 == ret)
+ LOG_STRERROR ("write");
+ return -1;
+ }
off += ret;
}
return size;
@@ -404,6 +426,8 @@
if (-1 == select (max + 1, &to_check, NULL, NULL, &tv))
{
/* an error or timeout -> something's wrong or all plugins hung up */
+ if (EINTR != errno)
+ LOG_STRERROR ("select");
return -1;
}
for (i=0;i<num_channels;i++)
@@ -421,6 +445,8 @@
channel->size + iret,
proc, proc_cls)) )
{
+ if (-1 == iret)
+ LOG_STRERROR ("read");
EXTRACTOR_IPC_channel_destroy_ (channel);
channels[i] = NULL;
}
Modified: Extractor/src/main/extractor_logging.h
===================================================================
--- Extractor/src/main/extractor_logging.h 2012-07-30 14:35:34 UTC (rev
22986)
+++ Extractor/src/main/extractor_logging.h 2012-07-30 14:46:36 UTC (rev
22987)
@@ -42,12 +42,19 @@
/**
* Log a message.
*
- * @param fmt format string
- * @param ... arguments for fmt (printf-style)
+ * @param ... format string and arguments for fmt (printf-style)
*/
-#define LOG(fmt, ...) EXTRACTOR_log_ (__FILE__, __LINE__, fmt, __VA_ARGS__)
+#define LOG(...) EXTRACTOR_log_(__FILE__, __LINE__, __VA_ARGS__)
+
#else
+
+/**
+ * Log a message.
+ *
+ * @param ... format string and arguments for fmt (printf-style)
+ */
#define LOG(...)
+
#endif
Modified: Extractor/src/main/extractor_plugin_main.c
===================================================================
--- Extractor/src/main/extractor_plugin_main.c 2012-07-30 14:35:34 UTC (rev
22986)
+++ Extractor/src/main/extractor_plugin_main.c 2012-07-30 14:46:36 UTC (rev
22987)
@@ -22,7 +22,6 @@
* @brief main loop for an out-of-process plugin
* @author Christian Grothoff
*/
-
#include "platform.h"
#include "plibc.h"
#include "extractor.h"
@@ -30,6 +29,7 @@
#include "extractor_datasource.h"
#include "extractor_plugins.h"
#include "extractor_ipc.h"
+#include "extractor_logging.h"
#include "extractor_plugin_main.h"
#include <dirent.h>
#include <sys/types.h>
@@ -120,24 +120,37 @@
{
case SEEK_CUR:
if ( (pos < 0) && (pc->read_position < - pos) )
- return -1;
+ {
+ LOG ("Invalid seek operation\n");
+ return -1;
+ }
if ( (pos > 0) &&
( (pc->read_position + pos < pc->read_position) ||
(pc->read_position + pos > pc->file_size) ) )
- return -1;
+ {
+ LOG ("Invalid seek operation\n");
+ return -1;
+ }
npos = (uint64_t) (pc->read_position + pos);
break;
case SEEK_END:
if (pos > 0)
- return -1;
+ {
+ LOG ("Invalid seek operation\n");
+ return -1;
+ }
pos = (int64_t) (pc->file_size + pos);
/* fall-through! */
case SEEK_SET:
if ( (pos < 0) || (pc->file_size < pos) )
- return -1;
+ {
+ LOG ("Invalid seek operation\n");
+ return -1;
+ }
npos = (uint64_t) pos;
break;
default:
+ LOG ("Invalid seek operation\n");
return -1;
}
if ( (pc->shm_off <= npos) &&
@@ -155,15 +168,24 @@
srm.requested_bytes = pc->file_size - npos;
srm.file_offset = npos;
if (-1 == EXTRACTOR_write_all_ (pc->out, &srm, sizeof (srm)))
- return -1;
+ {
+ LOG ("Failed to send MESSAGE_SEEK\n");
+ return -1;
+ }
if (-1 ==
EXTRACTOR_read_all_ (pc->in,
&reply, sizeof (reply)))
- return -1;
- if (MESSAGE_SEEK != reply)
+ {
+ LOG ("Failed to read response to MESSAGE_SEEK\n");
+ return -1;
+ }
+ if (MESSAGE_SEEK != reply)
return -1; /* was likely a MESSAGE_DISCARD_STATE */
if (-1 == EXTRACTOR_read_all_ (pc->in, &um.reserved, sizeof (um) - 1))
- return -1;
+ {
+ LOG ("Failed to read UPDATE_MESSAGE\n");
+ return -1;
+ }
pc->shm_off = um.shm_off;
pc->shm_ready_bytes = um.shm_ready_bytes;
if ( (pc->shm_off <= npos) &&
@@ -174,6 +196,7 @@
}
/* oops, serious missunderstanding, we asked to seek
and then were notified about a different position!? */
+ LOG ("Got invalid UPDATE_MESSAGE in response to my seek\n");
return -1;
}
@@ -200,7 +223,10 @@
if ( ( (pc->read_position >= pc->shm_off + pc->shm_ready_bytes) ||
(pc->read_position < pc->shm_off) ) &&
(-1 == plugin_env_seek (pc, pc->read_position, SEEK_SET)) )
- return -1;
+ {
+ LOG ("Failed to seek to satisfy read\n");
+ return -1;
+ }
if (pc->read_position + count > pc->shm_off + pc->shm_ready_bytes)
count = pc->shm_off + pc->shm_ready_bytes - pc->read_position;
dp = pc->shm;
@@ -220,6 +246,7 @@
plugin_env_get_size (void *cls)
{
struct ProcessingContext *pc = cls;
+
return pc->file_size;
}
@@ -275,11 +302,17 @@
(data_len !=
EXTRACTOR_write_all_ (pc->out,
data, data_len)) )
- return 1;
+ {
+ LOG ("Failed to send meta message\n");
+ return 1;
+ }
if (-1 ==
EXTRACTOR_read_all_ (pc->in,
&reply, sizeof (reply)))
- return 1;
+ {
+ LOG ("Failed to read response to meta message\n");
+ return 1;
+ }
if (MESSAGE_CONTINUE_EXTRACTING != reply)
return 1;
return 0;
@@ -298,14 +331,23 @@
struct InitMessage init;
if (NULL != pc->shm)
- return -1;
+ {
+ LOG ("Cannot handle 'init' message, have already been initialized\n");
+ return -1;
+ }
if (sizeof (struct InitMessage) - 1
!= EXTRACTOR_read_all_ (pc->in,
&init.reserved,
sizeof (struct InitMessage) - 1))
- return -1;
+ {
+ LOG ("Failed to read 'init' message\n");
+ return -1;
+ }
if (init.shm_name_length > MAX_SHM_NAME)
- return -1;
+ {
+ LOG ("Invalid 'init' message\n");
+ return -1;
+ }
{
char shm_name[init.shm_name_length + 1];
@@ -313,7 +355,10 @@
!= EXTRACTOR_read_all_ (pc->in,
shm_name,
init.shm_name_length))
- return -1;
+ {
+ LOG ("Failed to read 'init' message\n");
+ return -1;
+ }
shm_name[init.shm_name_length] = '\0';
pc->shm_map_size = init.shm_map_size;
@@ -324,14 +369,20 @@
#else
pc->shm_id = open (shm_name, O_RDONLY, 0);
if (-1 == pc->shm_id)
- return -1;
+ {
+ LOG_STRERROR_FILE ("open", shm_name);
+ return -1;
+ }
pc->shm = mmap (NULL,
pc->shm_map_size,
PROT_READ,
MAP_SHARED,
pc->shm_id, 0);
if ( ((void*) -1) == pc->shm)
- return -1;
+ {
+ LOG_STRERROR_FILE ("mmap", shm_name);
+ return -1;
+ }
#endif
}
return 0;
@@ -355,7 +406,10 @@
!= EXTRACTOR_read_all_ (pc->in,
&start.reserved,
sizeof (struct StartMessage) - 1))
- return -1;
+ {
+ LOG ("Failed to read 'start' message\n");
+ return -1;
+ }
pc->shm_ready_bytes = start.shm_ready_bytes;
pc->file_size = start.file_size;
pc->read_position = 0;
@@ -369,7 +423,10 @@
pc->plugin->extract_method (&ec);
done = MESSAGE_DONE;
if (-1 == EXTRACTOR_write_all_ (pc->out, &done, sizeof (done)))
- return -1;
+ {
+ LOG ("Failed to write 'done' message\n");
+ return -1;
+ }
if ( (NULL != pc->plugin->specials) &&
(NULL != strstr (pc->plugin->specials, "force-kill")) )
{
@@ -400,7 +457,10 @@
unsigned char code;
if (1 != EXTRACTOR_read_all_ (pc->in, &code, 1))
- break;
+ {
+ LOG ("Failed to read next request\n");
+ break;
+ }
switch (code)
{
case MESSAGE_INIT_STATE:
@@ -417,6 +477,7 @@
/* odd, we're already in the start state... */
continue;
default:
+ LOG ("Received invalid messag %d\n", (int) code);
/* error, unexpected message */
return;
}
@@ -440,16 +501,21 @@
fd = open ("/dev/null", flags);
if (-1 == fd)
- return; /* good luck */
+ {
+ LOG_STRERROR_FILE ("open", "/dev/null");
+ return; /* good luck */
+ }
if (fd == target_fd)
return; /* already done */
if (-1 == dup2 (fd, target_fd))
{
+ LOG_STRERROR ("dup2");
(void) close (fd);
return; /* good luck */
}
/* close original result from 'open' */
- (void) close (fd);
+ if (0 != close (fd))
+ LOG_STRERROR ("close");
}
#endif
@@ -479,7 +545,8 @@
if ( (NULL != plugin->specials) &&
(NULL != strstr (plugin->specials, "close-stderr")))
{
- (void) close (2);
+ if (0 != close (2))
+ LOG_STRERROR ("close");
#ifndef WINDOWS
open_dev_null (2, O_WRONLY);
#endif
@@ -487,7 +554,8 @@
if ( (NULL != plugin->specials) &&
(NULL != strstr (plugin->specials, "close-stdout")))
{
- (void) close (1);
+ if (0 != close (1))
+ LOG_STRERROR ("close");
#ifndef WINDOWS
open_dev_null (1, O_WRONLY);
#endif
@@ -507,7 +575,10 @@
(((void*) 1) != pc.shm) )
munmap (pc.shm, pc.shm_map_size);
if (-1 != pc.shm_id)
- (void) close (pc.shm_id);
+ {
+ if (0 != close (pc.shm_id))
+ LOG_STRERROR ("close");
+ }
#endif
}
@@ -529,7 +600,10 @@
// FIXME: check for errors from 'EXTRACTOR_read_all_'!
if (NULL == (ret = malloc (sizeof (struct EXTRACTOR_PluginList))))
- return NULL;
+ {
+ LOG_STRERROR ("malloc");
+ return NULL;
+ }
GetSystemInfo (&si);
ret->allocation_granularity = si.dwAllocationGranularity;
EXTRACTOR_read_all_ (fd, &i, sizeof (size_t));
Modified: Extractor/src/main/extractor_plugins.c
===================================================================
--- Extractor/src/main/extractor_plugins.c 2012-07-30 14:35:34 UTC (rev
22986)
+++ Extractor/src/main/extractor_plugins.c 2012-07-30 14:46:36 UTC (rev
22987)
@@ -25,6 +25,7 @@
#include "extractor_plugins.h"
#include "extractor_plugpath.h"
#include "extractor_ipc.h"
+#include "extractor_logging.h"
/**
@@ -55,9 +56,11 @@
return NULL;
sym_name++;
if (NULL == (sym = strdup (sym_name)))
- return NULL;
- dot = strchr (sym, '.');
- if (NULL != dot)
+ {
+ LOG_STRERROR ("strdup");
+ return NULL;
+ }
+ if (NULL != (dot = strchr (sym, '.')))
*dot = '\0';
if (NULL == (name = malloc(strlen(sym) + strlen(template) + 1)))
{
@@ -72,34 +75,29 @@
if (NULL == symbol)
{
/* now try with the '_' */
-#if DEBUG
char *first_error = strdup (lt_dlerror ());
-#endif
symbol = lt_dlsym (lib_handle, name);
-#if DEBUG
if (NULL == symbol)
{
- fprintf (stderr,
- "Resolving symbol `%s' failed, "
- "so I tried `%s', but that failed also. Errors are: "
- "`%s' and `%s'.\n",
- name+1,
- name,
- first_error == NULL ? "out of memory" : first_error,
- lt_dlerror());
+ LOG ("Resolving symbol `%s' failed, "
+ "so I tried `%s', but that failed also. Errors are: "
+ "`%s' and `%s'.\n",
+ name+1,
+ name,
+ first_error == NULL ? "out of memory" : first_error,
+ lt_dlerror ());
}
if (NULL != first_error)
free (first_error);
-#endif
}
if ( (NULL != symbol) &&
(NULL != options) )
{
/* get special options */
- sprintf(name,
- "_EXTRACTOR_%s_options",
- sym);
+ sprintf (name,
+ "_EXTRACTOR_%s_options",
+ sym);
/* try without '_' first */
opt_fun = lt_dlsym (lib_handle, name + 1);
if (NULL == opt_fun)
@@ -134,11 +132,8 @@
plugin->libname = EXTRACTOR_find_plugin_ (plugin->short_libname);
if (NULL == plugin->libname)
{
-#if DEBUG
- fprintf (stderr,
- "Failed to find plugin `%s'\n",
- plugin->short_libname);
-#endif
+ LOG ("Failed to find plugin `%s'\n",
+ plugin->short_libname);
plugin->flags = EXTRACTOR_OPTION_DISABLED;
return -1;
}
@@ -153,12 +148,9 @@
(WideCharToMultiByte (CP_ACP, 0, wlibname, -1,
llibname, sizeof (llibname), NULL, NULL) < 0) )
{
-#if DEBUG
- fprintf (stderr,
- "Loading `%s' plugin failed: %s\n",
- plugin->short_libname,
- "can't convert plugin name to local encoding");
-#endif
+ LOG ("Loading `%s' plugin failed: %s\n",
+ plugin->short_libname,
+ "can't convert plugin name to local encoding");
free (plugin->libname);
plugin->libname = NULL;
plugin->flags = EXTRACTOR_OPTION_DISABLED;
@@ -173,12 +165,9 @@
lt_dladvise_destroy (&advise);
if (NULL == plugin->libraryHandle)
{
-#if DEBUG
- fprintf (stderr,
- "Loading `%s' plugin failed: %s\n",
- plugin->short_libname,
- lt_dlerror ());
-#endif
+ LOG ("Loading `%s' plugin failed: %s\n",
+ plugin->short_libname,
+ lt_dlerror ());
free (plugin->libname);
plugin->libname = NULL;
plugin->flags = EXTRACTOR_OPTION_DISABLED;
@@ -190,12 +179,9 @@
&plugin->specials);
if (NULL == plugin->extract_method)
{
-#if DEBUG
- fprintf (stderr,
- "Resolving `extract' method of plugin `%s' failed: %s\n",
- plugin->short_libname,
- lt_dlerror ());
-#endif
+ LOG ("Resolving `extract' method of plugin `%s' failed: %s\n",
+ plugin->short_libname,
+ lt_dlerror ());
lt_dlclose (plugin->libraryHandle);
free (plugin->libname);
plugin->libname = NULL;
@@ -230,9 +216,8 @@
return prev; /* no change, library already loaded */
if (NULL == (libname = EXTRACTOR_find_plugin_ (library)))
{
- fprintf (stderr,
- "Could not load `%s'\n",
- library);
+ LOG ("Could not load plugin `%s'\n",
+ library);
return prev;
}
if (NULL == (result = malloc (sizeof (struct EXTRACTOR_PluginList))))
@@ -367,11 +352,8 @@
}
if (NULL == pos)
{
-#if DEBUG
- fprintf(stderr,
- "Unloading plugin `%s' failed!\n",
- library);
-#endif
+ LOG ("Unloading plugin `%s' failed!\n",
+ library);
return first;
}
/* found, close library */
Modified: Extractor/src/main/extractor_plugpath.c
===================================================================
--- Extractor/src/main/extractor_plugpath.c 2012-07-30 14:35:34 UTC (rev
22986)
+++ Extractor/src/main/extractor_plugpath.c 2012-07-30 14:46:36 UTC (rev
22987)
@@ -32,8 +32,8 @@
#include <ltdl.h>
#include "extractor_plugpath.h"
+#include "extractor_logging.h"
-
/**
* Function to call on paths.
*
@@ -78,6 +78,7 @@
return in;
}
+
#if LINUX
/**
* Try to determine path by reading /proc/PID/exe or
@@ -146,6 +147,7 @@
lnk = cut_bin (lnk);
if (NULL == (ret = realloc (lnk, strlen(lnk) + 6)))
{
+ LOG_STRERROR ("realloc");
free (lnk);
return NULL;
}
@@ -178,6 +180,7 @@
path = cut_bin (path);
if (NULL == (ret = realloc (path, strlen(path) + 6)))
{
+ LOG_STRERROR ("realloc");
free (path);
return NULL;
}
@@ -223,7 +226,11 @@
(void) func (path, &len);
if (0 == len)
return NULL;
- path = GNUNET_malloc (len);
+ if (NULL == (path = malloc (len)))
+ {
+ LOG_STRERROR ("malloc");
+ return NULL;
+ }
if (0 != func (path, &len))
{
GNUNET_free (path);
@@ -259,7 +266,10 @@
if ( (NULL == path) || (0 == strlen (path)) )
continue;
if (NULL == (p = strdup (path)))
- return NULL;
+ {
+ LOG_STRERROR ("strdup");
+ return NULL;
+ }
s = p + strlen (p);
while ( (s > p) && ('/' != *s) )
s--;
@@ -291,9 +301,13 @@
if (NULL == (p = getenv ("PATH")))
return NULL;
if (NULL == (path = strdup (p))) /* because we write on it */
- return NULL;
+ {
+ LOG_STRERROR ("strdup");
+ return NULL;
+ }
if (NULL == (buf = malloc (strlen(path) + 20)))
{
+ LOG_STRERROR ("malloc");
free (path);
return NULL;
}
@@ -304,14 +318,17 @@
sprintf(buf, "%s/%s", pos, "extract");
if (0 == stat(buf, &sbuf))
{
- pos = strdup(pos);
free (buf);
free (path);
- if (NULL == pos)
- return NULL;
+ if (NULL == (pos = strdup(pos)))
+ {
+ LOG_STRERROR ("strdup");
+ return NULL;
+ }
pos = cut_bin (pos);
if (NULL == (ret = realloc (pos, strlen(pos) + 5)))
{
+ LOG_STRERROR ("realloc");
free (pos);
return NULL;
}
@@ -329,9 +346,9 @@
if (NULL == pos)
return NULL;
pos = cut_bin (pos);
- ret = realloc (pos, strlen(pos) + 5);
- if (NULL == ret)
+ if (NULL == (ret = realloc (pos, strlen(pos) + 5)))
{
+ LOG_STRERROR ("realloc");
free (pos);
return NULL;
}
@@ -412,7 +429,10 @@
if (NULL != (p = getenv ("LIBEXTRACTOR_PREFIX")))
{
if (NULL == (d = strdup (p)))
- return;
+ {
+ LOG_STRERROR ("strdup");
+ return;
+ }
for (prefix = strtok (d, PATH_SEPARATOR_STR);
NULL != prefix;
prefix = strtok (NULL, PATH_SEPARATOR_STR))
@@ -500,9 +520,9 @@
if (NULL == (sym_name = strrchr (ent->d_name, '_')))
continue;
sym_name++;
- sym = strdup (sym_name);
- if (NULL == sym)
+ if (NULL == (sym = strdup (sym_name)))
{
+ LOG_STRERROR ("strdup");
CLOSEDIR (dir);
return;
}
@@ -573,8 +593,7 @@
char *sym;
char *dot;
- dir = opendir (path);
- if (NULL == dir)
+ if (NULL == (dir = opendir (path)))
return;
while (NULL != (ent = readdir (dir)))
{
@@ -586,18 +605,16 @@
(la[2] == '\0')) )
continue; /* only load '.so' and '.dll' */
- sym_name = strrchr (ent->d_name, '_');
- if (sym_name == NULL)
+ if (NULL == (sym_name = strrchr (ent->d_name, '_')))
continue;
sym_name++;
- sym = strdup (sym_name);
- if (NULL == sym)
+ if (NULL == (sym = strdup (sym_name)))
{
+ LOG_STRERROR ("strdup");
closedir (dir);
return;
}
- dot = strchr (sym, '.');
- if (dot != NULL)
+ if (NULL != (dot = strchr (sym, '.')))
*dot = '\0';
#if DEBUG > 1
fprintf (stderr,
Modified: Extractor/src/main/extractor_print.c
===================================================================
--- Extractor/src/main/extractor_print.c 2012-07-30 14:35:34 UTC (rev
22986)
+++ Extractor/src/main/extractor_print.c 2012-07-30 14:46:36 UTC (rev
22987)
@@ -20,7 +20,7 @@
#include "platform.h"
#include "extractor.h"
-
+#include "extractor_logging.h"
#include "iconv.c"
/**
@@ -58,10 +58,14 @@
cd = iconv_open (nl_langinfo(CODESET),
"UTF-8");
if (((iconv_t) -1) == cd)
- return 1;
- buf = iconv_helper(cd, data);
+ {
+ LOG_STRERROR ("iconv_open");
+ return 1;
+ }
+ buf = iconv_helper (cd, data);
if (NULL == buf)
{
+ LOG_STRERROR ("iconv_helper");
ret = -1;
}
else
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r22987 - Extractor/src/main,
gnunet <=