[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: CWD of job-monitored subprocess
From: |
Alex fxmbsw7 Ratchev |
Subject: |
Re: CWD of job-monitored subprocess |
Date: |
Sun, 23 Jan 2022 09:21:13 +0100 |
i am not sure at all of what you write, and your overcomplicated codes i
dont read
but maybe if u handle the args absolutely in the beginning
play file1 file2
then play does
file=$PWD/$1 for example
cd /
handle "$file" ( absolute path )
greets
On Sun, Jan 23, 2022, 02:41 Steffen Nurpmeso <steffen@sdaoden.eu> wrote:
> Hello.
>
> Some time back i struggled with a problem and just now wondered
> whether anyone has an approach to deal with the problem.
>
> For long i use some shell functions to listen to music, but one
> day i opened the lid of my laptop and found that one encfs
> filesystem has not been unmounted on lid close, and that has been
> because i thoughtlessly started playing some music while my CWD
> was down in one of its directories.
>
> So i rewrote those functions, but it turns out to be an
> impossibility in job-monitored subprocesses, because some
> intermediate shell environment still keeps the CWD where we
> started going.
>
> So for example MP4/AAC files i now play via
>
> mp4play() (
> __r_d_b_x__ y "${@}"
> eval "${__x__} faad -q -w \"${__r__}\" |\
> sox -q -t raw -r 44100 -c 2 -b 16 -e signed-integer - -t alsa"
> )
> mp4playq() {
> #set -m
> (
> __r_d_b_x__ y "${@}"
> eval "${__x__} faad -q -w \"${__r__}\" |\
> sox -q -t raw -r 44100 -c 2 -b 16 -e signed-integer - -t alsa"
> ) &
> }
>
> Where *q() is just "silent, immediately in the background".
> The helper is now (it digs -==stdin and can seek input forward)
>
> __r_d_b_x__() {
> [ "${#}" -lt 2 ] && exit 64
> if [ "${2}" = - ]; then
> [ "${1}" != y ] && exit 64
> __r__=- __d__=- __b__=-
> else
> __r__=$(realpath "${2}")
> __d__=$(dirname "${__r__}")
> __b__=$(basename "${__r__}")
> fi
>
> __x__=
> if [ "${1}" = y ] && [ ${#} -gt 2 ]; then
> if [ "${__r__}" != - ]; then
> exec 5<&0 <"${__r__}"
> __r__=-
> fi
> dd skip=${3} ibs=1 count=0 2>/dev/null
> __x__='cat |'
> fi
>
> cd /
> }
>
> So the helper cd(1)s to / in order to change the CWD of the
> actually running subprocess. However, one may see
>
> [1]+ Stopped ( __r_d_b_x__ y "${@}"; eval "${__x__}
> faad -q -w \"${__r__}\" | sox -q -t raw -r 44100 -c 2 -b 16 -e
> signed-integer - -t alsa" ) (wd: /usr/ports/core)
> (wd now: ~/sec.arena/configs.git/home)
>
> So the wd: of the actual music job is not / but /usr/ports/core.
> I then gave up, thinking all i could do is temporily switch the
> shell's CWD as such to /, start the subprocess, and then go back,
> no problem no more now that the helper uses that super expensive
> realpath, dirname, basename .. for nothing :), but the will to do
> it was gone, as the problem normally does not occur.
>
> Howver, maybe someone knows a better approach to make the
> supervising shell move away? I mean, it must have held some
> reference, otherwise the filesystem would have been unmounted?
>
> Ciao from Germany,
>
> --steffen
> |
> |Der Kragenbaer, The moon bear,
> |der holt sich munter he cheerfully and one by one
> |einen nach dem anderen runter wa.ks himself off
> |(By Robert Gernhardt)
>
>