ソースコードを調べる
FreeBSDでなにか問題が発生したり解決したいことがでてきた場合には、
しかし、
FreeBSDでソースコードを調べる方法はいくつかあります。ここでは3つの方法を採り上げて、
Subversionでソースコードをチェック
FreeBSDのソースコードはSubversionで管理されています。基本的にはSubversionを使って調査したい対象となるバージョンのFreeBSDのソースコードをダウンロードしてきて、
まず、
# FreeBSD 10.2系のソースコードを取得 svn checkout https://svn.FreeBSD.org/base/releng/10.2 ./ # FreeBSD 9.3系のソースコードを取得 svn checkout https://svn.FreeBSD.org/base/releng/9.3 ./ # FreeBSD 10.2-RELEASEのソースコードを取得 svn checkout https://svn.FreeBSD.org/base/release/10.2.0 ./ # FreeBSD 9.3-RELEASEのソースコードを取得 svn checkout https://svn.FreeBSD.org/base/release/9.3.0 ./ # 開発版のソースコードを取得 svn checkout https://svn.FreeBSD.org/base/head ./ # 10系安定版のソースコードを取得 svn checkout https://svn.FreeBSD.org/base/stable/10 ./ # 9系安定版のソースコードを取得 svn checkout https://svn.FreeBSD.org/base/stable/9 ./
あとは何も考えずにキーワードでgrep(1)検索を行います。次のようにlpr(1)コマンドのソースコードの1つである
# cd /usr/src/ # grep -r 'unable to get official' * usr.sbin/lpr/common_source/net.c: asprintf(&error, "unable to get official name " #
該当する部分をみると、
# cat -n usr.sbin/lpr/common_source/net.c
…略…
171 /*
172 * Figure out whether the local machine is the same
173 * as the remote machine (RM) entry (if it exists).
174 * We do this by counting the intersection of our
175 * address list and theirs. This is better than the
176 * old method (comparing the canonical names), as it
177 * allows load-sharing between multiple print servers.
178 * The return value is an error message which must be
179 * free()d.
180 */
181 char *
182 checkremote(struct printer *pp)
183 {
184 char lclhost[MAXHOSTNAMELEN];
185 struct addrinfo hints, *local_res, *remote_res, *lr, *rr;
186 char *error;
187 int ncommonaddrs, errno;
188 char h1[NI_MAXHOST], h2[NI_MAXHOST];
189
190 if (!pp->rp_matches_local) { /* Remote printer doesn't match local */
191 pp->remote = 1;
192 return NULL;
193 }
194
195 pp->remote = 0; /* assume printer is local */
196 if (pp->remote_host == NULL)
197 return NULL;
198
199 /* get the addresses of the local host */
200 gethostname(lclhost, sizeof(lclhost));
201 lclhost[sizeof(lclhost) - 1] = '\0';
202
203 memset(&hints, 0, sizeof(hints));
204 hints.ai_family = family;
205 hints.ai_socktype = SOCK_STREAM;
206 hints.ai_flags = AI_PASSIVE;
207 if ((errno = getaddrinfo(lclhost, NULL, &hints, &local_res)) != 0) {
208 asprintf(&error, "unable to get official name " ← ここにヒットしてる
209 "for local machine %s: %s",
210 lclhost, gai_strerror(errno));
211 return error;
212 }
ようするに名前解決に失敗している、
# cd /usr/src/ # grep -r MAXNS * | grep define include/resolv.h:#define MAXNS 3 /*%< max # name servers we'll track */ #
実はこれは実際にあった問題で、
svnwebでソースコードをチェック
すでにどこのソースコードを読めばよいか検討がついているという場合には、

Subversionを利用するのが面倒な環境を使っているとか、
GitHubでソースコードをチェック
FreeBSDのソースコード自体はSubversionで管理されていますが、

GitHubはソースコードの検索サービスを提供していますので、


最近、
ソースコードは情報のかたまり
何も知らない状態ですとFreeBSDハンドブックのようにある程度のクオリティでまとめられた文章が有益ですし、
ソースコードの大半はC言語で記述されていますので、