diff --git a/init.nbd-server b/init.nbd-server index 78ec8cc..cea68b0 100644 --- a/init.nbd-server +++ b/init.nbd-server @@ -31,12 +31,16 @@ test -x $NBD_BIN || { echo "$NBD_BIN not installed"; NBD_CONFIG=/etc/nbd-server.conf NBD29_CONFIG=/etc/nbd-server/config test -r $NBD_CONFIG && { - echo "$NBD_CONFIG: Using old style config file deprecated"; + echo "$NBD_CONFIG: Using old style config file unsupported"; } -test -r $NBD_CONFIG || test -r $NBD29_CONFIG || { +test -r $NBD29_CONFIG || { echo "No config file $NBD29_CONFIG existing"; - if [ "$1" = "stop" ]; then exit 0; - else exit 6; fi; } + if [ "$1" = "stop" ]; then + exit 0; + else + exit 6; + fi; +} # Shell functions sourced from /etc/rc.status: . /etc/rc.status @@ -49,44 +53,21 @@ case "$1" in echo -n "Starting nbd-server " ## Start daemon with startproc(8). If this fails ## the return value is set appropriately by startproc. - if test -r $NBD29_CONFIG; then - $NBD_BIN - rc_check - else - declare -i started - started=0 - while read port file options; do - if test -z "$port"; then continue; fi - if test "${port:0:1}" = "#"; then continue; fi - echo -n " $port" - #/sbin/startproc -p /var/run/nbd-server.$port.pid $NBD_BIN $port $file $options - $NBD_BIN $port $file $options - rc_check - let started+=1 - done < $NBD_CONFIG - fi - # Remember status and be verbose - if test $_rc_status = 0 -a $started = 0; then - rc_status -s - else - true - rc_status -v - fi + startproc $NBD_BIN + rc_status -v ;; stop) echo -n "Shutting down nbd-server " ## Stop daemon with killproc(8) and if this fails ## killproc sets the return value according to LSB. - if test -r $NBD29_CONFIG; then - killall ${NBD_BIN##*/} - else - while read port file options; do - if test -z "$port"; then continue; fi - if test "${port:0:1}" = "#"; then continue; fi - echo -n " $port" - /sbin/killproc -p /var/run/nbd-server.$port.pid $NBD_BIN $port $file $options - done < $NBD_CONFIG - fi + #killall ${NBD_BIN##*/} + $0 status >/dev/null 2>&1 + stat=$? + if test $stat = 3; then echo -n " (not running) "; + elif test $stat != 0; then echo -n " (dead) "; fi + killproc $NBD_BIN + # TODO: Only kill nbd-server processes started by config file. + # Remember status and be verbose rc_status -v ;; @@ -97,7 +78,7 @@ case "$1" in if test "$1" = "condrestart"; then echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}" fi - $0 status + $0 status >/dev/null 2>&1 if test $? = 0; then $0 restart else @@ -123,45 +104,31 @@ case "$1" in echo -n "Reload service nbd-server " ## if it supports it: - /sbin/killproc -HUP $NBD_BIN + #/sbin/killproc -HUP $NBD_BIN #touch /var/run/nbd-server.pid - rc_status -v + #rc_status -v ## Otherwise: - #$0 try-restart - #rc_status + $0 try-restart + rc_status ;; reload) ## Like force-reload, but if daemon does not support ## signaling, do nothing (!) - - # If it supports signaling: - echo -n "Reload service nbd-server " - /sbin/killproc -HUP $NBD_BIN - #touch /var/run/nbd-server.pid - rc_status -v + #$0 force-reload + #rc_status ## Otherwise if it does not support reload: - #rc_failed 3 - #rc_status -v + echo -n "Reload service nbd-server " + rc_failed 3 + rc_status -v ;; status) echo -n "Checking for service nbd-server " ## Check status with checkproc(8), if process is running ## checkproc will return with exit status 0. + checkproc $NBD_BIN - # NOTE: checkproc returns LSB compliant status values. - while read port file options; do - if test -z "$port"; then continue; fi - if test "${port:0:1}" = "#"; then continue; fi - echo -n " $port" - if ! test -r /var/run/nbd-server.$port.pid; then rc_failed 3; echo -n ":DIS"; continue; fi - read PID 0 && (ret=rawexpwrite(a, buf, len, client)) > 0 ) { + a += ret; +@@ -907,7 +907,7 @@ ssize_t rawexpread(off_t a, char *buf, s + * @return 0 on success, nonzero on failure + **/ + int rawexpread_fully(off_t a, char *buf, size_t len, CLIENT *client) { +- ssize_t ret; ++ ssize_t ret = 0; + + while(len > 0 && (ret=rawexpread(a, buf, len, client)) > 0 ) { + a += ret; +@@ -1266,7 +1266,7 @@ void serveconnection(CLIENT *client) { + void set_peername(int net, CLIENT *client) { + struct sockaddr_in addrin; + struct sockaddr_in netaddr; +- size_t addrinlen = sizeof( addrin ); ++ socklen_t addrinlen = sizeof( addrin ); + char *peername; + char *netname; + char *tmp; +@@ -1486,7 +1486,7 @@ int serveloop(GArray* servers) { + } + /* child */ + g_hash_table_destroy(children); +- for(i=0;ilen,serve=(g_array_index(servers, SERVER*, i));i++) { ++ for(i=0; (ilen && (serve=(g_array_index(servers, SERVER*, i)))); i++) { + close(serve->socket); + } + /* FALSE does not free the diff --git a/nbd-2.9.5.tar.bz2 b/nbd-2.9.5.tar.bz2 new file mode 100644 index 0000000..83314f5 --- /dev/null +++ b/nbd-2.9.5.tar.bz2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:60a951191f5d3a74d974d681bd75a701a16056e2206e7d53546be5b5e89241ff +size 179919 diff --git a/nbd-server-daemonize-0.diff b/nbd-server-daemonize-0.diff new file mode 100644 index 0000000..3b036cc --- /dev/null +++ b/nbd-server-daemonize-0.diff @@ -0,0 +1,27 @@ +diff -uNrp nbd-2.9.5.orig/nbd-server.c nbd-2.9.5/nbd-server.c +--- nbd-2.9.5.orig/nbd-server.c 2007-07-08 11:58:44.000000000 +0200 ++++ nbd-2.9.5/nbd-server.c 2007-07-30 16:48:09.400856000 +0200 +@@ -1323,17 +1323,17 @@ void destroy_pid_t(gpointer data) { + void daemonize(SERVER* serve) { + FILE*pidf; + +- if(!(serve->port)) { +- return; +- } +- if(daemon(0,0)<0) { ++ //if (!serve) { ++ // return; ++ //} ++ if(daemon(0,0) < 0) { + err("daemon"); + } + if(!*pidftemplate) { + if(serve) { +- strncpy(pidftemplate, "/var/run/server.%d.pid", 255); ++ strncpy(pidftemplate, "/var/run/nbd-server.%d.pid", 255); + } else { +- strncpy(pidftemplate, "/var/run/server.pid", 255); ++ strncpy(pidftemplate, "/var/run/nbd-server.pid", 255); + } + } + snprintf(pidfname, 255, pidftemplate, serve ? serve->port : 0); diff --git a/nbd.changes b/nbd.changes index 3c0e50a..223a1d1 100644 --- a/nbd.changes +++ b/nbd.changes @@ -1,3 +1,22 @@ +------------------------------------------------------------------- +Mon Jul 30 15:51:16 CEST 2007 - garloff@suse.de + +- Convert options from old nbd-server.conf to new nbd-server/config + on update and drop support for old config file syntax. +- Fix daemonize(0) segfault and pid filename. +- Fix compiler warnings. +- Fix /dev filename docu. +- Use startproc, killproc, checkproc in init script +- nbd-server does not support SIGHUP, fix init script accordingly. + +------------------------------------------------------------------- +Tue Jul 17 00:54:45 CEST 2007 - garloff@suse.de + +- Update to nbd-2.9.5: + * Support for more platforms, pkgconfig, debug build. + * -o option to convert cmdline options to config file. + * Fix duplication in handling nonblocking server socket. + ------------------------------------------------------------------- Mon Mar 12 23:45:45 CET 2007 - garloff@suse.de diff --git a/nbd.spec b/nbd.spec index bf58cef..e33c7c3 100644 --- a/nbd.spec +++ b/nbd.spec @@ -1,5 +1,5 @@ # -# spec file for package nbd (Version 2.9.2) +# spec file for package nbd (Version 2.9.5) # # Copyright (c) 2007 SUSE LINUX Products GmbH, Nuernberg, Germany. # This file and all modifications and additions to the pristine @@ -13,13 +13,16 @@ Name: nbd BuildRequires: doxygen glib2-devel PreReq: %insserv_prereq -Version: 2.9.2 +Version: 2.9.5 Release: 1 -License: GNU General Public License (GPL) +License: GPL v2 or later Group: Productivity/Networking/Other Autoreqprov: on Source: %{name}-%{version}.tar.bz2 Source2: init.nbd-server +Patch1: nbd-server-daemonize-0.diff +Patch2: nbd-2.9.5-warn.diff +Patch3: nbd-2.9.5-doc.diff Summary: Network Block Device Server and Client Utilities URL: http://nbd.sourceforge.net/ Prefix: /usr @@ -54,6 +57,9 @@ Authors: %prep %setup +%patch1 -p1 +%patch2 -p1 +%patch3 -p1 touch nbd-client.8 %build @@ -62,7 +68,7 @@ export CFLAGS="$RPM_OPT_FLAGS -fstack-protector" #export CFLAGS="$RPM_OPT_FLAGS" ./configure --with-gnu-ld --prefix=/usr --mandir=%{_mandir} \ --infodir=%{_infodir} --libdir=%{_libdir} --libexecdir=%{_libdir} \ - --program-prefix="" --build=%{_target_cpu}-suse-linux + --program-prefix="" --sysconfdir=/etc --build=%{_target_cpu}-suse-linux make doxygen @@ -72,7 +78,11 @@ mkdir -p $RPM_BUILD_ROOT/etc/init.d install %SOURCE2 $RPM_BUILD_ROOT/etc/init.d/nbd-server mkdir -p $RPM_BUILD_ROOT/usr/bin ln -s ../../etc/init.d/nbd-server $RPM_BUILD_ROOT/usr/bin/rcnbd-server -echo "#Port file options" > $RPM_BUILD_ROOT/etc/nbd-server.conf +#echo "#Port file options" > $RPM_BUILD_ROOT/etc/nbd-server.conf +mkdir -p $RPM_BUILD_ROOT/etc/nbd-server +touch $RPM_BUILD_ROOT/etc/nbd-server/config +touch $RPM_BUILD_ROOT/etc/nbd-server/allow +grep -A16 -B1 '^\[generic\]' README > $RPM_BUILD_ROOT/etc/nbd-server/config.example %files %defattr(-,root,root) @@ -84,15 +94,50 @@ echo "#Port file options" > $RPM_BUILD_ROOT/etc/nbd-server.conf %{_mandir}/man8/nbd-client.8.gz %doc README %doc doc/html -%config(noreplace) /etc/nbd-server.conf +#%config(noreplace) /etc/nbd-server.conf +%dir /etc/nbd-server +%ghost %config(noreplace) /etc/nbd-server/config +%ghost %config(noreplace) /etc/nbd-server/allow +/etc/nbd-server/config.example %post %{fillup_and_insserv -f nbd-server} +if test -e /etc/nbd-server.conf; then + # Do we have to create a generic section? + unset generic + if test -e /etc/nbd-server/config; then generic=1; fi + while read port file opts; do + if test -z "$port"; then continue; fi + if test "${port:0:1}" = "#"; then continue; fi + if test -z "$generic"; then + echo -e "[generic]\n\t# No generic options yet\n" > /etc/nbd-server/config + generic=1 + fi + FN=${file%/*} + nm="cvt.$port.${FN##*/}.${file##*/}" + echo " ... convert $port $file $opts -> $nm" + /usr/bin/nbd-server $port $file $opts -o "$nm" >> /etc/nbd-server/config + done < /etc/nbd-server.conf + mv /etc/nbd-server.conf /etc/nbd-server.conf.converted +fi %postun %{insserv_cleanup} %changelog +* Mon Jul 30 2007 - garloff@suse.de +- Convert options from old nbd-server.conf to new nbd-server/config + on update and drop support for old config file syntax. +- Fix daemonize(0) segfault and pid filename. +- Fix compiler warnings. +- Fix /dev filename docu. +- Use startproc, killproc, checkproc in init script +- nbd-server does not support SIGHUP, fix init script accordingly. +* Tue Jul 17 2007 - garloff@suse.de +- Update to nbd-2.9.5: + * Support for more platforms, pkgconfig, debug build. + * -o option to convert cmdline options to config file. + * Fix duplication in handling nonblocking server socket. * Mon Mar 12 2007 - garloff@suse.de - Update to 2.9.2: * make child socket nonblocking