手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆
浏览模式: 标准 | 列表分类:Linux

How to get a “codesigned” gdb on OSX?

这是一篇backup的文章。起因是我的命令行下的gdb出现了:

XML/HTML代码
  1. Starting program: /usr/local/Cellar/php56/5.6.9/bin/php /server/yii hprose  
  2. Unable to find Mach task port for process-id 30717: (os/kern) failure (0x5).  
  3.  (please check gdb is codesigned - see taskgated(8))  

于是google了一下,发现也有人在问类似的问题:

XML/HTML代码
  1. Because I need a Python-enabled gdb, I installed another version via  
  2.   
  3. brew tap homebrew/dupes  
  4. brew install gdb  
  5. I want to use this gdb with Eclipse CDT, where I entered the path to the binary in the Debugging settings. However, launching a program for debugging fails with the following message:  
  6.   
  7. Error in final launch sequence  
  8. Failed to execute MI command:  
  9. -exec-run  
  10. Error message from debugger back end:  
  11. Unable to find Mach task port for process-id 39847: (os/kern) failure (0x5).\n (please check gdb is codesigned - see taskgated(8))  
  12. Unable to find Mach task port for process-id 39847: (os/kern) failure (0x5).\n (please check gdb is codesigned - see taskgated(8))  
  13. What does "codesigned" mean in this context? How can I get this gdbrunning?  

有一个5个点赞的,我发现无效:

XML/HTML代码
  1. t would seem you need to sign the executable. See these links for more information. You should be able to get away with self signing if you don't plan on redistributing that version of gdb.  
  2.   
  3. https://developer.apple.com/library/mac/#documentation/Security/Conceptual/CodeSigningGuide/Introduction/Introduction.html  
  4.   
  5. https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man1/codesign.1.html  
  6.   
  7. Alternatively, you could disable code signing on your system, although this presents a security risk. To do so try running sudo spctl --master-disable in the Terminal.  

24人点赞的看上去不错:

XML/HTML代码
  1. I.1 Codesigning the Debugger  
  2.   
  3. The Darwin Kernel requires the debugger to have special permissions before it is allowed to control other processes. These permissions are granted by codesigning the GDB executable. Without these permissions, the debugger will report error messages such as:  
  4.   
  5. Starting program: /x/y/foo  
  6. Unable to find Mach task port for process-id 28885: (os/kern) failure (0x5).  
  7.  (please check gdb is codesigned - see taskgated(8))  
  8. Codesigning requires a certificate. The following procedure explains how to create one:  
  9.   
  10. Start the Keychain Access application (in /Applications/Utilities/Keychain Access.app)  
  11. Select the Keychain Access -> Certificate Assistant -> Create a Certificate... menu  
  12. Then:  
  13. Choose a name for the new certificate (this procedure will use "gdb-cert" as an example)  
  14. Set "Identity Type" to "Self Signed Root"  
  15. Set "Certificate Type" to "Code Signing"  
  16. Activate the "Let me override defaults" option  
  17. Click several times on "Continue" until the "Specify a Location For The Certificate" screen appears, then set "Keychain" to "System"  
  18. Click on "Continue" until the certificate is created  
  19. Finally, in the view, double-click on the new certificate, and set "When using this certificate" to "Always Trust"  
  20. Exit the Keychain Access application and restart the computer (this is unfortunately required)  
  21. Once a certificate has been created, the debugger can be codesigned as follow. In a Terminal, run the following command...  
  22.   
  23. codesign -f -s  "gdb-cert"  <gnat_install_prefix>/bin/gdb  
  24. ... where "gdb-cert" should be replaced by the actual certificate name chosen above, and should be replaced by the location where you installed GNAT.  
  25. source: https://gcc.gnu.org/onlinedocs/gcc-4.8.1/gnat_ugn_unw/Codesigning-the-Debugger.html  

这个4人点赞的简洁明了:

XML/HTML代码
  1. I made gdb work on OSX 10.9 without codesigning this way (described here):  
  2.   
  3. Install gdb with macports. (may be you can skip it)  
  4.   
  5. sudo nano /System/Library/LaunchDaemons/com.apple.taskgated.plist  
  6. change option string from -s to -sp at line 22, col 27.  
  7.   
  8. reboot the computer.  
  9.   
  10. Use gdb  

然而这都没有什么卵用,这时候一个2人点赞的说了一个重点:

XML/HTML代码
  1. It's a very old topic, but I am adding a response, because out of many available instructions, only one contained just the right steps to make a self-signed debugger work.  
  2.   
  3. You have to create a self-signed root certificate and then sign the gdb executable with it, but many people complained that it did not work for them. Neither did it for me until I stumbled upon this link.  
  4.   
  5. The key point missing in other manuals is that you have to restart your computer for the changes to take effect. Once I did that, everything worked as intended.  
  6.   
  7. I hope, this will help others.  

是的,他在have to restart上加粗了!!!

最后一个回复表示使用了4人点赞的那个建议,并表示他就是这么完成的!原文来自:http://stackoverflow.com/questions/13913818/how-to-get-a-codesigned-gdb-on-osx

 

