debian/0000755000000000000000000000000011626013174007167 5ustar debian/rules0000755000000000000000000000025511626005543010252 0ustar #!/usr/bin/make -f # Uncomment this to turn on verbose mode. #export DH_VERBOSE=1 %: dh $@ --with autoreconf override_dh_clean:: find po -name \*.gmo -delete dh_clean debian/source/0000755000000000000000000000000011324657540010475 5ustar debian/source/format0000644000000000000000000000001411324472525011701 0ustar 3.0 (quilt) debian/watch0000644000000000000000000000010611324472300010210 0ustar version=3 http://corsair626.no-ip.org/microdc/ microdc2-(.*)\.tar\.gz debian/docs0000644000000000000000000000001411324453536010042 0ustar NEWS README debian/control0000644000000000000000000000225111626005701010567 0ustar Source: microdc2 Section: net Priority: extra Maintainer: Al Nikolov Build-Depends: debhelper (>= 7.0.50~), dh-autoreconf, libreadline-dev, libxml2-dev (>= 2.6.16), libbz2-dev Standards-Version: 3.9.2 Homepage: http://corsair626.no-ip.org/microdc/ Package: microdc2 Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends} Description: command-line based Direct Connect client microdc2 is a command-line based Direct Connect client that uses the GNU Readline library for user interaction. It was developed from ground up and does not depend on any other program. Despite the command-line user interface, it was designed to be user friendly and simple to use. It can work on headless host (under `screen`, for instance) ant thus, doesn't require you to run an expensive X11 session, as other clients do. . microdc2 is currently in beta state - there may be many bugs not yet discovered. It also lacks some features that other clients support, such as file hashing, multiple hub connections, and hub list support. . Direct Connect protocol is used for P2P file sharing. See it's description on http://en.wikipedia.org/wiki/Direct_Connect_(file_sharing). debian/README.source0000644000000000000000000000054611324472044011353 0ustar microdc2 for Debian ------------------- This package uses quilt to manage all modifications to the upstream source. Changes are stored in the source package as diffs in debian/patches and applied during the build. Please see: /usr/share/doc/quilt/README.source for more information on how to apply the patches, modify patches, or remove a patch. debian/patches/0000755000000000000000000000000011626012052010610 5ustar debian/patches/rename-manpage0000644000000000000000000001433411324702611013417 0ustar Description: Rename manpage Rename manpage to the proper name. Get rid of non-unicode Polish manpage. Author: Al Nikolov Last-Update: 2010-01-17 Index: microdc2-0.15.6/src/Makefile.am =================================================================== --- microdc2-0.15.6.orig/src/Makefile.am 2010-01-17 21:07:10.000000000 +0000 +++ microdc2-0.15.6/src/Makefile.am 2010-01-17 21:06:47.000000000 +0000 @@ -63,9 +63,7 @@ # $(LIBICONV) - not yet used -man_MANS = \ - microdc.1 \ - microdc.pl.1 +man_MANS = microdc2.1 EXTRA_DIST = \ $(man_MANS) Index: microdc2-0.15.6/src/microdc.1 =================================================================== --- microdc2-0.15.6.orig/src/microdc.1 2010-01-17 21:07:10.000000000 +0000 +++ /dev/null 1970-01-01 00:00:00.000000000 +0000 @@ -1,64 +0,0 @@ -.\" -*- nroff -*- -.\" microdc.1 - Manual page for microdc. -.\" -.\" Copyright (C) 2004, 2005 Oskar Liljeblad -.\" -.\" This program is free software; you can redistribute it and/or modify -.\" it under the terms of the GNU General Public License as published by -.\" the Free Software Foundation; either version 2 of the License, or -.\" (at your option) any later version. -.\" -.\" This program is distributed in the hope that it will be useful, -.\" but WITHOUT ANY WARRANTY; without even the implied warranty of -.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -.\" GNU Library General Public License for more details. -.\" -.\" You should have received a copy of the GNU General Public License along -.\" with this program; if not, write to the Free Software Foundation, -.\" Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -.\" -.TH MICRODC "1" "September 17, 2005" "microdc" -.SH NAME -microdc - A command-line based Direct Connect client -.SH SYNOPSIS -.B microdc -.RI [ OPTION ]... -.SH DESCRIPTION -microdc is a command-line based Direct Connect client that uses the GNU -Readline library for user interaction. It was developed from ground up and -does not depend on any other program. Despite the command-line user -interface, microdc was designed to be user friendly and simple to use. -.SH OPTIONS -This program follows the usual GNU command line syntax, with long -options starting with two dashes (`--'). -.TP -\fB\-c, \-\-config\fR=\fIFILE\fR -Read configuration script from FILE rather than ~/.microdc/config. -.TP -\fB\-n, \-\-no\-config\fR -Do not read config file on startup. -.TP -\fB\-\-help\fR -Show summary of options. -.TP -\fB\-\-version\fR -Output version information and exit. -.SH FILES -The following files are used by microdc (~ represents the current user's home directory): -.TP -\fB~/.microdc/config\fR -This file is loaded on startup. It contains commands, one per line, that will be executed -on startup. You can override loading of this file with --config and --no-config. -.TP -\fB~/.microdc/history\fR -This is the command history file. It contains a list of commands that were typed and -executed from the microdc prompt. It can safely be removed. -.SH REPORTING BUGS -Report bugs to <\fIoskar@osk.mine.nu\fP>. -.SH AUTHOR -The author of \fBmicrodc\fP and this manual page is Oskar Liljeblad <\fIoskar@osk.mine.nu\fP>. -.SH COPYRIGHT -Copyright \(co 2004, 2005 Oskar Liljeblad - -This is free software; see the source for copying conditions. There is NO -warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Index: microdc2-0.15.6/src/microdc2.1 =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ microdc2-0.15.6/src/microdc2.1 2006-10-22 08:35:50.000000000 +0000 @@ -0,0 +1,64 @@ +.\" -*- nroff -*- +.\" microdc.1 - Manual page for microdc. +.\" +.\" Copyright (C) 2004, 2005 Oskar Liljeblad +.\" +.\" This program is free software; you can redistribute it and/or modify +.\" it under the terms of the GNU General Public License as published by +.\" the Free Software Foundation; either version 2 of the License, or +.\" (at your option) any later version. +.\" +.\" This program is distributed in the hope that it will be useful, +.\" but WITHOUT ANY WARRANTY; without even the implied warranty of +.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +.\" GNU Library General Public License for more details. +.\" +.\" You should have received a copy of the GNU General Public License along +.\" with this program; if not, write to the Free Software Foundation, +.\" Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +.\" +.TH MICRODC "1" "September 17, 2005" "microdc" +.SH NAME +microdc - A command-line based Direct Connect client +.SH SYNOPSIS +.B microdc +.RI [ OPTION ]... +.SH DESCRIPTION +microdc is a command-line based Direct Connect client that uses the GNU +Readline library for user interaction. It was developed from ground up and +does not depend on any other program. Despite the command-line user +interface, microdc was designed to be user friendly and simple to use. +.SH OPTIONS +This program follows the usual GNU command line syntax, with long +options starting with two dashes (`--'). +.TP +\fB\-c, \-\-config\fR=\fIFILE\fR +Read configuration script from FILE rather than ~/.microdc/config. +.TP +\fB\-n, \-\-no\-config\fR +Do not read config file on startup. +.TP +\fB\-\-help\fR +Show summary of options. +.TP +\fB\-\-version\fR +Output version information and exit. +.SH FILES +The following files are used by microdc (~ represents the current user's home directory): +.TP +\fB~/.microdc/config\fR +This file is loaded on startup. It contains commands, one per line, that will be executed +on startup. You can override loading of this file with --config and --no-config. +.TP +\fB~/.microdc/history\fR +This is the command history file. It contains a list of commands that were typed and +executed from the microdc prompt. It can safely be removed. +.SH REPORTING BUGS +Report bugs to <\fIoskar@osk.mine.nu\fP>. +.SH AUTHOR +The author of \fBmicrodc\fP and this manual page is Oskar Liljeblad <\fIoskar@osk.mine.nu\fP>. +.SH COPYRIGHT +Copyright \(co 2004, 2005 Oskar Liljeblad + +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. debian/patches/series0000644000000000000000000000030211626011510012016 0ustar disable-touching-debian disable-libxml2-version-check rename-manpage disable-make-tthsum debian-link-system-bz2 slave-mode rehash-command logfile-segfault-fix main-loop-fix minus-in-manpage-fix debian/patches/disable-touching-debian0000644000000000000000000000137111324702517015205 0ustar Description: Disable touching files in the debian directory Touching files there complicates maintainer's job. Author: Al Nikolov Last-Update: 2010-01-17 Index: microdc2-0.15.6/Makefile.am =================================================================== --- microdc2-0.15.6.orig/Makefile.am 2010-01-17 04:55:33.000000000 +0000 +++ microdc2-0.15.6/Makefile.am 2010-01-17 04:55:16.000000000 +0000 @@ -25,9 +25,6 @@ clean-local: -rm -f build-stamp configure-stamp stamp-h1 - -rm -f debian/compat debian/files debian/@PACKAGE@.substvars - -rm -f debian/stamp-* - -rm -rf debian/@PACKAGE@ # This macro is useful until gnulib-tool is incorporated into autoreconf. # Unfortunately the ./configure script is first run if configure.ac is debian/patches/rehash-command0000644000000000000000000000213111626002220013412 0ustar Description: Add function to refresh share on demand Author: Daniel Andersson Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=612372 Last-Update: 2011-08-26 --- a/src/command.c +++ b/src/command.c @@ -65,6 +65,7 @@ static void cmd_help(int argc, char **argv); static void cmd_exit(int argc, char **argv); static void cmd_say(int argc, char **argv); +static void cmd_rehash(int argc, char **argv); static void cmd_msg(int argc, char **argv); static void cmd_raw(int argc, char **argv); static void cmd_disconnect(int argc, char **argv); @@ -268,6 +269,9 @@ "\n" "Example:\n" " say \"hi everyone!\"\n")); + add_builtin_command("rehash", cmd_rehash, NULL, + _("rehash"), + _("Refresh share.\n")); add_builtin_command("search", cmd_search, NULL, _("search WORD..."), _("Issue a search for the specified search words.\n")); @@ -874,6 +878,12 @@ } static void +cmd_rehash(int argc, char **argv) +{ + local_file_list_update_init(); +} + +static void cmd_msg(int argc, char **argv) { char *t1; debian/patches/debian-link-system-bz20000644000000000000000000000242511325714162014737 0ustar Description: Link against the system bz2 library Author: Al Nikolov Forwarded: non-needed Last-Update: 2010-01-21 Index: microdc2-0.15.6/configure.ac =================================================================== --- microdc2-0.15.6.orig/configure.ac 2010-01-20 23:55:08.000000000 +0000 +++ microdc2-0.15.6/configure.ac 2010-01-20 23:57:34.000000000 +0000 @@ -64,6 +64,7 @@ # AC_MSG_WARN([XML libxml2 library version 2.6.16 or later is required to support XML filelists]) # fi #fi +AC_CHECK_LIB(bz2, BZ2_bzRead,, AC_MSG_ERROR([Missing bz2 library])) # Checks for header files @@ -80,7 +81,6 @@ lib/Makefile src/Makefile src/common/Makefile - src/bzip2/Makefile src/tth/Makefile rpm/microdc.spec]) AC_CONFIG_FILES([slackware/microdc.SlackBuild], Index: microdc2-0.15.6/src/Makefile.am =================================================================== --- microdc2-0.15.6.orig/src/Makefile.am 2010-01-20 23:55:08.000000000 +0000 +++ microdc2-0.15.6/src/Makefile.am 2010-01-20 23:57:20.000000000 +0000 @@ -1,4 +1,4 @@ -SUBDIRS = common bzip2 tth +SUBDIRS = common tth AM_CFLAGS = \ -Wall \ @@ -40,7 +40,6 @@ microdc2_LDADD = \ common/libcommon.a \ - bzip2/libbzip2.a \ tth/libtth.a \ ../lib/libgnu.a \ $(READLINE_LIBS) \ debian/patches/minus-in-manpage-fix0000644000000000000000000000141511626012467014477 0ustar Description: fix minus signs in options. Author: Al Nikolov Last-Updated: 2011-08-27 Index: microdc2-0.15.6/src/microdc2.1 =================================================================== --- microdc2-0.15.6.orig/src/microdc2.1 2011-08-27 00:41:15.000000000 +0300 +++ microdc2-0.15.6/src/microdc2.1 2011-08-27 00:41:32.000000000 +0300 @@ -48,7 +48,7 @@ .TP \fB~/.microdc/config\fR This file is loaded on startup. It contains commands, one per line, that will be executed -on startup. You can override loading of this file with --config and --no-config. +on startup. You can override loading of this file with \-\-config and \-\-no-config. .TP \fB~/.microdc/history\fR This is the command history file. It contains a list of commands that were typed and debian/patches/main-loop-fix0000644000000000000000000001342611626000301013212 0ustar Description: fix for CPU usage 100% in main loop. Author: Daniel Andersson Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=612889 Last-Update: 2011-08-26 Index: microdc2-0.15.6/src/main.c =================================================================== --- microdc2-0.15.6.orig/src/main.c 2011-02-11 02:36:28.353479995 +0100 +++ microdc2-0.15.6/src/main.c 2011-02-11 02:37:22.823479996 +0100 @@ -55,6 +55,15 @@ #include "common/msgq.h" #include "microdc.h" +/* Define the macro below for orphan handle checking (useful for debugging) */ +#define CHECK_ORPHAN_HANDLES + +#ifdef CHECK_ORPHAN_HANDLES +#define IF_ORPHAN_HANDLES(x) x +#else +#define IF_ORPHAN_HANDLES(x) +#endif + enum { VERSION_OPT = 256, HELP_OPT @@ -1306,34 +1315,60 @@ break; } - if (running && FD_ISSET(signal_pipe[0], &res_read_fds)) - read_signal_input(); - if (running && FD_ISSET(STDIN_FILENO, &res_read_fds)) + if (running && FD_ISSET(signal_pipe[0], &res_read_fds)) { + FD_CLR(signal_pipe[0], &res_read_fds); + read_signal_input(); + } + if (running && FD_ISSET(STDIN_FILENO, &res_read_fds)) { + IF_ORPHAN_HANDLES (FD_CLR(STDIN_FILENO, &res_read_fds)); screen_read_input(); - if (running && listen_socket >= 0 && FD_ISSET(listen_socket, &res_read_fds)) + } + if (running && listen_socket >= 0 && FD_ISSET(listen_socket, &res_read_fds)) { + IF_ORPHAN_HANDLES (FD_CLR(listen_socket, &res_read_fds)); handle_listen_connection(); - if (running && hub_socket >= 0 && FD_ISSET(hub_socket, &res_read_fds)) + } + if (running && hub_socket >= 0 && FD_ISSET(hub_socket, &res_read_fds)) { + IF_ORPHAN_HANDLES (FD_CLR(hub_socket, &res_read_fds)); hub_input_available(); - if (running && hub_socket >= 0 && FD_ISSET(hub_socket, &res_write_fds)) + } + if (running && hub_socket >= 0 && FD_ISSET(hub_socket, &res_write_fds)) { + IF_ORPHAN_HANDLES (FD_CLR(hub_socket, &res_write_fds)); hub_now_writable(); + } if (running) check_hub_activity(); - if (running && search_socket >= 0 && FD_ISSET(search_socket, &res_read_fds)) + if (running && search_socket >= 0 && FD_ISSET(search_socket, &res_read_fds)) { + IF_ORPHAN_HANDLES (FD_CLR(search_socket, &res_read_fds)); search_input_available(); - if (running && search_socket >= 0 && FD_ISSET(search_socket, &res_write_fds)) + } + if (running && search_socket >= 0 && FD_ISSET(search_socket, &res_write_fds)) { + IF_ORPHAN_HANDLES (FD_CLR(search_socket, &res_write_fds)); search_now_writable(); - if (running && FD_ISSET(lookup_request_mq->fd, &res_write_fds)) + } + if (running && FD_ISSET(lookup_request_mq->fd, &res_write_fds)) { + IF_ORPHAN_HANDLES (FD_CLR(lookup_request_mq->fd, &res_write_fds)); lookup_request_fd_writable(); - if (running && FD_ISSET(lookup_result_mq->fd, &res_read_fds)) + } + if (running && FD_ISSET(lookup_result_mq->fd, &res_read_fds)) { + IF_ORPHAN_HANDLES (FD_CLR(lookup_result_mq->fd, &res_read_fds)); lookup_result_fd_readable(); - if (running && FD_ISSET(parse_request_mq->fd, &res_write_fds)) + } + if (running && FD_ISSET(parse_request_mq->fd, &res_write_fds)) { + IF_ORPHAN_HANDLES (FD_CLR(parse_request_mq->fd, &res_write_fds)); parse_request_fd_writable(); - if (running && FD_ISSET(parse_result_mq->fd, &res_read_fds)) + } + if (running && FD_ISSET(parse_result_mq->fd, &res_read_fds)) { + IF_ORPHAN_HANDLES (FD_CLR(parse_result_mq->fd, &res_read_fds)); parse_result_fd_readable(); - if (running && FD_ISSET(update_request_mq->fd, &res_write_fds)) + } + if (running && FD_ISSET(update_request_mq->fd, &res_write_fds)) { + IF_ORPHAN_HANDLES (FD_CLR(update_request_mq->fd, &res_write_fds)); update_request_fd_writable(); - if (running && FD_ISSET(update_result_mq->fd, &res_read_fds)) + } + if (running && FD_ISSET(update_result_mq->fd, &res_read_fds)) { + IF_ORPHAN_HANDLES (FD_CLR(update_result_mq->fd, &res_read_fds)); update_result_fd_readable(); + } if (running) { HMapIterator it; @@ -1341,13 +1376,36 @@ hmap_iterator(user_conns, &it); while (running && it.has_next(&it)) { DCUserConn *uc = it.next(&it); - if (uc->put_mq != NULL && FD_ISSET(uc->put_mq->fd, &res_write_fds)) + if (uc->put_mq != NULL && FD_ISSET(uc->put_mq->fd, &res_write_fds)) { + IF_ORPHAN_HANDLES (FD_CLR(uc->put_mq->fd, &res_write_fds)); user_request_fd_writable(uc); - if (uc->get_mq != NULL && FD_ISSET(uc->get_mq->fd, &res_read_fds)) - user_result_fd_readable(uc); + } + if (uc->get_mq != NULL && FD_ISSET(uc->get_mq->fd, &res_read_fds)) { + IF_ORPHAN_HANDLES (FD_CLR(uc->get_mq->fd, &res_read_fds)); + user_result_fd_readable(uc); + } } } - } + +#ifdef CHECK_ORPHAN_HANDLES + /* Check for orphan file handles */ + { + int i; + for (i = 0; i < FD_SETSIZE; i++) { + if (FD_ISSET (i, &res_read_fds)) { + warn(_("Orphan READ file handle %d, closing\n"), i); + close (i); + FD_CLR (i, &read_fds); + } + if (FD_ISSET (i, &res_write_fds)) { + warn(_("Orphan WRITE file handle %d, closing\n"), i); + close (i); + FD_CLR (i, &write_fds); + } + } + } +#endif + } cleanup: debian/patches/disable-libxml2-version-check0000644000000000000000000000364511324702446016263 0ustar Description: Disable the libxml2 version check The check is broken (dotted version to integer conversion is wrong). . Since the Debian package has versionned dependency on a fresh version of libxml2-dev, the version check isn't needed. And probably libxml2 older than version 2.6.16 aren't in the wild anymore. Author: Al Nikolov Last-Update: 2010-01-17 Index: microdc2-0.15.6/configure.ac =================================================================== --- microdc2-0.15.6.orig/configure.ac 2010-01-17 04:45:33.000000000 +0000 +++ microdc2-0.15.6/configure.ac 2010-01-17 04:44:54.000000000 +0000 @@ -47,12 +47,12 @@ #AH_TEMPLATE([XML_SAVE_FORMAT], [1], [Define if libxml2 has no such option for xmlSave- functions]) AC_PATH_PROG(XML_CONFIG, xml2-config) AC_PATH_PROG(TR, tr) -if test -n "$XML_CONFIG" && test -n "$TR"; then - LIBXML2_VERSION=`$XML_CONFIG --version | $TR -d "."` - if test $LIBXML2_VERSION -eq 2616; then - AC_DEFINE([XML_SAVE_FORMAT], [1], [The libxml2 version 2.6.16 has no such option defined in the library headers]) - fi - if test $LIBXML2_VERSION -ge 2616; then +#if test -n "$XML_CONFIG" && test -n "$TR"; then +# LIBXML2_VERSION=`$XML_CONFIG --version | $TR -d "."` +# if test $LIBXML2_VERSION -eq 2616; then +# AC_DEFINE([XML_SAVE_FORMAT], [1], [The libxml2 version 2.6.16 has no such option defined in the library headers]) +# fi +# if test $LIBXML2_VERSION -ge 2616; then AC_DEFINE([HAVE_LIBXML2]) LIBXML2_LIBS="`$XML_CONFIG --libs`" LIBXML2_CFLAGS="`$XML_CONFIG --cflags`" @@ -60,10 +60,10 @@ AC_SUBST(LIBXML2_CFLAGS) # LIBS="$LIBS $LIBXML2_LIBS" # CFLAGS="$CFLAGS $LIBXML2_CFLAGS" - else - AC_MSG_WARN([XML libxml2 library version 2.6.16 or later is required to support XML filelists]) - fi -fi +# else +# AC_MSG_WARN([XML libxml2 library version 2.6.16 or later is required to support XML filelists]) +# fi +#fi # Checks for header files debian/patches/disable-make-tthsum0000644000000000000000000000154711325705377014421 0ustar Description: Disable make tthsum There is a package tthsum in Debian. Author: Al Nikolov Last-Update: 2010-01-21 Index: microdc2-0.15.6/src/Makefile.am =================================================================== --- microdc2-0.15.6.orig/src/Makefile.am 2010-01-17 21:30:23.000000000 +0000 +++ microdc2-0.15.6/src/Makefile.am 2010-01-17 21:30:47.000000000 +0000 @@ -8,7 +8,7 @@ -I$(top_builddir)/lib \ -I$(top_srcdir)/lib -bin_PROGRAMS = microdc2 tthsum +bin_PROGRAMS = microdc2 microdc2_SOURCES = \ command.c \ @@ -33,9 +33,6 @@ charsets.h \ microdc.h -tthsum_SOURCES = \ - tth.c - #microdc_tth_SOURCES = \ # tth_file.c \ # tth_file.h \ @@ -52,11 +49,6 @@ $(LIBXML2_LIBS) -tthsum_LDADD = \ - tth/libtth.a \ - ../lib/libgnu.a \ - $(LIBINTL) - #microdc_tth_LDADD = \ # tth/libtth.a \ # ../lib/libgnu.a debian/patches/slave-mode0000644000000000000000000003107611626011254012601 0ustar Description: Allow two or more simultaneous hub connections. Author: Daniel Andersson Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=612890 Last-Update: 2011-08-26 Index: microdc2-0.15.6/src/local_flist.c =================================================================== --- microdc2-0.15.6.orig/src/local_flist.c 2011-02-11 02:56:18.543479994 +0100 +++ microdc2-0.15.6/src/local_flist.c 2011-02-11 02:59:20.533480000 +0100 @@ -66,6 +66,7 @@ pid_t update_child; int incoming_update_type = -1; char* update_status = NULL; +time_t filelist_mtime = 0; static const char* filelist_name = "filelist"; static const char* new_filelist_name = "new-filelist"; @@ -78,6 +79,8 @@ #define ENOTFILELIST (1 << 16) #define EWRONGVERSION (ENOTFILELIST + 1) +bool report_error(MsgQ* status_mq, const char* fmt, ...); + int compare_pointers(void* p1, void* p2) { return p1 != p2; @@ -119,20 +122,61 @@ return is_already_shared_inode(root, st.st_dev, st.st_ino); } -DCFileList* read_local_file_list(const char* path) +void lock_file (const char* path) +{ + int fd, timeout = 20; + char fn [300]; + snprintf (fn, sizeof (fn), "%s.lock", path); + while ((fd = open (fn, O_RDONLY | O_CREAT | O_EXCL, 0600) < 0)) { + if (errno != EEXIST) { + /* It seems there's no way to report an error from here to parent? */ + /*report_error(result_mq, _("%s: Failed to create filelist lock, filelist will be not multiprocess-safe\n"), fn);*/ + break; + } + /* Wait some time for the lock to be released */ + sleep (1); + if (!--timeout) { + /*report_error(result_mq, _("%s: Filelist semaphore locked, but owner seems dead, breaking lock\n"), fn);*/ + break; + } + } + if (fd >= 0) + close (fd); +} + +void unlock_file (const char* path) +{ + char fn [300]; + snprintf (fn, sizeof (fn), "%s.lock", path); + unlink (fn); +} + +/* if old_root is not NULL, rereads the file list only if file changed */ +DCFileList* read_local_file_list(const char* path, DCFileList *old_root) { struct stat st; DCFileList *root = NULL; + /* First of all, check if filelist is not locked by other process */ + lock_file (path); + if (stat(path, &st) < 0) { if (errno != ENOENT) { TRACE(("cannot stat %s: %d, %s\n", path, errno, errstr)); + unlock_file (path); return NULL; } } else if (!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode)) { + unlock_file (path); return NULL; } + if (old_root && filelist_mtime == st.st_mtime) { + unlock_file (path); + return old_root; + } + filelist_mtime = st.st_mtime; + int fd = open(path, O_RDONLY); if (fd >= 0) { void* mapped = mmap(0, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); @@ -158,12 +202,22 @@ root = new_file_node("", DC_TYPE_DIR, NULL); } + unlock_file (path); + + if (old_root) + filelist_free (old_root); + return root; } bool write_local_file_list(const char* path, DCFileList* root) { bool result = false; + struct stat st; + + /* Check if filelist is not locked by other process */ + lock_file (path); + int fd = open(path, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); if (fd >= 0) { unsigned char* data = NULL; @@ -194,8 +248,14 @@ result = (size == data_size); cleanup: + /* Update filelist mtime */ + if (stat(path, &st) == 0) + filelist_mtime = st.st_mtime; + close(fd); } + + unlock_file (path); return result; } @@ -487,6 +547,7 @@ /* Inability to register these signals is not a fatal error. */ sigact.sa_flags = SA_RESTART; sigact.sa_handler = SIG_IGN; + sigemptyset (&sigact.sa_mask); #ifdef HAVE_STRUCT_SIGACTION_SA_RESTORER sigact.sa_restorer = NULL; #endif @@ -503,7 +564,7 @@ goto cleanup; } - if (NULL == (root = read_local_file_list(flist_filename))) { + if (NULL == (root = read_local_file_list(flist_filename, NULL))) { if (errno == ENOTFILELIST) { report_error(result_mq, "Cannot load FileList - %s: Invalid file format\n", flist_filename); } else if (errno == EWRONGVERSION) { @@ -527,7 +588,7 @@ max_fd = MAX(hash_result_mq->fd, max_fd); while (true) { - tv.tv_sec = filelist_refresh_timeout; + tv.tv_sec = FILELIST_SLAVE_MODE ? 60 : filelist_refresh_timeout; tv.tv_usec = 0; fd_set r_ready = readable, w_ready = writable; @@ -577,13 +638,19 @@ fflush(stderr); */ } + + if (FILELIST_SLAVE_MODE && update_hash) { + /* Unexpected hash update received while in slave filelist mode */ + update_hash = false; + } + time_t now = time(NULL); if (update_hash && ((hashing == NULL && hash_files->cur == 0) || (now - hash_start) > filelist_hash_refresh_timeout)) { hash_start = now; if (write_local_file_list(new_flist_filename, root)) { rename(new_flist_filename, flist_filename); } else { - unlink(new_filelist_name); + unlink(new_flist_filename); } if (!send_filelist(result_mq, root)) { @@ -607,11 +674,7 @@ msgq_get(request_mq, MSGQ_INT, &update_type, MSGQ_END); } else { if (update_type == FILELIST_UPDATE_REFRESH_INTERVAL) { - time_t interval = 0; - msgq_get(request_mq, MSGQ_INT, &interval, MSGQ_END); - if (interval != 0) { - filelist_refresh_timeout = interval; - } + msgq_get(request_mq, MSGQ_INT, &filelist_refresh_timeout, MSGQ_END); } else { char *name; int len = 0; @@ -626,13 +689,15 @@ case FILELIST_UPDATE_ADD_DIR_NAME: if (is_already_shared(root, name)) { // report error here - report_error(result_mq, "%s directory is already shared as subfolder of existing shared tree\n", name); - } else { + report_error(result_mq, _("%s directory is already shared as subfolder of existing shared tree\n"), name); + } else if (FILELIST_SLAVE_MODE) + report_error(result_mq, _("Cannot add directory %s to share list while in slave filelist mode\n"), name); + else { char* bname = xstrdup(base_name(name)); if (hmap_contains_key(root->dir.children, bname)) { /* we already have the shared directory with the same name */ - report_error(result_mq, "%s directory cannot be shared as %s because there is already shared directory with the same name\n", name, bname); + report_error(result_mq, _("%s directory cannot be shared as %s because there is already shared directory with the same name\n"), name, bname); } else { DCFileList* node = new_file_node(bname, DC_TYPE_DIR, root); node->dir.real_path = xstrdup(name); @@ -642,28 +707,30 @@ } break; case FILELIST_UPDATE_DEL_DIR_NAME: - //selected = 0; { char* bname = xstrdup(base_name(name)); DCFileList* node = hmap_get(root->dir.children, bname); - if (node != NULL && node->type == DC_TYPE_DIR) { - if (strcmp(node->dir.real_path, name) == 0) { + if (node != NULL && node->type == DC_TYPE_DIR && + strcmp(node->dir.real_path, name) == 0) { + if (FILELIST_SLAVE_MODE) + report_error(result_mq, _("Cannot remove directory %s from share list while in slave filelist mode\n"), name); + else { node = hmap_remove(root->dir.children, bname); filelist_free(node); if (write_local_file_list(new_flist_filename, root)) { rename(new_flist_filename, flist_filename); } else { - unlink(new_filelist_name); + unlink(new_flist_filename); } if (!send_filelist(result_mq, root)) { goto cleanup; } - } else { - report_error(result_mq, "%s directory is not shared\n"); } } + else + report_error(result_mq, _("%s directory is not shared\n"), name); free(bname); } break; @@ -703,18 +770,27 @@ } } } - if (selected == 0) { + + if (FILELIST_SLAVE_MODE && selected >= 0) { + // Check if filelist has been changed since we last read it + DCFileList *new_root = read_local_file_list(flist_filename, root); + if (new_root != root) { + root = new_root; + send_filelist(result_mq, root); + } + } + else if (selected == 0) { // just look through shared directories for new or deleted files if (hashing == NULL && !initial) - report_status(result_mq, "Refreshing FileList"); + report_status(result_mq, _("Refreshing FileList")); if (lookup_filelist_changes(root, hash_files)) { if (write_local_file_list(new_flist_filename, root)) { rename(new_flist_filename, flist_filename); } else { - unlink(new_filelist_name); + unlink(new_flist_filename); } - + if (!send_filelist(result_mq, root)) { break; } Index: microdc2-0.15.6/src/microdc.h =================================================================== --- microdc2-0.15.6.orig/src/microdc.h 2011-02-11 02:56:29.033479994 +0100 +++ microdc2-0.15.6/src/microdc.h 2011-02-11 02:57:37.883479998 +0100 @@ -596,6 +596,7 @@ extern pid_t update_child; extern char* update_status; extern time_t filelist_refresh_timeout; +#define FILELIST_SLAVE_MODE (filelist_refresh_timeout <= 0) bool local_file_list_update_init(void); bool local_file_list_init(void); void local_file_list_update_finish(void); Index: microdc2-0.15.6/src/microdc2.1 =================================================================== --- microdc2-0.15.6.orig/src/microdc2.1 2011-02-11 02:56:22.863479997 +0100 +++ microdc2-0.15.6/src/microdc2.1 2011-02-11 02:58:55.453480003 +0100 @@ -43,6 +43,12 @@ .TP \fB\-\-version\fR Output version information and exit. +.TP +\fB\-\-filelist_refresh_interval\fR=\fINUMBER\fR +Local filelist refresh interval (in seconds). If set to zero, program runs in a +special \fIslave\fR mode: it never updates the file list, just checks every minute +if the filelist changes, and if so - reads it. This is pretty useful if you connect +to several hubs and use same filelist. .SH FILES The following files are used by microdc (~ represents the current user's home directory): .TP debian/patches/logfile-segfault-fix0000644000000000000000000000411011626004002014540 0ustar Description: fix for segfault if logfile is specified in config file. Origin: http://arch.yu.wildpark.net/build/old/microdc2/logfile_segfault.patch Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=609746 Last-Update: 2011-08-26 Index: microdc2-0.15.6/src/main.c --- a/src/screen.c Fri Jan 25 18:46:56 2008 +0200 +++ b/src/screen.c Sat Jan 26 01:28:53 2008 +0200 @@ -228,10 +228,29 @@ static void static void flag_vputf(DCDisplayFlag flag, const char *format, va_list args) { - //va_list args2; + if (log_fh != NULL && log_flags & flag) { + char c_time[1024]; + time_t now = time(NULL); + struct tm _tm = {0}; + va_list args_dup; - //va_copy(args2, args); + if (NULL != localtime_r(&now, &_tm) && 0 != strftime(c_time, 1023, "%d.%m.%Y %H:%M:%S", &_tm)) { + fprintf(log_fh, "%s ", c_time); + } + // args would become undefined after xvasprintf() call, so make a copy + // of args to use it later below. + va_copy(args_dup, args); + char* msg = xvasprintf(format, args_dup); + va_end(args_dup); + + char* log_msg = main_to_log_string(msg); + free(msg); + fprintf(log_fh, log_msg); + free(log_msg); + fflush(log_fh); + } + if (display_flags & flag) { if (screen_state == SCREEN_SUSPENDED) { ptrv_append(suspend_msgs, xvasprintf(format, args)); @@ -243,21 +262,6 @@ flag_vputf(DCDisplayFlag flag, const cha vprintf(format, args); fflush(stdout); } - } - if (log_fh != NULL && log_flags & flag) { - char c_time[1024]; - time_t now = time(NULL); - struct tm _tm = {0}; - if (NULL != localtime_r(&now, &_tm) && 0 != strftime(c_time, 1023, "%d.%m.%Y %H:%M:%S", &_tm)) { - fprintf(log_fh, "%s ", c_time); - } - char* msg = xvasprintf(format, args); - //va_end(args2); - char* log_msg = main_to_log_string(msg); - free(msg); - fprintf(log_fh, log_msg); - free(log_msg); - fflush(log_fh); } } debian/changelog0000644000000000000000000000143211626012745011044 0ustar microdc2 (0.15.6-2) unstable; urgency=low * Fixed short description to omit the starting 'a' article. * Updated Standards-Version. * Dropped cdbs, relaying on DH7 now. * Fixed CPU usage 100% in main loop. Closes: #612889. * Fixed segmentation fault if logfile option set in config file. Closes: #609746. * Added function to refresh share on demand. Closes: #612372. * Added slave mode. Closes: #612890. * Fixed minus signs in the manpage. * Fixed debian/copyright to avoid lintian's false positive error helper-templates-in-copyright. -- Al Nikolov Sat, 27 Aug 2011 00:52:26 +0300 microdc2 (0.15.6-1) unstable; urgency=low * Initial release for Debian (Closes: #565461). -- Al Nikolov Fri, 15 Jan 2010 22:30:10 +0000 debian/copyright0000644000000000000000000000710511626012041011115 0ustar This work was packaged for Debian by: Al Nikolov on Sun, 17 Jan 2010 00:18:31 +0000 It was downloaded from: http://corsair626.no-ip.org/microdc/ Upstream Authors: Vladimir Chugunov Oskar Liljeblad Jakub Jankowski Tiago Cogumbreiro Mark Lee Kanedaaa Copyright: Copyright (C) 2006 Vladimir Chugunov Copyright (C) 1998-2005 Oskar Liljeblad Copyright (C) 1987-2009 Free Software Foundation, Inc. Copyright (C) 1994 X Consortium Copyright (C) 1995-1997, 2000-2005 by Ulrich Drepper Copyright (C) 2005 Jakub Jankowski Copyright (C) 1996-2005 Julian R Seward Copyright (C) 2006 Alexey Illarionov License: This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. On Debian systems, the complete text of the GNU General Public License version 2 can be found in `/usr/share/common-licenses/GPL-2'. License exceptions: Parts of the software included in the upstream tarball are covered by other licenses. src/bzip2: Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 3. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 4. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. The Debian packaging is: Copyright (C) 2010 Al Nikolov you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. debian/compat0000644000000000000000000000000211326605432010366 0ustar 7