|
|
1.1 root 1: // vi:set ts=4:
2:
3: //
4: // nono
5: // Copyright (C) 2024 nono project
6: // Licensed under nono-license.txt
7: //
8:
9: #include "runx.h"
10: #include <stdio.h>
11: #include <signal.h>
12: #include <sys/param.h>
13: #include <sys/sysctl.h>
14:
15: // ページサイズを取得する。
16: int
17: getpgsize()
18: {
19: const int mib[2] = { CTL_HW, HW_PAGESIZE };
20: int val;
21: size_t len;
22:
23: len = sizeof(val);
24: if (sysctl(mib, countof(mib), &val, &len, NULL, 0) < 0) {
25: err(1, "sysctl");
26: }
27: return val;
28: }
29:
30: // シグナル名(定数名) を返す。なければ "signal %d" を返す。
31: // スタティック変数を返す場合があるので同時に2回呼ばないこと。
32: // (Linux には sigabbrev_np() がある)
33: const char *
34: signame(int signo)
35: {
36: static char buf[16];
37: static const struct {
38: int val;
39: const char *name;
40: } table[] = {
41: // <sys/signal.h> から加工した一覧。
42: // ターゲットは NetBSD だと分かっているので細かいことは気にしない。
43: #define E(s) { s, #s }
44: E(SIGHUP),
45: E(SIGINT),
46: E(SIGQUIT),
47: E(SIGILL),
48: E(SIGTRAP),
49: E(SIGABRT),
50: E(SIGEMT),
51: E(SIGFPE),
52: E(SIGKILL),
53: E(SIGBUS),
54: E(SIGSEGV),
55: E(SIGSYS),
56: E(SIGPIPE),
57: E(SIGALRM),
58: E(SIGTERM),
59: E(SIGURG),
60: E(SIGSTOP),
61: E(SIGTSTP),
62: E(SIGCONT),
63: E(SIGCHLD),
64: E(SIGTTIN),
65: E(SIGTTOU),
66: E(SIGIO),
67: E(SIGXCPU),
68: E(SIGXFSZ),
69: E(SIGVTALRM),
70: E(SIGPROF),
71: E(SIGWINCH),
72: E(SIGINFO),
73: E(SIGUSR1),
74: E(SIGUSR2),
75: E(SIGPWR),
76: #undef E
77: };
78: for (int i = 0; i < countof(table); i++) {
79: if (signo == table[i].val) {
80: return table[i].name;
81: }
82: }
83: snprintf(buf, sizeof(buf), "signal %d", signo);
84: return buf;
85: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.