summarylogtreecommitdiffstats
path: root/01-debian-patches.all
blob: c7e3363f029420e546450adb78cccc36cafa9c5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
diff -urNp buffer-1.19.orig/buffer.c buffer-1.19/buffer.c
--- buffer-1.19.orig/buffer.c	2000-01-04 03:46:11.000000000 +0100
+++ buffer-1.19/buffer.c	2008-09-20 01:19:18.000000000 +0200
@@ -81,7 +81,7 @@
  * Christoph Wicki <wicki@iis.ethz.ch>
  *
  * Revision 1.7  1992/07/23  20:42:03  lmjm
- * Added 't' option to print total writen at end.
+ * Added 't' option to print total written at end.
  *
  * Revision 1.6  1992/04/07  19:57:30  lmjm
  * Added Kevins -B and -p options.
@@ -96,7 +96,7 @@
  * Make sofar printing size an option.
  * 
  * Revision 1.3  90/05/15  23:27:46  lmjm
- * Added -S option (show how much has been writen).
+ * Added -S option (show how much has been written).
  * Added -m option to specify how much shared memory to grab.
  * Now tries to fill this with blocks.
  * reader waits for writer to terminate and then frees the shared mem and sems.
@@ -112,11 +112,15 @@
  * Initial revision
  * 
  */
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <signal.h>
 #include <fcntl.h>
 #include <errno.h>
+#include <sys/time.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/ipc.h>
@@ -139,6 +143,14 @@
 #define K *1024
 #define M *1024*1024
 
+#if defined __GNUC__ || __STDC_VERSION__ >= 199901L
+#define NUM_K_TYPE unsigned long long
+#define NUM_K_FMT "llu"
+#else
+#define NUM_K_TYPE unsigned long
+#define NUM_K_FMT "lu"
+#endif
+
 /* Some forward declarations */
 void byee();
 void start_reader_and_writer();
@@ -162,7 +174,7 @@ void write_block_to_stdout();
 void pr_out();
 void end_writer();
 
-/* When showing print a note every this many bytes writen */
+/* When showing print a note every this many bytes written */
 int showevery = 0;
 #define PRINT_EVERY 10 K
 
@@ -253,7 +265,9 @@ char *progname = "buffer";
 
 char print_total = 0;
 /* Number of K output */
-unsigned long outk = 0;
+NUM_K_TYPE outk = 0;
+
+struct timeval starttime;
 
 int
 main( argc, argv )
@@ -265,6 +279,8 @@ main( argc, argv )
 	set_handlers();
 
 	buffer_allocate();
+	
+	gettimeofday(&starttime, NULL);
 
 	start_reader_and_writer();
 
@@ -290,7 +306,7 @@ parse_args( argc, argv )
 
 	while( (c = getopt( argc, argv, "BS:Zdm:s:b:p:u:ti:o:z:" )) != -1 ){
 		switch( c ){
-		case 't': /* Print to stderr the total no of bytes writen */
+		case 't': /* Print to stderr the total no of bytes written */
 			print_total++;
 			break;
 		case 'u': /* pause after write for given microseconds */
@@ -387,8 +403,8 @@ parse_args( argc, argv )
 			fprintf( stderr, "Usage: %s [-B] [-t] [-S size] [-m memsize] [-b blocks] [-p percent] [-s blocksize] [-u pause] [-i infile] [-o outfile] [-z size]\n",
 				progname );
 			fprintf( stderr, "-B = blocked device - pad out last block\n" );
-			fprintf( stderr, "-t = show total amount writen at end\n" );
-			fprintf( stderr, "-S size = show amount writen every size bytes\n" );
+			fprintf( stderr, "-t = show total amount written at end\n" );
+			fprintf( stderr, "-S size = show amount written every size bytes\n" );
 			fprintf( stderr, "-m size = size of shared mem chunk to grab\n" );
 			fprintf( stderr, "-b num = number of blocks in queue\n" );
 			fprintf( stderr, "-p percent = don't start writing until percent blocks filled\n" );
@@ -400,6 +416,11 @@ parse_args( argc, argv )
 			byee( -1 );
 		}
 	}
+	
+	if (argc > optind) {
+		fprintf( stderr, "too many arguments\n" );
+		byee( -1 );
+	}
 
 	if (zflag) showevery = blocksize;
 
