Mail archive
alpine-devel

[alpine-devel] [PATCH] main/iaxmodem: Create/modify init.d scripts iaxmodem can now be run using '/etc/init.d/iaxmodem start' iaxmodem is also being patched so it can handle '-P <pidfile>' option.

From: Mika Havela <mika.havela_at_gmail.com>
Date: Mon, 6 May 2013 06:52:55 +0000

---
 main/iaxmodem/APKBUILD         |  54 ++++++++++++++----
 main/iaxmodem/iaxmodem.c.patch | 126 +++++++++++++++++++++++++++++++++++++++++
 main/iaxmodem/iaxmodem.confd   |   5 ++
 main/iaxmodem/iaxmodem.initd   |  14 ++---
 4 files changed, 179 insertions(+), 20 deletions(-)
 create mode 100644 main/iaxmodem/iaxmodem.c.patch
diff --git a/main/iaxmodem/APKBUILD b/main/iaxmodem/APKBUILD
index 650004c..d29f232 100644
--- a/main/iaxmodem/APKBUILD
+++ b/main/iaxmodem/APKBUILD
_at_@ -1,38 +1,57 @@
 # Contributor: Cameron Banta <cbanta_at_gmail.com>
+# Contributor: Mika Havela <mika.havela_at_gmail.com>
 # Maintainer: Cameron Banta <cbanta_at_gmail.com>
 pkgname=iaxmodem
 pkgver=1.2.0
-pkgrel=4
+pkgrel=5
 pkgdesc="Softmodem for hylafax that connects to VOIP gateway with IAX"
 url="http://iaxmodem.sourceforge.net/"
 arch="all"
 license="GPL"
-depends=
-makedepends="tiff-dev"
-install=
+depends=""
+depends_dev="uclibc-dev"
+makedepends="$depends_dev tiff-dev"
+install=""
 subpackages="$pkgname-doc"
 source="http://downloads.sourceforge.net/$pkgname/$pkgname-$pkgver.tar.gz
-	nocxx.patch"
+	iaxmodem.c.patch
+	$pkgname.confd
+	$pkgname.initd"
 
-build() {
-	cd "$srcdir/$pkgname-$pkgver"
-
-	# purge usless C++ check
-	patch lib/libiax2/configure < ../nocxx.patch || return 1
+_builddir=$srcdir/$pkgname-$pkgver
+prepare() {
+	local i
+	cd "$_builddir"
+	for i in $source; do
+		case $i in
+		*.patch) msg $i; patch -p1 -i "$srcdir"/$i || return 1;;
+		esac
+	done
+}
 
+build() {
+	cd "$_builddir"
 	./configure
 	make || return 1
+
+}
+
+package() {
+	cd "$_builddir"
 	install -m755 -s -D "$srcdir/$pkgname-$pkgver/iaxmodem" \
 		"$pkgdir/usr/sbin/iaxmodem"
 	mkdir -p "$pkgdir/etc/iaxmodem"
 	mkdir -p "$pkgdir/var/log/iaxmodem"
 
+	install -m755 -D "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
+	install -m644 -D "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
+
 	#library licenses
 	install -m644 -D "$srcdir/$pkgname-$pkgver/lib/libiax2/COPYING" \
 		"$pkgdir"/usr/share/licenses/$pkgname/libiax2.COPYING
 	install -m644 -D "$srcdir/$pkgname-$pkgver/lib/libiax2/COPYING.LIB" \
 		"$pkgdir"/usr/share/licenses/$pkgname/libiax2.COPYING.LIB
-	
+
 	install -m644 -D "$srcdir/$pkgname-$pkgver/lib/spandsp/COPYING" \
 		"$pkgdir"/usr/share/licenses/$pkgname/libspandsp.COPYING
 
_at_@ -51,5 +70,16 @@ build() {
 
 }
 
+
 md5sums="f8b26cfeed188e5c1dcbc5ae5ef923b3  iaxmodem-1.2.0.tar.gz
-28513788ba4d556ccd538867dc6205ab  nocxx.patch"
+2d4425db0e1163c598caffb3e9fd5250  iaxmodem.c.patch
+fe1ee78ad3787ceb580c56de4dd7717d  iaxmodem.confd
+ebd0ff874932fc4056d92dfb475bbbe5  iaxmodem.initd"
+sha256sums="fa263c0df0870cb8133c4bee141146ca5db47ece6db50899a6acf508d76591ed  iaxmodem-1.2.0.tar.gz
+943f6738656bcde9a734e984e4de9d413a8a89c5d03195f863365e4fe814a0ec  iaxmodem.c.patch
+31c8dc226eaddd8b9bfc8c233178b1b192edc951f125dc3f3b064fac2c472ec7  iaxmodem.confd
+e9f8dd4767f4697f1d378c3de3fe9138e478939ee94e6cf102581cd87f50600b  iaxmodem.initd"
+sha512sums="53b66a0977366541ffaa743fcbefa11c20eb9ea7182245a1d11bc7fd015d98a4ec8086b3cb85b8de84f63d67221bccb1a868fe9f0a603de600023ea158909707  iaxmodem-1.2.0.tar.gz
+562b7c749daf48868fb2e324e1671d73ba023b52b29c7d710c5ebeb05e94f08ea8bada5cd19da1e16a8ded04bf1c29ecb6ce15c68c649eded7afff0424ae6e3b  iaxmodem.c.patch
+daf187f639c0342c27ff95f73077e994d772231f7a0ea562bcffbad76511f9fc63f5447aa8b620e7e6c9c007a0c4535a7215016cf489959c6c2151867c289eba  iaxmodem.confd
+22093cb5472740c4fd3eeefc36f12f42e2bafa4c2f9d03ba37aaec19f43dba18263863da8487e92af382affd10143eb0f976f19c62502f6159b93de944ec83e3  iaxmodem.initd"
diff --git a/main/iaxmodem/iaxmodem.c.patch b/main/iaxmodem/iaxmodem.c.patch
new file mode 100644
index 0000000..d078e02
--- /dev/null
+++ b/main/iaxmodem/iaxmodem.c.patch
_at_@ -0,0 +1,126 @@
+--- iaxmodem-1.2.0/iaxmodem.c
++++ iaxmodem-1.2.0_new/iaxmodem.c
+_at_@ -1691,40 +1691,77 @@
+     reload_modems();
+ }
+ 
++void help_about()
++{
++	printf("Usage: iaxmodem [options] [configfile]\n\
++\n\
++Valid options are:\n\
++  -h|-H                print this help information\n\
++  -V                   display iaxmodem version\n\
++  -F                   prevent parent process from detaching itself from the controlling tty\n\
++  -P <pid-file>        pid file to be used\n\
++\n\
++Version: iaxmodem-%s / %s / %s\n", MODEMVER, DSPVER, IAXVER);
++	_exit(-1);
++}
++
+ int
+ main(int argc, char** argv)
+ {
+     int ret;
+     char config[256];
+     int isdaemon = 1;
++    int foundconfig = 0;
+     int fd;
+     FILE *pidfile;
++    char *pfile = "/var/run/iaxmodem.pid";
+ 
++	int c, prev_ind;
++	while(prev_ind = optind, (c =  getopt(argc, argv, ":VFhHP:")) != EOF) {
++		if ( optind == prev_ind + 2 && *optarg == '-' ) {
++			c = ':';
++			-- optind;
++		}
++		switch (c) {
++			case 'h':
++			case 'H':
++				help_about();
++				break;
++			case 'V':
++				printf("Version: iaxmodem-%s / %s / %s\n", MODEMVER, DSPVER, IAXVER);
++				_exit(0);
++				break;
++			case 'F':
++				isdaemon = 0;
++				break;
++			case 'P':
++				pfile = optarg;
++				break;
++			case ':':
++				printlog(LOG_ERROR, "Invalid usage of options\n");
++				help_about();
++				_exit(1);
++				break;
++			default:
++				help_about();
++				break;
++		}
++	}
++
++	/* Set config file to be the last argument unless it contains the '-' sign (preventing a option to be used as a config name) */
++	if ((argc > 1) && (!strstr(argv[argc-1], "-" )) && (!strstr(argv[argc-2], "-P" ))) {
++		snprintf(config, sizeof(config), "%s", argc[argv-1]);
++		foundconfig = 1;
++	}
++
+     if (geteuid() != 0) {
+       printlog(LOG_ERROR, "Error: run iaxmodem as root\n");
+       _exit(-1);
+     }
+ 
+-    if (argc == 2 && strncmp(argv[1], "-V", 2) == 0) {
+-	printf("%s\n%s\n%s\n", MODEMVER, DSPVER, IAXVER);
+-	_exit(0);
+-    }
++    if (foundconfig)
++	iaxmodem(config, 1);
+ 
+-    /* If a config is specified, behave in non-daemon mode */
+-    if (argc == 2) {
+-
+-	snprintf(config, sizeof(config), "%s", argv[1]);
+-
+-	if (!strncmp(config, "-F", 2)) {
+-
+-		isdaemon = 0;
+-
+-	} else {
+-      
+-		iaxmodem(config, 1);
+-	}
+-    }
+-
+     /* 
+      * iaxmodem() never returns, so the code below won't be reached if
+      * a config file is specified on the command line
+_at_@ -1737,7 +1774,7 @@
+     }
+ 
+     /* Write pid to pidfile */
+-    pidfile = fopen("/var/run/iaxmodem.pid", "w");
++    pidfile = fopen(pfile, "w");
+     if (pidfile == NULL) {
+       printlog(LOG_ERROR, "Fatal error: could not open pidfile /var/run/iaxmodem.pid: %s\n", strerror(errno));
+       exit(-1);
+_at_@ -1770,7 +1807,7 @@
+     checklog("/var/log/iaxmodem/iaxmodem");
+     fd = open("/var/log/iaxmodem/iaxmodem", O_WRONLY | O_APPEND | O_CREAT | O_LARGEFILE, logmode);
+     if (fd < 0) {
+-      printlog(LOG_ERROR, "Error: could not open /var/log/iaxmodem/iaxmodem: %s\n", strerror(errno));
++      printlog(LOG_ERROR, "Fatal error: could not open pidfile %s: %s\n", pfile, strerror(errno));
+     } else {
+       dup2(fd, STDERR_FILENO);
+     }
+_at_@ -1791,7 +1828,7 @@
+       }
+ 
+     /* Control process only */
+-    unlink("/var/run/iaxmodem.pid");
++    unlink(pfile);
+ 
+     exit(0);
+ }
diff --git a/main/iaxmodem/iaxmodem.confd b/main/iaxmodem/iaxmodem.confd
index 082a920..36217d1 100644
--- a/main/iaxmodem/iaxmodem.confd
+++ b/main/iaxmodem/iaxmodem.confd
_at_@ -5,3 +5,8 @@
 #
 #IAXMODEM_NICE="-5"
 