hostname被清除后导致proftpd无法启动的故障

由于需要上传一个文件到服务器,所以才发现ftp服务居然没有启动。

到线上进行检查:

XML/HTML代码
  1. root@(none):~# ps aux|grep proftpd  
  2. root     31447  0.0  0.0   9288  2004 pts/0    S+   17:11   0:00 grep proftpd  
  3. root@(none):~# /etc/init.d/proftpd start  
  4. [....] Starting ftp server: proftpd_none_ proftpd[31473]: warning: unable to determine IP address of '_none_'  
  5. _none_ proftpd[31473]: error: no valid servers configured  
  6. _none_ proftpd[31473]: Fatal: error processing configuration file '/etc/proftpd/proftpd.conf'  
  7.  failed!  

咦,启动失败,这个_none_是什么意思?难道就是那个hostname没有设定的原因?

于是:hostname neatstudio.com ,然后重新退出ssh并登录,再启动ftp就OK了。

上文中的root@(none),我也不知道这个hostname是被哪个程序给清除了。不过也确实才知道,原来hostname不设置还会导致proftpd无法启动!汗

 

Tags: hostname, proftpd

快速将googleapis的链接换为useso的国内镜像

在使用第三方的程序时,特别是国外的项目,总是会碰到引用googleapis的问题,比如字体之类的,对于国外用户来说这玩意真方便,google也会帮你做CDN,多好啊,但在国内,你遇到的卡顿就不是一点两点了,有时候甚至会拖慢得页面打不开

所以,Wordpress、drupal 之类的程序在拿到手的第一时间就应该将里面的地址换掉,当然Wordpress还有插件,但drupal就不一定有了!

那怎么办?偷懒的办法是用PHP程序,递归查找并替换,如果是在本地,找个工具替换一下即可,现在的IDE都有这功能,如果已经部署到线上,那么只要你有ssh,你就可以尝试:sed -i s/googleapis/useso/g `grep -rl googleapis ./` ,该命令是将当前目录下含有googleapis的文件列出来,然后用sed进行全文替换。

如果做国外站的用户,我想他们一定是很痛苦的,如果用googleapis的数据吧,国内打开就卡死,用国内的cdn吧,国外又卡。当然 有解决方案~~

How to set up a clean UTF-8 environment in Linux

 本来不想转,但真心是有用,以前的方法也有点过时,而且主要是不方便,所以就来贴个更全的。这种问题非常容易 遇到,用ubuntu、debian在阿里云上,原来都正常的,你只要一apt-get update一下,原来的LC环境就全没了。

原文地址在:http://perlgeek.de/en/article/set-up-a-clean-utf8-environment , 我上一次写关于这个的问题是在2012年了,那篇的标题是:perl: warning: Setting locale failed. 也可以看一下

How to set up a clean UTF-8 environment in Linux

Many people have problems with handling non-ASCII characters in their programs, or even getting their IRC client or text editor to display them correctly.

To efficiently work with text data, your environment has to be set up properly - it is so much easier to debug a problem which has encoding issues if you can trust your terminal to correctly display correct UTF-8.

I will show you how to set up such a clean environment on Debian Lenny, but most things work independently of the distribution, and parts of it even work on other Unix-flavored operating systems like MacOS X.

Choosing an encoding

In the end the used character encoding doesn't matter much, as long as it's a Unicode encoding, i.e. one which can be used to encode all Unicode characters.

UTF-8 is usually a good choice because it efficiently encodes ASCII data too, and the character data I typically deal with still has a high percentage of ASCII chars. It is also used in many places, and thus one can often avoid conversions.

Whatever you do, chose one encoding and stick to it, for your whole system. On Linux that means text files, file names, locales and all text based applications (mutt, slrn, vim, irssi, ...).

For the rest of this article I assume UTF-8, but it should work very similarly for other character encodings.

Locales: installing

Check that you have the locales package installed. On Debian you can do that with.

$ dpkg -l locales Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Cfg-files/Unpacked/Failed-cfg/Half-inst/trig-aWait/Trig-pend |/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad) ||/ Name           Version        Description +++-==============-==============-============================================ ii  locales        2.7-18         GNU C Library: National Language (locale) da

The last line is the important one: if it starts with ii, the package is installed, and everything is fine. If not, install it. As root, type

$ aptitude install locales

If you get a dialog asking for details, read on to the next section.

Locales: generation

make sure that on your system an UTF-8 locale is generated. As root, type

$ dpkg-reconfigure locales

You'll see a long list of locales, and you can navigate that list with the up/down arrow keys. Pressing the space bar toggles the locale under the cursor. Make sure to select at least one UTF-8 locale, for example en_US-UTF-8 is usually supported very well. (The first part of the locale name stands for the language, the second for the country or dialect, and the third for the character encoding).

In the next step you have the option to make one of the previously selected locales the default. Picking a default UTF-8 locale as default is usually a good idea, though it might change how some programs work, and thus shouldn't be done servers hosting sensitive applications.

Locales: configuration

If you chose a default locale in the previous step, log out completely and then log in again. In any case you can configure your per-user environment with environment variables.

