From da4e1efd8c17ddc4b5e86c031f95938424f3bd9b Mon Sep 17 00:00:00 2001 From: dschmenk Date: Wed, 28 Aug 2013 15:13:01 -0700 Subject: [PATCH] Fix early exit from Apple II connect and install permissions --- src/A2PI.PO | Bin 143360 -> 143360 bytes src/a2tty.c | 106 +++++++++++++++++++++++++++++++++++++++++++++++++ src/install.sh | 1 + 3 files changed, 107 insertions(+) create mode 100755 src/a2tty.c diff --git a/src/A2PI.PO b/src/A2PI.PO index cce3aa2e8a9f1af42d66c4f2881056460d2b11bc..a9be4013c3a6c2dfdd9187ba8012eee91a6b5764 100755 GIT binary patch delta 1117 zcmZWoU2NM_6i)2MPNx;6rLc@{!$VAJ#P$F}U3oy_F%uD!_>n4vG{asZgbaKiv9DgT%dZa#r)xbUOK&}q z%~htP+%IM6YATx}Xyxx)!kbH5La=sbV%bi0l_sU>nX*>6nX8gGiF3u=kkmASgJ}^#y#f8hnRe7wBDdPtIA}M zRct|q6oHh0lz~))&c@T;B6wI*fqnQPuD473#~JNey*0+}LS?A4F;>g#->Wv-vx}KD z?(R!ez&tJ;?HYEy+e~_P@6Pa5e{v34XnZN zIw(=@mgx7QLQywBcVk%XGqYV2%r?bN7J=IoBQ)6ne_|byYtT*BfiwROuYvqxs7Dq< zC*_NwUYuV*lE2Vx#W;eja)$dzR0dHw`|7XgRQ zylNR*hep#oH#{zL+YkTT;PKMwFEbvext$)&@Tw~_y#V@w2PlK6{5vI#{PzCD?Z+L$ z(dIe%E;ZoWiWU~ZeBRB+T}~x{MM}Cd;RR4WwJw+uhj22!)(uSUTIAxO*svmG1r*ZD zOPyHj$jjJ^bbkw(gY>-?QU&QTMAbQHtAg3Cd~OwK4lG@@^sY1O2~5u;OXdea2_cG! z)Om|`^T{HZ+uj&M42ZF06%z)T5IfEU8DtVA@H_iC9lBKmf{eNfLAIB-0{ka6G00da z=5WCd`F0m%3HBgTgWEN*;A>3SfNN}cbpW)8epJ4|Wux43RJMJ~;O;tu#b*mkpqqsn z=$qzq+KB#CzbxGM!tm#rhrIS{U+Kr>i)Xtj)--)RFjh@7&;)}(nX+A=l^r;xRORLz8J2d_T zdwuamqVF-nxZ_b_@y{;d@@r=&?sc)Pw~DjU)of~PEOl__L+T4VW&goWQ9CF81-$HB Ag8%>k delta 1001 zcmZWo-EY%Y6nE^#b}KrisEkZ2V7{bAzym{SyZ<25qD?}3=))wu^(Eq=Q36{(=gYC*KpMmV=C+rzBmbIwdDT!2iqv=r+T6Dp`5tYqMNo9*b zz3C%^MeWAIw$?{LxCXPXT>s1BY@ZOi0@l4W|`j$UbQa28bSTf52n#y%XdgH{n52d)?DcLF|lH4Ja>sMvr) z!VbvpYN6j&EuUSYKsW!3iin05|f+Hz8`3pt%fgi+Pr{tOSgg8DDdj0@2bqTFE$=aRimfE!`StX1|(qz+DYy zL^1^#iBy5@Q(U?!#zeGaM +#define RUN 0 +#define STOP 1 + +int a2cin(int fd, char cin) +{ + unsigned char cinpkt[2]; + cinpkt[0] = 0x96; // keyboard input + cinpkt[1] = cin; + return (write(fd, cinpkt, 2)); +} +int main(int argc, char **argv) +{ + struct termios oldtio,newtio; + fd_set readset, openset; + unsigned char iopkt[2]; + int state = RUN, echochr = 0; + int pifd = a2open(argc > 1 ? argv[1] : "127.0.0.1"); + if (pifd < 0) + { + perror("Unable to connect to Apple II Pi"); + exit(EXIT_FAILURE); + } + /* + * Are we running interactively? + */ + if (isatty(STDIN_FILENO)) + { + /* + * Change input setting to work better as a terminal. + */ + tcgetattr(STDIN_FILENO, &oldtio); /* save current port settings */ + bzero(&newtio, sizeof(newtio)); + newtio.c_cflag = /*BAUDRATE | CRTSCTS |*/ CS8 | CLOCAL | CREAD; + newtio.c_iflag = IGNPAR; + newtio.c_oflag = 0; + newtio.c_lflag = 0; /* set input mode (non-canonical, no echo,...) */ + newtio.c_cc[VTIME] = 0; /* inter-character timer unused */ + newtio.c_cc[VMIN] = 1; /* blocking read until 1 char received */ + tcsetattr(STDIN_FILENO, TCSANOW, &newtio); + /* + * Prepare for select(). + */ + echofd = 0; + FD_ZERO(&openset); + FD_SET(pifd, &openset); + FD_SET(STDIN_FILENO, &openset); + /* + * Event loop + */ + while (state == RUN) + { + memcpy(&readset, &openset, sizeof(openset)); + if (select(pifd + 1, &readset, NULL, NULL, NULL) > 0) + { + /* + * Apple II character output. + */ + if (FD_ISSET(pifd, &readset)) + { + if (read(pifd, iopkt, 2) == 2) + { + /* + * Acknowledgement. + */ + } + else + /* + * Some kind of client/server error. + */ + state = STOP; + } + if (FD_ISSET(STDIN_FILENO, &readset)) + { + if (read(STDIN_FILENO, iopkt, 1) == 1) + { + /* + * Chain input character to child. + */ + } + else + /* + * stdin probably closed. + */ + state = STOP; + } + if (FD_ISSET(fdecho, &readset)) + { + if (read(STDIN_FILENO, iopkt, 1) == 1) + { + /* + * Send stdout as cin to Apple II. + */ + if (opkt[0] == 0x04) // Ctrl-D + state = STOP; + a2cin(pifd, iopkt[0] | 0x80); + } + } + } + } + } + tcsetattr(STDIN_FILENO, TCSANOW, &oldtio); + a2close(pifd); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/src/install.sh b/src/install.sh index 5b6449b..f009f29 100755 --- a/src/install.sh +++ b/src/install.sh @@ -22,5 +22,6 @@ if [ -f /etc/rc.local ] ; then if ! grep a2pid /etc/rc.local > /dev/null ; then mv /etc/rc.local /etc/rc.local.bak sed -e '/^exit/i\# Start Apple II Pi' -e '/^exit/i\/usr/local/bin/a2serclk' -e '/^exit/i\/usr/local/bin/a2pid --daemon' /etc/rc.local.bak > /etc/rc.local + chmod +x /etc/rc.local fi fi \ No newline at end of file