公司的ssh2整合了ldap,当ssh登录时密码提示并不能在当前最新版本的sshpass上被捕获,导致无法实现自动输入密码,现在sshpass1.05的版本基础上增加两行代码即可
修改main.c文件:
[code="cpp"]
setsid();
// This line makes the ptty our controlling tty. We do not otherwise need it open
slavept=open(name, O_RDWR );
dup2(slavept,STDERR_FILENO);// 增加错误输出文件描述符重定向到伪终端
close( slavept );
close( masterpt );
char **new_argv=malloc(sizeof(char *)*(argc+1));
[/code]
[code="cpp"]
terminate=ret;
if( terminate ) {
close( slavept );
}
kill(childpid, SIGKILL ); //增加当handleoutput返回的数值大于0,也就是异常的时候直接杀死子进程,避免当在ldap验证的时候密码提示重复输入导致异常
[/code]
最近在Apache2.4上实践使用c/c++编写高性能cgi程序,在apache上配置mod_fastcgi模式的时候按照步骤始终不能成功,一直卡在mod_fastcgi的make上。提示错误如下(错误内容有省略):
[code="plain"]
/usr/local/apache/build/libtool --silent --mode=compile gcc -std=gnu99 -g -O2 -pthread -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE -I/usr/local/apache/include -I. -I/root/httpd-2.4.3/srclib/apr/include -I/root/httpd-2.4.3/srclib/apr-util/include -prefer-pic -c mod_fastcgi.c && touch mod_fastcgi.slo
mod_fastcgi.c: In function 'send_to_pm':
mod_fastcgi.c:175: warning: initialization from incompatible pointer type
mod_fastcgi.c:175: warning: passing argument 5 of 'ap_log_error_' makes integer from pointer without a cast
/usr/local/apache/include/http_log.h:372: note: expected 'apr_status_t' but argument is of type 'struct server_rec *'
mod_fastcgi.c:236: warning: initialization from incompatible pointer type
mod_fastcgi.c:236: error: expected expression before ')' token
mod_fastcgi.c:236: warning: passing argument 5 of 'ap_log_error_' makes integer from pointer without a cast
/usr/local/apache/include/http_log.h:372: note: expected 'apr_status_t' but argument is of type 'struct server_rec *'
mod_fastcgi.c: In function 'init_module':
mod_fastcgi.c:297: warning: initialization from incompatible pointer type
mod_fastcgi.c:297: warning: passing argument 5 of 'ap_log_error_' makes integer from pointer without a cast
/usr/local/apache/include/http_log.h:372: note: expected 'apr_status_t' but argument is of type 'struct server_rec *'
mod_fastcgi.c:301: warning: initialization from incompatible pointer type
mod_fastcgi.c:301: warning: passing argument 5 of 'ap_log_error_' makes integer from pointer without a cast
/usr/local/apache/include/http_log.h:372: note: expected 'apr_status_t' but argument is of type 'struct server_rec *'
mod_fastcgi.c:329: warning: initialization from incompatible pointer type
mod_fastcgi.c:329: error: expected expression before ')' token
[/code]
于是搜寻各大网站终于在一个serverfault上找到有人提供的mod_fastcgi for apache2.4的解决方案
https://github.com/ByteInternet/libapache-mod-fastcgi
于是赶紧下载下来解压编译,依旧提示类似的编译错误,看了下安装手册才发现需要先大补丁才能编译。于是尝试使用作者提供的patch来给fastcgi官网提供的源码包打补丁:
(1)下载补丁文件
/upload/other/byte-compile-against-apache24.diff
(2) cd /root/mod_fastcgi-2.4.6 并上传本文中提供的diff patch文件到此目录
(3) 然后patch -p1 < byte-compile-against-apache24.diff 即可
(4)注意修改Makefile.AP2 为Makefile 同时修改里面的apache的路径(top_dir)为自己apache所部属的路径。
(5) 最后make && make install 编译mod_fastcgi,然后在apache的conf文件中加入module即可。
附编译fcgi遇到的问题:
如下错误:
[code="plain"]
g++ -DHAVE_CONFIG_H -I. -I. -I.. -I../include -g -O2 -c fcgio.cpp -MT fcgio.lo -MD -MP -MF .deps/fcgio.TPlo -fPIC -DPIC -o .libs/fcgio.lo
fcgio.cpp: In destructor 'virtual fcgi_streambuf::~fcgi_streambuf()':
fcgio.cpp:50: error: 'EOF' was not declared in this scope
fcgio.cpp: In member function 'virtual int fcgi_streambuf::overflow(int)':
fcgio.cpp:70: error: 'EOF' was not declared in this scope
fcgio.cpp:75: error: 'EOF' was not declared in this scope
fcgio.cpp: In member function 'virtual int fcgi_streambuf::sync()':
fcgio.cpp:86: error: 'EOF' was not declared in this scope
fcgio.cpp:87: error: 'EOF' was not declared in this scope
fcgio.cpp: In member function 'virtual int fcgi_streambuf::underflow()':
fcgio.cpp:113: error: 'EOF' was not declared in this scope
make[2]: *** [fcgio.lo] Error 1
make[2]: Leaving directory `/root/fcgi-2.4.1-SNAP-0311112127/libfcgi'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/root/fcgi-2.4.1-SNAP-0311112127'
make: *** [all] Error 2
[/code]
我的gcc版本是4.4,搜寻网上的解决方案是在fcgio.h上加载cstdio头部
引文链接:https://bugs.gentoo.org/show_bug.cgi?id=256654
在编写fcgi程序的时候我们时常需要reload cgi才能重新看到新编译的程序效果,其实我们可以在apache的配置文件中加上如下配置来提供自动的reload策略,而不需要人工的重启来重新加载新程序。
[code="plain"]
<IfModule mod_fastcgi.c>
FastCgiconfig -autoUpdate
</IfModule>
[/code]
在codemirror的控件加载并隐藏div层中,再次display block的时候textarea加载的codemirror是没有正常激活的,当textarea中有文本内容时同样也无法正常显示。在官方的google groups中开发者给出了使用refresh()方法的提示,但是如果当切换隐藏层到显示层的时候,同时触发refresh方法并不能正常激活textarea重新加载,解决方法是使用timeout函数进行延时加载。
伪代码如下:
var editor=CodeMirror.fromTextArea(document.getElementById('textarea), {
mode : 'shell',
lineNumbers : true,
matchBrackets : true
});
代码块
$("#div").show()
setTimeout(function(){
editor.refresh();
},200);