From: Ben Gras Date: Mon, 25 Aug 2014 16:35:59 +0000 (+0200) Subject: INIT died problem / build system robustness X-Git-Tag: v3.3.0~50 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zlib_tech.html?a=commitdiff_plain;h=refs%2Fchanges%2F77%2F2777%2F2;p=minix.git INIT died problem / build system robustness Changes provoked by debugging / making 'PM: INIT died' error debuggable. This was caused (in one instance) by a missing /dev/console (and everything else) on the boot time ramdisk. . sanity-check against this case by checking for console . PM: print init stacktrace and exit status when init dies . eliminate some explicitly invoked ${MAKE}s and a rm -rf in Makefiles, causing race conditions; use explicit ordering (.WAIT) instead, moving some of the burden of dependencies of partial builds to the user. On the plus side, generate ramdisk just once. . make mkfs.mfs fail as soon as it sees an error missing file in the proto file. - except for EACCES on minix native for the mfs test. also fix some fmt warnings. . init: include debug info in executable Change-Id: I8eea4986a4f64ecaf223aff5da321d8b4f4a3fa4 --- diff --git a/Makefile b/Makefile index 502982b75..c3680458a 100644 --- a/Makefile +++ b/Makefile @@ -138,12 +138,13 @@ _SRC_TOP_OBJ_= # BUILD_${dir}=no, or that have no ${dir}/Makefile. # _SUBDIR= tools lib include gnu external crypto/external bin games -.if defined(__MINIX) -_SUBDIR+= minix -.endif # defined(__MINIX) _SUBDIR+= libexec sbin usr.bin _SUBDIR+= usr.sbin share sys etc tests compat _SUBDIR+= .WAIT rescue .WAIT distrib regress +.if defined(__MINIX) +# the minix subdir depends on some other things (e.g. lib/) +_SUBDIR+= .WAIT minix +.endif # defined(__MINIX) .for dir in ${_SUBDIR} .if "${dir}" == ".WAIT" \ diff --git a/minix/Makefile b/minix/Makefile index a2a3cbe4d..8705154ac 100644 --- a/minix/Makefile +++ b/minix/Makefile @@ -3,7 +3,6 @@ SUBDIR+= include .WAIT SUBDIR+= benchmarks SUBDIR+= bin SUBDIR+= commands -SUBDIR+= drivers SUBDIR+= fs SUBDIR+= kernel SUBDIR+= lib @@ -17,4 +16,7 @@ SUBDIR+= tests SUBDIR+= usr.bin SUBDIR+= usr.sbin +# BJG - build drivers last as the ramdisk depends on some other drivers +SUBDIR+= .WAIT drivers + .include diff --git a/minix/drivers/Makefile b/minix/drivers/Makefile index 748559813..328c1415c 100644 --- a/minix/drivers/Makefile +++ b/minix/drivers/Makefile @@ -20,6 +20,8 @@ SUBDIR+= vmm_guest SUBDIR+= bus SUBDIR+= tty SUBDIR+= hid -SUBDIR+= storage + +# BJG - build storage last as the ramdisk depends on some other things +SUBDIR+= .WAIT storage .include diff --git a/minix/drivers/storage/Makefile b/minix/drivers/storage/Makefile index 4597c2e39..da7307bc2 100644 --- a/minix/drivers/storage/Makefile +++ b/minix/drivers/storage/Makefile @@ -17,7 +17,9 @@ SUBDIR+= at_wini SUBDIR+= floppy .endif # ${MACHINE_ARCH} == "i386" -# memory driver must be last for ramdisk image -SUBDIR+= ramdisk .WAIT memory +# memory driver must be last for ramdisk image. +# Everything else must be done before ramdisk as it needs +# executables from other targets. +SUBDIR+= .WAIT ramdisk .WAIT memory .include diff --git a/minix/drivers/storage/memory/Makefile b/minix/drivers/storage/memory/Makefile index a782b53fa..860b5e79e 100644 --- a/minix/drivers/storage/memory/Makefile +++ b/minix/drivers/storage/memory/Makefile @@ -26,8 +26,9 @@ touch-genfiles: ${OBJCOPY} -Ibinary -B${MACHINE_CPU} -O${MACHINE_GNU_PLATFORM} $< $@ CLEANFILES+= ../ramdisk/image -../ramdisk/image: .PHONY - ${MAKE} -C ${RAMDISK_PATH} image +# BJG - don't invoke parallel Makes +#../ramdisk/image: .PHONY +# ${MAKE} -C ${RAMDISK_PATH} image CLEANFILES+= imgrd.mfs imgrd.mfs: ../ramdisk/image diff --git a/minix/drivers/storage/ramdisk/Makefile b/minix/drivers/storage/ramdisk/Makefile index 5edb62fea..89d3e855f 100644 --- a/minix/drivers/storage/ramdisk/Makefile +++ b/minix/drivers/storage/ramdisk/Makefile @@ -151,8 +151,9 @@ CLEANFILES += ${lib}.so.0 ${lib}.so.0:${PROGROOT}/lib/${lib}/${lib}.so.0 ${INSTALL} $> $@ -${PROGROOT}/lib/${lib}/${lib}.so.0: - ${MAKE} -C ${NETBSDSRCDIR}/lib/${lib} all +# BJG - Don't invoke parallel Makes +#${PROGROOT}/lib/${lib}/${lib}.so.0: +# ${MAKE} -C ${NETBSDSRCDIR}/lib/${lib} all .endfor .for lib in ${PROG_MINIXLIBS} @@ -161,8 +162,9 @@ CLEANFILES += ${lib}.so.0 ${lib}.so.0:${PROGROOT}/minix/lib/${lib}/${lib}.so.0 ${INSTALL} $> $@ -${PROGROOT}/minix/lib/${lib}/${lib}.so.0: - ${MAKE} -C ${NETBSDSRCDIR}/minix/lib/${lib} all +# BJG - Don't invoke parallel Makes +#${PROGROOT}/minix/lib/${lib}/${lib}.so.0: +# ${MAKE} -C ${NETBSDSRCDIR}/minix/lib/${lib} all .endfor # Generate dependencies rules for binaries @@ -170,8 +172,9 @@ ${PROGROOT}/minix/lib/${lib}/${lib}.so.0: ${prog}: ${PROGROOT}/${dir.${prog}}/${prog} ${INSTALL} $> $@ -${PROGROOT}/${dir.${prog}}/${prog}: - ${MAKE} -C ${NETBSDSRCDIR}/${dir.${prog}} all +# BJG - don't invoke parallel Makes +#${PROGROOT}/${dir.${prog}}/${prog}: +# ${MAKE} -C ${NETBSDSRCDIR}/${dir.${prog}} all .endfor # prog realall image: proto.gen ${ETC:C/^/etc\//} ${EXTRA} \ @@ -182,7 +185,6 @@ realall image: proto.gen ${ETC:C/^/etc\//} ${EXTRA} \ etc/pwd.db etc/spwd.db etc/passwd: etc/master.passwd etc/master.passwd: ${NETBSDSRCDIR}/etc/master.passwd - rm -rf ${.OBJDIR}/etc/ mkdir -p ${.OBJDIR}/etc ${INSTALL} $> $@ ${TOOL_PWD_MKDB} -V 0 -p -d . etc/master.passwd @@ -201,8 +203,9 @@ proto.dev.mtree: proto.dev: proto.dev.mtree etc/pwd.db etc/spwd.db etc/passwd etc/group ${TOOL_MTREE} -f ${.TARGET}.mtree -N ${.OBJDIR}/etc -C -K device | \ ${TOOL_TOPROTO} | ${TOOL_SED} -e '1,4d' | \ - ${TOOL_SED} -e '$$d' |${TOOL_SED} -e '$$d' > ${.TARGET}.tmp && \ - mv ${.TARGET}.tmp ${.TARGET} + ${TOOL_SED} -e '$$d' |${TOOL_SED} -e '$$d' > ${.TARGET}.tmp + grep console ${.TARGET}.tmp # sanity check; is there a console entry? + mv ${.TARGET}.tmp ${.TARGET} proto.gen: ${PROTO} ${PROTO_FILES} proto.dev ${PROGRAMS} ${STRIP} ${PROGRAMS} diff --git a/minix/servers/pm/forkexit.c b/minix/servers/pm/forkexit.c index a221d3c9f..218fff5e0 100644 --- a/minix/servers/pm/forkexit.c +++ b/minix/servers/pm/forkexit.c @@ -314,7 +314,8 @@ int dump_core; /* flag indicating whether to dump core */ vm_notify_sig_wrapper(rmp->mp_endpoint); if (proc_nr_e == INIT_PROC_NR) { - printf("PM: INIT died\n"); + printf("PM: INIT died with exit status %d; showing stacktrace\n", exit_status); + sys_diagctl_stacktrace(proc_nr_e); return; } if (proc_nr_e == VFS_PROC_NR) diff --git a/minix/usr.sbin/mkfs.mfs/mkfs.c b/minix/usr.sbin/mkfs.mfs/mkfs.c index b1037ad7f..92e98b96b 100644 --- a/minix/usr.sbin/mkfs.mfs/mkfs.c +++ b/minix/usr.sbin/mkfs.mfs/mkfs.c @@ -308,7 +308,7 @@ main(int argc, char *argv[]) } else { if(bblocks < strtol(token[0], (char **) NULL, 10)) { errx(1, "%s: number of blocks given as parameter(%d)" - " is too small for given proto file(%d).", + " is too small for given proto file(%ld).", argv[optind], bblocks, strtol(token[0], (char **) NULL, 10)); }; @@ -432,7 +432,7 @@ main(int argc, char *argv[]) (int)next_inode-1, next_zone); } - if(insertmode) printf("%ld\n", written_fs_size); + if(insertmode) printf("%llu\n", written_fs_size); return(0); @@ -502,7 +502,15 @@ sizeup_dir(struct fs_size * fssize) fssize->zonecount++; /* Symlink contents is always stored a block */ } else { if ((f = fopen(token[4], "rb")) == NULL) { - warn("dynamic sizing: can't open %s", token[4]); +/* on minix natively, allow EACCES and skip the entry. + * while crossbuilding, always fail on error. + */ +#ifdef __minix + if(errno == EACCES) + warn("dynamic sizing: can't open %s", token[4]); + else +#endif + err(1, "dynamic sizing: can't open %s", token[4]); } else if (fseek(f, 0, SEEK_END) < 0) { pexit("dynamic size detection failed: seek to end of %s", token[4]); @@ -805,8 +813,15 @@ eat_dir(ino_t parent) } else { /* Regular file. Go read it. */ if ((f = open(token[4], O_RDONLY)) < 0) { - fprintf(stderr, "%s: Can't open %s: %s\n", - progname, token[4], strerror(errno)); +/* on minix natively, allow EACCES and skip the entry. + * while crossbuilding, always fail on error. + */ +#ifdef __minix + if(errno == EACCES) + warn("Can't open %s", token[4]); + else +#endif + err(1, "Can't open %s", token[4]); } else { eat_file(n, f); } @@ -1103,7 +1118,7 @@ alloc_inode(int mode, int usrid, int grpid) num = next_inode++; if (num > nrinodes) { - pexit("File system does not have enough inodes (only %d)", nrinodes); + pexit("File system does not have enough inodes (only %llu)", nrinodes); } b = ((num - 1) / inodes_per_block) + inode_offset; off = (num - 1) % inodes_per_block; @@ -1114,7 +1129,7 @@ alloc_inode(int mode, int usrid, int grpid) get_block(b, inodes); if (inodes[off].i_mode) { - pexit("allocation new inode %d with non-zero mode - this cannot happen", + pexit("allocation new inode %llu with non-zero mode - this cannot happen", num); } inodes[off].i_mode = mode; @@ -1614,7 +1629,7 @@ mkfs_write(void * buf, size_t count) if(w < 0) err(1, "mkfs_write: write failed"); if(w != count) - errx(1, "mkfs_write: short write: %ld != %ld", w, count); + errx(1, "mkfs_write: short write: %zd != %zu", w, count); /* Check if this has made the FS any bigger; count bytes after offset */ fssize = mkfs_seek(0, SEEK_CUR); diff --git a/sbin/init/Makefile b/sbin/init/Makefile index 602b5e07a..03f4fdd96 100644 --- a/sbin/init/Makefile +++ b/sbin/init/Makefile @@ -7,6 +7,12 @@ DPADD= ${LIBUTIL} LDADD= -lutil CPPFLAGS+= -DMFS_DEV_IF_NO_CONSOLE -DSUPPORT_UTMP -DSUPPORT_UTMPX +#.if defined(__MINIX) +# BJG - by default produce line numbers in case init exits without producing +# output +DBG=-g +#.endif + .ifdef INIT_CHROOT CPPFLAGS+= -DCHROOT .elifdef SMALLPROG