Howto

共 127 篇文章。

Tips about writing a manpage

Cheatsheets

From des@:

groff -Tlatin1 -mdoc strtonum.3 2>&1 | less

A even better version from ru@:

cd /usr/src/lib/libc
make manlint MAN=strtonum.3 # to check stderr
make all-man MAN=strtonum.3 -DMANBUILDCAT # to format

参与评论

重新设计了d的一组API

Development

将个性化的factory提取出来,改为使用通用的factory生成同一协议的protocol对象,并将业务逻辑对象作为factory的一个参数。这样做使得代码冗余大大降低了。

参与评论

赞一个csh……

Cheatsheets

以前一直以为不行的,今天仔细看了一下manpage:

如欲让sysctl之后能使用tab补齐,则应使用:

complete sysctl ’n/*/`sysctl -Na`/'

试了一下,不错!

参与评论

while(0)是干吗的?

Development

今天 renzhen 同学问起为什么很多宏都定义为 do { something… } while(0),我也顺便温习了一下。

简而言之:如果希望宏表现的和函数接近,就需要这样做。

阅读全文… ( 本文约 124 字,阅读大致需要 1 分钟 )

关于如何扩展复杂且难懂的C代码的一点经验谈

Development

有时,我们会希望扩展一些现有的C代码。这些代码可能经历了相当久的运行考验——它们至少目前工作起来没有问题——然而,它们可能存在各种各样的问题,比如:

  • 缺少注释。
  • 过分使用的goto语句。
  • 变量名不规范。
  • 逻辑复杂难懂。
  • 过分使用表达式赋值(if (foo = bar()) {})
  • 直接返回函数返回值(这是合法的,但会给增加功能带来困难)

要扩展这类代码是一件有挑战的事情。

阅读全文… ( 本文约 705 字,阅读大致需要 2 分钟 )

一次postfix在线升级

SysAdmin

没啥技术含量,做个笔记而已。

相关日志如下:

Jan 11 22:19:02 tarsier postfix/postfix-script: stopping the Postfix mail system
Jan 11 22:19:02 tarsier postfix/master[92875]: terminating on signal 15
Jan 11 22:19:02 tarsier postfix/postfix-script: starting the Postfix mail system
Jan 11 22:19:02 tarsier postfix/master[70250]: daemon started – version 2.2.8, configuration /usr/local/etc/postfix

阅读全文… ( 本文约 581 字,阅读大致需要 2 分钟 )

用 iPython 做shell

Development

学习一种语言最快的方法就是逼自己干什么事情的时候都用它——有一个利用了Python来实现的shell——iPython,可以用来代替默认的shell。

阅读全文… ( 本文约 193 字,阅读大致需要 1 分钟 )

HOWTO: upgrade OpenLDAP from a major release to another

SysAdmin

Just for reference for future upgrades.

Today I managed to upgrade from OpenLDAP 2.2.29 to OpenLDAP 2.3.11. This is a large upgrade, so all and foremost thing is to backup. Additionally, to keep downtime as less as possible, build these stuff first!

On FreeBSD, the recommended way of installing third party software is to use ports(7). Note that OpenLDAP is separated into two ports, openldap2X-server and openldap2X-client, and building the server requires the client library, therefore, you can not easily do build on the production server (and this SHOULD be avoided anyway).

A solution is to use a separated box (or jail for smaller deployments), to build packages and use pkg_add to install them.

阅读全文… ( 本文约 445 字,阅读大致需要 3 分钟 )