#
原來使用boost::asio 庫時,基本上只用了一個io_serve 這種情況下,其實并不能把多線程的好處利用起來。 當異步任務多的時候,集中到一個線程上去了。
這邊有網友貼了一個完整的asio 多線程服務器。
http://blog.sina.com.cn/s/blog_48d4cf2d0100nvei.html
粗看了一下, 服務器里面的session封裝不給力,沒有用到shared_ptr 。 多次出現delete .
這個其實用智能指針,可以很方便的管理生命周期。
APKTool反編譯后再打包出錯(Error retrieving parent for item: No resource found that matches the given name '@*android:style/Theme.Light')
看出錯情形,是styles.xml出錯了,因為是自己寫的,所以打開原始的XML與反編譯后的XML一對比,發現反編譯后的XML里<resources>/<style>的parent屬性出錯了,由原本的android:Theme.xxx變成了@*android:style/Theme.xxx,前面多出來@*,中間多出來style/,原因找到就好辦了,將這些XML改正確,再打包,成了!
http://dreamisx.blog.163.com/blog/static/1150048392012112024649308/
另外還有一些@*的不能改。
如果報lib png 的錯。直接打開畫圖程序一個個重新覆蓋一下就行了。 這個是體力活。
一、背景
項目需要,研究了使用ossec ,其中有一個ossec agentless的功能,可以實現遠程的文件完整性校驗 。為方便使用, 決定采用證書模式來處理登陸。
二、配置過程
以下直接抄了 http://praetorianprefect.com/archives/2009/11/ossec-agentless-to-save-the-day/
obsd46# sudo -u ossec ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/var/ossec/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /var/ossec/.ssh/id_rsa. Your public key has been saved in /var/ossec/.ssh/id_rsa.pub. The key fingerprint is: b8:c3:47:9a:33:09:5c:eb:54:a0:82:39:a6:06:63:08 ossec@obsd45.ptnsecurity.com The key's randomart image is: +--[ RSA 2048]----+ |E . | |oo . . | |Bo. . . . | |=o o . + | |.. o + S | |. = * | | @ . | | = | | | +-----------------+
Now that the SSH keys are present, we can add the host without a password. The special command line argument used with register_host.sh
is NOPASS
in all capitals, which will tell OSSEC supplied scripts to make use of SSH keys.
obsd46# /var/ossec/agentless/register_host.sh add root@172.17.20.20 NOPASS
Enabling SSH key on the host to be monitored.
You will now need to securely get the contents of /var/ossec/.ssh/id_rsa.pub
to 172.17.20.20.
Using SSH and the password for a single time will make this simple. This will create the /root/.ssh
if it is not already created, but might throw an error as it does if the directory is already present. This is not a problem and can be ignored.
obsd46# cat /var/ossec/.ssh/id_rsa.pub | ssh root@172.17.20.20 "( mkdir /root/.ssh/; cat - >> /root/.ssh/authorized_keys )" root@172.17.20.20 's password: mkdir: cannot create directory `/root/.ssh/': File exists obsd46# ssh root@172.17.20.20 "cat /root/.ssh/authorized_keys " root@172.17.20.20 's password: ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAzyTBo7CqkI0TISR9S+KPS/gYY60nkD7Qe8wTTXrAEFvPNFJ NJJpVVKsij6zw86lvTZ6hx9ib1M+MXvt+70uF/z1hYwnYrczR2TR03Z5nwOUA9OK61nBWXVwCi9GsQs6Oeo mY9vkBDoKzB52+TKKSk9ZoC+HYPiT5SaiHZvMOV7kWuwF67lnYwlG5FdkRdOiXp7DcRjje4/Hixg7RLLl7o dEXpIakzGfalt3yQDmwvSUZhyg3OuoKimTeNiKU/jlHlmEPuDZpiQe6QhFH38EeEIZTdHsYITodl8sY+n9I eNMalGIHPs+bph+qcK+6cOb1RGaeGqJBFjaqPUyismz0bw== ossec@obsd45.ptnsecurity.com
We can also verify that it worked with the following command.
obsd46# sudo -u ossec ssh root@172.17.20.20 The authenticity of host '172.17.20.20 (172.17.20.20)' can't be established. RSA key fingerprint is 14:cd:f2:e9:c3:5b:07:28:68:75:a7:b5:88:c2:6b:77. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '172.17.20.20' (RSA) to the list of known hosts. Last login: Tue Oct 6 12:40:05 2009 from 172.17.20.154 [linux26.ptnsecurity.com ~]# exit
三、問題
在以上各種折騰完成后,使用root賬號已經可以正常登陸使用了
但在使用普通賬號的mytest時卻一直失敗。 經網上搜索有以下版本的信息
http://www.2cto.com/os/201206/137286.html
http://serverfault.com/questions/230771/ssh-configuration-publickeys-permission-denied-publickey-password-error
另外還有一個網址一時忘記了。
中途試著將密碼鑒權關閉,直接報錯:Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
最終查看 /var/log/secure Authentication refused: bad ownership or modes for directory /home/mytest/.ssh
想起來我忘記的那個網址上有一句話: .ssh 目錄需要是 755 不能是775 。。。然后修改就搞定了!!!!完成收工。
當設備驅動 程序創建一個 系統線程運行時,線程運行在system process中,任務管理器在計算cpu占用時,以進程為單位,無法確定CPU實際消耗在哪個驅動上。
以下為一個使用的例子
1、打開cmd窗口。
2、執行dir \\computername\c$ /s 遍歷列出c盤文件,這個list會很大,所以一直會運行。
3、運行process explorer ,打開system process 屬性頁面
4、切換到線程標簽頁
5、按Cswith data 排序 ,在start address處將可以看到srv2.sys 設備驅動。此處即表示線程對應的驅動程序。點擊module按鈕可以瀏覽驅動文件的屬性。
早上收到郵件。VDR又故障了,這次的錯是 Failed to create snapshot. Error -3941
google了一下, VDR的知識文章還是略少了。 各種都不相關啊。
最后在官方的KB中 找到一篇看上去有點像的文章
http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1028924
結果也是大失所望。居然說是磁盤超過備份限制。。。官方的文章果然各種二。
最后各種折騰,發現是虛擬機上直聯了一塊PCI設備。導致無法創建快照。
E100007: Miscellaneous error
到VDP 控制臺去查看日志后 有以下結果。
avvcbimage error 12041 disk size in backup is different than target and changed block processing was requested, restore of disk at failed please collect administrator log and submit a support request
原因應當是我修改硬盤屬性導致。
以下文字摘自"Windows Internals Fifth Edition "
An object handle is an index into a process-specific handle table, pointed to by the executive
process (EPROCESS) block (described in Chapter 5). The first handle index is 4, the second
8, and so on. A process’s handle table contains pointers to all the objects that the process
has opened a handle to. Handle tables are implemented as a three-level scheme, similar
to the way that the x86 memory management unit implements virtual-to-physical address
152 Windows Internals, Fifth Edition
translation, giving a maximum of more than
16,000,000 handles per process
The test program Testlimit from Sysinternals has an option to open handles to an object
until it cannot open any more handles. You can use this to see how many handles can
be created in a single process on your system. Because handle tables are allocated from
paged pool, you might run out of paged pool before you hit the maximum number of
handles that can be created in a single process. To see how many handles you can create
on your system, follow these steps:
1. Download the Testlimit .zip file from www.microsoft.com/technet/ sysinternals, and
unzip it into a directory.
Run Process Explorer, and then click View and then System Information. Notice
the current and maximum size of paged pool. (To display the maximum pool size
values, Process Explorer must be configured properly to access the symbols for
the kernel image, Ntoskrnl.exe.) Leave this system information display running so
that you can see pool utilization when you run the Testlimit program.
3. Open a command prompt.
4. Run the Testlimit program with the -h switch (do this by typing testlimit –h).
When Testlimit fails to open a new handle, it will display the total number of
handles it was able to create. If the number is less than approximately 16 million,
you are probably running out of paged pool before hitting the theoretical perprocess
handle limit.
5. Close the Command Prompt window; doing this will kill the Testlimit process, thus
closing all the open handles.
從80386開始,Intel 處理器處理 4KB的頁。
32位線性地址分為 10 10 12 三部分。 directory table offsetcr3控制寄存器中存放正使用的頁目錄的物理地址。
一個頁目錄項與頁表項結構相同。 其中有20位Field 包含頁框的物理地址。
當從cr3 中獲取到頁目錄地址時,取線性地址的高10位取頁目錄(4KB,每一個32位占4字節,共1024個頁表)中指向的頁表項地址(20位的Field)
使用取出來的物理地址得到頁表地址,線性地址的中間10位,取頁表內偏移量,取含有數據的頁的物理地址。
最終使用線性地址的12位取頁內數據偏移量。
頁目錄項指向的頁表中有4096的物理地址,也就是對應1024個頁表項,剛好與線性地址的10位相符。
而頁表項指向的項含有4096的物理地址,偏移量需要線性地址的12來取offset
cr4寄存器,PSE標記,可使得擴展分頁與常規分頁共存。
cr0 的PG = 0時,線性地址被解析為物理地址。
How to: Set a Thread Name in Native Code
dddd
最近在分析webkit 項目 。分享其中幾個tips!一、WTF庫WTF的詳細含義未找到出處,在webkit上找了找,大致是webkit 項目 繼承使用的之前的一個封裝庫。其中包涵了數值轉換,字符串,智能指針,線程管理,線程間同步等函數庫。從源代碼的命名來看,有多種移植版本,如以下注釋
// For portability, we do not use thread-safe statics natively supported by some compilers (e.g. gcc).
#define AtomicallyInitializedStatic(T, name) \
WTF::lockAtomicallyInitializedStaticMutex(); \
static T name; \
WTF::unlockAtomicallyInitializedStaticMutex();
二、How to: Set a Thread Name in Native Code
MSDN的釋義是To set a thread name in your program, use the SetThreadName function
原文見:http://msdn.microsoft.com/en-us/library/xcb2z8hs(VS.90).aspx
1//
2 // Usage: SetThreadName (-1, "MainThread");
3 //
4 #include <windows.h>
5 const DWORD MS_VC_EXCEPTION=0x406D1388;
6
7 #pragma pack(push,8)
8 typedef struct tagTHREADNAME_INFO
9 {
10 DWORD dwType; // Must be 0x1000.
11 LPCSTR szName; // Pointer to name (in user addr space).
12 DWORD dwThreadID; // Thread ID (-1=caller thread).
13 DWORD dwFlags; // Reserved for future use, must be zero.
14 } THREADNAME_INFO;
15 #pragma pack(pop)
16
17 void SetThreadName( DWORD dwThreadID, char* threadName)
18 {
19 THREADNAME_INFO info;
20 info.dwType = 0x1000;
21 info.szName = threadName;
22 info.dwThreadID = dwThreadID;
23 info.dwFlags = 0;
24
25 __try
26 {
27 RaiseException( MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info );
28 }
29 __except(EXCEPTION_EXECUTE_HANDLER)
30 {
31 }
32 }
一、準備編譯
此步參照網絡上的文章,中文翻譯或者直接查看官網,推薦 官網,翻譯后的文章可能會少掉一些步驟。
二、編譯中注意事項
下載與安裝
DirectX SDK 這一步是必須的,否則會提示少了d3d9.h 文件以及一系列的lib文件。
i18n.cc 文件中可能有一個錯誤
typedef BOOL( WINAPI* GetPreferredUILanguages_Fn)(DWORD, PULONG, PWZZSTR, PULONG);
這一行報錯。 __stdcall 前缺少) ,經查看,此函數聲明對應一個指針數組中的函數。
第三個參數應當為PWSTR .修改后。base.lib 項目編譯通過
-- update 此處是windows SDK 7 中的函數聲明。需要更新SDK包后就編譯OK啦。
三、編譯最好選在休息時間。
夜間編譯其實也不錯,但若出問題,可能反而浪費了時間。