mirror of https://github.com/martanne/abduco
Compare commits
48 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
8c32909a15 | |
|
|
936602106a | |
|
|
bf6587209f | |
|
|
a75f3e7261 | |
|
|
2fc2671808 | |
|
|
c31eb7fad9 | |
|
|
6ff68d3d5a | |
|
|
62b6fce308 | |
|
|
042fa2255b | |
|
|
4a2c9ded43 | |
|
|
b47b66188f | |
|
|
4742cdcfca | |
|
|
58fee22707 | |
|
|
b2ada74d43 | |
|
|
5bf6b3178b | |
|
|
32a839d76a | |
|
|
cef844ec9d | |
|
|
7d0e9d91b6 | |
|
|
070e34b502 | |
|
|
fcac3b17ed | |
|
|
c3ea8f5bde | |
|
|
8f80aa8044 | |
|
|
c33ee37b43 | |
|
|
4c3e2c8c70 | |
|
|
0681dc8daf | |
|
|
35b3f61015 | |
|
|
5eb7317971 | |
|
|
884e3bb2ca | |
|
|
e48ea73ce0 | |
|
|
bb7e4e77f4 | |
|
|
17b386e93f | |
|
|
52d5c7d098 | |
|
|
fd34b98db7 | |
|
|
c901f2bbb8 | |
|
|
5a46912d62 | |
|
|
3e3308d4e3 | |
|
|
fdbda93131 | |
|
|
315338a572 | |
|
|
650f2ec348 | |
|
|
a1db9e2dae | |
|
|
66a17ed03d | |
|
|
1f1c02a3b0 | |
|
|
482237919b | |
|
|
7ee5e79cf5 | |
|
|
8964601fe1 | |
|
|
6375556846 | |
|
|
228b609361 | |
|
|
df780cf6cc |
|
|
@ -0,0 +1,11 @@
|
||||||
|
image: alpine/edge
|
||||||
|
sources:
|
||||||
|
- https://github.com/martanne/abduco
|
||||||
|
tasks:
|
||||||
|
- build: |
|
||||||
|
cd abduco
|
||||||
|
./configure
|
||||||
|
make
|
||||||
|
- test: |
|
||||||
|
cd abduco
|
||||||
|
./testsuite.sh
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
image: debian/stable
|
||||||
|
sources:
|
||||||
|
- https://github.com/martanne/abduco
|
||||||
|
tasks:
|
||||||
|
- build: |
|
||||||
|
cd abduco
|
||||||
|
./configure
|
||||||
|
make
|
||||||
|
- test: |
|
||||||
|
cd abduco
|
||||||
|
./testsuite.sh
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
image: freebsd/latest
|
||||||
|
sources:
|
||||||
|
- https://github.com/martanne/abduco
|
||||||
|
tasks:
|
||||||
|
- build: |
|
||||||
|
cd abduco
|
||||||
|
./configure
|
||||||
|
make
|
||||||
|
- test: |
|
||||||
|
cd abduco
|
||||||
|
./testsuite.sh
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
image: openbsd/latest
|
||||||
|
sources:
|
||||||
|
- https://github.com/martanne/abduco
|
||||||
|
tasks:
|
||||||
|
- build: |
|
||||||
|
cd abduco
|
||||||
|
./configure
|
||||||
|
make
|
||||||
|
- test: |
|
||||||
|
cd abduco
|
||||||
|
./testsuite.sh
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
name: Coverity Scan
|
||||||
|
|
||||||
|
env:
|
||||||
|
PROJECT: abduco
|
||||||
|
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: '0 0 * * 0' # once a week
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
scan:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Download Coverity Build Tool
|
||||||
|
run: |
|
||||||
|
wget -q https://scan.coverity.com/download/cxx/linux64 --post-data "token=$TOKEN&project=martanne/${PROJECT}" -O cov-analysis-linux64.tar.gz
|
||||||
|
mkdir cov-analysis-linux64
|
||||||
|
tar xzf cov-analysis-linux64.tar.gz --strip 1 -C cov-analysis-linux64
|
||||||
|
env:
|
||||||
|
TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
|
||||||
|
|
||||||
|
- name: Configure
|
||||||
|
run: ./configure
|
||||||
|
|
||||||
|
- name: Build with cov-build
|
||||||
|
run: |
|
||||||
|
export PATH=$(pwd)/cov-analysis-linux64/bin:$PATH
|
||||||
|
cov-build --dir cov-int make
|
||||||
|
|
||||||
|
- name: Submit the result to Coverity Scan
|
||||||
|
run: |
|
||||||
|
tar czvf ${PROJECT}.tgz cov-int
|
||||||
|
curl \
|
||||||
|
--form project=martanne/${PROJECT} \
|
||||||
|
--form token=$TOKEN \
|
||||||
|
--form email=mat@brain-dump.org \
|
||||||
|
--form file=@${PROJECT}.tgz \
|
||||||
|
--form version=trunk \
|
||||||
|
--form description="`./${PROJECT} -v`" \
|
||||||
|
https://scan.coverity.com/builds?project=martanne/${PROJECT}
|
||||||
|
env:
|
||||||
|
TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
name: macOS
|
||||||
|
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os:
|
||||||
|
- macos-10.15
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
steps:
|
||||||
|
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: |
|
||||||
|
./configure
|
||||||
|
make
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: |
|
||||||
|
./testsuite.sh
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
name: Manual
|
||||||
|
|
||||||
|
env:
|
||||||
|
PROJECT: abduco
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
paths:
|
||||||
|
- '*.1'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
man:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Dependency
|
||||||
|
run: sudo apt install mandoc
|
||||||
|
|
||||||
|
- name: Manual generation
|
||||||
|
run: |
|
||||||
|
mkdir man
|
||||||
|
sed -e "s/VERSION/$(git describe --always)/" ${PROJECT}.1 | \
|
||||||
|
mandoc -W warning -T utf8 -T html -O man=%N.%S.html -O style=mandoc.css 1> \
|
||||||
|
"man/${PROJECT}.1.html" || true
|
||||||
|
wget 'https://cvsweb.bsd.lv/~checkout~/mandoc/mandoc.css?rev=1.46&content-type=text/plain' -O man/mandoc.css
|
||||||
|
ln -sf "${PROJECT}.1.html" man/index.html
|
||||||
|
|
||||||
|
- name: Upload
|
||||||
|
env:
|
||||||
|
DEPLOY_TOKEN: ${{ secrets.GIT_DEPLOY_TOKEN }}
|
||||||
|
run: |
|
||||||
|
git clone --depth=1 --single-branch --branch gh-pages "https://x-access-token:${DEPLOY_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" /tmp/gh-pages
|
||||||
|
git config --global user.name "${GITHUB_ACTOR}"
|
||||||
|
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
|
||||||
|
mkdir -p /tmp/gh-pages/man
|
||||||
|
rm -f /tmp/gh-pages/man/*
|
||||||
|
cp -av man/*.html /tmp/gh-pages/man/
|
||||||
|
cp -av man/*.css /tmp/gh-pages/man/
|
||||||
|
cd /tmp/gh-pages
|
||||||
|
git add -A && git commit --allow-empty -am "Publishing from ${GITHUB_REPOSITORY} ${GITHUB_SHA}"
|
||||||
|
git push origin gh-pages
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
# normal ignores
|
/config.h
|
||||||
.*
|
/config.mk
|
||||||
*.[ao]
|
/abduco
|
||||||
*.lo
|
*.css
|
||||||
*.so
|
*.gcda
|
||||||
tags
|
*.gcno
|
||||||
!.gitignore
|
*.gcov
|
||||||
|
*.html
|
||||||
|
*.o
|
||||||
|
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
language: c
|
|
||||||
compiler:
|
|
||||||
- gcc
|
|
||||||
- clang
|
|
||||||
env:
|
|
||||||
- DEBUG=
|
|
||||||
- DEBUG=debug
|
|
||||||
script: make $DEBUG
|
|
||||||
4
LICENSE
4
LICENSE
|
|
@ -1,4 +1,6 @@
|
||||||
Copyright (c) 2013-2016 Marc André Tanner <mat at brain-dump.org>
|
ISC License
|
||||||
|
|
||||||
|
Copyright (c) 2013-2018 Marc André Tanner <mat at brain-dump.org>
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
|
|
|
||||||
71
Makefile
71
Makefile
|
|
@ -1,62 +1,67 @@
|
||||||
include config.mk
|
-include config.mk
|
||||||
|
|
||||||
|
VERSION = 0.6
|
||||||
|
|
||||||
|
CFLAGS_STD ?= -std=c99 -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -DNDEBUG
|
||||||
|
CFLAGS_STD += -DVERSION=\"${VERSION}\"
|
||||||
|
|
||||||
|
LDFLAGS_STD ?= -lc -lutil
|
||||||
|
|
||||||
|
STRIP ?= strip
|
||||||
|
INSTALL ?= install
|
||||||
|
|
||||||
|
PREFIX ?= /usr/local
|
||||||
|
SHAREDIR ?= ${PREFIX}/share
|
||||||
|
|
||||||
SRC = abduco.c
|
SRC = abduco.c
|
||||||
OBJ = ${SRC:.c=.o}
|
|
||||||
|
|
||||||
all: clean options abduco
|
all: abduco
|
||||||
|
|
||||||
options:
|
|
||||||
@echo abduco build options:
|
|
||||||
@echo "CFLAGS = ${CFLAGS}"
|
|
||||||
@echo "LDFLAGS = ${LDFLAGS}"
|
|
||||||
@echo "CC = ${CC}"
|
|
||||||
|
|
||||||
config.h:
|
config.h:
|
||||||
cp config.def.h config.h
|
cp config.def.h config.h
|
||||||
|
|
||||||
.c.o:
|
config.mk:
|
||||||
@echo CC $<
|
@touch $@
|
||||||
@${CC} -c ${CFLAGS} $<
|
|
||||||
|
|
||||||
${OBJ}: config.h config.mk
|
abduco: config.h config.mk *.c
|
||||||
|
${CC} ${CFLAGS} ${CFLAGS_STD} ${CFLAGS_AUTO} ${CFLAGS_EXTRA} ${SRC} ${LDFLAGS} ${LDFLAGS_STD} ${LDFLAGS_AUTO} -o $@
|
||||||
abduco: ${OBJ}
|
|
||||||
@echo CC -o $@
|
|
||||||
@${CC} -o $@ ${OBJ} ${LDFLAGS}
|
|
||||||
|
|
||||||
debug: clean
|
debug: clean
|
||||||
@make CFLAGS='${DEBUG_CFLAGS}'
|
make CFLAGS_EXTRA='${CFLAGS_DEBUG}'
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@echo cleaning
|
@echo cleaning
|
||||||
@rm -f abduco ${OBJ} abduco-${VERSION}.tar.gz
|
@rm -f abduco abduco-*.tar.gz
|
||||||
|
|
||||||
dist: clean
|
dist: clean
|
||||||
@echo creating dist tarball
|
@echo creating dist tarball
|
||||||
@mkdir -p abduco-${VERSION}
|
@git archive --prefix=abduco-${VERSION}/ -o abduco-${VERSION}.tar.gz HEAD
|
||||||
@cp -R LICENSE Makefile README.md testsuite.sh config.def.h config.mk \
|
|
||||||
${SRC} debug.c client.c server.c forkpty-aix.c forkpty-sunos.c \
|
|
||||||
abduco.1 abduco-${VERSION}
|
|
||||||
@tar -cf abduco-${VERSION}.tar abduco-${VERSION}
|
|
||||||
@gzip abduco-${VERSION}.tar
|
|
||||||
@rm -rf abduco-${VERSION}
|
|
||||||
|
|
||||||
install: abduco
|
installdirs:
|
||||||
@echo stripping executable
|
@${INSTALL} -d ${DESTDIR}${PREFIX}/bin \
|
||||||
@${STRIP} abduco
|
${DESTDIR}${MANPREFIX}/man1
|
||||||
|
|
||||||
|
install: abduco installdirs
|
||||||
@echo installing executable file to ${DESTDIR}${PREFIX}/bin
|
@echo installing executable file to ${DESTDIR}${PREFIX}/bin
|
||||||
@mkdir -p ${DESTDIR}${PREFIX}/bin
|
@${INSTALL} -m 0755 abduco ${DESTDIR}${PREFIX}/bin
|
||||||
@cp -f abduco ${DESTDIR}${PREFIX}/bin
|
|
||||||
@chmod 755 ${DESTDIR}${PREFIX}/bin/abduco
|
|
||||||
@echo installing manual page to ${DESTDIR}${MANPREFIX}/man1
|
@echo installing manual page to ${DESTDIR}${MANPREFIX}/man1
|
||||||
@mkdir -p ${DESTDIR}${MANPREFIX}/man1
|
@mkdir -p ${DESTDIR}${MANPREFIX}/man1
|
||||||
@sed "s/VERSION/${VERSION}/g" < abduco.1 > ${DESTDIR}${MANPREFIX}/man1/abduco.1
|
@sed "s/VERSION/${VERSION}/g" < abduco.1 > ${DESTDIR}${MANPREFIX}/man1/abduco.1
|
||||||
@chmod 644 ${DESTDIR}${MANPREFIX}/man1/abduco.1
|
@chmod 644 ${DESTDIR}${MANPREFIX}/man1/abduco.1
|
||||||
|
|
||||||
|
install-strip: install
|
||||||
|
${STRIP} ${DESTDIR}${PREFIX}/bin/abduco
|
||||||
|
|
||||||
|
install-completion:
|
||||||
|
@echo installing zsh completion file to ${DESTDIR}${SHAREDIR}/zsh/site-functions
|
||||||
|
@install -Dm644 contrib/abduco.zsh ${DESTDIR}${SHAREDIR}/zsh/site-functions/_abduco
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
@echo removing executable file from ${DESTDIR}${PREFIX}/bin
|
@echo removing executable file from ${DESTDIR}${PREFIX}/bin
|
||||||
@rm -f ${DESTDIR}${PREFIX}/bin/abduco
|
@rm -f ${DESTDIR}${PREFIX}/bin/abduco
|
||||||
@echo removing manual page from ${DESTDIR}${MANPREFIX}/man1
|
@echo removing manual page from ${DESTDIR}${MANPREFIX}/man1
|
||||||
@rm -f ${DESTDIR}${MANPREFIX}/man1/abduco.1
|
@rm -f ${DESTDIR}${MANPREFIX}/man1/abduco.1
|
||||||
|
@echo removing zsh completion file from ${DESTDIR}${SHAREDIR}/zsh/site-functions
|
||||||
|
@rm -f ${DESTDIR}${SHAREDIR}/zsh/site-functions/_abduco
|
||||||
|
|
||||||
.PHONY: all options clean dist install uninstall debug
|
.PHONY: all clean dist install installdirs install-strip install-completion uninstall debug
|
||||||
|
|
|
||||||
71
README.md
71
README.md
|
|
@ -1,15 +1,15 @@
|
||||||
# abduco a tool for session {at,de}tach support
|
# abduco a tool for session {at,de}tach support
|
||||||
|
|
||||||
[abduco](http://www.brain-dump.org/projects/abduco) provides
|
[abduco](https://www.brain-dump.org/projects/abduco) provides
|
||||||
session management i.e. it allows programs to be run independently
|
session management i.e. it allows programs to be run independently
|
||||||
from their controlling terminal. That is programs can be detached -
|
from their controlling terminal. That is programs can be detached -
|
||||||
run in the background - and then later reattached. Together with
|
run in the background - and then later reattached. Together with
|
||||||
[dvtm](http://www.brain-dump.org/projects/dvtm) it provides a
|
[dvtm](https://www.brain-dump.org/projects/dvtm) it provides a
|
||||||
simpler and cleaner alternative to tmux or screen.
|
simpler and cleaner alternative to tmux or screen.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
abduco is in many ways very similar to [dtach]("http://dtach.sf.net)
|
abduco is in many ways very similar to [dtach](http://dtach.sf.net)
|
||||||
but is a completely independent implementation which is actively maintained,
|
but is a completely independent implementation which is actively maintained,
|
||||||
contains no legacy code, provides a few additional features, has a
|
contains no legacy code, provides a few additional features, has a
|
||||||
cleaner, more robust implementation and is distributed under the
|
cleaner, more robust implementation and is distributed under the
|
||||||
|
|
@ -17,38 +17,30 @@ cleaner, more robust implementation and is distributed under the
|
||||||
|
|
||||||
## News
|
## News
|
||||||
|
|
||||||
* [abduco-0.5](http://www.brain-dump.org/projects/abduco/abduco-0.5.tar.gz)
|
* [abduco-0.6](https://www.brain-dump.org/projects/abduco/abduco-0.6.tar.gz)
|
||||||
[released](http://lists.suckless.org/dev/1601/28094.html) (09.01.2016)
|
[released](https://lists.suckless.org/dev/1603/28589.html) (24.03.2016)
|
||||||
* [abduco-0.4](http://www.brain-dump.org/projects/abduco/abduco-0.4.tar.gz)
|
* [abduco-0.5](https://www.brain-dump.org/projects/abduco/abduco-0.5.tar.gz)
|
||||||
[released](http://lists.suckless.org/dev/1503/26027.html) (18.03.2015)
|
[released](https://lists.suckless.org/dev/1601/28094.html) (09.01.2016)
|
||||||
* [abduco-0.3](http://www.brain-dump.org/projects/abduco/abduco-0.3.tar.gz)
|
* [abduco-0.4](https://www.brain-dump.org/projects/abduco/abduco-0.4.tar.gz)
|
||||||
[released](http://lists.suckless.org/dev/1502/25557.html) (19.02.2015)
|
[released](https://lists.suckless.org/dev/1503/26027.html) (18.03.2015)
|
||||||
* [abduco-0.2](http://www.brain-dump.org/projects/abduco/abduco-0.2.tar.gz)
|
* [abduco-0.3](https://www.brain-dump.org/projects/abduco/abduco-0.3.tar.gz)
|
||||||
[released](http://lists.suckless.org/dev/1411/24447.html) (15.11.2014)
|
[released](https://lists.suckless.org/dev/1502/25557.html) (19.02.2015)
|
||||||
* [abduco-0.1](http://www.brain-dump.org/projects/abduco/abduco-0.1.tar.gz)
|
* [abduco-0.2](https://www.brain-dump.org/projects/abduco/abduco-0.2.tar.gz)
|
||||||
[released](http://lists.suckless.org/dev/1407/22703.html) (05.07.2014)
|
[released](https://lists.suckless.org/dev/1411/24447.html) (15.11.2014)
|
||||||
* [Initial announcement](http://lists.suckless.org/dev/1403/20372.html)
|
* [abduco-0.1](https://www.brain-dump.org/projects/abduco/abduco-0.1.tar.gz)
|
||||||
|
[released](https://lists.suckless.org/dev/1407/22703.html) (05.07.2014)
|
||||||
|
* [Initial announcement](https://lists.suckless.org/dev/1403/20372.html)
|
||||||
on the suckless development mailing list (08.03.2014)
|
on the suckless development mailing list (08.03.2014)
|
||||||
|
|
||||||
## Download
|
## Download
|
||||||
|
|
||||||
Either download the latest source tarball
|
Either download the latest [source tarball](https://github.com/martanne/abduco/releases),
|
||||||
[abduco-0.5.tar.gz](http://www.brain-dump.org/projects/abduco/abduco-0.5.tar.gz)
|
|
||||||
with sha1sum
|
|
||||||
|
|
||||||
37c51a0d5c3dd216251d84d5c1b550f119ad53c9 abduco-0.5.tar.gz
|
|
||||||
|
|
||||||
compile and install it
|
compile and install it
|
||||||
|
|
||||||
$EDITOR config.mk && make && sudo make install
|
./configure && make && sudo make install
|
||||||
|
|
||||||
or use one of the distribution provided binary packages:
|
or use one of the distribution provided
|
||||||
|
[binary packages](https://repology.org/project/abduco/packages).
|
||||||
* [Debian](https://packages.debian.org/search?keywords=abduco)
|
|
||||||
* [Fedora](https://admin.fedoraproject.org/pkgdb/package/abduco/)
|
|
||||||
* [Gentoo](http://packages.gentoo.org/package/app-misc/abduco/)
|
|
||||||
* [Ubuntu](http://packages.ubuntu.com/search?keywords=abduco)
|
|
||||||
* [Mac OS X](http://www.braumeister.org/formula/abduco) via homebrew
|
|
||||||
|
|
||||||
## Quickstart
|
## Quickstart
|
||||||
|
|
||||||
|
|
@ -165,21 +157,14 @@ command line options.
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
||||||
You can always fetch the current code base from the git repository.
|
You can always fetch the current code base from the git repository
|
||||||
|
located at [Github](https://github.com/martanne/abduco/) or
|
||||||
git clone https://github.com/martanne/abduco.git
|
[Sourcehut](https://git.sr.ht/~martanne/abduco).
|
||||||
|
|
||||||
or
|
|
||||||
|
|
||||||
git clone git://repo.or.cz/abduco.git
|
|
||||||
|
|
||||||
If you have comments, suggestions, ideas, a bug report, a patch or something
|
If you have comments, suggestions, ideas, a bug report, a patch or something
|
||||||
else related to abduco then write to the
|
else related to abduco then write to the
|
||||||
[suckless developer mailing list](http://suckless.org/community)
|
[suckless developer mailing list](https://suckless.org/community)
|
||||||
or contact me directly mat[at]brain-dump.org.
|
or contact me directly.
|
||||||
|
|
||||||
[](https://travis-ci.org/martanne/abduco)
|
|
||||||
[](https://scan.coverity.com/projects/4285)
|
|
||||||
|
|
||||||
### Debugging
|
### Debugging
|
||||||
|
|
||||||
|
|
@ -192,8 +177,8 @@ to temporary files as follows:
|
||||||
|
|
||||||
If you want to run client and server with one command (e.g. using the `-c`
|
If you want to run client and server with one command (e.g. using the `-c`
|
||||||
option) then within `gdb` the option `set follow-fork-mode {child,parent}`
|
option) then within `gdb` the option `set follow-fork-mode {child,parent}`
|
||||||
might be useful. Similarly to get a syscall trace `strace -o abduco -ff [abduco-cmd]`
|
might be useful. Similarly to get a syscall trace `strace -o abduco -ff
|
||||||
proved to be handy.
|
[abduco-cmd]` proved to be handy.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|
|
||||||
347
abduco.1
347
abduco.1
|
|
@ -1,137 +1,226 @@
|
||||||
.TH ABDUCO 1 abduco\-VERSION
|
.Dd March 18, 2018
|
||||||
.nh
|
.Dt ABDUCO 1
|
||||||
.SH NAME
|
.Os abduco VERSION
|
||||||
abduco - terminal session manager
|
.
|
||||||
.SH SYNOPSIS
|
.Sh NAME
|
||||||
.B abduco
|
.Nm abduco
|
||||||
.RB [ \-e
|
.Nd terminal session manager
|
||||||
.IR detachkey ]
|
.
|
||||||
.RB [ \-r ]
|
.Sh SYNOPSIS
|
||||||
.RB [ \-f ]
|
.Nm
|
||||||
.RB \-c
|
.Fl a
|
||||||
.RB name
|
.Op options ...
|
||||||
.RB command
|
.Cm name
|
||||||
.RI [ args \ ... "" ]
|
.
|
||||||
.br
|
.Nm
|
||||||
.B abduco
|
.Fl A
|
||||||
.RB [ \-e
|
.Op options ...
|
||||||
.IR detachkey ]
|
.Cm name
|
||||||
.RB [ \-r ]
|
.Cm command Op args ...
|
||||||
.RB [ \-f ]
|
.
|
||||||
.RB \-n
|
.Nm
|
||||||
.RB name
|
.Fl c
|
||||||
.RB command
|
.Op options ...
|
||||||
.RI [ args \ ... "" ]
|
.Cm name
|
||||||
.br
|
.Cm command Op args ...
|
||||||
.B abduco
|
.
|
||||||
.RB [ \-e
|
.Nm
|
||||||
.IR detachkey ]
|
.Fl n
|
||||||
.RB [ \-r ]
|
.Op options ...
|
||||||
.RB [ \-f ]
|
.Cm name
|
||||||
.RB [ \-l ]
|
.Cm command Op args ...
|
||||||
.RB \-A
|
.
|
||||||
.RB name
|
.Sh DESCRIPTION
|
||||||
.RB command
|
.
|
||||||
.RI [ args \ ... "" ]
|
.Nm
|
||||||
.br
|
disassociates a given application from its controlling
|
||||||
.B abduco
|
terminal, thereby providing roughly the same session attach/detach support as
|
||||||
.RB [ \-e
|
.Xr screen 1 ,
|
||||||
.IR detachkey ]
|
.Xr tmux 1 ,
|
||||||
.RB [ \-r ]
|
or
|
||||||
.RB [ \-l ]
|
.Xr dtach 1 .
|
||||||
.RB \-a
|
.Pp
|
||||||
.RB name
|
A session comprises of an
|
||||||
.br
|
.Nm
|
||||||
.SH DESCRIPTION
|
server process which spawns a user
|
||||||
.B abduco
|
command in its own pseudo terminal
|
||||||
provides a way to disconnect a given application from its controlling
|
.Pq see Xr pty 7 .
|
||||||
terminal, thus it provides roughly the same session attach/detach support as
|
Each session is given a name represented by a unix domain socket
|
||||||
.BR screen(1) , " tmux(1)" " or" " dtach(1)".
|
.Pq see Xr unix 7
|
||||||
|
stored in the local file system.
|
||||||
If the
|
.Nm
|
||||||
.BR command
|
clients can connect to it and their standard input output streams
|
||||||
to execute is not specified, the environment variable
|
are relayed to the command supervised by the server.
|
||||||
.BR $ABDUCO_CMD
|
.Pp
|
||||||
is examined, if it is not set
|
.Nm
|
||||||
.BR dvtm(1)
|
operates on the raw I/O byte stream without interpreting any terminal
|
||||||
is executed.
|
escape sequences.
|
||||||
|
As a consequence the terminal state is not preserved across sessions.
|
||||||
All session related information is stored in the following directories (first
|
If this functionality is desired, it should be provided by another
|
||||||
to succeed is used):
|
utility such as
|
||||||
.RS
|
.Xr dvtm 1 .
|
||||||
.nf
|
.
|
||||||
.PP
|
.Ss ACTIONS
|
||||||
.B $ABDUCO_SOCKET_DIR/abduco
|
.
|
||||||
.B $HOME/.abduco
|
If no command line arguments are given, all currently active sessions are
|
||||||
.B $TMPDIR/abduco/$USER
|
listed sorted by their respective creation date.
|
||||||
.B /tmp/abduco/$USER
|
Lines starting with an asterisk
|
||||||
.fi
|
.Pq *
|
||||||
.RE
|
indicate that at least one client is currently connected.
|
||||||
|
|
||||||
However if a given session name represents either a relative or absolute path
|
|
||||||
it is used unmodified.
|
|
||||||
|
|
||||||
If for some reason the
|
|
||||||
.BR unix(7)
|
|
||||||
domain socket representing a session is deleted, sending
|
|
||||||
.BR SIGUSR1
|
|
||||||
to the server process will recreate it.
|
|
||||||
.SH OPTIONS
|
|
||||||
If no command line arguments are given all currently active sessions are
|
|
||||||
printed sorted by their respective creation date. Lines starting with an
|
|
||||||
asterik
|
|
||||||
.BR *
|
|
||||||
indicate that at least one client is connected.
|
|
||||||
A plus sign
|
A plus sign
|
||||||
.BR +
|
.Pq +
|
||||||
indicates that the command terminated while no client was connected, attach
|
signals that the command terminated while no client was connected.
|
||||||
to get its exit status.
|
Attaching to the session will print its exit status.
|
||||||
.TP
|
The next column shows the PID of the server process, followed by the session
|
||||||
.B \-v
|
.Ic name .
|
||||||
Print version information to standard output and exit.
|
.Pp
|
||||||
.TP
|
.Nm
|
||||||
.B \-r
|
provides different actions of which one must be provided.
|
||||||
Readonly session, i.e. user input is ignored.
|
.
|
||||||
.TP
|
.Bl -tag -width indent
|
||||||
.B \-e \fIdetachkey\fR
|
.It Fl a
|
||||||
Set the key to detach which by default is set to CTRL+\\ i.e. ^\\ to detachkey.
|
Attach to an existing session.
|
||||||
.TP
|
.It Fl A
|
||||||
.BI \-f
|
Try to connect to an existing session, upon failure create said session and attach immediately to it.
|
||||||
|
.It Fl c
|
||||||
|
Create a new session and attach immediately to it.
|
||||||
|
.It Fl n
|
||||||
|
Create a new session but do not attach to it.
|
||||||
|
.El
|
||||||
|
.
|
||||||
|
.Ss OPTIONS
|
||||||
|
.
|
||||||
|
Additionally the following options can be provided to further tweak
|
||||||
|
the behavior.
|
||||||
|
.Bl -tag -width indent
|
||||||
|
.It Fl e Ar detachkey
|
||||||
|
Set the key to detach.
|
||||||
|
Defaults to
|
||||||
|
.Aq Ctrl+\e
|
||||||
|
which is specified as ^\\ i.e. Ctrl is represented as a caret
|
||||||
|
.Pq ^ .
|
||||||
|
.It Fl f
|
||||||
Force creation of session when there is an already terminated session of the same name,
|
Force creation of session when there is an already terminated session of the same name,
|
||||||
after showing its exit status.
|
after showing its exit status.
|
||||||
.TP
|
.It Fl l
|
||||||
.BI \-c
|
|
||||||
Create a new session and attach immediately to it.
|
|
||||||
.TP
|
|
||||||
.BI \-n
|
|
||||||
Create a new session but do not attach to it.
|
|
||||||
.TP
|
|
||||||
.BI \-A
|
|
||||||
Try to connect to an existing session, upon failure create said session and attach immediately to it.
|
|
||||||
.TP
|
|
||||||
.BI \-a
|
|
||||||
Attach to an existing session.
|
|
||||||
.TP
|
|
||||||
.BI \-l
|
|
||||||
Attach with the lowest priority, meaning this client will be the last to control the size.
|
Attach with the lowest priority, meaning this client will be the last to control the size.
|
||||||
.SH EXAMPLE
|
.It Fl p
|
||||||
|
Pass through content of standard input to the session.
|
||||||
|
Implies the
|
||||||
|
.Fl q
|
||||||
|
and
|
||||||
|
.Fl l
|
||||||
|
options.
|
||||||
|
.It Fl q
|
||||||
|
Be quiet, do not print informative messages.
|
||||||
|
.It Fl r
|
||||||
|
Read-only session, user input is ignored.
|
||||||
|
.It Fl v
|
||||||
|
Print version information and exit.
|
||||||
|
.El
|
||||||
|
.
|
||||||
|
.Sh SIGNALS
|
||||||
|
.
|
||||||
|
.Bl -tag -width indent
|
||||||
|
.It Dv SIGWINCH
|
||||||
|
Whenever the primary client resizes its terminal the server process will deliver a
|
||||||
|
.Ev SIGWINCH
|
||||||
|
signal to the supervised process.
|
||||||
|
.It Dv SIGUSR1
|
||||||
|
If for some reason the unix domain socket representing a session is deleted, sending
|
||||||
|
.Ev SIGUSR1
|
||||||
|
to the server process will recreate it.
|
||||||
|
.It Dv SIGTERM
|
||||||
|
Detaches a client.
|
||||||
|
.El
|
||||||
|
.
|
||||||
|
.Sh ENVIRONMENT
|
||||||
|
.
|
||||||
|
.Bl -tag -width indent
|
||||||
|
.It Ev ABDUCO_CMD
|
||||||
|
If
|
||||||
|
.Ic command
|
||||||
|
is not specified, the environment variable
|
||||||
|
.Ev $ABDUCO_CMD
|
||||||
|
is examined, if it is not set
|
||||||
|
.Xr dvtm 1
|
||||||
|
is executed.
|
||||||
|
.It Ev ABDUCO_SESSION
|
||||||
|
The current session name available to the supervised command.
|
||||||
|
.It Ev ABDUCO_SOCKET
|
||||||
|
The absolute path of the session socket available to the supervised command.
|
||||||
|
.El
|
||||||
|
.Pp
|
||||||
|
See the
|
||||||
|
.Sx FILES
|
||||||
|
section for environment variables used in determining the location
|
||||||
|
of unix domain sockets representing sessions.
|
||||||
|
.Sh FILES
|
||||||
|
.
|
||||||
|
All session related information is stored in the following directories (first
|
||||||
|
to succeed is used):
|
||||||
|
.Bl -bullet
|
||||||
|
.It
|
||||||
|
.Ev $ABDUCO_SOCKET_DIR/abduco
|
||||||
|
.It
|
||||||
|
.Ev $HOME/.abduco
|
||||||
|
.It
|
||||||
|
.Ev $TMPDIR/abduco/$USER
|
||||||
|
.It
|
||||||
|
.Ev /tmp/abduco/$USER
|
||||||
|
.El
|
||||||
|
.
|
||||||
|
.Pp
|
||||||
|
However, if a given session
|
||||||
|
.Ic name
|
||||||
|
represents either a relative or absolute path it is used unmodified.
|
||||||
|
.
|
||||||
|
.
|
||||||
|
.Sh EXAMPLES
|
||||||
|
.
|
||||||
Start a new session (assuming
|
Start a new session (assuming
|
||||||
.BR dvtm(1)
|
.Xr dvtm 1
|
||||||
is in
|
is in
|
||||||
.BR $PATH )
|
.Ev $PATH )
|
||||||
with
|
with
|
||||||
.nf
|
.Pp
|
||||||
|
.Dl $ abduco -c my-session
|
||||||
.B abduco -c my-session
|
.Pp
|
||||||
|
|
||||||
.fi
|
|
||||||
do some work, then detach by pressing
|
do some work, then detach by pressing
|
||||||
.B CTRL+\e
|
.Aq Ctrl+\e ,
|
||||||
and later reattach with
|
list existing session by running
|
||||||
.nf
|
.Nm
|
||||||
|
without any arguments and later reattach with
|
||||||
.B abduco -a my-session
|
.Pp
|
||||||
|
.Dl $ abduco -a my-session
|
||||||
.fi
|
.Pp
|
||||||
.SH AUTHOR
|
Alternatively, we can also explicitly specify the command to run.
|
||||||
abduco is written by Marc André Tanner <mat at brain-dump.org>
|
.Pp
|
||||||
|
.Dl $ abduco -c my-session /bin/sh
|
||||||
|
.Pp
|
||||||
|
Attach with a
|
||||||
|
.Aq Ctrl+z
|
||||||
|
as detach key.
|
||||||
|
.Pp
|
||||||
|
.Dl $ abduco -e ^z -a my-session
|
||||||
|
.Pp
|
||||||
|
Send a command to an existing session.
|
||||||
|
.Pp
|
||||||
|
.Dl $ echo make | abduco -a my-session
|
||||||
|
.Pp
|
||||||
|
Or in a slightly more interactive fashion.
|
||||||
|
.Pp
|
||||||
|
.Dl $ abduco -p my-session
|
||||||
|
.Dl make
|
||||||
|
.Dl ^D
|
||||||
|
.
|
||||||
|
.Sh SEE ALSO
|
||||||
|
.Xr dvtm 1 ,
|
||||||
|
.Xr dtach 1 ,
|
||||||
|
.Xr tmux 1 ,
|
||||||
|
.Xr screen 1
|
||||||
|
.
|
||||||
|
.Sh AUTHORS
|
||||||
|
.Nm
|
||||||
|
is written by
|
||||||
|
.An Marc André Tanner Aq mat at brain-dump.org
|
||||||
|
|
|
||||||
104
abduco.c
104
abduco.c
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2013-2016 Marc André Tanner <mat at brain-dump.org>
|
* Copyright (c) 2013-2018 Marc André Tanner <mat at brain-dump.org>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <inttypes.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
@ -66,17 +67,21 @@ enum PacketType {
|
||||||
MSG_ATTACH = 1,
|
MSG_ATTACH = 1,
|
||||||
MSG_DETACH = 2,
|
MSG_DETACH = 2,
|
||||||
MSG_RESIZE = 3,
|
MSG_RESIZE = 3,
|
||||||
MSG_REDRAW = 4,
|
MSG_EXIT = 4,
|
||||||
MSG_EXIT = 5,
|
MSG_PID = 5,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
unsigned int type;
|
uint32_t type;
|
||||||
size_t len;
|
uint32_t len;
|
||||||
union {
|
union {
|
||||||
char msg[BUFSIZ];
|
char msg[4096 - 2*sizeof(uint32_t)];
|
||||||
struct winsize ws;
|
struct {
|
||||||
int i;
|
uint16_t rows;
|
||||||
|
uint16_t cols;
|
||||||
|
} ws;
|
||||||
|
uint32_t i;
|
||||||
|
uint64_t l;
|
||||||
} u;
|
} u;
|
||||||
} Packet;
|
} Packet;
|
||||||
|
|
||||||
|
|
@ -116,7 +121,7 @@ typedef struct {
|
||||||
static Server server = { .running = true, .exit_status = -1, .host = "@localhost" };
|
static Server server = { .running = true, .exit_status = -1, .host = "@localhost" };
|
||||||
static Client client;
|
static Client client;
|
||||||
static struct termios orig_term, cur_term;
|
static struct termios orig_term, cur_term;
|
||||||
static bool has_term, alternate_buffer;
|
static bool has_term, alternate_buffer, quiet, passthrough;
|
||||||
|
|
||||||
static struct sockaddr_un sockaddr = {
|
static struct sockaddr_un sockaddr = {
|
||||||
.sun_family = AF_UNIX,
|
.sun_family = AF_UNIX,
|
||||||
|
|
@ -203,12 +208,12 @@ static bool recv_packet(int socket, Packet *pkt) {
|
||||||
static void info(const char *str, ...) {
|
static void info(const char *str, ...) {
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, str);
|
va_start(ap, str);
|
||||||
if (str) {
|
if (str && !quiet) {
|
||||||
fprintf(stderr, "%s: %s: ", server.name, server.session_name);
|
fprintf(stderr, "%s: %s: ", server.name, server.session_name);
|
||||||
vfprintf(stderr, str, ap);
|
vfprintf(stderr, str, ap);
|
||||||
fprintf(stderr, "\r\n");
|
fprintf(stderr, "\r\n");
|
||||||
}
|
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
|
}
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -218,7 +223,7 @@ static void die(const char *s) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void usage(void) {
|
static void usage(void) {
|
||||||
fprintf(stderr, "usage: abduco [-a|-A|-c|-n] [-r] [-l] [-f] [-e detachkey] name command\n");
|
fprintf(stderr, "usage: abduco [-a|-A|-c|-n] [-p] [-r] [-q] [-l] [-f] [-e detachkey] name command\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -253,11 +258,15 @@ static int session_connect(const char *name) {
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool session_exists(const char *name) {
|
static pid_t session_exists(const char *name) {
|
||||||
int fd = session_connect(name);
|
Packet pkt;
|
||||||
if (fd != -1)
|
pid_t pid = 0;
|
||||||
close(fd);
|
if ((server.socket = session_connect(name)) == -1)
|
||||||
return fd != -1;
|
return pid;
|
||||||
|
if (client_recv_packet(&pkt) && pkt.type == MSG_PID)
|
||||||
|
pid = pkt.u.l;
|
||||||
|
close(server.socket);
|
||||||
|
return pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool session_alive(const char *name) {
|
static bool session_alive(const char *name) {
|
||||||
|
|
@ -273,7 +282,7 @@ static bool create_socket_dir(struct sockaddr_un *sockaddr) {
|
||||||
if (socketfd == -1)
|
if (socketfd == -1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
size_t maxlen = sizeof(sockaddr->sun_path);
|
const size_t maxlen = sizeof(sockaddr->sun_path);
|
||||||
uid_t uid = getuid();
|
uid_t uid = getuid();
|
||||||
struct passwd *pw = getpwuid(uid);
|
struct passwd *pw = getpwuid(uid);
|
||||||
|
|
||||||
|
|
@ -343,7 +352,10 @@ static bool create_socket_dir(struct sockaddr_un *sockaddr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool set_socket_name(struct sockaddr_un *sockaddr, const char *name) {
|
static bool set_socket_name(struct sockaddr_un *sockaddr, const char *name) {
|
||||||
size_t maxlen = sizeof(sockaddr->sun_path);
|
const size_t maxlen = sizeof(sockaddr->sun_path);
|
||||||
|
const char *session_name = NULL;
|
||||||
|
char buf[maxlen];
|
||||||
|
|
||||||
if (name[0] == '/') {
|
if (name[0] == '/') {
|
||||||
if (strlen(name) >= maxlen) {
|
if (strlen(name) >= maxlen) {
|
||||||
errno = ENAMETOOLONG;
|
errno = ENAMETOOLONG;
|
||||||
|
|
@ -351,7 +363,7 @@ static bool set_socket_name(struct sockaddr_un *sockaddr, const char *name) {
|
||||||
}
|
}
|
||||||
strncpy(sockaddr->sun_path, name, maxlen);
|
strncpy(sockaddr->sun_path, name, maxlen);
|
||||||
} else if (name[0] == '.' && (name[1] == '.' || name[1] == '/')) {
|
} else if (name[0] == '.' && (name[1] == '.' || name[1] == '/')) {
|
||||||
char buf[maxlen], *cwd = getcwd(buf, sizeof buf);
|
char *cwd = getcwd(buf, sizeof buf);
|
||||||
if (!cwd)
|
if (!cwd)
|
||||||
return false;
|
return false;
|
||||||
if (!xsnprintf(sockaddr->sun_path, maxlen, "%s/%s", cwd, name))
|
if (!xsnprintf(sockaddr->sun_path, maxlen, "%s/%s", cwd, name))
|
||||||
|
|
@ -363,9 +375,18 @@ static bool set_socket_name(struct sockaddr_un *sockaddr, const char *name) {
|
||||||
errno = ENAMETOOLONG;
|
errno = ENAMETOOLONG;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
session_name = name;
|
||||||
strncat(sockaddr->sun_path, name, maxlen - strlen(sockaddr->sun_path) - 1);
|
strncat(sockaddr->sun_path, name, maxlen - strlen(sockaddr->sun_path) - 1);
|
||||||
strncat(sockaddr->sun_path, server.host, maxlen - strlen(sockaddr->sun_path) - 1);
|
strncat(sockaddr->sun_path, server.host, maxlen - strlen(sockaddr->sun_path) - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!session_name) {
|
||||||
|
strncpy(buf, sockaddr->sun_path, sizeof buf);
|
||||||
|
session_name = basename(buf);
|
||||||
|
}
|
||||||
|
setenv("ABDUCO_SESSION", session_name, 1);
|
||||||
|
setenv("ABDUCO_SOCKET", sockaddr->sun_path, 1);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -442,13 +463,14 @@ static bool create_session(const char *name, char * const argv[]) {
|
||||||
sa.sa_handler = SIG_IGN;
|
sa.sa_handler = SIG_IGN;
|
||||||
sigaction(SIGPIPE, &sa, NULL);
|
sigaction(SIGPIPE, &sa, NULL);
|
||||||
sigaction(SIGHUP, &sa, NULL);
|
sigaction(SIGHUP, &sa, NULL);
|
||||||
chdir("/");
|
if (chdir("/") == -1)
|
||||||
|
_exit(EXIT_FAILURE);
|
||||||
#ifdef NDEBUG
|
#ifdef NDEBUG
|
||||||
int fd = open("/dev/null", O_RDWR);
|
int fd = open("/dev/null", O_RDWR);
|
||||||
if (fd != -1) {
|
if (fd != -1) {
|
||||||
dup2(fd, 0);
|
dup2(fd, STDIN_FILENO);
|
||||||
dup2(fd, 1);
|
dup2(fd, STDOUT_FILENO);
|
||||||
dup2(fd, 2);
|
dup2(fd, STDERR_FILENO);
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
#endif /* NDEBUG */
|
#endif /* NDEBUG */
|
||||||
|
|
@ -479,8 +501,7 @@ static bool create_session(const char *name, char * const argv[]) {
|
||||||
return false;
|
return false;
|
||||||
default: /* parent = client process */
|
default: /* parent = client process */
|
||||||
close(client_pipe[1]);
|
close(client_pipe[1]);
|
||||||
int status;
|
while (waitpid(pid, NULL, 0) == -1 && errno == EINTR);
|
||||||
wait(&status); /* wait for first fork */
|
|
||||||
ssize_t len = read_all(client_pipe[0], errormsg, sizeof(errormsg));
|
ssize_t len = read_all(client_pipe[0], errormsg, sizeof(errormsg));
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
write_all(STDERR_FILENO, errormsg, len);
|
write_all(STDERR_FILENO, errormsg, len);
|
||||||
|
|
@ -540,7 +561,8 @@ static int session_comparator(const struct dirent **a, const struct dirent **b)
|
||||||
static int list_session(void) {
|
static int list_session(void) {
|
||||||
if (!create_socket_dir(&sockaddr))
|
if (!create_socket_dir(&sockaddr))
|
||||||
return 1;
|
return 1;
|
||||||
chdir(sockaddr.sun_path);
|
if (chdir(sockaddr.sun_path) == -1)
|
||||||
|
die("list-session");
|
||||||
struct dirent **namelist;
|
struct dirent **namelist;
|
||||||
int n = scandir(sockaddr.sun_path, &namelist, session_filter, session_comparator);
|
int n = scandir(sockaddr.sun_path, &namelist, session_filter, session_comparator);
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
|
|
@ -549,19 +571,20 @@ static int list_session(void) {
|
||||||
while (n--) {
|
while (n--) {
|
||||||
struct stat sb; char buf[255];
|
struct stat sb; char buf[255];
|
||||||
if (stat(namelist[n]->d_name, &sb) == 0 && S_ISSOCK(sb.st_mode)) {
|
if (stat(namelist[n]->d_name, &sb) == 0 && S_ISSOCK(sb.st_mode)) {
|
||||||
|
pid_t pid = 0;
|
||||||
strftime(buf, sizeof(buf), "%a%t %F %T", localtime(&sb.st_mtime));
|
strftime(buf, sizeof(buf), "%a%t %F %T", localtime(&sb.st_mtime));
|
||||||
char status = ' ';
|
char status = ' ';
|
||||||
char *local = strstr(namelist[n]->d_name, server.host);
|
char *local = strstr(namelist[n]->d_name, server.host);
|
||||||
if (local) {
|
if (local) {
|
||||||
*local = '\0'; /* truncate hostname if we are local */
|
*local = '\0'; /* truncate hostname if we are local */
|
||||||
if (!session_exists(namelist[n]->d_name))
|
if (!(pid = session_exists(namelist[n]->d_name)))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (sb.st_mode & S_IXUSR)
|
if (sb.st_mode & S_IXUSR)
|
||||||
status = '*';
|
status = '*';
|
||||||
else if (sb.st_mode & S_IXGRP)
|
else if (sb.st_mode & S_IXGRP)
|
||||||
status = '+';
|
status = '+';
|
||||||
printf("%c %s\t%s\n", status, buf, namelist[n]->d_name);
|
printf("%c %s\t%jd\t%s\n", status, buf, (intmax_t)pid, namelist[n]->d_name);
|
||||||
}
|
}
|
||||||
free(namelist[n]);
|
free(namelist[n]);
|
||||||
}
|
}
|
||||||
|
|
@ -583,7 +606,7 @@ int main(int argc, char *argv[]) {
|
||||||
server.name = basename(argv[0]);
|
server.name = basename(argv[0]);
|
||||||
gethostname(server.host+1, sizeof(server.host) - 1);
|
gethostname(server.host+1, sizeof(server.host) - 1);
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "aAclne:frv")) != -1) {
|
while ((opt = getopt(argc, argv, "aAclne:fpqrv")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'a':
|
case 'a':
|
||||||
case 'A':
|
case 'A':
|
||||||
|
|
@ -601,6 +624,12 @@ int main(int argc, char *argv[]) {
|
||||||
case 'f':
|
case 'f':
|
||||||
force = true;
|
force = true;
|
||||||
break;
|
break;
|
||||||
|
case 'p':
|
||||||
|
passthrough = true;
|
||||||
|
break;
|
||||||
|
case 'q':
|
||||||
|
quiet = true;
|
||||||
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
client.flags |= CLIENT_READONLY;
|
client.flags |= CLIENT_READONLY;
|
||||||
break;
|
break;
|
||||||
|
|
@ -608,7 +637,7 @@ int main(int argc, char *argv[]) {
|
||||||
client.flags |= CLIENT_LOWPRIORITY;
|
client.flags |= CLIENT_LOWPRIORITY;
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
puts("abduco-"VERSION" © 2013-2016 Marc André Tanner");
|
puts("abduco-"VERSION" © 2013-2018 Marc André Tanner");
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
|
|
@ -625,12 +654,22 @@ int main(int argc, char *argv[]) {
|
||||||
else
|
else
|
||||||
cmd = default_cmd;
|
cmd = default_cmd;
|
||||||
|
|
||||||
|
if (server.session_name && !isatty(STDIN_FILENO))
|
||||||
|
passthrough = true;
|
||||||
|
|
||||||
|
if (passthrough) {
|
||||||
|
if (!action)
|
||||||
|
action = 'a';
|
||||||
|
quiet = true;
|
||||||
|
client.flags |= CLIENT_LOWPRIORITY;
|
||||||
|
}
|
||||||
|
|
||||||
if (!action && !server.session_name)
|
if (!action && !server.session_name)
|
||||||
exit(list_session());
|
exit(list_session());
|
||||||
if (!action || !server.session_name)
|
if (!action || !server.session_name)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
if (tcgetattr(STDIN_FILENO, &orig_term) != -1) {
|
if (!passthrough && tcgetattr(STDIN_FILENO, &orig_term) != -1) {
|
||||||
server.term = orig_term;
|
server.term = orig_term;
|
||||||
has_term = true;
|
has_term = true;
|
||||||
}
|
}
|
||||||
|
|
@ -658,6 +697,7 @@ int main(int argc, char *argv[]) {
|
||||||
die("create-session");
|
die("create-session");
|
||||||
if (action == 'n')
|
if (action == 'n')
|
||||||
break;
|
break;
|
||||||
|
/* fall through */
|
||||||
case 'a':
|
case 'a':
|
||||||
if (!attach_session(server.session_name, true))
|
if (!attach_session(server.session_name, true))
|
||||||
die("attach-session");
|
die("attach-session");
|
||||||
|
|
|
||||||
13
client.c
13
client.c
|
|
@ -22,7 +22,8 @@ static bool client_recv_packet(Packet *pkt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void client_restore_terminal(void) {
|
static void client_restore_terminal(void) {
|
||||||
if (has_term)
|
if (!has_term)
|
||||||
|
return;
|
||||||
tcsetattr(STDIN_FILENO, TCSAFLUSH, &orig_term);
|
tcsetattr(STDIN_FILENO, TCSAFLUSH, &orig_term);
|
||||||
if (alternate_buffer) {
|
if (alternate_buffer) {
|
||||||
printf("\033[?25h\033[?1049l");
|
printf("\033[?25h\033[?1049l");
|
||||||
|
|
@ -32,6 +33,8 @@ static void client_restore_terminal(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void client_setup_terminal(void) {
|
static void client_setup_terminal(void) {
|
||||||
|
if (!has_term)
|
||||||
|
return;
|
||||||
atexit(client_restore_terminal);
|
atexit(client_restore_terminal);
|
||||||
|
|
||||||
cur_term = orig_term;
|
cur_term = orig_term;
|
||||||
|
|
@ -78,8 +81,8 @@ static int client_mainloop(void) {
|
||||||
if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) != -1) {
|
if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) != -1) {
|
||||||
Packet pkt = {
|
Packet pkt = {
|
||||||
.type = MSG_RESIZE,
|
.type = MSG_RESIZE,
|
||||||
.u = { .ws = ws },
|
.u = { .ws = { .rows = ws.ws_row, .cols = ws.ws_col } },
|
||||||
.len = sizeof(ws),
|
.len = sizeof(pkt.u.ws),
|
||||||
};
|
};
|
||||||
if (client_send_packet(&pkt))
|
if (client_send_packet(&pkt))
|
||||||
client.need_resize = false;
|
client.need_resize = false;
|
||||||
|
|
@ -97,6 +100,7 @@ static int client_mainloop(void) {
|
||||||
if (client_recv_packet(&pkt)) {
|
if (client_recv_packet(&pkt)) {
|
||||||
switch (pkt.type) {
|
switch (pkt.type) {
|
||||||
case MSG_CONTENT:
|
case MSG_CONTENT:
|
||||||
|
if (!passthrough)
|
||||||
write_all(STDOUT_FILENO, pkt.u.msg, pkt.len);
|
write_all(STDOUT_FILENO, pkt.u.msg, pkt.len);
|
||||||
break;
|
break;
|
||||||
case MSG_RESIZE:
|
case MSG_RESIZE:
|
||||||
|
|
@ -129,6 +133,9 @@ static int client_mainloop(void) {
|
||||||
} else if (!(client.flags & CLIENT_READONLY)) {
|
} else if (!(client.flags & CLIENT_READONLY)) {
|
||||||
client_send_packet(&pkt);
|
client_send_packet(&pkt);
|
||||||
}
|
}
|
||||||
|
} else if (len == 0) {
|
||||||
|
debug("client-stdin: EOF\n");
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
19
config.mk
19
config.mk
|
|
@ -1,19 +0,0 @@
|
||||||
# abduco version
|
|
||||||
VERSION = 0.6
|
|
||||||
|
|
||||||
# Customize below to fit your system
|
|
||||||
|
|
||||||
PREFIX ?= /usr/local
|
|
||||||
MANPREFIX = ${PREFIX}/share/man
|
|
||||||
|
|
||||||
INCS = -I.
|
|
||||||
LIBS = -lc -lutil
|
|
||||||
|
|
||||||
CPPFLAGS = -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700
|
|
||||||
CFLAGS += -std=c99 -pedantic -Wall ${INCS} -DVERSION=\"${VERSION}\" -DNDEBUG ${CPPFLAGS}
|
|
||||||
LDFLAGS += ${LIBS}
|
|
||||||
|
|
||||||
DEBUG_CFLAGS = ${CFLAGS} -UNDEBUG -O0 -g -ggdb
|
|
||||||
|
|
||||||
CC ?= cc
|
|
||||||
STRIP ?= strip
|
|
||||||
|
|
@ -0,0 +1,244 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# Based on the configure script from musl libc, MIT licensed
|
||||||
|
|
||||||
|
usage () {
|
||||||
|
cat <<EOF
|
||||||
|
Usage: $0 [OPTION]... [VAR=VALUE]...
|
||||||
|
|
||||||
|
To assign environment variables (e.g., CC, CFLAGS...), specify them as
|
||||||
|
VAR=VALUE. See below for descriptions of some of the useful variables.
|
||||||
|
|
||||||
|
Defaults for the options are specified in brackets.
|
||||||
|
|
||||||
|
Configuration:
|
||||||
|
--srcdir=DIR source directory [detected]
|
||||||
|
|
||||||
|
Installation directories:
|
||||||
|
--prefix=PREFIX main installation prefix [/usr/local]
|
||||||
|
--exec-prefix=EPREFIX installation prefix for executable files [PREFIX]
|
||||||
|
|
||||||
|
Fine tuning of the installation directories:
|
||||||
|
--bindir=DIR user executables [EPREFIX/bin]
|
||||||
|
--sharedir=DIR share directories [PREFIX/share]
|
||||||
|
--docdir=DIR misc. documentation [PREFIX/share/doc]
|
||||||
|
--mandir=DIR man pages [PREFIX/share/man]
|
||||||
|
|
||||||
|
Some influential environment variables:
|
||||||
|
CC C compiler command [detected]
|
||||||
|
CFLAGS C compiler flags [-Os -pipe ...]
|
||||||
|
LDFLAGS Linker flags
|
||||||
|
|
||||||
|
Use these variables to override the choices made by configure.
|
||||||
|
|
||||||
|
EOF
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# Helper functions
|
||||||
|
|
||||||
|
quote () {
|
||||||
|
tr '\n' ' ' <<EOF | grep '^[-[:alnum:]_=,./:]* $' >/dev/null 2>&1 && { echo "$1" ; return 0 ; }
|
||||||
|
$1
|
||||||
|
EOF
|
||||||
|
printf %s\\n "$1" | sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/" -e "s#^'\([-[:alnum:]_,./:]*\)=\(.*\)\$#\1='\2#"
|
||||||
|
}
|
||||||
|
echo () { printf "%s\n" "$*" ; }
|
||||||
|
fail () { echo "$*" ; exit 1 ; }
|
||||||
|
fnmatch () { eval "case \"\$2\" in $1) return 0 ;; *) return 1 ;; esac" ; }
|
||||||
|
cmdexists () { type "$1" >/dev/null 2>&1 ; }
|
||||||
|
trycc () { test -z "$CC" && cmdexists "$1" && CC=$1 ; }
|
||||||
|
|
||||||
|
stripdir () {
|
||||||
|
while eval "fnmatch '*/' \"\${$1}\"" ; do eval "$1=\${$1%/}" ; done
|
||||||
|
}
|
||||||
|
|
||||||
|
trycppif () {
|
||||||
|
printf "checking preprocessor condition %s... " "$1"
|
||||||
|
echo "typedef int x;" > "$tmpc"
|
||||||
|
echo "#if $1" >> "$tmpc"
|
||||||
|
echo "#error yes" >> "$tmpc"
|
||||||
|
echo "#endif" >> "$tmpc"
|
||||||
|
if $CC $2 -c -o "$tmpo" "$tmpc" >/dev/null 2>&1 ; then
|
||||||
|
printf "false\n"
|
||||||
|
return 1
|
||||||
|
else
|
||||||
|
printf "true\n"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
tryflag () {
|
||||||
|
printf "checking whether compiler accepts %s... " "$2"
|
||||||
|
echo "typedef int x;" > "$tmpc"
|
||||||
|
if $CC $CFLAGS_TRY $2 -c -o "$tmpo" "$tmpc" >/dev/null 2>&1 ; then
|
||||||
|
printf "yes\n"
|
||||||
|
eval "$1=\"\${$1} \$2\""
|
||||||
|
eval "$1=\${$1# }"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
printf "no\n"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
tryldflag () {
|
||||||
|
printf "checking whether linker accepts %s... " "$2"
|
||||||
|
echo "typedef int x;" > "$tmpc"
|
||||||
|
if $CC $LDFLAGS_TRY -nostdlib -shared "$2" -o "$tmpo" "$tmpc" >/dev/null 2>&1 ; then
|
||||||
|
printf "yes\n"
|
||||||
|
eval "$1=\"\${$1} \$2\""
|
||||||
|
eval "$1=\${$1# }"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
printf "no\n"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Beginning of actual script
|
||||||
|
|
||||||
|
CFLAGS_AUTO=
|
||||||
|
CFLAGS_TRY=
|
||||||
|
LDFLAGS_AUTO=
|
||||||
|
LDFLAGS_TRY=
|
||||||
|
SRCDIR=
|
||||||
|
PREFIX=/usr/local
|
||||||
|
EXEC_PREFIX='$(PREFIX)'
|
||||||
|
BINDIR='$(EXEC_PREFIX)/bin'
|
||||||
|
MANDIR='$(PREFIX)/share/man'
|
||||||
|
|
||||||
|
for arg ; do
|
||||||
|
case "$arg" in
|
||||||
|
--help|-h) usage ;;
|
||||||
|
--srcdir=*) SRCDIR=${arg#*=} ;;
|
||||||
|
--prefix=*) PREFIX=${arg#*=} ;;
|
||||||
|
--exec-prefix=*) EXEC_PREFIX=${arg#*=} ;;
|
||||||
|
--bindir=*) BINDIR=${arg#*=} ;;
|
||||||
|
--sharedir=*) SHAREDIR=${arg#*=} ;;
|
||||||
|
--docdir=*) DOCDIR=${arg#*=} ;;
|
||||||
|
--mandir=*) MANDIR=${arg#*=} ;;
|
||||||
|
--enable-*|--disable-*|--with-*|--without-*|--*dir=*|--build=*) ;;
|
||||||
|
-* ) echo "$0: unknown option $arg" ;;
|
||||||
|
CC=*) CC=${arg#*=} ;;
|
||||||
|
CFLAGS=*) CFLAGS=${arg#*=} ;;
|
||||||
|
CPPFLAGS=*) CPPFLAGS=${arg#*=} ;;
|
||||||
|
LDFLAGS=*) LDFLAGS=${arg#*=} ;;
|
||||||
|
*=*) ;;
|
||||||
|
*) ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
for i in SRCDIR PREFIX EXEC_PREFIX BINDIR MANDIR ; do
|
||||||
|
stripdir $i
|
||||||
|
done
|
||||||
|
|
||||||
|
#
|
||||||
|
# Get the source dir for out-of-tree builds
|
||||||
|
#
|
||||||
|
if test -z "$SRCDIR" ; then
|
||||||
|
SRCDIR="${0%/configure}"
|
||||||
|
stripdir SRCDIR
|
||||||
|
fi
|
||||||
|
abs_builddir="$(pwd)" || fail "$0: cannot determine working directory"
|
||||||
|
abs_srcdir="$(cd $SRCDIR && pwd)" || fail "$0: invalid source directory $SRCDIR"
|
||||||
|
test "$abs_srcdir" = "$abs_builddir" && SRCDIR=.
|
||||||
|
test "$SRCDIR" != "." -a -f Makefile -a ! -h Makefile && fail "$0: Makefile already exists in the working directory"
|
||||||
|
|
||||||
|
#
|
||||||
|
# Get a temp filename we can use
|
||||||
|
#
|
||||||
|
i=0
|
||||||
|
set -C
|
||||||
|
while : ; do i=$(($i+1))
|
||||||
|
tmpc="./conf$$-$PPID-$i.c"
|
||||||
|
tmpo="./conf$$-$PPID-$i.o"
|
||||||
|
2>|/dev/null > "$tmpc" && break
|
||||||
|
test "$i" -gt 50 && fail "$0: cannot create temporary file $tmpc"
|
||||||
|
done
|
||||||
|
set +C
|
||||||
|
trap 'rm -f "$tmpc" "$tmpo"' EXIT INT QUIT TERM HUP
|
||||||
|
|
||||||
|
#
|
||||||
|
# Find a C compiler to use
|
||||||
|
#
|
||||||
|
printf "checking for C compiler... "
|
||||||
|
trycc cc
|
||||||
|
trycc gcc
|
||||||
|
trycc clang
|
||||||
|
printf "%s\n" "$CC"
|
||||||
|
test -n "$CC" || { echo "$0: cannot find a C compiler" ; exit 1 ; }
|
||||||
|
|
||||||
|
printf "checking whether C compiler works... "
|
||||||
|
echo "typedef int x;" > "$tmpc"
|
||||||
|
if output=$($CC $CPPFLAGS $CFLAGS -c -o "$tmpo" "$tmpc" 2>&1) ; then
|
||||||
|
printf "yes\n"
|
||||||
|
else
|
||||||
|
printf "no; compiler output follows:\n%s\n" "$output"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
#
|
||||||
|
# Figure out options to force errors on unknown flags.
|
||||||
|
#
|
||||||
|
tryflag CFLAGS_TRY -Werror=unknown-warning-option
|
||||||
|
tryflag CFLAGS_TRY -Werror=unused-command-line-argument
|
||||||
|
tryldflag LDFLAGS_TRY -Werror=unknown-warning-option
|
||||||
|
tryldflag LDFLAGS_TRY -Werror=unused-command-line-argument
|
||||||
|
|
||||||
|
CFLAGS_STD="-std=c99 -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -DNDEBUG -D_FORTIFY_SOURCE=2"
|
||||||
|
LDFLAGS_STD="-lc -lutil"
|
||||||
|
|
||||||
|
OS=$(uname)
|
||||||
|
|
||||||
|
case "$OS" in
|
||||||
|
FreeBSD) CFLAGS_STD="$CFLAGS_STD -D_BSD_SOURCE -D__BSD_VISIBLE=1" ;;
|
||||||
|
*BSD) CFLAGS_STD="$CFLAGS_STD -D_BSD_SOURCE" ;;
|
||||||
|
Darwin) CFLAGS_STD="$CFLAGS_STD -D_DARWIN_C_SOURCE" ;;
|
||||||
|
AIX) CFLAGS_STD="$CFLAGS_STD -D_ALL_SOURCE" ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
tryflag CFLAGS -pipe
|
||||||
|
|
||||||
|
# Try flags to optimize binary size
|
||||||
|
tryflag CFLAGS -Os
|
||||||
|
tryflag CFLAGS -ffunction-sections
|
||||||
|
tryflag CFLAGS -fdata-sections
|
||||||
|
tryldflag LDFLAGS_AUTO -Wl,--gc-sections
|
||||||
|
|
||||||
|
# Try hardening flags
|
||||||
|
tryflag CFLAGS -fPIE
|
||||||
|
tryflag CFLAGS_AUTO -fstack-protector-all
|
||||||
|
tryldflag LDFLAGS -Wl,-z,now
|
||||||
|
tryldflag LDFLAGS -Wl,-z,relro
|
||||||
|
tryldflag LDFLAGS_AUTO -pie
|
||||||
|
|
||||||
|
printf "creating config.mk... "
|
||||||
|
|
||||||
|
cmdline=$(quote "$0")
|
||||||
|
for i ; do cmdline="$cmdline $(quote "$i")" ; done
|
||||||
|
|
||||||
|
exec 3>&1 1>config.mk
|
||||||
|
|
||||||
|
cat << EOF
|
||||||
|
# This version of config.mk was generated by:
|
||||||
|
# $cmdline
|
||||||
|
# Any changes made here will be lost if configure is re-run
|
||||||
|
SRCDIR = $SRCDIR
|
||||||
|
PREFIX = $PREFIX
|
||||||
|
EXEC_PREFIX = $EXEC_PREFIX
|
||||||
|
BINDIR = $BINDIR
|
||||||
|
MANPREFIX = $MANDIR
|
||||||
|
CC = $CC
|
||||||
|
CFLAGS = $CFLAGS
|
||||||
|
LDFLAGS = $LDFLAGS
|
||||||
|
CFLAGS_STD = $CFLAGS_STD
|
||||||
|
LDFLAGS_STD = $LDFLAGS_STD
|
||||||
|
CFLAGS_AUTO = $CFLAGS_AUTO
|
||||||
|
LDFLAGS_AUTO = $LDFLAGS_AUTO
|
||||||
|
CFLAGS_DEBUG = -U_FORTIFY_SOURCE -UNDEBUG -O0 -g -ggdb -Wall -Wextra -pedantic -Wno-unused-parameter -Wno-sign-compare
|
||||||
|
EOF
|
||||||
|
exec 1>&3 3>&-
|
||||||
|
|
||||||
|
printf "done\n"
|
||||||
|
|
||||||
|
test "$SRCDIR" = "." || ln -sf $SRCDIR/Makefile .
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
#compdef abduco
|
||||||
|
|
||||||
|
typeset -A opt_args
|
||||||
|
|
||||||
|
_abduco_sessions() {
|
||||||
|
declare -a sessions
|
||||||
|
sessions=( $(abduco | sed '1d;s/.*\t[0-9][0-9]*\t//') )
|
||||||
|
_describe -t session 'session' sessions
|
||||||
|
}
|
||||||
|
|
||||||
|
_abduco_firstarg() {
|
||||||
|
if (( $+opt_args[-a] || $+opt_args[-A] )); then
|
||||||
|
_abduco_sessions
|
||||||
|
elif (( $+opt_args[-c] || $+opt_args[-n] )); then
|
||||||
|
_guard "^-*" 'session name'
|
||||||
|
elif [[ -z $words[CURRENT] ]]; then
|
||||||
|
compadd "$@" -S '' -- -
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
_arguments -s \
|
||||||
|
'(-a -A -c -n -f)-a[attach to an existing session]' \
|
||||||
|
'(-a -A -c -n)-A[attach to a session, create if does not exist]' \
|
||||||
|
'(-a -A -c -n -l)-c[create a new session and attach to it]' \
|
||||||
|
'(-a -A -c -n -l)-n[create a new session but do not attach to it]' \
|
||||||
|
'-e[set the detachkey (default: ^\\)]:detachkey' \
|
||||||
|
'(-a)-f[force create the session]' \
|
||||||
|
'(-q)-p[pass-through mode]' \
|
||||||
|
'-q[be quiet]' \
|
||||||
|
'-r[read-only session, ignore user input]' \
|
||||||
|
'(-c -n)-l[attach with the lowest priority]' \
|
||||||
|
'(-)-v[show version information and exit]' \
|
||||||
|
'1: :_abduco_firstarg' \
|
||||||
|
'2:command:_path_commands' \
|
||||||
|
'*:: :{ shift $((CURRENT-3)) words; _precommand; }'
|
||||||
12
debug.c
12
debug.c
|
|
@ -16,8 +16,8 @@ static void print_packet(const char *prefix, Packet *pkt) {
|
||||||
[MSG_ATTACH] = "ATTACH",
|
[MSG_ATTACH] = "ATTACH",
|
||||||
[MSG_DETACH] = "DETACH",
|
[MSG_DETACH] = "DETACH",
|
||||||
[MSG_RESIZE] = "RESIZE",
|
[MSG_RESIZE] = "RESIZE",
|
||||||
[MSG_REDRAW] = "REDRAW",
|
|
||||||
[MSG_EXIT] = "EXIT",
|
[MSG_EXIT] = "EXIT",
|
||||||
|
[MSG_PID] = "PID",
|
||||||
};
|
};
|
||||||
const char *type = "UNKNOWN";
|
const char *type = "UNKNOWN";
|
||||||
if (pkt->type < countof(msgtype) && msgtype[pkt->type])
|
if (pkt->type < countof(msgtype) && msgtype[pkt->type])
|
||||||
|
|
@ -29,15 +29,21 @@ static void print_packet(const char *prefix, Packet *pkt) {
|
||||||
fwrite(pkt->u.msg, pkt->len, 1, stderr);
|
fwrite(pkt->u.msg, pkt->len, 1, stderr);
|
||||||
break;
|
break;
|
||||||
case MSG_RESIZE:
|
case MSG_RESIZE:
|
||||||
fprintf(stderr, "%dx%d", pkt->u.ws.ws_col, pkt->u.ws.ws_row);
|
fprintf(stderr, "%"PRIu16"x%"PRIu16, pkt->u.ws.cols, pkt->u.ws.rows);
|
||||||
break;
|
break;
|
||||||
case MSG_ATTACH:
|
case MSG_ATTACH:
|
||||||
fprintf(stderr, "readonly: %d low-priority: %d",
|
fprintf(stderr, "readonly: %d low-priority: %d",
|
||||||
pkt->u.i & CLIENT_READONLY,
|
pkt->u.i & CLIENT_READONLY,
|
||||||
pkt->u.i & CLIENT_LOWPRIORITY);
|
pkt->u.i & CLIENT_LOWPRIORITY);
|
||||||
break;
|
break;
|
||||||
|
case MSG_EXIT:
|
||||||
|
fprintf(stderr, "status: %"PRIu32, pkt->u.i);
|
||||||
|
break;
|
||||||
|
case MSG_PID:
|
||||||
|
fprintf(stderr, "pid: %"PRIu32, pkt->u.i);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "len: %zu", pkt->len);
|
fprintf(stderr, "len: %"PRIu32, pkt->len);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
|
|
|
||||||
58
server.c
58
server.c
|
|
@ -75,27 +75,6 @@ static int server_set_socket_non_blocking(int sock) {
|
||||||
return fcntl(sock, F_SETFL, flags | O_NONBLOCK);
|
return fcntl(sock, F_SETFL, flags | O_NONBLOCK);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Client *server_accept_client(void) {
|
|
||||||
int newfd = accept(server.socket, NULL, NULL);
|
|
||||||
if (newfd == -1 || server_set_socket_non_blocking(newfd) == -1)
|
|
||||||
goto error;
|
|
||||||
Client *c = client_malloc(newfd);
|
|
||||||
if (!c)
|
|
||||||
goto error;
|
|
||||||
if (!server.clients)
|
|
||||||
server_mark_socket_exec(true, true);
|
|
||||||
c->socket = newfd;
|
|
||||||
c->state = STATE_CONNECTED;
|
|
||||||
c->next = server.clients;
|
|
||||||
server.clients = c;
|
|
||||||
server.read_pty = true;
|
|
||||||
return c;
|
|
||||||
error:
|
|
||||||
if (newfd != -1)
|
|
||||||
close(newfd);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool server_read_pty(Packet *pkt) {
|
static bool server_read_pty(Packet *pkt) {
|
||||||
pkt->type = MSG_CONTENT;
|
pkt->type = MSG_CONTENT;
|
||||||
ssize_t len = read(server.pty, pkt->u.msg, sizeof(pkt->u.msg));
|
ssize_t len = read(server.pty, pkt->u.msg, sizeof(pkt->u.msg));
|
||||||
|
|
@ -157,6 +136,35 @@ static void server_sigterm_handler(int sig) {
|
||||||
exit(EXIT_FAILURE); /* invoke atexit handler */
|
exit(EXIT_FAILURE); /* invoke atexit handler */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Client *server_accept_client(void) {
|
||||||
|
int newfd = accept(server.socket, NULL, NULL);
|
||||||
|
if (newfd == -1 || server_set_socket_non_blocking(newfd) == -1)
|
||||||
|
goto error;
|
||||||
|
Client *c = client_malloc(newfd);
|
||||||
|
if (!c)
|
||||||
|
goto error;
|
||||||
|
if (!server.clients)
|
||||||
|
server_mark_socket_exec(true, true);
|
||||||
|
c->socket = newfd;
|
||||||
|
c->state = STATE_CONNECTED;
|
||||||
|
c->next = server.clients;
|
||||||
|
server.clients = c;
|
||||||
|
server.read_pty = true;
|
||||||
|
|
||||||
|
Packet pkt = {
|
||||||
|
.type = MSG_PID,
|
||||||
|
.len = sizeof pkt.u.l,
|
||||||
|
.u.l = getpid(),
|
||||||
|
};
|
||||||
|
server_send_packet(c, &pkt);
|
||||||
|
|
||||||
|
return c;
|
||||||
|
error:
|
||||||
|
if (newfd != -1)
|
||||||
|
close(newfd);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static void server_sigusr1_handler(int sig) {
|
static void server_sigusr1_handler(int sig) {
|
||||||
int socket = server_create_socket(server.session_name);
|
int socket = server_create_socket(server.session_name);
|
||||||
if (socket != -1) {
|
if (socket != -1) {
|
||||||
|
|
@ -221,10 +229,12 @@ static void server_mainloop(void) {
|
||||||
break;
|
break;
|
||||||
case MSG_RESIZE:
|
case MSG_RESIZE:
|
||||||
c->state = STATE_ATTACHED;
|
c->state = STATE_ATTACHED;
|
||||||
case MSG_REDRAW:
|
if (!(c->flags & CLIENT_READONLY) && c == server.clients) {
|
||||||
if (!(c->flags & CLIENT_READONLY) && (client_packet.type == MSG_REDRAW || c == server.clients)) {
|
|
||||||
debug("server-ioct: TIOCSWINSZ\n");
|
debug("server-ioct: TIOCSWINSZ\n");
|
||||||
ioctl(server.pty, TIOCSWINSZ, &client_packet.u.ws);
|
struct winsize ws = { 0 };
|
||||||
|
ws.ws_row = client_packet.u.ws.rows;
|
||||||
|
ws.ws_col = client_packet.u.ws.cols;
|
||||||
|
ioctl(server.pty, TIOCSWINSZ, &ws);
|
||||||
}
|
}
|
||||||
kill(-server.pid, SIGWINCH);
|
kill(-server.pid, SIGWINCH);
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
28
testsuite.sh
28
testsuite.sh
|
|
@ -7,6 +7,9 @@ ABDUCO_OPTS="-e ^\\"
|
||||||
[ ! -z "$1" ] && ABDUCO="$1"
|
[ ! -z "$1" ] && ABDUCO="$1"
|
||||||
[ ! -x "$ABDUCO" ] && echo "usage: $0 /path/to/abduco" && exit 1
|
[ ! -x "$ABDUCO" ] && echo "usage: $0 /path/to/abduco" && exit 1
|
||||||
|
|
||||||
|
TESTS_OK=0
|
||||||
|
TESTS_RUN=0
|
||||||
|
|
||||||
detach() {
|
detach() {
|
||||||
sleep 1
|
sleep 1
|
||||||
printf ""
|
printf ""
|
||||||
|
|
@ -74,12 +77,14 @@ run_test_attached() {
|
||||||
local output="$name.out"
|
local output="$name.out"
|
||||||
local output_expected="$name.expected"
|
local output_expected="$name.expected"
|
||||||
|
|
||||||
|
TESTS_RUN=$((TESTS_RUN + 1))
|
||||||
echo -n "Running test attached: $name "
|
echo -n "Running test attached: $name "
|
||||||
expected_abduco_attached_output "$name" "$cmd" > "$output_expected" 2>&1
|
expected_abduco_attached_output "$name" "$cmd" > "$output_expected" 2>&1
|
||||||
$ABDUCO -c "$name" $cmd 2>&1 | sed 's/.$//' > "$output"
|
|
||||||
|
|
||||||
if diff -u "$output_expected" "$output" && check_environment; then
|
if $ABDUCO -c "$name" $cmd 2>&1 | sed 's/.$//' > "$output" && sleep 1 &&
|
||||||
|
diff -u "$output_expected" "$output" && check_environment; then
|
||||||
rm "$output" "$output_expected"
|
rm "$output" "$output_expected"
|
||||||
|
TESTS_OK=$((TESTS_OK + 1))
|
||||||
echo "OK"
|
echo "OK"
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
|
|
@ -97,6 +102,7 @@ run_test_detached() {
|
||||||
local output="$name.out"
|
local output="$name.out"
|
||||||
local output_expected="$name.expected"
|
local output_expected="$name.expected"
|
||||||
|
|
||||||
|
TESTS_RUN=$((TESTS_RUN + 1))
|
||||||
echo -n "Running test detached: $name "
|
echo -n "Running test detached: $name "
|
||||||
expected_abduco_detached_output "$name" "$cmd" > "$output_expected" 2>&1
|
expected_abduco_detached_output "$name" "$cmd" > "$output_expected" 2>&1
|
||||||
|
|
||||||
|
|
@ -104,6 +110,7 @@ run_test_detached() {
|
||||||
$ABDUCO -a "$name" 2>&1 | sed 's/.$//' > "$output" &&
|
$ABDUCO -a "$name" 2>&1 | sed 's/.$//' > "$output" &&
|
||||||
diff -u "$output_expected" "$output" && check_environment; then
|
diff -u "$output_expected" "$output" && check_environment; then
|
||||||
rm "$output" "$output_expected"
|
rm "$output" "$output_expected"
|
||||||
|
TESTS_OK=$((TESTS_OK + 1))
|
||||||
echo "OK"
|
echo "OK"
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
|
|
@ -121,6 +128,7 @@ run_test_attached_detached() {
|
||||||
local output="$name.out"
|
local output="$name.out"
|
||||||
local output_expected="$name.expected"
|
local output_expected="$name.expected"
|
||||||
|
|
||||||
|
TESTS_RUN=$((TESTS_RUN + 1))
|
||||||
echo -n "Running test: $name "
|
echo -n "Running test: $name "
|
||||||
$cmd >/dev/null 2>&1
|
$cmd >/dev/null 2>&1
|
||||||
expected_abduco_epilog "$name" $? > "$output_expected" 2>&1
|
expected_abduco_epilog "$name" $? > "$output_expected" 2>&1
|
||||||
|
|
@ -129,6 +137,7 @@ run_test_attached_detached() {
|
||||||
$ABDUCO -a "$name" 2>&1 | tail -1 | sed 's/.$//' > "$output" &&
|
$ABDUCO -a "$name" 2>&1 | tail -1 | sed 's/.$//' > "$output" &&
|
||||||
diff -u "$output_expected" "$output" && check_environment; then
|
diff -u "$output_expected" "$output" && check_environment; then
|
||||||
rm "$output" "$output_expected"
|
rm "$output" "$output_expected"
|
||||||
|
TESTS_OK=$((TESTS_OK + 1))
|
||||||
echo "OK"
|
echo "OK"
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
|
|
@ -144,17 +153,16 @@ run_test_dvtm() {
|
||||||
return 0;
|
return 0;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
TESTS_RUN=$((TESTS_RUN + 1))
|
||||||
local name="dvtm"
|
local name="dvtm"
|
||||||
local output="$name.out"
|
local output="$name.out"
|
||||||
local output_expected="$name.expected"
|
local output_expected="$name.expected"
|
||||||
|
|
||||||
echo exit | dvtm >/dev/null 2>&1
|
: > "$output_expected"
|
||||||
expected_abduco_epilog "$name" $? > "$output_expected"
|
if dvtm_session | $ABDUCO -c "$name" > "$output" 2>&1 &&
|
||||||
local len=`wc -c "$output_expected" | awk '{ print $1 }'`
|
|
||||||
len=$((len+1))
|
|
||||||
if dvtm_session | $ABDUCO -c "$name" 2>&1 | tail -c $len | sed 's/.$//' > "$output" &&
|
|
||||||
diff -u "$output_expected" "$output" && check_environment; then
|
diff -u "$output_expected" "$output" && check_environment; then
|
||||||
rm "$output" "$output_expected"
|
rm "$output" "$output_expected"
|
||||||
|
TESTS_OK=$((TESTS_OK + 1))
|
||||||
echo "OK"
|
echo "OK"
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
|
|
@ -165,8 +173,8 @@ run_test_dvtm() {
|
||||||
|
|
||||||
test_non_existing_command || echo "Execution of non existing command FAILED"
|
test_non_existing_command || echo "Execution of non existing command FAILED"
|
||||||
|
|
||||||
run_test_attached "seq" "seq 1 1000"
|
run_test_attached "awk" "awk 'BEGIN {for(i=1;i<=1000;i++) print i}'"
|
||||||
run_test_detached "seq" "seq 1 1000"
|
run_test_detached "awk" "awk 'BEGIN {for(i=1;i<=1000;i++) print i}'"
|
||||||
|
|
||||||
run_test_attached "false" "false"
|
run_test_attached "false" "false"
|
||||||
run_test_detached "false" "false"
|
run_test_detached "false" "false"
|
||||||
|
|
@ -203,3 +211,5 @@ run_test_attached_detached "attach-detach" "./long-running.sh"
|
||||||
rm ./long-running.sh
|
rm ./long-running.sh
|
||||||
|
|
||||||
run_test_dvtm
|
run_test_dvtm
|
||||||
|
|
||||||
|
[ $TESTS_OK -eq $TESTS_RUN ]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue