03 Apr 2013
OS : opensuse11.4
需求:判断磁盘是否存在,不想搞的很复杂也不想用写的方式来确定磁盘的存在,所以就想用读的方式来确定,但是呢,系统有cache,所有即使在拔去硬盘的情况下依然能读到文件,尝试了O_SYNC O_DIRECT对read都无效,搞了整1天,汗流浃背,找啊找啊,用posix_fadvise可以达到目的。有别的简单方法的,求指教。
ps : 一个好工具vmtouch
代码示例:
int clear_file_cache(const char* filename)
{
struct stat st;
int fd;
if(stat(filename, &st) < 0)
{
perror("stat error!");
return -1;
}
fd = open(filename, O_RDONLY);
if(fd < 0)
{
perror("open error!");
return -1;
}
if(posix_fadvise(fd, 0, st.st_size, POSIX_FADV_DONTNEED) != 0)
{
perror("posix_fadvise error!");
return -1;
}
else
printf("clear cache OK!\n");
return 0;
}
02 Apr 2013
用转换构造函数可以将一个指定类型的数据转换为类的对象.
用类型转换函数(type conversion function)可以将一个类的对象转换为一个指定类型的数据.
类型转换函数的一般形式为:
operator 类型名()
{实现转换的语句}
在函数名前面不能指定函数类型,函数没有参数.
#include <string>
#include <iostream>
using namespace std;
class A {
string s;
public:
A() : s("hello") {}
virtual ~A() {}
operator const string&() { return s; }
};
int main() {
A a;
cout << string(a) << endl;
}
02 Apr 2013
#!/bin/sh
while true
do
AUTH_ID=`ps -ef | grep auth | grep -v grep |grep -v xinitrc | awk '{print $13}'`
if [ "$AUTH_ID" = "" ];then
echo "waiting for ready, retry 10s later..."
else
x11vnc -auth $AUTH_ID -display :0 -xdamage -ncache_cr
fi
sleep 10
done
os: opensuse 11.4
02 Apr 2013
OS: ubuntu 12.1
gcc: 4.6.3
arm gcc: 4.5.1
QT: qt-x11-opensource-src-4.5.3
QT-embedded: qt-embedded-linux-opensource-src-4.5.3
编译qt-x11-opensource-src-4.5.3
./configure –qvfb
make
cd tools/qvfb //进入此目录,准备对它进行编译
make
sudo make install
编译过程中出现的错误:
error: ‘ppd_file_t’ does not name a type
解决方法:
打开src/gui/painting/qcups_p.h
做如下修改:
#ifndef QT_NO_CUPS
#include //加入ppd头文件
QT_BEGIN_NAMESPACE
安装 arm-linux-gcc
(略)
编译qt-embedded-linux-opensource-src-4.5.3
./configure -embedded arm -qt-libpng
make
sudo make install
编译时间会很长,可以使用下面的配置来减少编译时间:
./configure -embedded arm -qt-libpng \
-release \
-shared \
-fast \
-no-largefile \
-qt-sql-sqlite \
-no-qt3support \
-no-xmlpatterns \
-no-mmx \
-no-3dnow \
-no-sse \
-no-sse2 \
-no-svg \
-no-webkit \
-qt-zlib \
-qt-gif \
-qt-libtiff \
-qt-libpng \
-qt-libmng \
-qt-libjpeg \
-make libs \
-xplatform qws/linux-arm-g++ \
-nomake tools \
-nomake examples \
-nomake docs \
-nomake demo \
-no-nis \
-no-cups \
-no-iconv \
-no-dbus \
-no-openssl \
-embedded arm \
-little-endian \
-qt-freetype \
-depths 16,18 \
-qt-gfx-linuxfb \
-no-gfx-transformed \
-no-gfx-multiscreen \
-no-gfx-vnc \
-no-gfx-qvfb \
-qt-kbd-usb \
-no-glib
02 Apr 2013
OS: ubuntu 12.04
安装vsftpd
apt-get install vsftpd
编辑 /etc/vsftpd.conf
listen=YES
#anonymous_enable=YES
local_enable=YES
write_enable=YES
#anon_upload_enable=YES
anonymous_enable=NO #默认是允许
dirmessage_enable=YES # 允许进入文件夹
xferlog_enable=YES # 允许 ftp 日志记录允许
connect_from_port_20=YES # 允许使用20号端口作为数据传送端口
secure_chroot_dir=/var/run/vsftpd/empty
pam_service_name=vsftpd
rsa_cert_file=/etc/ssl/private/vsftpd.pem
设置ftp文件夹
mkdir -p /home/ftp/upload
mkdir -p /home/ftp/download
chmod 755 /home/ftp
chmod 777 /home/ftp/upload
chmod 755 /home/ftp/download
设置ftp用户
-
增加ftp组:groupadd ftpgroup
-
编辑 /etc/vsftpd.conf:
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.chroot_list
-
增加ftp用户: useradd -g ftpgroup -d /home/ftp -M upload ftpuser
-
设置ftp用户密码: passwd ftpuser
-
编辑 /etc/vsftpd.chroot_list:
ftpuser
-
重启vsftp服务: service vsftpd restart