Bullwinkle: Hey Rocky, watch me pull a rabbit out of my hat.
Rocky: But that trick never works.
Bullwinkle: This time for sure.
Presto!
Well, I'm gettin' close.
Rocky: And now it's time for another special feature.
--- "Rocky and His Friends"
XmDipmon 是一个很棒的小应用程序,它显示一个按钮来指示 Internet 连接的状态。当连接断开时,它会闪烁并发出蜂鸣声,这在农村电话系统中太常见了。不幸的是,XmDipmon 仅适用于 dip,这使得它对于大多数使用 chat 进行连接的人来说毫无用处。
构建 XmDipmon 不是问题。XmDipmon 链接到 Motif 库,但它可以很好地使用 Lesstif 构建和工作。挑战在于修改软件包,使其在使用 chat 时也能工作。这实际上涉及到修改源代码,并且必然需要一些编程知识。
"When xmdipmon starts up, it checks for a file called /etc/dip.pid
(you can let it look at another file by using the -pidfile
command line option). This file contains the PID of the dip
deamon (dip switches itself into deamon mode once it has
established a connection)."
--- from the XmDipmon README file
使用 -pidfile 选项,可以指示程序在启动时检查不同的文件,该文件仅在成功 chat 登录期间存在。明显的选择是调制解调器锁定文件。因此,我们可以尝试使用 xmdipmon -pidfile /var/lock/LCK..ttyS3 来调用程序(这假设调制解调器在 com 端口 #4,ttyS3 上)。然而,这只解决了问题的一部分。程序持续监控 dip daemon,我们需要更改它,使其改为轮询与 chat 或 ppp 关联的进程。
只有一个源文件,幸运的是它有很好的注释。扫描 xmdipmon.c
文件,我们找到了 getProcFile 函数,其头部描述如下所示。
/*****
* Name: getProcFile
* Return Type: Boolean
* Description: tries to open the /proc entry as read from the dip pid file.
<snip>
*****/
我们现在正朝着正确的方向前进。跟踪到函数体内部...
/* we watch the status of the real dip deamon */
sprintf(buf, "/proc/%i/status", pid);
procfile = (String)XtMalloc(strlen(buf)*sizeof(char)+1);
strcpy(procfile, buf);
procfile[strlen(buf)] = '\0';
罪魁祸首是第 2383 行
sprintf(buf, "/proc/%i/status", pid);
^^^^^^^^^^^^^^^^^^^^^
这检查 dip daemon 进程是否正在运行。那么,我们如何更改它来监视 pppd daemon 呢?
查看 pppd 手册页
FILES
/var/run/pppn.pid (BSD or Linux), /etc/ppp/pppn.pid (others)
Process-ID for pppd process on ppp interface unit n.
将 xmdipmon.c
中的第 2383 行更改为
sprintf(buf, "/var/run/ppp0.pid" );
重新构建修改后的软件包。构建没有问题。现在使用新的命令行参数进行测试。它工作得非常好。蓝色小按钮指示何时已建立到 ISP 的 ppp
连接,并在连接断开时闪烁并发出蜂鸣声。现在我们有了一个功能齐全的 chat 监视器。
XmDipmon 可以从 Ripley Linux Tools 下载。