@@ -510,9 +531,9 @@ buffer_allocate()
 	get_buffer();
 
 	if( debug )
-		fprintf( stderr, "%s pbuffer is 0x%08x, buffer_size is %d [%d x %d]\n",
+		fprintf( stderr, "%s pbuffer is 0x%08lx, buffer_size is %d [%d x %d]\n",
 			proc_string,
-			(char *)pbuffer, buffer_size, blocks, blocksize );
+			(unsigned long)pbuffer, buffer_size, blocks, blocksize );
 
 #ifdef SYS5
 	memset( (char *)pbuffer, '\0', buffer_size );
@@ -531,7 +552,17 @@ buffer_allocate()
 	pbuffer->blocks_free_lock = 1;
 	/* start this off so lock() can be called on it for each block
 	 * till all the blocks are used up */
+	/* Initializing the semaphore to "blocks - 1" causes a hang when using option
+	 * "-p 100" because it always keeps one block free, so we'll never reach 100% fill
+	 * level. However, there doesn't seem to be a good reason to keep one block free,
+	 * so we initialize the semaphore to "blocks" instead.
+	 * <mbuck@debian.org> 2004-01-11
+	 */	
+#if 0
 	sem_set( pbuffer->semid, pbuffer->blocks_free_lock, blocks - 1 );
+#else
+	sem_set( pbuffer->semid, pbuffer->blocks_free_lock, blocks );
+#endif
 
 	/* Detattach the shared memory so the fork doesnt do anything odd */
 	shmdt( (char *)pbuffer );
