Debian Codegraph @

src/autoconf

raw symbols ◀ ▶
Source reconstructed at patch state 4 of 6 — not the installed (fully patched) source.
6 Debian patches touch this file
1 #! /bin/sh
2 :
3 # Copyright (c) 1990-1997, S.R. van den Berg, The Netherlands
4 #$Id: autoconf,v 1.136 2001/08/10 18:52:30 guenther Exp $
5
6 # All possible entries in autoconf.h:
7
8 # #define UNISTD_H_MISSING
9 # #define STDDEF_H_MISSING
10 # #define STDLIB_H_MISSING
11 # #define DIRENT_H_MISSING
12 # #define SYS_DIRENT_H_MISSING
13 # #define NDIR_H_MISSING
14 # #define SYS_NDIR_H_MISSING
15 # #define SYS_DIR_H_MISSING
16 # #define SYS_WAIT_H_MISSING
17 # #define SYS_UTSNAME_H_MISSING
18 # #define STRING_H_MISSING
19 # #define SYSEXITS_H_MISSING
20 #Ok #define SYS_FILE_H_MISSING
21 #Ok #define SYSLOG_H_MISSING
22 # #define MATH_H_MISSING
23 # #define LIMITS_H_MISSING
24 # #define NO_const
25 # #define volatile
26 # #define P(args) ()
27 # #define NO_enum
28 # #define void char
29 # typedef int mode_t;
30 # typedef int pid_t;
31 # typedef int uid_t;
32 # typedef int gid_t;
33 # typedef unsigned size_t;
34 # typedef long off_t;
35 # typedef long time_t;
36 # #define NOmemmove
37 #Ok #define NObcopy
38 # #define NOstrcspn
39 # #define NOstrpbrk
40 # #define NOopendir
41 # #define NOrename
42 # #define NOsetrgid
43 # #define NOsetegid
44 # #define NOsetregid
45 # #define NOsetresgid
46 # #define setrgid_BRAIN_DAMAGE
47 # #define setrgid_RUNTIME_CHECK
48 #Ok #define TOGGLE_SGID_OK
49 # #define NOpow
50 # #define NOmkdir
51 # #define NOfstat
52 # #define NOuname
53 # #define NO_exit
54 # #define NOstrtol
55 # #define NOstrtod
56 # #define NOstrerror
57 #Ok #define NOstrlcat
58 #Ok #define NOstrncasecmp
59 #Ok #define NOsys_errlist
60 #Ok #define NObzero
61 # #define NOmemset
62 # #define NOwaitpid
63 #Ok #define NOftruncate
64 # #define SLOWstrstr
65 #Ok #define CAN_chown
66 # #define strchr(s,c) index(s,c)
67 # #define NOinitgroups
68 # #define NOfsync
69 #Ok #define endpwent()
70 #Ok #define endgrent()
71 #Ok #define endhostent()
72 #Ok #define endservent()
73 #Ok #define endprotoent()
74 # #define h_0addr_list h_addr
75 #Ok #define NOpw_passwd
76 #Ok #define NOpw_class
77 #Ok #define NOpw_gecos
78 #Ok #define NO_COMSAT
79 # #define _GUID_T
80 #Ok #define UDP_protocolno 17
81 #Ok #define BIFF_serviceport "512"
82 #Ok #define IP_localhost {127,0,0,1}
83 # #define WMACROS_NON_POSIX
84 # #define oBRAIN_DAMAGE
85 #Ok #define GOT_bin_test
86 #Ok #define MAX_argc 128
87 #Ok #define MAX_envc 128
88 #Ok #define SMALLHEAP
89 # #define NOfcntl_lock
90 #Ok #define USElockf
91 #Ok #define USEflock
92 #Ok #define MAILSPOOLDIR "/var/mail/"
93 #Ok #define SENDMAIL "/usr/sbin/sendmail"
94 # #define buggy_SENDMAIL
95 # #define DEFflagsendmail ""
96 #Ok #define CF_no_procmail_yet
97 #Ok #define defSPATH "PATH=/bin:/usr/bin:/usr/local/bin"
98 #Ok #define defPATH "PATH=$HOME/bin:/bin:/usr/bin:/usr/local/bin"
99 #Ok #define INEFFICIENTrealloc
100 #Ok #define PM_VERSION "n.nn"
101
102 # A conforming ISO C compiler and POSIX library should not have any defines
103 # not marked as "Ok" in the autoconf.h file.
104 # Anything else indicates failure of your system to comply with either
105 # the ISO or POSIX standards (but procmail should be installable anyway).
106
107 if test -z "$IFS"
108 then IFS=" \
109 \
110
111 "
112 export IFS
113 fi
114
115 SHELL=$1
116 PATH=.:$PATH
117 shift; RM="$1"
118 shift; MV="$1"
119 shift; DEVNULL=$1
120 shift; FGREP="$1"
121 shift; MAKE="$1"
122 shift; O=$1
123 shift; LOCKINGTEST="$1"
124 shift; BINDIR=$1
125 shift; ACONF=$1
126
127 test 1 != $# &&
128 echo "Don't start this script directly, use \`make ../autoconf.h'" && exit 1
129
130 if test -f make_n
131 then
132 $RM make_n
133 else
134 # We were mistakenly invoked under "make -n", so pretend this didn't happen.
135 exit 0
136 fi
137
138 export SHELL PATH
139
140 test "X$LOCKINGTEST" = X__defaults__ && LOCKINGTEST=""
141
142 OLDTESTDIRS=""
143 tailpid=""
144 echo "" >_locktst.pid
145
146 if test -f $ACONF
147 then
148 if $FGREP -e "/* autoconf completed */" $ACONF >$DEVNULL
149 then
150 cat <<HERE
151 ==============================================================================
152 Would you like to skip running autoconf and use the existing autoconf.h file?
153 When in doubt, press return [n]:
154 HERE
155 read a
156 case "$a"n in
157 [yY]*) touch $ACONF; exit 0;;
158 esac
159 fi
160 trap "kill \`cat _locktst.pid\` 2>$DEVNULL;cp $ACONF $ACONF.tmp
161 test ! -z \"\$OLDTESTDIRS\" && $RM -r \$OLDTESTDIRS \$OLDTESTDIRS 2>$DEVNULL
162 test ! -z \"\$tailpid\" && kill \$tailpid 2>$DEVNULL
163 kill \`cat _locktst.pid\` 2>$DEVNULL; exit 1" 1 2 3 13 15
164 else
165 trap "kill \`cat _locktst.pid\` 2>$DEVNULL;$RM -r $ACONF.tmp
166 test ! -z \"\$OLDTESTDIRS\" && $RM -r \$OLDTESTDIRS \$OLDTESTDIRS 2>$DEVNULL
167 mv $ACONF $ACONF.tmp 2>$DEVNULL
168 test ! -z \"\$tailpid\" && kill \$tailpid 2>$DEVNULL
169 kill \`cat _locktst.pid\` 2>$DEVNULL; exit 1" 1 2 3 13 15
170 fi
171
172 nocore=yes
173 set dummy *core*
174 test -f $2 && nocore=no
175
176 set dummy $LOCKINGTEST
177 shift
178 LOCKINGTEST="$*"
179
180 test ! -z "$LOCKINGTEST" && exec 9>&1 1>$DEVNULL # make it shut up
181
182 cat <<HERE
183 ==============================================================================
184 In order for the kernel-locking tests to work as intended I have to be able to
185 test-lock files on as many semantically different filesystems as possible (for
186 more information about this, READ PARAGRAPH TWO in INSTALL). To suppress this
187 prompt you can set the LOCKINGTEST variable in the Makefile.
188 
189 Please add writable directories to the list. You should only add directories
190 that reside on filesystems that have unique characteristics. E.g. if you have
191 several remote NFS partitions, pick some unique client-server pairs, there is
192 little use in picking the same server twice from the same client-machine.
193 An excellent candidate would be a remotely mounted mail spool directory.
194 ==============================================================================
195 HERE
196
197 testdirs="/tmp ."
198
199 case "$LOCKINGTEST" in
200 ""|*[a-zA-Z/]*) b=dummy ;;
201 *) b=""; testdirs=$LOCKINGTEST; LOCKINGTEST=dummy ;;
202 esac
203
204 while test ! -z "$b"
205 do
206 echo ""
207 b=""
208 OLDTESTDIRS="$TESTDIRS"
209 TESTDIRS=""
210 for a in $testdirs
211 do $RM -r $a/_locktest
212 if mkdir $a/_locktest 2>$DEVNULL
213 then
214 b="$b $a"
215 TESTDIRS="$TESTDIRS $a/_locktest"
216 else
217 echo 2>&1 "Can't create $a/_locktest"
218 fi
219 done
220 OLDTESTDIRS="$TESTDIRS"
221 testdirs="$b"
222 echo ""
223 echo "I will temporarily use a testdirectory named _locktest"
224 echo "in the following directories:"
225 echo ""
226 echo $testdirs
227 echo ""
228 echo "If you would like to add any, please specify them below,"
229 echo "press return to continue:"
230 echo ""
231 if test -z "$LOCKINGTEST"
232 then
233 read b
234 elif test dummy = "$LOCKINGTEST"
235 then
236 b=""
237 else
238 testdirs=""; b="$LOCKINGTEST"; LOCKINGTEST=dummy
239 echo $b
240 fi
241 testdirs="$testdirs $b"
242 done
243
244 if test dummy = "$LOCKINGTEST"
245 then
246 exec 1>&9 9>&- # you can speak again
247 echo "Using the following directories for the LOCKINGTESTs:"
248 echo " $testdirs"
249 fi
250
251 cat >grepfor <<HERE
252 $FGREP -e "\$1" _autotst.rrr >$DEVNULL && echo "\$2" >>$ACONF
253 HERE
254 chmod 0755 grepfor
255
256 cat >$ACONF <<HERE
257 /* This file was automagically generated by autoconf */
258
259 HERE
260
261 echo >_locktst.h
262
263 $RM _autotst.$O
264
265 cat >_autotst.c <<HERE
266 #include "$ACONF"
267 #include <sys/types.h>
268 #include <time.h>
269 void*vvoid;
270 int main(){int i=0;char*p="t";
271 vvoid=p;
272 {time_t vtime;i+=vtime=1;}
273 {off_t voff;i+=voff=1;}
274 return !vvoid+!i;}
275 #include <unistd.h>
276 int empty()
277 { return setsid();
278 }
279 HERE
280
281 if $MAKE _autotst.$O 2>&1 | $FGREP -v include/ >_autotst.rrr
282 test -f _autotst.$O
283 then
284 $MAKE _autotst >$DEVNULL 2>&1 || echo "#define setsid()" >>_locktst.h
285 else
286 grepfor void '#define void char'
287 grepfor time_t 'typedef long time_t;'
288 grepfor off_t 'typedef long off_t;'
289 if $MAKE _autotst.$O >$DEVNULL 2>&1
290 then
291 $MAKE _autotst >$DEVNULL 2>&1 || echo "#define setsid()" >>_locktst.h
292 else
293 echo "#define UNISTD_H_MISSING" >>$ACONF
294 echo "#define setsid()" >>_locktst.h
295 fi
296 fi
297
298 $RM _autotst.$O _autotst
299
300 cat >_autotst.c <<HERE
301 #include "$ACONF"
302 #include <sys/types.h>
303 #ifndef UNISTD_H_MISSING
304 #include <unistd.h>
305 #endif
306 #include <fcntl.h>
307 #ifndef SYS_FILE_H_MISSING
308 #include <sys/file.h>
309 #endif
310 int main(){
311 #ifdef F_SETLKW
312 fcntl(0,F_SETLKW,0);
313 #endif
314 #ifdef F_LOCK
315 lockf(0,F_LOCK,(off_t)0);
316 #endif
317 #ifdef LOCK_EX
318 flock(0,LOCK_EX);
319 #endif
320 return 0;}
321 HERE
322
323 echo 'Initiating fcntl()/kernel-locking-support tests'
324 if $MAKE _autotst.$O >$DEVNULL 2>&1
325 then
326 :
327 else
328 $RM _autotst.$O
329 echo "#define SYS_FILE_H_MISSING" >>$ACONF
330 if $MAKE _autotst.$O >_autotst.rrr 2>&1
331 then
332 :
333 else
334 echo 2>&1 "Whoeaaa! There's something fishy going on here."
335 echo 2>&1 "You have a look and see if you detect anything uncanny:"
336 echo 2>&1 "*******************************************************"
337 cat 2>&1 _autotst.rrr
338 echo 2>&1 "*******************************************************"
339 echo 2>&1 "I suggest you take a look at the definition of CFLAGS* and CC"
340 echo 2>&1 "in the Makefile before you try make again."
341 kill -15 $$
342 fi
343 fi
344 $MAKE _autotst >_autotst.rrr 2>&1
345 $RM _autotst.$O _autotst
346
347 $FGREP fcntl _autotst.rrr >$DEVNULL && echo "#undef F_SETLKW" >>_locktst.h
348 $FGREP lockf _autotst.rrr >$DEVNULL && echo "#undef F_LOCK" >>_locktst.h
349 $FGREP flock _autotst.rrr >$DEVNULL && cat >>_locktst.h <<HERE
350 #ifdef LOCK_EX
351 #undef LOCK_EX
352 #endif
353 #ifndef SYS_FILE_H_MISSING
354 #define SYS_FILE_H_MISSING
355 #endif
356 HERE
357
358 cat >_autotst.c <<HERE
359 #include "$ACONF"
360 #include "../config.h"
361 #include <sys/types.h>
362 #ifndef UNISTD_H_MISSING
363 #include <unistd.h> /* getpid() getppid() */
364 #endif
365 #include <stdio.h>
366 #include <time.h>
367 #include <fcntl.h>
368 #include <signal.h> /* SIGKILL */
369 #ifndef tell
370 #define tell(fd) lseek(fd,(off_t)0,SEEK_CUR)
371 #endif
372 #ifndef EXIT_SUCCESS
373 #define EXIT_SUCCESS 0
374 #endif
375 #include "_locktst.h"
376 #ifndef SYS_FILE_H_MISSING
377 #include <sys/file.h>
378 #endif
379 #ifndef SEEK_SET
380 #define SEEK_SET 0
381 #define SEEK_CUR 1
382 #define SEEK_END 2
383 #endif
384
385 #define MIN_locks 128 /* minimum of consecutive successful locks */
386 #define SLEEP_loop 64 /* iterations in the busy loop */
387 #define SLEEP_delay 0 /* sleep() time per busy iteration */
388 #define SLEEP_retreat 1 /* extra sleep() when quota reached */
389 #define TIME_OUT_SEC 16 /* initial timeout per lock */
390 #define NR_of_forks 8 /* concurrent test-programs */
391 #define NR_of_lockfiles 2 /* lockfiles used in testing (<=4) */
392 #define GROW 3 /* when timing got worse */
393 #define DECAY 7/8 /* when timing got better */
394 #define GOBBLE 256 /* for the SunOS crash test */
395
396 #define LOCKS_per_child (((MIN_locks+NR_of_forks-1)/NR_of_forks+1)/2)
397 #define SHIFT_childno 3
398 #define MASK_fileno ((1<<SHIFT_childno)-1)
399 #define MASK_childno (~MASK_fileno)
400
401 #ifdef NO_fcntl_LOCK
402 #undef F_SETLKW
403 #endif
404 #ifdef NO_lockf_LOCK
405 #undef F_LOCK
406 #endif
407 #ifdef NO_flock_LOCK
408 #undef LOCK_EX
409 #endif
410
411 #define FIRST_lock 0x04 /* testing is in order of importance */
412 #define MSK_fcntl 0x04 /* don't change this order unless you */
413 #define MSK_lockf 0x02 /* change locking.c as well, fdlock() */
414 #define MSK_flock 0x01 /* and hotwired LOCKINGTEST */
415
416 int dolock,child[NR_of_forks],timeout,fdcollect;
417 char dirlocktest[]="_locktest";
418
419 #include <stdlib.h>
420 int killchildren();
421 int fdlock(int fd);
422 int sfdlock(int fd);
423 int fdunlock();
424
425 void stimeout()
426 { timeout=1;close(fdcollect);killchildren();
427 }
428
429 void Terminate()
430 { stimeout();exit(1);
431 }
432
433 static unsigned long seed;
434
435 unsigned psrand()
436 { return (unsigned)(seed*=69069L)>>8;
437 }
438
439 unsigned sfork()
440 { int pid;
441 while((pid=fork())<0)
442 fprintf(stderr,"Couldn't fork _locktst, retrying\n"),sleep(TIME_OUT_SEC);
443 return pid;
444 }
445
446 int main(int argc,char*argv[])
447 { int goodlock,testlock,i,pip[2],pipw[2];time_t otimet;unsigned dtimet;
448 static char filename[]="_locktst.l0";
449 close(0);goodlock=0;testlock=FIRST_lock;signal(SIGPIPE,SIG_DFL);
450 if(argc==2)
451 { char*p;
452 for(p=argv[1];;)
453 { switch(*p++) /* parse the hotwire */
454 { case '1':goodlock<<=1;goodlock++;
455 continue;
456 case '0':goodlock<<=1;
457 continue;
458 case '\0':
459 #ifndef F_SETLKW /* sanity check, for the less gifted */
460 goodlock&=~MSK_fcntl;
461 #endif
462 #ifndef F_LOCK
463 goodlock&=~MSK_lockf;
464 #endif
465 #ifndef LOCK_EX
466 goodlock&=~MSK_flock;
467 #endif
468 goto skip_tests;
469 }
470 break; /* oops, no hotwire */
471 }
472 goodlock=0;
473 }
474 if(sfork()) /* try to ditch the controlling tty */
475 return EXIT_SUCCESS; /* to prevent rather messy kernel-diagnostics */
476 setsid(); /* from appearing on your tty */
477 fprintf(stderr,"\
478 Every two digits a file is locked. First digit: which file, second digit:\n\
479 which program, XX indicates a lock conflict or failure\n");
480 do
481 { int countlocks;
482 signal(SIGTERM,SIG_DFL);argc=1;dolock=goodlock|testlock;
483 do
484 { char*curdir;
485 curdir=argv[argc];otimet=time((time_t*)0);
486 if(sfork())
487 { close(1);close(2);i=NR_of_lockfiles;chdir(curdir);
488 chdir(dirlocktest);
489 do /* prime the lock, see if it vanishes */
490 { filename[sizeof filename-2]='0'+--i;
491 lseek(goodlock=open(filename,O_WRONLY),(off_t)0,SEEK_END);
492 fdlock(goodlock);
493 }
494 while(i);
495 for(;;) /* synchronising "busy"-wait */
496 sleep(TIME_OUT_SEC); /* until the games can be started */
497 }
498 sleep(1);pipe(pip);pipe(pipw);i=NR_of_forks;*child=0;
499 fprintf(stderr,"\nStarting test %x on %s\n",dolock,curdir);
500 while((child[--i]=sfork())&&i); /* divide and conquer */
501 if(!*child)
502 { unsigned char lockflag;int fd,childno=i<<SHIFT_childno;
503 int mylocks=LOCKS_per_child;
504 close(pipw[0]);close(pip[0]);close(1);
505 seed=time((time_t*)0)+getpid()|1;chdir(curdir);chdir(dirlocktest);
506 close(pipw[1]);
507 for(;;) /* and lock away! */
508 { filename[sizeof filename-2]='0'+(i=psrand()%NR_of_lockfiles);
509 lockflag=childno|i<<1|1;
510 lseek(fd=open(filename,O_WRONLY),(off_t)0,SEEK_END);
511 if(sfdlock(fd))
512 lockflag&=~1,fprintf(stderr,"XX%x",lockflag);
513 write(pip[1],&lockflag,1);
514 fprintf(stderr," %x%x",i,childno>>SHIFT_childno);
515 lseek(fd,(off_t)0,SEEK_END);write(fd,&lockflag,1);
516 for(i=SLEEP_loop;i;i--,time((time_t*)0),sleep(SLEEP_delay));
517 lockflag&=~1;write(pip[1],&lockflag,1);
518 if(fdunlock()||close(fd))
519 { write(pip[1],&lockflag,1);fprintf(stderr,"XX%x",lockflag);
520 return 1;
521 }
522 if(--mylocks<0)
523 sleep(SLEEP_retreat);
524 }
525 }
526 signal(SIGTERM,Terminate);
527 ;{ unsigned char lckdfil[NR_of_lockfiles],curflag;
528 int j,ppid; /* give all children a chance */
529 ppid=getppid();
530 if(sfork()) /* discard the old body, let init adopt our children */
531 return EXIT_SUCCESS;
532 ;{ FILE*fp;
533 if(fp=fopen("_locktst.pid","w"))
534 fprintf(fp,"%ld",(long)getpid()),fclose(fp);
535 }
536 countlocks=MIN_locks;close(pip[1]);close(pipw[1]);
537 for(j=NR_of_lockfiles;lckdfil[--j]=0,j;);
538 timeout=0;sleep(1);read(pipw[0],&curflag,1);close(pipw[0]);
539 kill(ppid,SIGKILL);fdcollect=pip[0];signal(SIGALRM,stimeout);
540 dtimet=(time((time_t*)0)-otimet)*GROW+TIME_OUT_SEC;
541 do
542 { unlink("_locktst.alive");alarm(dtimet+2); /* watchdog */
543 dtimet=(otimet=time((time_t*)0)-otimet)>dtimet?
544 otimet*GROW:otimet+(dtimet-otimet)*DECAY+1; /* load dependent */
545 otimet=time((time_t*)0);
546 }
547 while(1==read(fdcollect,&curflag,1)&&
548 (j=lckdfil[i=(curflag&MASK_fileno)>>1],!timeout)&&
549 ((j^(lckdfil[i]=curflag))==1||!(j&1)&&curflag&1)&&--countlocks);
550 alarm(0);close(fdcollect);killchildren();
551 fprintf(stdout,
552 "/*locktype: %x, countlocks: %x, timeout %x, watchdog %x, %s*/\n",
553 dolock,countlocks,timeout,dtimet,curdir);fflush(stdout);
554 }
555 }
556 while(!countlocks&&argv[++argc]);
557 if(!countlocks) /* Hurray! Locking was flawless */
558 goodlock=dolock; /* make a mark on our colt */
559 }
560 while(testlock>>=1);
561 skip_tests:
562 printf("/* Hotwire LOCKINGTEST=%c%c%c */\n",goodlock&0x4?'1':'0',
563 goodlock&0x2?'1':'0',goodlock&0x1?'1':'0');
564 printf("/* Procmail will lock via: dotlocking"); /* report our findings */
565 if(goodlock&MSK_fcntl)
566 printf(", fcntl()");
567 if(goodlock&MSK_lockf)
568 printf(", lockf()");
569 if(goodlock&MSK_flock)
570 printf(", flock()");
571 puts(" */");
572 if(!(goodlock&MSK_fcntl)) /* and in machine readable format */
573 puts("#define NOfcntl_lock");
574 if(goodlock&MSK_lockf)
575 puts("#define USElockf");
576 if(goodlock&MSK_flock)
577 { puts("#define USEflock");
578 #ifdef SYS_FILE_H_MISSING
579 puts("#define SYS_FILE_H_MISSING");
580 #endif
581 }
582 puts("Kernel-locking tests completed.");fprintf(stderr,"\n");
583 return EXIT_SUCCESS;
584 }
585
586 int killchildren()
587 { int i;
588 i=NR_of_forks;
589 do
590 if(child[--i]>0)
591 kill(child[i],SIGTERM),child[i]=0;
592 while(i);
593 return 0;
594 }
595
596 int sfdlock(int fd)
597 { int i;unsigned gobble[GOBBLE>>2];
598 for(i=GOBBLE>>2;i;gobble[--i]=~(unsigned)0); /* SunOS crash test */
599 return fdlock(fd);
600 }
601
602 static int oldfdlock;
603 #ifdef F_SETLKW
604 static struct flock flck; /* why can't it be a local variable? */
605 #endif
606 #ifdef F_LOCK
607 static off_t oldlockoffset;
608 #endif
609
610 int fdlock(int fd)
611 { int i;unsigned gobble[GOBBLE>>2];
612 for(i=GOBBLE>>2;i;gobble[--i]=~(unsigned)0); /* SunOS crash test */
613 oldfdlock=fd;fd=0;
614 if(MSK_fcntl&dolock)
615 #ifdef F_SETLKW
616 { static unsigned extra;
617 flck.l_type=F_WRLCK;flck.l_whence=SEEK_SET;flck.l_start=tell(oldfdlock);
618 if(!extra--)
619 extra=MIN_locks/4,flck.l_len=2,i|=fcntl(oldfdlock,F_SETLK,&flck);
620 flck.l_len=0;fd|=fcntl(oldfdlock,F_SETLKW,&flck);
621 }
622 #else
623 fd=1;
624 #endif
625 if(MSK_lockf&dolock)
626 #ifdef F_LOCK
627 oldlockoffset=tell(oldfdlock),fd|=lockf(oldfdlock,F_LOCK,(off_t)0);
628 #else
629 fd=1;
630 #endif
631 if(MSK_flock&dolock)
632 #ifdef LOCK_EX
633 fd|=flock(oldfdlock,LOCK_EX);
634 #else
635 fd=1;
636 #endif
637 return fd;
638 }
639
640 int fdunlock()
641 { int i;unsigned gobble[GOBBLE];
642 for(i=GOBBLE;i;gobble[--i]=~(unsigned)0); /* some SunOS libs mess this up */
643 if(MSK_flock&dolock)
644 #ifdef LOCK_EX
645 i|=flock(oldfdlock,LOCK_UN);
646 #else
647 i=1;
648 #endif
649 if(MSK_lockf&dolock)
650 #ifdef F_LOCK
651 { lseek(oldfdlock,oldlockoffset,SEEK_SET);
652 i|=lockf(oldfdlock,F_LOCK,(off_t)2);i|=lockf(oldfdlock,F_ULOCK,(off_t)0);
653 }
654 #else
655 i=1;
656 #endif
657 if(MSK_fcntl&dolock)
658 #ifdef F_SETLKW
659 flck.l_type=F_UNLCK,flck.l_len=0,i|=fcntl(oldfdlock,F_SETLK,&flck);
660 #else
661 i=1;
662 #endif
663 if(!i)
664 for(i=GOBBLE;i&&gobble[--i]==~(unsigned)0;);
665 return i;
666 }
667 HERE
668
669 if $MAKE _autotst >_autotst.rrr 2>&1
670 then
671 :
672 else
673 echo 2>&1 "Whoeaaa! There's something fishy going on here."
674 echo 2>&1 "You have a look and see if you detect anything uncanny:"
675 echo 2>&1 "*******************************************************"
676 cat 2>&1 _autotst.rrr
677 echo 2>&1 "*******************************************************"
678 echo 2>&1 "I suggest you take a look at the definition of LDFLAGS*"
679 echo 2>&1 "in the Makefile before you try make again."
680 kill -15 $$
681 fi
682
683 $MV _locktst _locktst.$$ 2>$DEVNULL
684 $RM _autotst.$O _autotst.rrr _locktst* 2>$DEVNULL
685 echo "" >_locktst.pid
686 $MV _autotst _locktst
687
688 case "$testdirs" in
689 *[a-zA-Z/]*)
690 for b in $TESTDIRS
691 do
692 for a in 0 1 2 3
693 do echo dummy_file >$b/_locktst.l$a
694 done
695 done ;;
696 *) TESTDIRS=$testdirs ;;
697 esac
698
699 echo 2>&1 ""
700
701 _locktst $TESTDIRS >_locktst.rrr 2>lock.log # will finish in the background
702 echo 'Proceeding with kernel-locking-support tests in the background'
703
704
705 cat >_autotst.c <<HERE
706 #include "$ACONF"
707 #ifndef UNISTD_H_MISSING
708 #include <unistd.h> /* execvp() */
709 #endif
710 int a(b)const int b[];
711 { return *++b; /* watcom 10.6 on QNX refuses this */
712 }
713 int main()
714 { char r[]="",*const*p;char*q="";const char*s="";
715 static const char*const nullp=0,*const*d= &nullp; /* AIX 3.2.3 failure */
716 static struct{const int a;int b;}c[2]={{0,0},{0,0}};/* IRIX 7.3.1 compiler */
717 /* requires initializers on static const objects */
718 --(c+1)->b; /* AIX 3.1.5 machines can't do this */
719 p= &q;
720 ;{ int pip[2];
721 pipe(pip);
722 if(fork()) /* this should hide core dumps from the shell */
723 { close(pip[1]); /* close the writing end */
724 return 1==read(pip[0],r,1)?0:1; /* wait for the rendevouz */
725 }
726 close(pip[0]); /* close the writing end */
727 if(!*d&&c[1].b) /* some magic to confuse the optimiser */
728 d=(const char*const*)p; /* core dumps Ultrix 4.3 ANSI C */
729 else /* so that it can't complain about the uselessness of this program */
730 execvp(q,p); /* IRIX 4.0.1 system-includes are wrong on this point */
731 if(write(pip[1],r,1)!=1) /* notify mam that we survived */
732 return 1; /* oops, lost mam somehow */
733 }
734 return r==s; /* Domain/OS warns here, not about "r==s" though */
735 }
736 HERE
737
738 echo 'Testing for const'
739 if $MAKE _autotst.$O 2>&1 | $FGREP -v include/ >_autotst.rrr
740 test -f _autotst.$O && $MAKE _autotst >$DEVNULL 2>&1 && _autotst
741 then
742 grepfor const '#define NO_const'
743 else
744 echo '#define NO_const' >>$ACONF
745 set dummy *core*
746 if test -f $2 -a $nocore = yes
747 then
748 echo "Removing core file (bogus readonly segment)"
749 $RM *core*
750 fi
751 fi
752 $RM _autotst.$O _autotst
753
754 cat >_autotst.c <<HERE
755 int main(){volatile int i;return (i=0);}
756 HERE
757
758 echo 'Testing for volatile'
759 if $MAKE _autotst.$O >$DEVNULL 2>&1 && test -f _autotst.$O
760 then
761 :
762 else
763 echo '#define volatile' >>$ACONF
764 not_ISO=yep
765 fi
766 $RM _autotst.$O
767
768 if $FGREP NO_const $ACONF >$DEVNULL
769 then
770 echo '#define P(args) ()' >>$ACONF
771 not_ISO=yep
772 else
773 cat >_autotst.c <<HERE
774 int main(const int argc,const char*const argv[]){return argc;}
775 HERE
776
777 echo 'Testing for prototypes'
778 if $MAKE _autotst.$O >$DEVNULL 2>&1 && test -f _autotst.$O
779 then
780 :
781 else
782 echo '#define P(args) ()' >>$ACONF
783 not_ISO=yep
784 fi
785 $RM _autotst.$O
786 fi
787
788 cat >_autotst.c <<HERE
789 enum foo { A, B, C, D=7, E, F= -3, G };
790 int main(){return !(A==0&&B==1&&C==2&&D==7&&E==8&&F==-3&&G==-2);}
791 HERE
792
793 echo 'Testing for enum'
794 if $MAKE _autotst.$O >$DEVNULL 2>&1 && test -f _autotst.$O &&
795 $MAKE _autotst >$DEVNULL 2>&1 && _autotst
796 then
797 :
798 else
799 echo '#define NO_enum' >>$ACONF
800 not_ISO=yep
801 fi
802 $RM _autotst.$O
803
804 if test -n "$not_ISO"
805 then
806 cat <<HERE
807
808 Your system appears to not (correctly) support at least one of:
809 const, volatile, function prototypes, and enum types. Future
810 versions of procmail will probably require support for all of them,
811 so you should either upgrade your compiler to one that's compliant
812 with the ISO C standard (the standard's over 10 years old, for
813 goodness sake), or send email to <[email protected]> explaining why
814 you need procmail to continue to support K&R C.
815
816 HERE
817 fi
818
819 echo 'Checking for POSIX and ANSI/ISO system include files'
820
821 cat >_autotst.c <<HERE
822 #include "includes.h"
823 int a;
824 #ifndef SYS_DIRENT_H_MISSING
825 typedef DIR*tDIR;
826 tDIR vDIR;
827 #endif
828 HERE
829
830 i0="";i1="";i2="";i3="";i4="";i5="";i6="";i7="";i8="";i9="";i10="";i11="";
831 i12="";i13=""
832 oldi=""
833
834 while $MAKE _autotst.$O 2>&1 | $FGREP -v include/ >_autotst.rrr
835 test ! -f _autotst.$O
836 do
837 test -z "$i0" && grepfor stddef.h "#define STDDEF_H_MISSING" && i0=I
838 test -z "$i1" && grepfor stdlib.h "#define STDLIB_H_MISSING" && i1=I
839 test -z "$i2" && grepfor dirent.h "#define DIRENT_H_MISSING" && i2=I
840 test -z "$i2" && grepfor DIR "#define DIRENT_H_MISSING \
841 /* <dirent.h> is there, but empty */" && i2=I
842 test -z "$i3" && grepfor ndir.h "#define NDIR_H_MISSING" && i3=I
843 test I = "$i3$i4" && grepfor sys/ndir.h "#define SYS_NDIR_H_MISSING" && i4=I
844 test I = "$i4$i5" && grepfor sys/dir.h "#define SYS_DIR_H_MISSING" && i5=I
845 test I = "$i5$i6" && grepfor sys/dirent.h "#define SYS_DIRENT_H_MISSING" \
846 && i6=I
847 test -z "$i7" && grepfor sys/wait.h "#define SYS_WAIT_H_MISSING" && i7=I
848 test -z "$i8" && grepfor sys/utsname.h "#define SYS_UTSNAME_H_MISSING" &&
849 i8=I
850 test -z "$i9" && grepfor string.h "#define STRING_H_MISSING" && i9=I
851 test -z "$i10" && grepfor sysexits.h "#define SYSEXITS_H_MISSING" && i10=I
852 test -z "$i11" && grepfor math.h "#define MATH_H_MISSING" && i11=I
853 test -z "$i12" && grepfor limits.h "#define LIMITS_H_MISSING" && i12=I
854 test -z "$i13" && grepfor syslog.h "#define SYSLOG_H_MISSING" && i13=I
855 newi="$i0$i1$i2$i3$i4$i5$i6$i7$i8$i9$i10$i11$i12$i13"
856 if test a$oldi = a$newi
857 then
858 echo 2>&1 "Whoeaaa! There's something fishy going on here."
859 echo 2>&1 "You have a look and see if you detect anything uncanny:"
860 echo 2>&1 "*******************************************************"
861 $MAKE _autotst.$O >_autotst.rrr 2>&1
862 cat 2>&1 _autotst.rrr
863 echo 2>&1 "*******************************************************"
864 echo 2>&1 "I suggest you take a look at the definition of CFLAGS*"
865 echo 2>&1 "in the Makefile before you try make again."
866 kill -15 $$
867 fi
868 oldi=$newi
869 echo \
870 " ...missing `expr $oldi : '.*'` include files, doublechecking..."
871 done
872
873 $RM _autotst.$O
874
875 cat >_autotst.c <<HERE
876 #include "includes.h"
877 #include "network.h"
878 int a;
879 HERE
880
881 echo 'Checking for network/comsat/biff support'
882
883 if $MAKE _autotst.$O >$DEVNULL 2>&1
884 test -f _autotst.$O
885 then
886 :
887 else
888 echo "#define NO_COMSAT" >>$ACONF
889 fi
890
891 $RM _autotst.$O
892
893 cat >_autotst.c <<HERE
894 #include "includes.h"
895 #ifndef NO_COMSAT
896 #include "network.h"
897 #endif
898 int main(){int i=0;
899 {size_t vsize_t;i+=vsize_t=1;}
900 {pid_t vpid_t;i+=vpid_t=1;}
901 {mode_t vmode_t;i+=vmode_t=1;}
902 {uid_t vuid_t;i+=vuid_t=1;}
903 {gid_t vgid_t;i+=vgid_t=1;}
904 #ifndef NO_COMSAT
905 {struct hostent vhostent;i+=!(vhostent.h_addr_list=0);}
906 #endif
907 #ifndef NOuname
908 {struct utsname vutsname;i+=!(*vutsname.nodename='\0');}
909 #endif
910 return !i;}
911 HERE
912
913 echo 'Testing for void*, size_t, off_t, pid_t, time_t, mode_t, uid_t & gid_t'
914
915 i1="";i2="";i3="";i4="";i5="";i6="";i7=""
916 oldi=""
917
918 while $MAKE _autotst.$O 2>&1 | $FGREP -v include/ >_autotst.rrr
919 test ! -f _autotst.$O
920 do
921 test -z "$i1" && grepfor size_t 'typedef unsigned size_t;' && i1=I
922 test -z "$i2" && grepfor pid_t 'typedef int pid_t;' && i2=I
923 test -z "$i3" && grepfor mode_t 'typedef int mode_t;' && i3=I
924 test -z "$i4" && grepfor uid_t 'typedef int uid_t;' && i4=I
925 test -z "$i5" && grepfor gid_t 'typedef int gid_t;' && i5=I
926 test -z "$i6" && grepfor h_addr_list '#define h_0addr_list h_addr' && i6=I
927 test -z "$i6" && grepfor hostent '#define h_0addr_list h_addr' && i6=I
928 test -z "$i6" && grepfor member '#define h_0addr_list h_addr' && i6=I
929 test -z "$i7" && grepfor utsname "#define NOuname \
930 /* <sys/utsname.h> is there, but empty */" && i7=I
931 newi="$i1$i2$i3$i4$i5$i6$i7"
932 if test a$oldi = a$newi
933 then
934 echo 2>&1 "Whoeaaa! There's something fishy going on here."
935 echo 2>&1 "You have a look and see if you detect anything uncanny:"
936 echo 2>&1 "*******************************************************"
937 $MAKE _autotst.$O >_autotst.rrr 2>&1
938 cat 2>&1 _autotst.rrr
939 echo 2>&1 "*******************************************************"
940 echo 2>&1 "I suggest you take a look at the definition of CFLAGS*"
941 echo 2>&1 "in the Makefile before you try make again."
942 kill -15 $$
943 fi
944 oldi=$newi
945 echo \
946 " ...missing `expr $oldi : '.*'` types, doublechecking..."
947 done
948
949 $RM _autotst.$O
950
951 cat >_autotst.c <<HERE
952 #include "$ACONF"
953 #include "../config.h"
954 #include <stdio.h>
955 #ifndef STDLIB_H_MISSING
956 #include <stdlib.h>
957 #define INITIAL 60
958 #else
959 void*realloc(),*malloc();
960 #endif
961 int main()
962 { char*p=malloc(1),*q=0;
963 size_t len,last,max=BLKSIZ*64; /* 1M on non-SMALLHEAP systems */
964 int count=0;
965 for(last=len=INITIAL;len<=max+INITIAL;len+=BLKSIZ)
966 { if(!(p=realloc(p,len)))
967 break;
968 if(p!=q)
969 count++,q=p,fprintf(stderr,"len=%lu p=%p\n",(unsigned long)len,p);
970 for(;last<len;last+=1024) /* touch at least every new page */
971 p[last]=last%127;
972 }
973 free(q);
974 printf("/* %d move%s in %d steps of size %d when reallocing */\n",
975 count,count==1?"":"s",(int)(max/BLKSIZ),BLKSIZ);
976 if(BLKSIZ*(10*count+1)>max)
977 { puts("#define INEFFICIENTrealloc");
978 exit(1);
979 }
980 exit(0);
981 }
982 HERE
983
984 echo 'Checking realloc implementation'
985
986 if $MAKE _autotst >$DEVNULL 2>&1
987 test -f _autotst
988 then
989 _autotst >_autotst.rrr 2>realloc.log
990 case "$?" in
991 0) cat _autotst.rrr >>$ACONF;;
992 1) cat _autotst.rrr >>$ACONF
993 echo 'Sorry, repeatedly reallocing is inefficient';;
994 *) echo "The test program failed somehow. Assuming realloc is fine";;
995 esac
996 fi
997
998 $RM _autotst.$O _autotst _autotst.rrr
999
1000 cat >_autotst.c <<HERE
1001 #include "includes.h"
1002 int main(){int i;i=1;
1003 i+=WIFEXITED(i);
1004 i+=WIFSTOPPED(i);
1005 i+=WEXITSTATUS(i);
1006 i+=WTERMSIG(i);
1007 return i;}
1008 HERE
1009
1010 echo 'Testing for WIFEXITED(), WIFSTOPPED(), WEXITSTATUS() & WTERMSIG()'
1011 if $MAKE _autotst.$O >_autotst.rrr 2>&1
1012 then
1013 $FGREP -v include/ <_autotst.rrr >_autotst.$O
1014 $MV _autotst.$O _autotst.rrr
1015 grepfor struct '#define WMACROS_NON_POSIX' ||
1016 grepfor union '#define WMACROS_NON_POSIX'
1017 else
1018 echo '#define WMACROS_NON_POSIX' >>$ACONF
1019 fi
1020 $RM _autotst.$O _autotst.rrr
1021
1022 cat >_autotst.c <<HERE
1023 #include <pwd.h>
1024 int main()
1025 { struct passwd*pw=getpwuid(0);
1026 return (pw->pw_passwd==0)+(pw->pw_class==0)+(pw->pw_gecos==0);
1027 }
1028 HERE
1029
1030 echo 'Testing for various struct passwd members'
1031 $MAKE _autotst.$O >_autotst.rrr 2>&1
1032 grepfor pw_passwd '#define NOpw_passwd'
1033 grepfor pw_class '#define NOpw_class'
1034 grepfor pw_gecos '#define NOpw_gecos'
1035 $RM _autotst.$O _autotst.rrr
1036
1037 cat >_autotst.c <<HERE
1038 #include "includes.h"
1039 #ifndef NO_COMSAT
1040 #include "network.h"
1041 #endif
1042 int setrgid();
1043 int setresgid();
1044 int main(){char a[2];
1045 endpwent();endgrent();memmove(a,"0",1);bcopy("0",a,1);strcspn(a,"0");
1046 strtol("0",(char**)0,10);strchr("0",'0');strpbrk(a,"0");rename(a,"0");
1047 setrgid(0);setegid(0);setregid(0,0);setresgid(0,0,0);opendir("0");
1048 initgroups("0",0);strstr("0","0");mkdir("0",0);pow(0.,0.);clock();
1049 waitpid((pid_t)-1,(int*)0,0);ftruncate(0,0);fsync(0);strtod("0.0",(char**)0);
1050 strncasecmp("0","0",3);strerror(ENOENT);strlcat(a,"0",2);
1051 bzero(a,2);memset(a,'\0',2);
1052 #ifdef S_ISLNK
1053 {struct stat stbuf;fstat(0,&stbuf);}
1054 #endif
1055 #ifndef NOuname
1056 {struct utsname b;uname(&b);}
1057 #endif
1058 #ifndef NO_COMSAT
1059 gethostbyname("0");getprotobyname(COMSATprotocol);endhostent();endservent();
1060 endprotoent();
1061 #endif
1062 _exit(0);
1063 return 0;}
1064 HERE
1065
1066 echo 'Testing for memmove, strchr, strpbrk, strcspn, strtol, strstr,'
1067 echo ' rename, setrgid, setegid, pow, opendir, mkdir, waitpid, fsync,'
1068 echo ' ftruncate, strtod, strncasecmp, strerror, strlcat,'
1069 echo ' memset, bzero, and _exit'
1070 if $MAKE _autotst.$O >_autotst.rrr 2>&1
1071 then
1072 :
1073 else
1074 echo 2>&1 "Whoeaaa! There's something fishy going on here."
1075 echo 2>&1 "You have a look and see if you detect anything uncanny:"
1076 echo 2>&1 "*******************************************************"
1077 cat 2>&1 _autotst.rrr
1078 echo 2>&1 "*******************************************************"
1079 echo 2>&1 "Your include files seem to be beyond repair <sigh>."
1080 echo 2>&1 "I give up."
1081 kill -15 $$
1082 fi
1083 $MAKE _autotst >_autotst.rrr 2>&1
1084 $RM _autotst _autotst.$O
1085
1086 # The simple ones
1087 for func in strcspn strpbrk rename pow mkdir fstat initgroups \
1088 strtol waitpid ftruncate fsync strtod strncasecmp strlcat memset bzero _exit
1089 do
1090 grepfor $func "#define NO$func"
1091 done
1092
1093 NOstrerror=no
1094 grepfor strerror "#define NOstrerror" && NOstrerror=yes
1095
1096 grepfor opendir "
1097 #define NOopendir /* the readdir library does not seem to be available
1098 this will slightly affect the way a filenumber is
1099 selected in MH-folders by procmail */
1100 "
1101 a=no
1102 grepfor setrgid '#define NOsetrgid' && a=yes
1103 if grepfor setegid '#define NOsetegid' || test $a = yes
1104 then
1105 grepfor setregid '#define NOsetregid' &&
1106 grepfor setresgid '#define NOsetresgid'
1107 fi
1108 grepfor strchr '#define strchr(s,c) index(s,c)'
1109 grepfor uname "\
1110 #define NOuname \
1111 /* <sys/utsname.h> defines it, the libraries don't */"
1112 grepfor endpwent '#define endpwent()'
1113 grepfor endgrent '#define endgrent()'
1114 if grepfor gethostbyname '#define NO_COMSAT'
1115 then
1116 :
1117 else
1118 grepfor getprotobyname '#define UDP_protocolno 17'
1119 grepfor endhostent '#define endhostent()'
1120 grepfor endservent '#define endservent()'
1121 grepfor endprotoent '#define endprotoent()'
1122 fi
1123 grepfor strstr '#define SLOWstrstr' ||
1124 grepfor clock '#define SLOWstrstr'
1125 grepfor memmove '#define NOmemmove' &&
1126 if $FGREP -e bcopy _autotst.rrr >$DEVNULL
1127 then
1128 echo '#define NObcopy' >>$ACONF
1129
1130 if test $NOstrerror = yes
1131 then
1132 cat >_autotst.c <<HERE
1133 #include "includes.h"
1134 extern int sys_nerr;extern char*sys_errlist[];
1135 int main(){
1136 return puts(sys_errlist[sys_nerr-1]);}
1137 HERE
1138
1139 echo 'Testing for sys_errlist'
1140 if $MAKE _autotst.$O >_autotst.rrr 2>&1
1141 then
1142 if $MAKE _autotst >_autotst.rrr 2>&1
1143 then
1144 echo '' >_autotst.rrr
1145 fi
1146 fi
1147 grepfor sys_errlist '#define NOsys_errlist'
1148 $RM _autotst _autotst.$O _autotst.rrr
1149 fi
1150
1151 echo 'Testing for brain damage'
1152 cat >_autotst.c <<HERE
1153 #include "includes.h"
1154 struct tests{int a,b;};
1155 int main(){
1156 return offsetof(struct tests,b);}
1157 HERE
1158 if $MAKE _autotst.$O >$DEVNULL 2>&1
1159 then
1160 :
1161 else
1162 echo 'Yep, it is' # ISC chokes on its own offsetof()
1163 echo '#define oBRAIN_DAMAGE' >>$ACONF
1164 fi
1165 $RM _autotst.$O
1166
1167 else
1168
1169 cat >_autotst.c <<HERE
1170 #include "includes.h"
1171 #define M256 256
1172 #define F33 33
1173 int main(){int j=0,i=M256-1;static char a[M256];
1174 do a[i]=i;while(i--);
1175 bcopy(a+F33,a,M256-F33);bcopy(a,a+F33,M256-F33);i=F33-1;
1176 do j|=a[i]!=(char)(i+F33);while(i--);i=M256-1;
1177 do j|=a[i]!=(char)i;while(--i!=F33-1);return !j;}
1178 HERE
1179
1180 echo 'Testing for bcopy handling overlaps'
1181 $MAKE _autotst >$DEVNULL 2>&1
1182
1183 if _autotst
1184 then
1185 echo 'Sorry, incompetent bcopy, using substitute instead'
1186 echo '#define NObcopy' >>$ACONF
1187 fi
1188 $RM _autotst.$O _autotst
1189 fi
1190 test -f /bin/test && echo "#define GOT_bin_test" >>$ACONF
1191
1192 cat >_autotst.c <<\HERE
1193 #define BENCHSIZE 16384
1194 #define GRANULARITY 64 /* maximal benchmark granularity */
1195 #include "sublib.c"
1196 #ifndef NO_COMSAT
1197 #include "network.h" /* also for ntohs() */
1198 #endif
1199 #undef malloc /* from shell.h */
1200 #ifdef BENCHSIZE
1201 #undef strstr /* from includes.h */
1202 #undef free /* from shell.h */
1203 unsigned long dobench(strstr,iter,haystack)char*(*const strstr)();
1204 unsigned long iter;const char*const haystack;
1205 { unsigned long to;
1206 to=(unsigned long)clock();
1207 do (*strstr)(haystack,FROM_EXPR);
1208 while(--iter);
1209 return (unsigned long)clock()-to;
1210 }
1211 #endif
1212 int main(int argc,const char*argv[])
1213 { if(argc==1)
1214 { char*haystack;
1215 #ifdef BENCHSIZE
1216 if(haystack=malloc(BENCHSIZE))
1217 { unsigned c1,c2,i;time_t t;
1218 unsigned long iter,titer,syscnt;
1219 for(i=c1=c2=0;i<BENCHSIZE-1;i++,c1++,c2++)
1220 { haystack[i]='a';
1221 if(c1==37)
1222 c1=0,haystack[i]='\n';
1223 if(c2==51)
1224 c2=0,haystack[i]='\n';
1225 }
1226 haystack[i]='\0';
1227 for(titer=~(unsigned long)0,t=0,iter=1;t<=1&&iter<<1&&iter<titer;)
1228 { t=time((time_t*)0);
1229 if((syscnt=dobench(strstr,iter<<=1,haystack))&&!~titer)
1230 titer=iter*GRANULARITY;
1231 t=time((time_t*)0)-t;
1232 }
1233 iter=dobench(sstrstr,iter,haystack);free(haystack);
1234 if(!syscnt)
1235 syscnt=1;
1236 if(!iter)
1237 iter=1;
1238 printf("\
1239 /* Your system's strstr() is %.2f times %sER than my C-routine */\n",
1240 syscnt>=iter?(double)syscnt/iter:(double)iter/syscnt,
1241 syscnt>=iter?"SLOW":"FAST");
1242 if(syscnt>iter+iter/16) /* if at least 1.0625 times slower */
1243 printf("\
1244 #define SLOWstrstr\t\t\t /* using my substitute instead */\n");
1245 }
1246 else
1247 printf("/* Insufficient memory to perform the benchmark! */\n");
1248 #endif /* SLOWstrstr */
1249 #ifndef NO_COMSAT
1250 #ifndef UDP_protocolno
1251 ;{ const struct protoent*p;
1252 if(p=getprotobyname(COMSATprotocol))
1253 { printf("#define UDP_protocolno %d\n",p->p_proto);
1254 #else
1255 ;{ if(1)
1256 {
1257 #endif
1258 ;{ const struct servent*serv;
1259 if(serv=getservbyname(COMSATservice,COMSATprotocol))
1260 printf("#define BIFF_serviceport \"%d\"\n",
1261 ntohs(serv->s_port));
1262 }
1263 #ifdef AF_INET
1264 ;{ const struct hostent*host;
1265 if(!strcmp("localhost",COMSAThost)&&
1266 (host=gethostbyname(COMSAThost))&&
1267 host->h_0addr_list&&host->h_addrtype==AF_INET&&
1268 host->h_length)
1269 { int j=host->h_length;
1270 const unsigned char*ad=(void*)host->h_0addr_list;
1271 printf("#define IP_localhost {");
1272 printf("%d",*ad++);
1273 while(--j)
1274 printf(",%d",*ad++);
1275 puts("}");
1276 }
1277 }
1278 #endif /* AF_INET */
1279 }
1280 else
1281 puts("#define NO_COMSAT");
1282 }
1283 #endif /* NO_COMSAT */
1284 ;{ unsigned long s=(size_t)~0;int bits;
1285 for(bits=1;s>>=1;bits++);
1286 if(bits<=16)
1287 { puts("#define SMALLHEAP");
1288 return 0;
1289 }
1290 }
1291 #ifdef _GUID_T /* ISC cc hack */
1292 ;{ struct passwd*p;
1293 if(sizeof(int)>sizeof(uid_t)&&(p=getpwnam("root"))&&(*p->pw_dir!='/'||
1294 (*p->pw_shell&&!(p->pw_shell)[1])))
1295 { puts("#define _GUID_T\ntypedef int uid_t;\ntypedef int gid_t;");
1296 goto skipsetrgid;
1297 }
1298 }
1299 #endif
1300 #ifndef NOinitgroups
1301 if(geteuid()==ROOT_uid)
1302 { setgid(2);
1303 if(!setrgid(3)&&(getgid()!=3||getegid()!=2))
1304 puts("#define setrgid_BRAIN_DAMAGE");
1305 else
1306 { setuid(2);
1307 if(!setgid(3)&&!setgid(2))
1308 puts("#define TOGGLE_SGID_OK");
1309 }
1310 }
1311 else
1312 #ifndef NGROUPS_MAX /* is this safeguard really needed? */
1313 #define NGROUPS_MAX 3
1314 #endif /* some OSes expect an array of ints? */
1315 { gid_t groups[NGROUPS_MAX*sizeof(int)/sizeof(gid_t)];unsigned i;
1316 for(i=getgroups(NGROUPS_MAX,groups);
1317 --i<NGROUPS_MAX&&groups[i]==getgid(););
1318 if(i<NGROUPS_MAX)
1319 { setegid(groups[i]);
1320 if(!setrgid(groups[i])&&getgid()!=groups[i])
1321 puts("#define setrgid_BRAIN_DAMAGE");
1322 }
1323 else
1324 puts("#define setrgid_RUNTIME_CHECK");
1325 }
1326 #endif
1327 skipsetrgid:;
1328 }
1329 #ifdef DEFsendmail
1330 if(argc==3)
1331 { printf("#define SENDMAIL \"%s\"\n",DEFsendmail);
1332 return 1;
1333 }
1334 #endif
1335 if(argc==4)
1336 { FILE*fp; /* in case we are root */
1337 chown(argv[1],2,getegid());setuid(2); /* adjust the directory first */
1338 if(!(fp=fopen(argv[2],"w")))
1339 goto openerr; /* shouldn't happen, really */
1340 fclose(fp); /* always clean up after yourself */
1341 if(!chown(argv[2],geteuid()==3?4:3,getegid()))
1342 openerr:
1343 printf("#define CAN_chown\n");
1344 }
1345 if(argc>4)
1346 #define MAX_ENVMEM 2048 /* typical environment size */
1347 #define MAX_ARGMEM (2048*1024L) /* upper limit arguments size */
1348 { static const char arg[]="e%04u=6789012345";unsigned diff;
1349 charNUM(num,diff);char**nargv;const char*einfo="";
1350 #define MAXT(type) (~(type)0>>1)
1351 sscanf(argv[1],"%u",&diff); /* what did our previous incarnation want? */
1352 if(!diff) /* first run? initialise the environment */
1353 { char*envs,**nenviron,**nenv;
1354 diff=MAX_ENVMEM/sizeof arg+1;
1355 if(!(nenviron=malloc(diff*sizeof*environ+MAX_ENVMEM)))
1356 goto printit; /* oops, panic already */
1357 envs=(char*)((nenv=nenviron)+diff);
1358 while(--diff) /* put in some colour */
1359 sprintf(*nenviron++=envs,arg,diff),envs+=sizeof arg;
1360 *(environ=nenv)="PATH=.";*nenviron=0;diff=argc; /* start doubling */
1361 }
1362 if(MAX_ARGMEM/sizeof arg<=argc) /* we are satisfied */
1363 { einfo=" /* soft limit */"; /* no reason to hog memory */
1364 goto printit;
1365 }
1366 ;{ unsigned narg;
1367 while(narg=argc+diff+1, /* allocate space for the new args */
1368 !(nargv=malloc(narg*sizeof*argv+(size_t)diff*sizeof arg)))
1369 if(!(diff>>=1)) /* oops, no space, back off */
1370 goto printit; /* panic */
1371 tmemmove(nargv,argv,argc*sizeof*argv);nargv[1]=num; /* copy old */
1372 ;{ char**pargv,*args;unsigned i;
1373 pargv=nargv+argc;args=(char*)(nargv+narg);i=diff;
1374 do
1375 { const char*p; /* and paint in the new ones */
1376 for(*pargv++=args,p=arg;*args++= *p++;);
1377 }
1378 while(--i);
1379 }
1380 }
1381 for(;;diff>>=1)
1382 { unsigned newdiff=diff>>1; /* take a small step for mankind */
1383 if(argc==diff) /* or shall we boldly go */
1384 newdiff=(unsigned)argc<<1; /* where no man has gone before? */
1385 ;{ unsigned maxdiff=MAXT(unsigned)-argc;
1386 if(newdiff>maxdiff) /* that would overflow argc */
1387 newdiff=maxdiff; /* and we wouldn't want that, would we now? */
1388 }
1389 if(!newdiff) /* reductio ad adsurdum? */
1390 break; /* yes, break off the engagement */
1391 sprintf(num,"%u",newdiff);nargv[argc+diff]=0; /* pass on the target */
1392 execv(argv[0],nargv); /* jeronimo! */
1393 }
1394 printit: /* we proudly present the findings */
1395 printf("#define MAX_argc %d%s\n",argc-2,einfo); /* of the jury! */
1396 }
1397 return EXIT_SUCCESS;
1398 }
1399 HERE
1400
1401 echo "Determining the maximum number of 16 byte arguments execv() takes"
1402
1403 if $MAKE _autotst >$DEVNULL 2>_autotst.rrr &&
1404 _autotst 0 012345678901234 012345678901234 012345678901234 \
1405 >>$ACONF 2>>_autotst.rrr
1406 then
1407 :
1408 else
1409 echo 2>&1 "Whoeaaa! This actually can't happen."
1410 echo 2>&1 "You have a look and see if you detect anything uncanny:"
1411 echo 2>&1 "*******************************************************"
1412 cat 2>&1 _autotst.rrr
1413 echo 2>&1 "*******************************************************"
1414 echo 2>&1 "I suggest you take a look at the definition of LDFLAGS*"
1415 echo 2>&1 "in the Makefile before you try make again."
1416 kill -15 $$
1417 fi
1418
1419 $RM _autotst.rrr
1420
1421 echo "Benchmarking your system's strstr() implementation"
1422
1423 _autotst >>$ACONF
1424
1425 found=no
1426
1427 for a in /var/mail /var/spool/mail /usr/spool/mail /usr/mail /spool/mail
1428 do
1429 test -d $a -a $found != yes &&
1430 echo '#define MAILSPOOLDIR "'$a'/"' >>$ACONF && found=yes
1431 done
1432 if test $found != yes
1433 then
1434 echo '#define MAILSPOOLDIR "/var/mail/"' >>$ACONF
1435 echo Could not find the system-mailbox directory, supplied default.
1436 fi
1437
1438 cat >lookfor <<HERE
1439 for a in /usr/sbin /usr/lib /lib /usr/etc /etc /usr/bin /bin /usr/local/bin \
1440 /usr/lbin /usr/local/lib /usr/local /usr/.lib /local/bin /sbin
1441 do
1442 if test -f "\$a/\$1"
1443 then
1444 echo '#define SENDMAIL "'"\$a/\$1"'"' >>$ACONF
1445 exit 0
1446 fi
1447 done
1448 exit 1
1449 HERE
1450 chmod 0755 lookfor
1451
1452 if _autotst 2 3 >>$ACONF
1453 test $? != 0 ||
1454 lookfor sendmail || lookfor smail || lookfor mail #|| lookfor rmail
1455 then
1456 :
1457 else
1458 echo 'Could not find any mailer. It should be a mailer accepting at least'
1459 echo 'one plain destination address as its only argument (any sendmail'
1460 echo 'compatible mailer will do), and the mail-to-be-sent on stdin.'
1461 echo 'What is your mailer called? (You can override this in config.h)'
1462 read a
1463 echo "#define SENDMAIL \"$a\"" >>$ACONF
1464 fi
1465
1466 grep '^#define SENDMAIL ".*/sendmail"' $ACONF >$DEVNULL ||
1467 echo "#define DEFflagsendmail \"\"" >>$ACONF
1468
1469 a=/tmp/_chowntst.$$
1470 $RM -r $a
1471 OLDTESTDIRS="$a $OLDTESTDIRS"
1472 mkdir $a
1473 mkdir $a/__
1474
1475 _autotst $a/__ $a/__/__ 4 >>$ACONF
1476
1477 cat /usr/lib/sendmail.cf /etc/sendmail.cf /etc/mail/sendmail.cf 2>$DEVNULL |
1478 grep 'Mlocal.*procmail' >$DEVNULL ||
1479 echo '#define CF_no_procmail_yet' >>$ACONF
1480
1481 # cat /usr/lib/sendmail.cf /etc/sendmail.cf /etc/mail/sendmail.cf 2>$DEVNULL |
1482 # grep '^V' >$DEVNULL ||
1483 # echo '#define buggy_SENDMAIL' >>$ACONF
1484
1485 lpath='/bin'
1486 bins="/bin"
1487
1488 for newd in /usr/bin $BINDIR /usr/bin/X11 /usr/X*/bin
1489 do
1490 if test -d $newd
1491 then
1492 oldid=`cd $newd; ls -id . .. ../.. 2>&1`
1493 for oldd in $bins
1494 do
1495 test "X`cd $oldd; ls -id . .. ../.. 2>&1`" = "X$oldid" && oldid=found
1496 done
1497 test found != "$oldid" && bins="$bins $newd" && lpath="$lpath:$newd"
1498 fi
1499 done
1500
1501 echo "#define defPATH \"PATH=\$HOME/bin:$lpath\"" >>$ACONF
1502 echo "#define defSPATH \"PATH=$lpath\"" >>$ACONF
1503
1504 sed -n -e 's/^ v\([^ ]*\) .*$/#define PM_VERSION "\1"/p' \
1505 ../patchlevel.h >>$ACONF
1506
1507 while $FGREP -e "Kernel-locking tests completed." _locktst.rrr >$DEVNULL; \
1508 test 0 != $?
1509 do
1510 if test -z "$tailpid"
1511 then
1512 echo "Waiting for the kernel-locking tests to finish..."
1513 exec 9>&2 2>$DEVNULL
1514 tail -f lock.log &
1515 tailpid=$!
1516 exec 2>&9 9>&-
1517 fi
1518 # if test ! -f _locktst.alive
1519 # then
1520 # echo >_locktst.alive
1521 # echo "Waiting for kernel-locking tests to finish..."
1522 # fi
1523 sleep 4
1524 done
1525 exec 9>&2 2>$DEVNULL
1526 test ! -z "$tailpid" && kill $tailpid && echo "" && echo ""
1527 tailpid=""
1528 wait # wait now, to prevent a notification message afterward
1529 exec 2>&9 9>&-
1530 echo "Collecting results from kernel-locking tests"
1531 sed -e '/^Kernel-locking tests completed./,$ d' <_locktst.rrr >>$ACONF
1532 set dummy *core*
1533 if test -f $2 -a $nocore = yes
1534 then
1535 echo "Removing core file (probably from the locking tests)"
1536 $RM *core*
1537 fi
1538
1539 echo "/* autoconf completed */" >>$ACONF
1540
1541 $RM -r $OLDTESTDIRS $OLDTESTDIRS 2>$DEVNULL
1542 $RM _autotst* _locktst* lookfor grepfor 2>$DEVNULL
1543
1544 echo =============================autoconf.h===================================
1545 cat $ACONF
1546 echo ==========================================================================