The following variables can effect programs: LANG, LANGUAGE, LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES, LC_PAPER, LC_NAME, LC_ADDRESS, LC_TELEPHONE, LC_MEASUREMENT, LC_IDENTIFICATION.

Most of the time it works to set all of these to the same value. Instead of setting all LC_ variables separately, you can set theLC_ALL. If you use bash as your shell, you can put these lines in your ~/.bashrc and ~/.profile files:

export LC_ALL=en_US.UTF-8 export LANG=en_US.UTF-8 export LANGUAGE=en_US.UTF-8

To make these changes active in the current shell, source the .bashrc:

$ source ~/.bashrc

All newly started interactive bash processes will respect these settings.

A Warning about Non-Interactive Processes

There are certain processes that don't get those environment variables, typically because they are started by some sort of daemon in the background.

Those include processes started from cronat, init scripts, or indirectly spawned from init scripts, like through a web server.

You might need to take additional steps to ensure that those programs get the proper environment variables.

Locales: check

Run the locale program. The output should be similar to this:

LANG=en_US.UTF-8 LANGUAGE=en_US.UTF-8 LC_CTYPE="en_US.UTF-8" LC_NUMERIC="en_US.UTF-8" LC_TIME="en_US.UTF-8" LC_COLLATE="en_US.UTF-8" LC_MONETARY="en_US.UTF-8" LC_MESSAGES="en_US.UTF-8" LC_PAPER="en_US.UTF-8" LC_NAME="en_US.UTF-8" LC_ADDRESS="en_US.UTF-8" LC_TELEPHONE="en_US.UTF-8" LC_MEASUREMENT="en_US.UTF-8" LC_IDENTIFICATION="en_US.UTF-8" LC_ALL=en_US.UTF-8

If not you've made a mistake in one of the previous steps, and need to recheck what you did.

Setting up the terminal emulator

Setting up the terminal emulator for your terminal emulator strongly depends on what you actually use. If you use xterm, you can start it as xterm -en utf-8konsole and the Gnome Terminal can be configured in their respective configuration menus.

Testing the terminal emulator

To test if you terminal emulator works, copy and paste this line in your shell:

perl -Mcharnames=:full -CS -wle 'print "\N{EURO SIGN}"'

This should print a Euro sign  on the console. If it prints a single question mark instead, your fonts might not contain it. Try installing additional fonts. If multiple different (nonsensical) characters are shown, the wrong character encoding is configured. Keep trying :-).

SSH

If you use SSH to log in into another machine, repeat the previous steps, making sure that the locale is set correctly, and that you can view a non-ASCII character like the Euro sign.

Screen

The screen program can work with UTF-8 if you tell it to.

The easiest (and sometimes the only) way is to start it with the -U option:

$ screen -U

and also when detaching (screen -Urd or so).

Inside a running screen you can try Ctrl+a :utf8 on<return>. If that doesn't work, exit your screen and start a new one with -U

Irssi

There's a complete guide for setting up irssi to use UTF-8, which partially overlaps with this one. The gist is:

/set term_charset utf-8 /set recode_autodetect_utf8 ON /set recode_fallback ISO-8859-15 /set recode ON

gogs 如何不使用端口进行访问

gogos 默认是 3000端口,如果你本身已经有了其他WEB服务,比如apache,当然不可能同时占用80端口,这时候就可以利用apapche的proxy功能。如果你是apt-get 安装 的apache,就方便了,debian/ubuntu 都支持a2ensiate,a2enmod这样的小脚本。你只要打开a2enmod proxy proxy_http就行了,然后新建一个site加入以下配置

XML/HTML代码
  1. <VirtualHost *:80>  
  2.     ServerAdmin test@test.com  
  3.     ServerName yoursitename  
  4.     ProxyRequests off  
  5.     ProxyPass / http://127.0.0.1:3000/  
  6.     ProxyPassReverse / http://127.0.0.1:3000  
  7.     <Proxy *>  
  8.         Order Deny,Allow  
  9.         Allow from all  
  10.     </Proxy>  
  11.     ErrorLog ${APACHE_LOG_DIR}/yoursitename.log  
  12.     LogLevel warn  
  13. </VirtualHost>  
是不是很简单,这时候你用supervisor启动后就可以通过WEB访问了.不过这时候有具小缺点,那就是如果你killall gogs进程的话,你会发现再也启动不了了.看启动的LOG会告诉你3000端口被占用,用netstat -an|grep 3000,发现有N个进程都是在CLOSE_WAIT的情况,这时候用: echo $(netstat -anp|grep 127.0.0.1:3000 |awk '{print $7}') 发现,全是apache2占着这些进程.

怀疑刚才在强杀gogs进程的时候,apache因为开着proxy导致刚刚向3000端口发起请求就挂起,导致异常关闭所以一直卡住(以前用nginx的做反代的时候也有类似问题,只要客户机挂了,nginx必须 重启),所以我重启了一下apache,立刻发现gogs启动成功.

至此,如果要 重启gogs最好是/etc/init.d/supervisor restart ,如果不正常就再重启一下apache...

OK,问题全部解决

 

Tags: gogs, apache