Package: im-switch
Version: 1.14
Severity: normal

VINE's setime (/usr/share/vine/imelib) is interesting which may give
idea for avoiding duplicated start of IME by im-switch initiated
scripts.

For example for set up IME with SCIM, first next function is run

setSCIM() {
    XMODIFIERS="@im=SCIM"
    GTK_IM_MODULE=scim
    QT_IM_MODULE=scim
    rpm -q --quiet scim-qtimm || QT_IM_MODULE=xim
    export XMODIFIERS GTK_IM_MODULE QT_IM_MODULE
    startScim
    checkKinput2Mod && kinput2ctl stop
    return 0
}

In here, 

startScim(){
    if [ -z "`pidofmyproc scim-launcher`" ] ; then
      scim -d >& /dev/null
    fi
    TK_KCPROTO=xim
}

Here pidofmyproc checks existing of scim-launcher and if it s not there,
it runs SCIM in daemon mode.

pidofmyproc is defined in /usr/share/vine/functions (a variant of
/etc/init.d/functions).  Here are the relevant portions:

pidofproc() {
        # Test syntax.
        if [ $# = 0 ] ; then
                echo "Usage: pidofproc {program}"
                return 1
        fi

        # First try "/var/run/*.pid" files
        if [ -f /var/run/$1.pid ] ; then
                pid=`head -1 /var/run/$1.pid`
                if [ "$pid" != "" ] ; then
                        echo $pid 
                        return 0
                fi
        fi

        # Next try "pidof"
        pid=`/sbin/pidof $1`
        if [ "$pid" != "" ] ; then
                echo $pid 
                return 0
        fi

        # Finally try to extract it from ps
        ps auxw | awk 'BEGIN { prog=ARGV[1]; ARGC=1 } 
                           { if ((prog == $11) || (("(" prog ")") == $11) ||
                           ((prog ":") == $11)) { print $2 ; exit 0 } }' $1
}


pidofmyproc() {
        # Test syntax.
        if [ $# = 0 ] ; then
                echo "Usage: ownofproc {program}"
                return 1
        fi

        # Next try "pidof"
        pid=`pidofproc $1`
        if [ "$pid" != "" ] ; then
                for i in $pid; do
                    user=`ps h -o user --pid $i`
                    if [ "${user}" = "${USER}" ]; then
                        echo -n $i" "
                    fi
                done
                echo
                return 0
        fi
}

I do not see the license for these script in the header but Miquel van
Smoorenburg is listed as the part of upstream.  In Debian there is pidof
command by him.  This is binary used above too.

Then I find the /lib/lsb/init-functions which has a bit diferent but
similar looking: pidofproc. 

pidofproc () {
    local pidfile line i pids= status specified pid
    pidfile=
    specified=

    OPTIND=1
    while getopts p: opt ; do
        case "$opt" in
            p)  pidfile="$OPTARG"; specified=1;;
        esac
    done
    shift $(($OPTIND - 1))

    if [ -z "${pidfile:-}" ]; then
        pidfile=/var/run/${1##*/}.pid
    fi

    if [ -f "$pidfile" ]; then
        read pid < "$pidfile"
        if [ -n "${pid:-}" ]; then
            if $(kill -0 "${pid:-}" 2> /dev/null); then
                echo "$pid"
                return 0
            else
                return 1 # program is dead and /var/run pid file exists
            fi
        fi
    fi
    if [ -x /bin/pidof -a ! "$specified" ]; then
        /bin/pidof -o %PPID $1
        status="$?"
        [ "$status" = 1 ] && return 3 # program is not running
        return 0
    fi
    return 4 # program or service is unknown
}

I was wondering -o here and 

       -o omitpid
              Tells pidof to omit processes with that process id. The  special
              pid  %PPID  can  be used to name the parent process of the pidof
              program, in other words the calling shell or shell script.

Since SCIM do not use PID file thing, simple pidof maybe more than enough.
In this case, using safer long option and 


local l_pid l_user
pid=$(/bin/pidof $1)
if [ -n "$l_pid" ] ; then
        for i in $l_pid; do
                l_user=$(ps --no-headers -o user --pid $i)
                if [ "${l_user}" = "${USER}" ]; then
                        echo -n $i" "
                fi
        done
        echo
        return 0
fi

Since we only use this to check existing process owned by the user, this
may be even more simplified.  Oh well, ... later



im-switch handles only 3 IME controling parameters.
 XMODIFIERS
 XIM
 GTK_IM_MODULE
 QT_IM_MODULE

It may be a good idea to add few more variables like VINE has in its 
imeset script:
 TK_KCPROTO=htt
 EMACS_IME
  ...





-- System Information:
Debian Release: lenny/sid
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.22-2-amd64 (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

im-switch depends on no packages.

Versions of packages im-switch recommends:
ii  x11-common                    1:7.2-5    X Window System (X.Org) infrastruc

-- no debconf information



-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to