@@ -651,7 +682,7 @@ get_next_free_block()
 int
 fill_block()
 {
-	int bytes;
+	int bytes = 0;
 	char *start;
 	int toread;
 	static char eof_reached = 0;
@@ -710,7 +741,7 @@ writer()
 {
 	int filled = 0;
 	int maxfilled = (blocks * percent) / 100;
-	int first_block;
+	int first_block = 0;
 
 	if( debug )
 		fprintf( stderr, "\tW: Entering writer\n blocks = %d\n maxfilled = %d\n",
@@ -745,7 +776,7 @@ writer()
 	}
 
 	if( print_total ){
-		fprintf( stderr, "Kilobytes Out %lu\n", outk );
+		fprintf( stderr, "Kilobytes Out %" NUM_K_FMT "\n", outk );
 	}
 
 	if( debug )
@@ -786,14 +817,14 @@ write_blocks_to_stdout( filled, first_bl
 void
 write_block_to_stdout()
 {
-	static unsigned long out = 0;
+	unsigned long out = 0;
 	static unsigned long last_gb = 0;
-	static unsigned long next_k = 0;
+	static NUM_K_TYPE next_k = 0;
 	int written;
 
 	if( next_k == 0 && showevery ){
 		if( debug > 3 )
-			fprintf( stderr, "W: next_k = %lu showevery = %d\n", next_k, showevery );
+			fprintf( stderr, "W: next_k = %" NUM_K_FMT " showevery = %d\n", next_k, showevery );
 		showevery = showevery / 1024;
 		next_k = showevery;
 	}
@@ -801,7 +832,7 @@ write_block_to_stdout()
 	if( (written = write( fdout, curr_block->data, curr_block->bytes )) != curr_block->bytes ){
 		report_proc();
 		perror( "write of data failed" );
-		fprintf( stderr, "bytes to write=%d, bytes written=%d, total written %10luK\n", curr_block->bytes, written, outk );
+		fprintf( stderr, "bytes to write=%d, bytes written=%d, total written %10" NUM_K_FMT "K\n", curr_block->bytes, written, outk );
 		byee( -1 );
 	}
 
@@ -828,7 +859,7 @@ write_block_to_stdout()
 	}
 	if( showevery ){
 		if( debug > 3 )
-			fprintf( stderr, "W: outk = %lu, next_k = %lu\n",
+			fprintf( stderr, "W: outk = %" NUM_K_FMT ", next_k = %" NUM_K_FMT "\n",
 				outk, next_k );
 		if( outk >= next_k ){
 			pr_out();
@@ -917,13 +948,12 @@ int
 do_size( arg )
 	char *arg;
 {
-	char format[ 20 ];
-	int ret;
+	int ret = 0;
 
-	*format = '\0';
-	sscanf( arg, "%d%s", &ret, format );
+	char unit = '\0';
+	sscanf( arg, "%d%c", &ret, &unit );
 
-	switch( *format ){
+	switch( unit ){
 	case 'm':
 	case 'M':
 		ret = ret K K;
@@ -944,7 +974,36 @@ do_size( arg )
 void
 pr_out()
 {
-	fprintf( stderr, " %10luK\r", outk );
+	struct timeval now;
+	unsigned long ms_delta, k_per_s;
+	
+	gettimeofday(&now, NULL);
+	ms_delta = (now.tv_sec - starttime.tv_sec) * 1000
+		   + (now.tv_usec - starttime.tv_usec) / 1000;
+	if (ms_delta) {
+		/* Use increased accuracy for small amounts of data,
+		 * decreased accuracy for *huge* throughputs > 4.1GB/s
+		 * to avoid division by 0. This will overflow if your
+		 * machine's throughput exceeds 4TB/s - you deserve to
+		 * loose if you're still using 32 bit longs on such a
+		 * beast ;-)
+		 * <mbuck@debian.org>
+		 */
+		if (outk < ULONG_MAX / 1000) {
+			k_per_s = (outk * 1000) / ms_delta;
+		} else if (ms_delta >= 1000) {
+			k_per_s = outk / (ms_delta / 1000);
+		} else {
+			k_per_s = (outk / ms_delta) * 1000;
+		}
+		fprintf( stderr, " %10" NUM_K_FMT "K, %10luK/s\r", outk, k_per_s );
+	} else {
+		if (outk) {
+			fprintf( stderr, " %10" NUM_K_FMT "K,          ?K/s\r", outk );
+		} else {
+			fprintf( stderr, "          0K,          0K/s\r");
+		}
+	}
 }
 
 #ifdef SYS5
diff -urNp buffer-1.19.orig/buffer.man buffer-1.19/buffer.man
--- buffer-1.19.orig/buffer.man	2000-01-04 03:44:32.000000000 +0100
+++ buffer-1.19/buffer.man	2008-09-20 01:18:48.000000000 +0200
@@ -37,7 +37,8 @@ Use the given file as the input file.  T
 Use the given file as the output file.  The default is stdout.
 .TP
 .B \-S size
-After every chunk this size has been writen print out how much been writen so far.
+After every chunk of this size has been written, print out how much has
+been written so far. Also prints the total througput.
 By default this is not set.
 .TP
 .B \-s size
@@ -71,9 +72,9 @@ After every write pause for this many mi
 throughput on some drives.)
 .TP
 .B \-B
-Force each block writen to be padded out to the blocksize.  This is needed by some tape
+Force each block written to be padded out to the blocksize.  This is needed by some tape
 and cartridge drives.  Defaults to unpadded.  This only affects the
-last block writen.
+last block written.
 .TP
 .B \-t
 On exiting print to stderr a brief message showing the total number of
@@ -82,7 +83,7 @@ bytes written.
 .B \-Z
 If reading/writing directly to a character device (like a tape drive)
 then after each gigabyte perform an lseek to the start of the file.
-Use this flag with extreme care.  If can only be used on devices where
+Use this flag with extreme care.  It can only be used on devices where
 an lseek does not rewind the tape but does reset the kernels position
 flags.  It is used to allow more than 2 gigabytes to be written.
 .PP
diff -urNp buffer-1.19.orig/debian/changelog buffer-1.19/debian/changelog
--- buffer-1.19.orig/debian/changelog	1970-01-01 01:00:00.000000000 +0100
+++ buffer-1.19/debian/changelog	2008-09-20 01:18:48.000000000 +0200
@@ -0,0 +1,98 @@
+buffer (1.19-7) unstable; urgency=low
+
+  * Really changed priority this time. Sigh.
+
+ -- Martin Buck <mbuck@debian.org>  Sat,  1 Jan 2005 23:46:26 +0100
+
+buffer (1.19-6) unstable; urgency=low
+
+  * Changed priority to optional. Closes: #283803
+
+ -- Martin Buck <mbuck@debian.org>  Thu, 30 Dec 2004 15:04:31 +0100
+
+buffer (1.19-5) unstable; urgency=low
+
+  * Disabled obsolete declaration of shmat(). Closes: #260395
+
+ -- Martin Buck <mbuck@debian.org>  Tue, 27 Jul 2004 23:50:50 +0200
+
+buffer (1.19-4) unstable; urgency=low
+
+  * Fixed hang when using option "-p 100". Closes: #224984
+
+ -- Martin Buck <mbuck@debian.org>  Sun, 11 Jan 2004 23:20:39 +0100
+
+buffer (1.19-3) unstable; urgency=low
+
+  * Added largefile support. Closes: #156847
+  * Made sure -S/-z works properly with files > 4 TB.
+  * Upgraded to Standards-Version 3.5.8
+
+ -- Martin Buck <mbuck@debian.org>  Fri, 31 Jan 2003 23:55:43 +0100
+
+buffer (1.19-2) unstable; urgency=low
+
+  * Fixed buffer overrun in option parsing.
+    Fixed (rather theoretical) potential division by zero in
+    throughput calculation.
+    Closes: #123543
+
+ -- Martin Buck <mbuck@debian.org>  Tue, 11 Dec 2001 23:34:46 +0100
+
+buffer (1.19-1) unstable; urgency=low
+
+  * New upstream version. Closes: #91961
+  * Added a few spelling fixes from FreeBSD version 1.17.1
+  * Added (slightly modified version of) patch from Marc Schaefer that prints
+    the throughput with option -S
+  * Fixed a few gcc warnings
+
+ -- Martin Buck <mbuck@debian.org>  Thu,  5 Apr 2001 22:10:07 +0200
+
+buffer (1.17-6) unstable; urgency=low
+
+  * Added Build-Depends. Closes: #70332
+
+ -- Martin Buck <mbuck@debian.org>  Mon,  5 Mar 2001 22:19:09 +0100
+
+buffer (1.17-5) unstable; urgency=low
+
+  * Cleaned up debian/rules
+  * Upgraded to Debian policy 3.0.1.1
+
+ -- Martin Buck <mbuck@debian.org>  Mon, 13 Sep 1999 23:19:57 +0200
+
+buffer (1.17-4) unstable; urgency=low
+
+  * buffer now complains if non-option arguments are found
+  * Document changes from original version in copyright-file
+  * Checked conformance with Debian policy 2.5.0
+
+ -- Martin Buck <mbuck@debian.org>  Sun, 29 Aug 1999 00:57:03 +0200
+
+buffer (1.17-3) unstable; urgency=low
+
+  * NMU;  added missing SEM_SEMUN_UNDEFINED 
+  * closes: #31931
+  * fixes: #31920
+
+ -- Hartmut Koptein <koptein@debian.org>  Fri,  9 Jul 1999 10:04:49 +0200
+
+buffer (1.17-2) unstable; urgency=low
+
+  * Applied patch from Paul Slootman (closes: Bug#26098):
+    - egcs complains about NULL where union expected. Now it builds on Alpha.
+    - typos in manpage fixed.
+  * Switched from debstd to debhelper
+
+ -- Martin Buck <mbuck@debian.org>  Wed,  9 Sep 1998 22:35:29 +0200
+
+buffer (1.17-1) unstable; urgency=low
+
+  * Initial Release.
+
+ -- Martin Buck <mbuck@debian.org>  Wed, 27 Aug 1997 01:11:29 +0200
+
+Local variables:
+mode: debian-changelog
+End:
diff -urNp buffer-1.19.orig/debian/control buffer-1.19/debian/control
--- buffer-1.19.orig/debian/control	1970-01-01 01:00:00.000000000 +0100
+++ buffer-1.19/debian/control	2008-09-20 01:18:48.000000000 +0200
@@ -0,0 +1,19 @@
+Source: buffer
+Section: utils
+Priority: optional
+Maintainer: Martin Buck <mbuck@debian.org>
+Standards-Version: 3.5.8
+Build-Depends: debhelper (>= 4)
+
+Package: buffer
+Architecture: any
+Depends: ${shlibs:Depends}
+Description: Buffering/reblocking program for tape backups, printing, etc.
+ Buffer implements double buffering and can be used to keep backup tapes
+ streaming or printers printing. It can also be used to convert a data
+ stream to a given output blocksize.
+ .
+ Buffer uses shared memory to convert a variable input data rate to a
+ constant output data rate. It is typically used in a pipe between a backup
+ program and the tape device, but there are also other applications like
+ buffering printer data in lpd's input filter.
diff -urNp buffer-1.19.orig/debian/copyright buffer-1.19/debian/copyright
--- buffer-1.19.orig/debian/copyright	1970-01-01 01:00:00.000000000 +0100
+++ buffer-1.19/debian/copyright	2008-09-20 01:18:48.000000000 +0200
@@ -0,0 +1,11 @@
+This package was debianized by Martin Buck mbuck@debian.org on
+Wed, 27 Aug 1997 01:11:29 +0200.
+
+It was downloaded from
+http://sunsite.org.uk/public/public/packages/buffer/
+
+Copyright:
+GPL (see /usr/share/common-licenses/GPL)
+In addtion under NO circumstances can I (Lee McLoughlin), or Imperial
+College, be held liable for any event caused by the running or storing of
+this program or its documentation.
diff -urNp buffer-1.19.orig/debian/rules buffer-1.19/debian/rules
--- buffer-1.19.orig/debian/rules	1970-01-01 01:00:00.000000000 +0100
+++ buffer-1.19/debian/rules	2008-09-20 01:18:48.000000000 +0200
@@ -0,0 +1,64 @@
+#!/usr/bin/make -f
+
+export DH_COMPAT = 4
+
+CFLAGS = -g -Wall -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
+
+ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
+  CFLAGS += -O0
+else
+  CFLAGS += -O2
+endif
+
+
+build: build-stamp
+build-stamp:
+	dh_testdir
+
+	make CFLAGS="$(CFLAGS)"
+
+	touch build-stamp
+
+clean:
+	dh_testdir
+	dh_testroot
+	-rm -f build-stamp install-stamp
+	-make clean
+	dh_clean
+
+install: install-stamp
+install-stamp: build-stamp
+	dh_testdir
+	dh_testroot
+	dh_clean -k
+	dh_installdirs usr/bin usr/share/man/man1
+	make install INSTBIN=debian/buffer/usr/bin INSTMAN=debian/buffer/usr/share/man/man1 S=1
+	touch install-stamp
+	
+binary-indep: build install
+
+binary-arch: build install
+	dh_testdir
+	dh_testroot
+	dh_installdocs README
+#	dh_installexamples
+#	dh_installmenu
+#	dh_installemacsen
+#	dh_installinit
+#	dh_installcron
+#	dh_installman
+#	dh_undocumented
+	dh_installchangelogs
+	dh_strip
+	dh_compress
+	dh_fixperms
+#	dh_suidregister
+	dh_installdeb
+	dh_shlibdeps
+	dh_gencontrol
+#	dh_makeshlibs
+	dh_md5sums
+	dh_builddeb
+
+binary: binary-indep binary-arch
+.PHONY: build clean binary-indep binary-arch binary install
diff -urNp buffer-1.19.orig/sem.c buffer-1.19/sem.c
--- buffer-1.19.orig/sem.c	2000-01-04 03:49:12.000000000 +0100
+++ buffer-1.19/sem.c	2008-09-20 01:18:48.000000000 +0200
@@ -27,6 +27,7 @@
  * semaphores */
 
 #include <stdio.h>
+#include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/ipc.h>
@@ -103,7 +119,7 @@ new_sems( nsems )
 	return sem;
 }
 
-static
+static void
 do_sem( sem_id, pbuf, err )
 	int sem_id;
 	struct sembuf *pbuf;
@@ -157,10 +173,13 @@ void
 remove_sems( sem_id )
 	int sem_id;
 {
+	union semun arg;
+
 	if( sem_id == -1 )
 		return;
 
-	if( semctl( sem_id, 0, IPC_RMID, NULL ) == -1 ){
+	arg.val = 0;
+	if( semctl( sem_id, 0, IPC_RMID, arg ) == -1 ){
 		report_proc();
 		perror( "internal error, failed to remove semaphore" );
 	}