+# Append various options to iaxmodem daemon.
+# run 'iaxmodem -h' for valid options
+# (Note that -P/pidfile is automatically set by the init.d script and can not be set here.)
+#IAXMODEM_OPTS=""
+
diff --git a/main/iaxmodem/iaxmodem.initd b/main/iaxmodem/iaxmodem.initd
index 7f072e6..89e68d0 100644
--- a/main/iaxmodem/iaxmodem.initd
+++ b/main/iaxmodem/iaxmodem.initd
_at_@ -3,12 +3,10 @@
 # Distributed under the terms of the GNU General Public License v2
 # $Header: /var/www/viewcvs.gentoo.org/raw_cvs/gentoo-x86/net-misc/iaxmodem/files/iaxmodem.initd,v 1.1 2008/10/14 23:53:39 sbriesen Exp $
 
-description="IAXmodem"
-description_reload="Reread configuration file and make the appropriate changes"
-extra_started_commands="reload"
 command="/usr/sbin/iaxmodem"
-pidfile="/var/run/iaxmodem.pid"
+pidfile="/var/run/${SVCNAME}.pid"
 name="iaxmodem"
+child="${SVCNAME#*.}"
 
 depend() {
 	use asterisk
_at_@ -17,15 +15,15 @@ depend() {
 }
 
 start() {
-	ebegin "Starting ${description}"
+	ebegin "Starting ${SVCNAME}"
 	start-stop-daemon --start --quiet --pidfile "${pidfile}" \
-		--env TMPDIR="/tmp" --nice ${IAXMODEM_NICE:-0} --exec "${command}"
+		--env TMPDIR="/tmp" --nice ${IAXMODEM_NICE:-0} --exec "${command}" -- "${IAXMODEM_OPTS} -P ${pidfile}"
 	eend ${?}
 }
 
 stop() {
 	local childs=""
-	ebegin "Stopping ${description}"
+	ebegin "Stopping ${SVCNAME}"
 	# start-stop-daemon doesn't kill childs reliable, so we
 	# use a combination of pgrep + start-stop-daemon + kill
 	[ -s "${pidfile}" ] && childs=$(pgrep -P $(cat "${pidfile}"))
_at_@ -38,7 +36,7 @@ stop() {
 }
 
 reload() {
-	ebegin "Reloading ${description} configuration"
+	ebegin "Reloading ${SVCNAME} configuration"
 	start-stop-daemon --stop --signal HUP --pidfile "${pidfile}"
 	eend ${?}
 }
-- 
1.8.2
---
Unsubscribe:  alpine-devel+unsubscribe_at_lists.alpinelinux.org
Help:         alpine-devel+help_at_lists.alpinelinux.org
---
Received on Mon May 06 2013 - 06:52:55 UTC