Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!cbosgd!ihnp4!occrsh!uokmax!rmtodd From: rmtodd@uokmax.UUCP Newsgroups: comp.os.minix Subject: Re: standard I/O and exit/_exit Message-ID: <622@uokmax.UUCP> Date: Fri, 10-Jul-87 22:51:06 EDT Article-I.D.: uokmax.622 Posted: Fri Jul 10 22:51:06 1987 Date-Received: Sun, 12-Jul-87 07:37:57 EDT References: <3118@felix.UUCP> <2352@hoptoad.uucp> <3169@felix.UUCP> <374@nikhefh.UUCP> <2827@ncoast.UUCP> Reply-To: rmtodd@uokmax.UUCP (Richard Michael Todd) Organization: University of Oklahoma, Norman Lines: 72 Summary: Here's how I did the exit/_exit mod to libc.a In article <2827@ncoast.UUCP> allbery@ncoast.UUCP (Brandon Allbery) writes: >+--------------- >| This module should be in the end of the library so the linker will encounter >| it always *after* the module containing the other initialisation of >| _cleanup. >+--------------- > >Won't work. The MINIX linker, unlike the UNIX one, always links everything, >not only the stuff that is referenced. (boo hiss!) Wait a minute. I've never had the MINIX assembler/linker link in any module that isn't referenced. Never. I've just set up my library to handle the exit/_exit functions correctly and it seems to work just fine, linking in only the stuff that needs to be linked in. The technique I used to set up the modules wasn't original with me--I saw it mentioned by someone named Doug Braun the last time the exit/_exit question arose in this newsgroup. Here's how it applies to MINIX and how I altered the library: 1. Cd to the library source dir (in my system /u/src/lib). 2. Edit printdat.c and include in it at the end the contents of cleanup.c , deleting the redundant #include. This way whenever the printdat module is loaded (which is whenever _io_table is referenced, i.e. any stdio file is referred to), the version of cleanup that flushes all stdio buffers is also linked in. You no longer need cleanup.c, so delete it. 3. Edit exit.c. Change the given exit() function so that it is now called _exit() (the new name for the direct system exit call). Add a new function exit() at the end that looks like this: ------------------------------------------------------------------------- PUBLIC int exit(status) int status; { _cleanup(); _exit(status); } ------------------------------------------------------------------------- 4. Create a new file 'fakecleanup.c' with this in it: int _cleanup() {} 5. Compile the changed and added files and rebuild the library. Note that the 'ar' commands 'r' (replace file) option is known to screw up the library's order (deleting the file from the old position and replacing it at the end. Yuk.) It's safest to recreate the library from scratch. What I do is cd to a subdirectory of /u/src/lib, unpack libc.a ("ar xv libc.a"), delete libc.a, move the *.s files I've just made from /u/src/lib to the subdirectory, and use a shell script to rebuild libc.a, which I then copy to /usr/lib. The shell script I use is included below; it shows a proper ordering of the files in the archive. Granted, it would be nice if 'ar' was fully functional, but this will do in the meantime. It takes about 3-4 minutes to rebuild the archive. ><> Has your cat been using MINIX a long time? :-) :-) (sorry, I couldn't resist...) --------------------------cut here for make.libc script ------------------ ar av libc.a getgrent.s getpwent.s crypt.s ar av libc.a fgets.s fprintf.s fputs.s fread.s freopen.s fclose.s ar av libc.a fopen.s fseek.s ftell.s fwrite.s gets.s scanf.s getc.s printdat.s ar av libc.a fflush.s setbuf.s sprintf.s doprintf.s putc.s ungetc.s strcmp.s ar av libc.a access.s chdir.s chmod.s chown.s chroot.s creat.s dup.s dup2.s ar av libc.a exec.s exit.s fakecleanup.s fork.s isatty.s fstat.s getegid.s getenv.s ar av libc.a geteuid.s getgid.s getpass.s close.s getuid.s ioctl.s kill.s ar av libc.a link.s lseek.s malloc.s brk.s brk2.s brksize.s mknod.s mktemp.s ar av libc.a getpid.s mount.s open.s perror.s pipe.s prints.s read.s setgid.s ar av libc.a setuid.s sleep.s alarm.s pause.s signal.s catchsig.s stat.s ar av libc.a stime.s strcat.s strcpy.s strlen.s strncat.s strncmp.s strncpy.s ar av libc.a sync.s time.s times.s umask.s umount.s unlink.s utime.s wait.s ar av libc.a stderr.s write.s syslib.s call.s atoi.s message.s sendrec.s ar av libc.a printk.s abort.s itoa.s stb.s abs.s atol.s ctype.s index.s bcopy.s ar av libc.a getutil.s rand.s rindex.s adi.s and.s cii.s cms.s cmu4.s com.s ar av libc.a csa2.s csb2.s cuu.s .dup.s dvi.s dvi4.s dvu.s dvu4.s exg.s fakfp.s ar av libc.a gto.s iaar.s ilar.s inn.s ior.s isar.s lar2.s loi.s mli.s mli4.s ar av libc.a ngi.s nop.s rck.s rmi.s rmi4.s rmu.s rmu4.s rol.s ror.s sar2.s ar av libc.a sbi.s set.s sli.s sri.s sti.s xor.s error.s unknown.s trp.s ar av libc.a setjmp.s