【发布时间】:2010-02-23 08:12:11
【问题描述】:
我的应用程序现在已作为产品密封,将与安装了 linux 系统的 PC 一起销售。我将如何为客户创建一个新用户,但我想将一个类似界面的应用程序绑定到用户,所以当我的客户通过终端登录时,选定的应用程序会自动运行,当连接结束时,应用程序会以同样的方式退出。 我知道,也许这可以通过编程方式实现......但是...... 你知道有什么建议吗??? 谢谢 都赞赏...
【问题讨论】:
我的应用程序现在已作为产品密封,将与安装了 linux 系统的 PC 一起销售。我将如何为客户创建一个新用户,但我想将一个类似界面的应用程序绑定到用户,所以当我的客户通过终端登录时,选定的应用程序会自动运行,当连接结束时,应用程序会以同样的方式退出。 我知道,也许这可以通过编程方式实现......但是...... 你知道有什么建议吗??? 谢谢 都赞赏...
【问题讨论】:
正如AProgrammer 所述,您可以将应用程序作为用户外壳或在配置文件中运行,如本例所示
# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.
# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022
# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
# run you app here
exec myapp
【讨论】:
如果您的应用程序是由xinetd 启动的,那么您可以让它在连接时启动。断开连接后,您的应用将收到SIGHUP,因此您可以抓住它并关闭。
【讨论】:
xinetd 启动的程序将其标准输入和标准输出连接到网络套接字,因此它们可以使用标准的 C I/O 函数与客户端通信,而不必直接处理套接字。
终端登录执行的程序是由/etc/passwd 中的字段确定的用户shell。您可以将您的程序作为外壳程序,或者安排您的程序由外壳程序启动脚本(~/.profile、~/.cshrc 取决于外壳程序)执行。
【讨论】: