1
0
mirror of https://github.com/Interlisp/maiko.git synced 2026-03-27 10:20:37 +00:00

Compare commits

...

8 Commits

Author SHA1 Message Date
Nick Briggs
bb0b011f90 Remove debugging printf(.) that was left in unixcomm.c 2022-01-03 22:48:23 -08:00
Nick Briggs
6bccbfbcf3 Clean up issues in Unix_handlecomm preventing clean process exit (#413)
When Medley closes a stream open to a process it uses a "unixcomm"
command (3) which should close() the communication channel open with
the process and give it a chance to handle that and exit cleanly
before using a SIGKILL on it.  We can't determine apriori whether the
process is going to cooperate, so we're stuck trying for up to 0.1s
(arbitrary choice!)  waiting for the process to exit, then it gets a
SIGKILL, and we wait up to 0.1s again to see that it really exited.
2021-12-23 10:46:37 -08:00
Nick Briggs
e3af3b03b9 Remove unused "readsock" field from Unix job table. 2021-12-21 21:33:03 -08:00
Nick Briggs
880747f2dc Add m68k to directories that .gitignore ignores for build artifacts 2021-12-09 21:15:48 -08:00
Nick Briggs
c7fd28a438 Removed unused (and unimplemented) stackcheck() and stackoverflow() routines
These routines were stubs that did nothing and were not called from anywhere
so lack value in even providing a template or hook for a fuller implementation.
Also note that "stackcheck" conflicts with a predefined symbol in some runtime
libraries.  Should these be implemented in the future they should use a
maiko-specific name.
2021-12-09 14:57:45 -08:00
Nick Briggs
e1efc860c4 Prefer typedef over #define where it can be used for type definitions 2021-12-09 14:48:52 -08:00
Nick Briggs
26fe840edf Convert "mkvdate" into a shell script instead of compiled C code (#411)
For all	systems other than DOS, use a simple shell script to create
the vdate.c (contains version date) that goes into every build.
2021-12-09 12:36:12 -08:00
Nick Briggs
212a0fa9c6 Add some support for cross-compilation to MC68000 AmigaOS (#412)
Add m68k to recognized CPUs (machinetype)
Add amigaos to recognized operating systems (osversion)
Add ability to override "config.guess" output w/ LDEARCH= to osversion
Add platform.h clauses to recognize AmigaOS 3 using gcc to cross-compile
2021-12-08 12:03:04 -08:00
11 changed files with 72 additions and 132 deletions

2
.gitignore vendored
View File

@@ -6,6 +6,8 @@
.DS_Store .DS_Store
# build directories # build directories
build/** build/**
*.m68k-x/**
*.m68k/**
*.386-x/** *.386-x/**
*.386/** *.386/**
*.ppc-x/** *.ppc-x/**

View File

@@ -390,7 +390,7 @@ SET(MAIKO_HDRS
) )
ADD_CUSTOM_TARGET(gen-vdate ADD_CUSTOM_TARGET(gen-vdate
COMMAND mkvdate > vdate.c COMMAND ../bin/mkvdate > vdate.c
BYPRODUCTS vdate.c BYPRODUCTS vdate.c
) )
@@ -422,10 +422,6 @@ IF(MAIKO_DISPLAY_X11)
TARGET_LINK_LIBRARIES(ldex ${MAIKO_LIBRARIES} ${MAIKO_DISPLAY_X11_LIBRARIES}) TARGET_LINK_LIBRARIES(ldex ${MAIKO_LIBRARIES} ${MAIKO_DISPLAY_X11_LIBRARIES})
ENDIF() ENDIF()
ADD_EXECUTABLE(mkvdate src/mkvdate.c)
TARGET_COMPILE_DEFINITIONS(mkvdate PUBLIC ${MAIKO_DEFINITIONS})
TARGET_INCLUDE_DIRECTORIES(mkvdate PUBLIC inc)
ADD_EXECUTABLE(setsout src/setsout.c src/byteswap.c) ADD_EXECUTABLE(setsout src/setsout.c src/byteswap.c)
TARGET_COMPILE_DEFINITIONS(setsout PUBLIC ${MAIKO_DEFINITIONS}) TARGET_COMPILE_DEFINITIONS(setsout PUBLIC ${MAIKO_DEFINITIONS})
TARGET_INCLUDE_DIRECTORIES(setsout PUBLIC inc) TARGET_INCLUDE_DIRECTORIES(setsout PUBLIC inc)

View File

@@ -12,6 +12,7 @@
os=${LDEARCH:-`./config.guess`} os=${LDEARCH:-`./config.guess`}
# o/s switch block # o/s switch block
case "$os" in case "$os" in
m68k-*) echo m68k ;;
sparc-*) echo sparc ;; sparc-*) echo sparc ;;
alpha-*) echo alpha ;; alpha-*) echo alpha ;;
i*86-*-*) echo 386 ;; i*86-*-*) echo 386 ;;

View File

@@ -160,9 +160,6 @@ $(OSARCHDIR)$(LDENAME): $(LIBFILES) $(EXTFILES) $(OBJECTDIR)vdate.o
$(OSARCHDIR)ldeether: $(OBJECTDIR)ldeether.o $(DLPIFILES) $(OSARCHDIR)ldeether: $(OBJECTDIR)ldeether.o $(DLPIFILES)
$(CC) $(OBJECTDIR)ldeether.o $(DLPIFILES) $(LDEETHERLDFLAGS) -o $(OSARCHDIR)ldeether $(CC) $(OBJECTDIR)ldeether.o $(DLPIFILES) $(LDEETHERLDFLAGS) -o $(OSARCHDIR)ldeether
$(OSARCHDIR)mkvdate: $(OBJECTDIR)mkvdate.o $(REQUIRED-INCS)
$(CC) $(OBJECTDIR)mkvdate.o $(LDFLAGS) -o $(OSARCHDIR)mkvdate
$(OSARCHDIR)tstsout: $(OBJECTDIR)tstsout.o $(BYTESWAPFILES) $(REQUIRED-INCS) $(OSARCHDIR)tstsout: $(OBJECTDIR)tstsout.o $(BYTESWAPFILES) $(REQUIRED-INCS)
$(CC) $(OBJECTDIR)tstsout.o $(BYTESWAPFILES) $(LDFLAGS) -lc -lm -o $(OSARCHDIR)tstsout $(CC) $(OBJECTDIR)tstsout.o $(BYTESWAPFILES) $(LDFLAGS) -lc -lm -o $(OSARCHDIR)tstsout
@@ -171,9 +168,9 @@ $(OSARCHDIR)setsout: $(OBJECTDIR)setsout.o $(REQUIRED-INCS)
#### Component files ###################################################### #### Component files ######################################################
$(OBJECTDIR)vdate.o: $(LIBFILES) $(EXTFILES) $(OSARCHDIR)mkvdate $(OBJECTDIR)vdate.o: $(LIBFILES) $(EXTFILES) mkvdate
$(RM) $(OBJECTDIR)vdate.c $(RM) $(OBJECTDIR)vdate.c
$(OSARCHDIR)mkvdate > $(OBJECTDIR)vdate.c $(BINDIR)mkvdate > $(OBJECTDIR)vdate.c
$(CC) $(RFLAGS) $(OBJECTDIR)vdate.c -o $(OBJECTDIR)vdate.o $(CC) $(RFLAGS) $(OBJECTDIR)vdate.c -o $(OBJECTDIR)vdate.o
$(OBJECTDIR)tstsout.o: $(SRCDIR)tstsout.c $(REQUIRED-INCS) \ $(OBJECTDIR)tstsout.o: $(SRCDIR)tstsout.c $(REQUIRED-INCS) \
@@ -197,9 +194,6 @@ $(OBJECTDIR)ldeboot.o: $(SRCDIR)ldeboot.c $(REQUIRED-INCS) \
$(OBJECTDIR)ldeether.o: $(SRCDIR)ldeether.c $(REQUIRED-INCS) $(OBJECTDIR)ldeether.o: $(SRCDIR)ldeether.c $(REQUIRED-INCS)
$(CC) $(RFLAGS) $(SRCDIR)ldeether.c -o $(OBJECTDIR)ldeether.o $(CC) $(RFLAGS) $(SRCDIR)ldeether.c -o $(OBJECTDIR)ldeether.o
$(OBJECTDIR)mkvdate.o: $(SRCDIR)mkvdate.c $(REQUIRED-INCS)
$(CC) $(RFLAGS) $(SRCDIR)mkvdate.c -o $(OBJECTDIR)mkvdate.o
$(OBJECTDIR)main.o: $(SRCDIR)main.c $(REQUIRED-INCS) \ $(OBJECTDIR)main.o: $(SRCDIR)main.c $(REQUIRED-INCS) \
$(INCDIR)lispemul.h $(INCDIR)dbprint.h \ $(INCDIR)lispemul.h $(INCDIR)dbprint.h \
$(INCDIR)emlglob.h $(INCDIR)address.h $(INCDIR)adr68k.h $(INCDIR)stack.h \ $(INCDIR)emlglob.h $(INCDIR)address.h $(INCDIR)adr68k.h $(INCDIR)stack.h \

5
bin/mkvdate Executable file
View File

@@ -0,0 +1,5 @@
#!/bin/sh
cat <<EOF
#include <time.h>
time_t MDate = $(date +%s);
EOF

View File

@@ -1,6 +1,7 @@
#!/bin/sh #!/bin/sh
os=`./config.guess` os=${LDEARCH:-`./config.guess`}
case "$os" in case "$os" in
m68k-*-amigaos) echo amigaos ;;
sparc-sun-sunos*) echo sunos4 ;; sparc-sun-sunos*) echo sunos4 ;;
sparc-sun-solaris1*) echo sunos4 ;; sparc-sun-solaris1*) echo sunos4 ;;
*-*-solaris2*) echo sunos5 ;; *-*-solaris2*) echo sunos5 ;;

View File

@@ -3,6 +3,4 @@
void stab(void); void stab(void);
void warn(const char *s); void warn(const char *s);
int error(const char *s); int error(const char *s);
int stackcheck(void);
void stackoverflow(void);
#endif #endif

View File

@@ -59,6 +59,13 @@
# define MAIKO_OS_DETECTED 1 # define MAIKO_OS_DETECTED 1
#endif #endif
#ifdef amigaos3
# define MAIKO_OS_AMIGAOS3 1
# define MAIKO_OS_NAME "AmigaOS 3"
# define MAIKO_OS_UNIX_LIKE 1
# define MAIKO_OS_DETECTED 1
#endif
/* __SVR4: Defined by clang, gcc, and Sun Studio. /* __SVR4: Defined by clang, gcc, and Sun Studio.
* __SVR4__ was only defined by Sun Studio. */ * __SVR4__ was only defined by Sun Studio. */
#if defined(__sun) && defined(__SVR4) #if defined(__sun) && defined(__SVR4)
@@ -137,6 +144,13 @@
# define MAIKO_ARCH_DETECTED 1 # define MAIKO_ARCH_DETECTED 1
#endif #endif
#ifdef __mc68000
# define MAIKO_ARCH_M68000 1
# define MAIKO_ARCH_NAME "Motorola68K"
# define MAIKO_ARCH_WORD_BITS 32
# define MAIKO_ARCH_DETECTED 1
#endif
/* Modern GNU C, Clang, Sun Studio provide __BYTE_ORDER__ /* Modern GNU C, Clang, Sun Studio provide __BYTE_ORDER__
* Older GNU C (ca. 4.0.1) provides __BIG_ENDIAN__/__LITTLE_ENDIAN__ * Older GNU C (ca. 4.0.1) provides __BIG_ENDIAN__/__LITTLE_ENDIAN__
*/ */

View File

@@ -187,8 +187,8 @@ error Must specify RELEASE to build Medley.
/* Set up defaults */ /* Set up defaults */
#define UNALIGNED_FETCH_OK #define UNALIGNED_FETCH_OK
#define UNSIGNED unsigned long typedef unsigned long UNSIGNED;
#define INT long typedef long INT;
@@ -237,9 +237,9 @@ typedef unsigned char u_char;
typedef unsigned long u_int; typedef unsigned long u_int;
typedef unsigned short u_short; typedef unsigned short u_short;
#undef UNALIGNED_FETCH_OK #undef UNALIGNED_FETCH_OK
#define USHORT unsigned typedef unsigned USHORT;
#else #else
#define USHORT unsigned short typedef unsigned short USHORT;
#endif /* DOS */ #endif /* DOS */
/****************************************************************/ /****************************************************************/

View File

@@ -141,39 +141,3 @@ uraidloop:
void warn(const char *s) void warn(const char *s)
{ printf("\nWARN: %s \n", s); } { printf("\nWARN: %s \n", s); }
/*****************************************************************
stackcheck
common sub-routine.
Not Implemented.
1.check Stack overflow.
(check CurrentStackPTR)
2.if overflow, return T (not 0).
Otherwise, return F (0).
******************************************************************/
int stackcheck() {
#ifdef TRACE2
printf("TRACE:stackcheck()\n");
#endif
return (0);
}
/*****************************************************************
stackoverflow
common sub-routine.
Not Implemented.
1.error handling of stack overflow.
******************************************************************/
void stackoverflow() {
#ifdef TRACE2
printf("TRACE:stackoverflow()\n");
#endif
printf("stackoverflow \n");
}

View File

@@ -89,7 +89,6 @@ enum UJTYPE {
/* These are indexed by WRITE socket# */ /* These are indexed by WRITE socket# */
struct unixjob { struct unixjob {
char *pathname; /* used by Lisp direct socket access subr */ char *pathname; /* used by Lisp direct socket access subr */
int readsock; /* Socket to READ from for this job. */
int PID; /* process ID associated with this slot */ int PID; /* process ID associated with this slot */
int status; /* status returned by subprocess (not shell) */ int status; /* status returned by subprocess (not shell) */
enum UJTYPE type; enum UJTYPE type;
@@ -284,7 +283,6 @@ int FindUnixPipes(void) {
cleareduj.status = -1; cleareduj.status = -1;
cleareduj.pathname = NULL; cleareduj.pathname = NULL;
cleareduj.PID = 0; cleareduj.PID = 0;
cleareduj.readsock = 0;
cleareduj.type = UJUNUSED; cleareduj.type = UJUNUSED;
for (int i = 0; i < NPROCS; i++) UJ[i] = cleareduj; for (int i = 0; i < NPROCS; i++) UJ[i] = cleareduj;
@@ -374,7 +372,7 @@ LispPTR Unix_handlecomm(LispPTR *args) {
/* Get command */ /* Get command */
N_GETNUMBER(args[0], command, bad); N_GETNUMBER(args[0], command, bad);
DBPRINT(("\nUnix_handlecomm: trying %d\n", command)); DBPRINT(("\nUnix_handlecomm: command %d\n", command));
switch (command) { switch (command) {
case 0: /* Fork pipe process */ case 0: /* Fork pipe process */
@@ -435,9 +433,9 @@ LispPTR Unix_handlecomm(LispPTR *args) {
UJ[PipeFD].type = UJPROCESS; UJ[PipeFD].type = UJPROCESS;
UJ[PipeFD].status = -1; UJ[PipeFD].status = -1;
UJ[PipeFD].PID = (d[1] << 8) | d[2] | (d[4] << 16) | (d[5] << 24); UJ[PipeFD].PID = (d[1] << 8) | d[2] | (d[4] << 16) | (d[5] << 24);
UJ[PipeFD].readsock = 0;
close(sockFD); close(sockFD);
unlink(PipeName); unlink(PipeName);
DBPRINT(("New process: slot/PipeFD %d PID %d\n", PipeFD, UJ[PipeFD].PID));
return (GetSmallp(PipeFD)); return (GetSmallp(PipeFD));
} else { } else {
DBPRINT(("Fork request failed.")); DBPRINT(("Fork request failed."));
@@ -482,17 +480,11 @@ LispPTR Unix_handlecomm(LispPTR *args) {
N_GETNUMBER(args[1], slot, bad); /* Get job # */ N_GETNUMBER(args[1], slot, bad); /* Get job # */
if (!valid_slot(slot)) return (NIL); /* No fd open; punt the read */ if (!valid_slot(slot)) return (NIL); /* No fd open; punt the read */
if (UJ[slot].readsock)
sock = UJ[slot].readsock;
else
sock = slot;
switch (UJ[slot].type) { switch (UJ[slot].type) {
case UJPROCESS: case UJPROCESS:
case UJSHELL: case UJSHELL:
case UJSOSTREAM: case UJSOSTREAM:
TIMEOUT(dest = read(sock, buf, 1)); TIMEOUT(dest = read(slot, buf, 1));
if (dest > 0) return (GetSmallp(buf[0])); if (dest > 0) return (GetSmallp(buf[0]));
/* Something's amiss; check our process status */ /* Something's amiss; check our process status */
wait_for_comm_processes(); wait_for_comm_processes();
@@ -523,66 +515,46 @@ LispPTR Unix_handlecomm(LispPTR *args) {
N_GETNUMBER(args[1], slot, bad); N_GETNUMBER(args[1], slot, bad);
DBPRINT(("Killing process in slot %d.\n", slot)); DBPRINT(("Terminating process in slot %d.\n", slot));
if (!valid_slot(slot)) return (ATOM_T);
if (valid_slot(slot)) switch (UJ[slot].type) { /* in all cases we need to close() the file descriptor */
case UJSHELL: close(slot);
case UJPROCESS:
/* First check to see it hasn't already died */
if (UJ[slot].status == -1) {
/* Kill the job */
kill(UJ[slot].PID, SIGKILL);
for (int i = 0; i < 10; i++) {
/* Waiting for the process to exit is possibly risky.
Sending SIGKILL is always supposed to kill
a process, but on very rare occurrences this doesn't
happen because of a Unix kernel bug, usually a user-
written device driver which hasn't been fully
debugged. So we time it out just be safe. */
if (UJ[slot].status != -1) break;
wait_for_comm_processes();
usleep(10);
}
}
break;
default: break;
}
else
return (ATOM_T);
switch (UJ[slot].type) { switch (UJ[slot].type) {
case UJUNUSED: case UJSHELL:
break; case UJPROCESS:
/* wait for up to 0.1s for it to exit on its own after the close() */
case UJSHELL: for (int i = 0; i < 10; i++) {
DBPRINT(("Kill 3 closing shell desc %d.\n", slot)); wait_for_comm_processes();
close(slot); if (UJ[slot].status != -1) break;
break; usleep(10000);
}
case UJPROCESS: /* check again before we terminate it */
DBPRINT(("Kill 3 closing process desc %d.\n", slot)); if (UJ[slot].status != -1) break;
close(slot); kill(UJ[slot].PID, SIGKILL);
if (UJ[slot].readsock) close(UJ[slot].readsock); for (int i = 0; i < 10; i++) {
break; /* Waiting for the process to exit is possibly risky.
Sending SIGKILL is always supposed to kill
case UJSOSTREAM: a process, but on very rare occurrences this doesn't
DBPRINT(("Kill 3 closing stream socket desc %d.\n", slot)); happen because of a Unix kernel bug, usually a user-
close(slot); written device driver which hasn't been fully
break; debugged. So we time it out just be safe. */
wait_for_comm_processes();
case UJSOCKET: usleep(10000);
DBPRINT(("Kill 3 closing raw socket desc %d.\n", slot)); if (UJ[slot].status != -1) break;
close(slot); }
break;
case UJSOCKET:
if (UJ[slot].pathname) {
DBPRINT(("Unlinking %s\n", UJ[slot].pathname)); DBPRINT(("Unlinking %s\n", UJ[slot].pathname));
if (UJ[slot].pathname) { if (unlink(UJ[slot].pathname) < 0) perror("Kill 3 unlink");
if (unlink(UJ[slot].pathname) < 0) perror("Kill 3 unlink"); free(UJ[slot].pathname);
free(UJ[slot].pathname); UJ[slot].pathname = NULL;
UJ[slot].pathname = NULL; }
} break;
break; default: break;
} }
UJ[slot].type = UJUNUSED; UJ[slot].type = UJUNUSED;
UJ[slot].readsock = UJ[slot].PID = 0; UJ[slot].PID = 0;
UJ[slot].pathname = NULL; UJ[slot].pathname = NULL;
/* If status available, return it, otherwise T */ /* If status available, return it, otherwise T */
@@ -674,8 +646,6 @@ LispPTR Unix_handlecomm(LispPTR *args) {
case UJPROCESS: case UJPROCESS:
DBPRINT(("Kill 5 closing process desc %d.\n", dest)); DBPRINT(("Kill 5 closing process desc %d.\n", dest));
close(dest); close(dest);
if (UJ[dest].readsock) close(UJ[dest].readsock);
UJ[dest].readsock = 0;
break; break;
case UJSOCKET: case UJSOCKET:
@@ -696,7 +666,7 @@ LispPTR Unix_handlecomm(LispPTR *args) {
} }
UJ[dest].type = UJUNUSED; UJ[dest].type = UJUNUSED;
UJ[dest].readsock = UJ[dest].PID = 0; UJ[dest].PID = 0;
return (ATOM_T); return (ATOM_T);
/* break; */ /* break; */
@@ -729,18 +699,13 @@ LispPTR Unix_handlecomm(LispPTR *args) {
N_GETNUMBER(args[1], slot, bad); /* Get job # */ N_GETNUMBER(args[1], slot, bad); /* Get job # */
if (!valid_slot(slot)) return (NIL); /* No fd open; punt the read */ if (!valid_slot(slot)) return (NIL); /* No fd open; punt the read */
if (UJ[slot].readsock)
sock = UJ[slot].readsock;
else
sock = slot;
bufp = (Addr68k_from_LADDR(args[2])); /* User buffer */ bufp = (Addr68k_from_LADDR(args[2])); /* User buffer */
DBPRINT(("Read buffer slot %d, type is %d\n", slot, UJ[slot].type)); DBPRINT(("Read buffer slot %d, type is %d\n", slot, UJ[slot].type));
switch (UJ[slot].type) { switch (UJ[slot].type) {
case UJSHELL: case UJSHELL:
case UJPROCESS: case UJPROCESS:
case UJSOSTREAM: dest = read(sock, bufp, 512); case UJSOSTREAM: dest = read(slot, bufp, 512);
#ifdef BYTESWAP #ifdef BYTESWAP
word_swap_page(bufp, 128); word_swap_page(bufp, 128);
#endif /* BYTESWAP */ #endif /* BYTESWAP */