apt-get install scim-chewing scim-modules-table
System Settings > Language Support > Install / Remove Languages… 選Chinese
System Settings > Language Support > keyboard input method system 選SCIM
接著啟動SCIM刪除不必要的輸入法
增加切換下一個輸入法的組合鍵
2001:db8:0:0:1:0:0:1 2001:0db8:0:0:1:0:0:1 2001:db8::1:0:0:1 2001:db8::0:1:0:0:1 2001:0db8::1:0:0:1 2001:db8:0:0:1::1 2001:db8:0000:0:1::1 2001:DB8:0:0:1::1
2001:db8:aaaa:bbbb:cccc:dddd:eeee:0001 2001:db8:aaaa:bbbb:cccc:dddd:eeee:001 2001:db8:aaaa:bbbb:cccc:dddd:eeee:01 2001:db8:aaaa:bbbb:cccc:dddd:eeee:1
2001:db8:0:0:0::1 2001:db8:0:0::1 2001:db8:0::1 2001:db8::1
# iptables -p tcp --help
iptables v1.4.12
Usage: iptables -[ACD] chain rule-specification [options]
iptables -I chain [rulenum] rule-specification [options]
iptables -R chain rulenum rule-specification [options]
iptables -D chain rulenum [options]
iptables -[LS] [chain [rulenum]] [options]
iptables -[FZ] [chain] [options]
iptables -[NX] chain
iptables -E old-chain-name new-chain-name
iptables -P chain target [options]
iptables -h (print this help information)
Commands:
Either long or short options are allowed.
--append -A chain Append to chain
--check -C chain Check for the existence of a rule
--delete -D chain Delete matching rule from chain
--delete -D chain rulenum
Delete rule rulenum (1 = first) from chain
--insert -I chain [rulenum]
Insert in chain as rulenum (default 1=first)
--replace -R chain rulenum
Replace rule rulenum (1 = first) in chain
--list -L [chain [rulenum]]
List the rules in a chain or all chains
--list-rules -S [chain [rulenum]]
Print the rules in a chain or all chains
--flush -F [chain] Delete all rules in chain or all chains
--zero -Z [chain [rulenum]]
Zero counters in chain or all chains
--new -N chain Create a new user-defined chain
--delete-chain
-X [chain] Delete a user-defined chain
--policy -P chain target
Change policy on chain to target
--rename-chain
-E old-chain new-chain
Change chain name, (moving any references)
Options:
--ipv4 -4 Nothing (line is ignored by ip6tables-restore)
--ipv6 -6 Error (line is ignored by iptables-restore)
[!] --proto -p proto protocol: by number or name, eg. `tcp'
[!] --source -s address[/mask][...]
source specification
[!] --destination -d address[/mask][...]
destination specification
[!] --in-interface -i input name[+]
network interface name ([+] for wildcard)
--jump -j target
target for rule (may load target extension)
--goto -g chain
jump to chain with no return
--match -m match
extended match (may load extension)
--numeric -n numeric output of addresses and ports
[!] --out-interface -o output name[+]
network interface name ([+] for wildcard)
--table -t table table to manipulate (default: `filter')
--verbose -v verbose mode
--line-numbers print line numbers when listing
--exact -x expand numbers (display exact values)
[!] --fragment -f match second or further fragments only
--modprobe= try to insert modules using this command
--set-counters PKTS BYTES set the counter during insert/append
[!] --version -V print package version.
tcp match options:
[!] --tcp-flags mask comp match when TCP flags & mask == comp
(Flags: SYN ACK FIN RST URG PSH ALL NONE)
[!] --syn match when only SYN flag set
(equivalent to --tcp-flags SYN,RST,ACK,FIN SYN)
[!] --source-port port[:port]
--sport ...
match source port(s)
[!] --destination-port port[:port]
--dport ...
match destination port(s)
[!] --tcp-option number match if TCP option set
# iptables -A INPUT -p icmp
# iptables -A INPUT -p icmp -j LOG
# iptables -A INPUT -p icmp -j ACCEPT
# iptables -L -v
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 icmp -- any any anywhere anywhere
0 0 LOG icmp -- any any anywhere anywhere
LOG level warning
0 0 ACCEPT icmp -- any any anywhere anywhere
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
# ping 127.0.0.1 -c 1
PING 127.0.0.1 (127.0.0.1): 56 data bytes
[ 6975.682678] IN=lo OUT= MAC=00:00:00:00:00:00:00:00:00:00:00:00:08:00 SRC=127.
0.0.1 DST=127.0.0.1 LEN=84 TOS=0x00 PREC=0x00 TTL=64 ID=0 DF PROTO=ICMP TYPE=8 C
ODE=0 ID=4908 SEQ=0
[ 6975.697694] IN=lo OUT= MAC=00:00:00:00:00:00:00:00:00:00:00:00:08:00 SRC=127.
0.0.1 DST=127.0.0.1 LEN=84 TOS=0x00 PREC=0x00 TTL=64 ID=49768 PROTO=ICMP TYPE=0
CODE=0 ID=4908 SEQ=0
64 bytes from 127.0.0.1: seq=0 ttl=64 time=34.397 ms
--- 127.0.0.1 ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max = 34.397/34.397/34.397 ms
# iptables -L -v
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
2 168 icmp -- any any anywhere anywhere
2 168 LOG icmp -- any any anywhere anywhere
LOG level warning
2 168 ACCEPT icmp -- any any anywhere anywhere
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 2 packets, 168 bytes)
pkts bytes target prot opt in out source destination
# ping -c 1 127.0.0.1 PING 127.0.0.1 (127.0.0.1): 56 data bytes 64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.2 ms --- 127.0.0.1 ping statistics --- 1 packets transmitted, 1 packets received, 0% packet loss round-trip min/avg/max = 0.2/0.2/0.2 ms # iptables -A INPUT -s 127.0.0.1 -p icmp -j DROP # ping -c 1 127.0.0.1 PING 127.0.0.1 (127.0.0.1): 56 data bytes --- 127.0.0.1 ping statistics --- 1 packets transmitted, 0 packets received, 100% packet loss #
iptables -D INPUT 1
iptables -D INPUT -s 127.0.0.1 -p icmp -j DROP
#include <iostream> #include <sqlite3.h> #include <cstdlib> #include <assert.h> using namespace std; int main(int argc, char** argv) { sqlite3 *conn; sqlite3_stmt *statement; // SQL Statement Object int ret = 0; int cols; // This routine opens a connection to an SQLite database file // and returns a database connection object. ret = sqlite3_open_v2("hello.db", &conn, SQLITE_OPEN_READONLY, NULL); if (ret) { cout << "can not open database\n"; exit(0); } ret = sqlite3_prepare_v2(conn, "select * from hello", -1, &statement, NULL); if (ret != SQLITE_OK) { cout << "We did not get any data\n"; exit(0); } cols = sqlite3_column_count(statement); for (int col = 0; col < cols; col++) { cout << " " << sqlite3_column_name(statement, col); }; cout << endl; while (true) { ret = sqlite3_step(statement); if (ret == SQLITE_ROW) { for (int col = 0; col < cols; col++) { switch (sqlite3_column_type(statement, col)) { case SQLITE_INTEGER: cout << " " << sqlite3_column_int(statement, col) << " "; break; case SQLITE_FLOAT: cout << " " << sqlite3_column_double(statement, col) << " "; break; case SQLITE_TEXT: cout << " " << sqlite3_column_text(statement, col) << " "; break; case SQLITE_NULL: cout << " " << "NULL" << " "; break; } }; cout << endl; } else if (ret == SQLITE_DONE) { cout << "done" << endl; break; } else { cout << "ret:" << ret << endl; break; } } sqlite3_finalize(statement); sqlite3_close(conn); return 0; }
int sqlite3_exec( sqlite3*, /* An open database */ const char *sql, /* SQL to be evaluated */ int (*callback)(void*,int,char**,char**), /* Callback function */ void *, /* 1st argument to callback */ char **errmsg /* Error msg written here */ );
#include <iostream> #include <sqlite3.h> using namespace std; int callback(void *data, int column, char **value, char **name) { int i; cout << (char *)data << endl; for (i = 0; i < column; i++) { cout << name[i] << ":" << (value[i] ?: "NULL") << endl << flush; } return 0; } int main(int argc, char** argv) { sqlite3 *conn; int ret = 0; char *errmsg = NULL; char data[] = "brook"; // This routine opens a connection to an SQLite database file // and returns a database connection object. ret = sqlite3_open_v2("hello.db", &conn, SQLITE_OPEN_READONLY, NULL); if (ret != SQLITE_OK) { cout << sqlite3_errmsg(conn) << ".(" << ret << ")" << endl; exit(0); } ret = sqlite3_exec(conn, "select * from hello", callback, data, &errmsg); if (ret != SQLITE_OK) { cout << "We did not get any data. " << errmsg << endl; sqlite3_free(errmsg); } sqlite3_close(conn); return 0; }
brook:~$ ls hello.db
ls: cannot access hello.db: No such file or directory
brook:~$ sqlite hello.db
Loading resources from /home/brook/.sqliterc
SQLite version 2.8.17
Enter ".help" for instructions
sqlite> .help
.databases List names and files of attached databases
.dump ?TABLE? ... Dump the database in a text format
.echo ON|OFF Turn command echo on or off
.exit Exit this program
.explain ON|OFF Turn output mode suitable for EXPLAIN on or off.
.header(s) ON|OFF Turn display of headers on or off
.help Show this message
.indices TABLE Show names of all indices on TABLE
.mode MODE Set mode to one of "line(s)", "column(s)",
"insert", "list", or "html"
.mode insert TABLE Generate SQL insert statements for TABLE
.nullvalue STRING Print STRING instead of nothing for NULL data
.output FILENAME Send output to FILENAME
.output stdout Send output to the screen
.prompt MAIN CONTINUE Replace the standard prompts
.quit Exit this program
.read FILENAME Execute SQL in FILENAME
.schema ?TABLE? Show the CREATE statements
.separator STRING Change separator string for "list" mode
.show Show the current values for various settings
.tables ?PATTERN? List names of tables matching a pattern
.timeout MS Try opening locked tables for MS milliseconds
.width NUM NUM ... Set column widths for "column" mode
sqlite> .tables
sqlite> create table hello (x integer PRIMARY KEY ASC, y);
sqlite> .tables
hello
sqlite> insert into hello (y) values('a');
sqlite> insert into hello (y) values(10);
sqlite> insert into hello (y) values(datetime('now'));
sqlite> select * from hello;
x y
---------- ----------
1 a
2 10
3 2012-07-30
sqlite> .quit
brook:~$ sqlite hello.db .dump Loading resources from /home/brook/.sqliterc BEGIN TRANSACTION; create table hello (x integer PRIMARY KEY ASC, y); INSERT INTO hello VALUES(1,'a'); INSERT INTO hello VALUES(2,10); INSERT INTO hello VALUES(3,'2012-07-30 04:20:12'); COMMIT; brook:~$ sqlite hello.db "select * from hello" Loading resources from /home/brook/.sqliterc x y ---------- ---------- 1 a 2 10 3 2012-07-30 brook:~$ cat ~/.sqliterc .mode column .header on .nullvalue NULL
#include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { char buf[128]; float a, b, c, d; FILE *fp; if ((fp = popen("(df -h 2>/dev/null) | tail -n +2", "r")) == NULL) { fprintf(stderr, "popen() failed\n"); return -1; } while (!feof(fp)) { fscanf(fp, "%*[^ ]%f%*[^1-9]%f%*[^1-9]%f%*[^1-9]%f%%%*[^\n]", &a, &b, &c, &d); printf("%f/%f/%f/%f\n", a, b, c, d); } return 0; }
#include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { char buf[] = "1 2 3 4 5"; float a, b, c, d; FILE *fp; if ((fp = popen("xargs -n 1 > /tmp/xx", "w")) == NULL) { fprintf(stderr, "popen() failed\n"); return -1; } fprintf(fp, "%s", buf); pclose(fp); return 0; }
#include <iostream>
class Command {
public:
virtual int exec(void *args) = 0;
};
// Receiver
class TV {
bool turn_on_off;
public:
void pwr_switch() {
if (turn_on_off) {
std::cout << "Turn off TV" << std::endl;
} else {
std::cout << "Turn on TV" << std::endl;
}
turn_on_off = !(turn_on_off);
}
};
class CmdTvSwitch: public Command {
TV *_tv;
public:
CmdTvSwitch(TV *tv) {
this->_tv = tv;
}
virtual int exec(void *args) {
this->_tv->pwr_switch();
return 0;
}
};
int main(int argc, char *argv[])
{
// Client
TV tv;
Command *c;
c = new CmdTvSwitch(&tv);
c->exec(NULL);
c->exec(NULL);
return 0;
}
var mac = /^\s*([\d[a-f]{2}:){5}[\d[a-f]{2}\s*$/i;
var ip = /^((\d)|(([1-9])\d)|(1\d\d)|(2(([0-4]\d)|5([0-5]))))\.((\d)|(([1-9])\d)|(1\d\d)|(2(([0-4]\d)|5([0-5]))))\.((\d)|(([1-9])\d)|(1\d\d)|(2(([0-4]\d)|5([0-5]))))\.((\d)|(([1-9])\d)|(1\d\d)|(2(([0-4]\d)|5([0-5]))))$/;
char *mac = "([[0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}";
char *ip = "^(([0-9])|(([1-9])[0-9])|(1[0-9][0-9])|(2(([0-4][0-9])|5([0-5]))))\\.(([0-9])|(([1-9])[0-9])|(1[0-9][0-9])|(2(([0-4][0-9])|5([0-5]))))\\.(([0-9])|(([1-9])[0-9])|(1[0-9][0-9])|(2(([0-4][0-9])|5([0-5]))))\\.(([0-9])|(([1-9])[0-9])|(1[0-9][0-9])|(2(([0-4][0-9])|5([0-5]))))$";
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
//<![CDATA[
function show() {
document.getElementById("xie").style.display = "";
document.getElementById("content1").style.display = "";
document.getElementById("content1").innerHTML = "內容<br/><input onclick='hide()' type='button' value='確定'/>";
}
function hide() {
document.getElementById("xie").style.display = "none";
document.getElementById("content1").style.display = "none";
}
//]]>
</script>
<title>JavaScript Mask</title>
</head>
<body>
<div style=
"filter:alpha(opacity=50); -moz-opacity:0.5; opacity: 0.5; width: 100%; background-color: White; display: none; height: 100%; position: absolute; left: 0; top: 0;"
id="xie"></div>
<div style=
"width: 100px; background-color: Red; display: none; height: 53px; position: absolute; left: 144px; top: 100px;"
id="content1"></div>
<input onclick="show()" type="button" value="顯示" />
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>auto table</title>
</head>
<body>
<table id="brook" summary=""></table>
<script type="text/javascript">
//<![CDATA[
function create_new_row_button(eT, msg) {
var eR = document.createElement("tr");
var eC = document.createElement("td");
var eB = document.createElement("input");
eB.type = "button"
eB.value= msg;
eB.style.width = "100px";
eT.appendChild(eR);
eR.appendChild(eC);
eC.appendChild(eB);
}
var station = [
{name: "CHT"},
{name: "TW"},
];
for (var i = 0; i < station.length; i++) {
create_new_row_button(document.getElementById("brook"),
station[i].name);
}
//]]>
</script>
</body>
</html>
| char * strerror(int errnum) | [Function] |
| char * strerror_r(int errnum, char *buf, size t n) | [Function] |
| void perror(const char *message) | [Function] |
| char * program_invocation_name | [Variable] |
| char * program_invocation_short_name | [Variable] |
| void error (int status, int errnum, const char *format, . . . ) | [Function] |
| error_at_line (int status, int errnum, const char *fname,unsigned int lineno, const char *format, . . . ) | [Function] |
#include <stdio.h>
#include <errno.h> // EINTR
#include <string.h> // strerror()
int main(int argc, char *argv[])
{
printf("%s\n", strerror(EINTR));
// print out "Interrupted system call"
return 0;
}
#define _GNU_SOURCE
#include <stdio.h>
#include <errno.h> // EINTR
#include <string.h> // strerror()
int main(int argc, char *argv[])
{
char buf[32];
printf("%s\n", strerror_r(EINTR, buf, sizeof(buf)));
// print out "Interrupted system call"
return 0;
}
#include <stdio.h>
#include <errno.h> // EINTR
#include <string.h> // strerror()
int main(int argc, char *argv[])
{
perror("my_perror_msg1");
// print out "my_perror_msg1: Success"
errno = EINTR;
perror("my_perror_msg2");
// print out "my_perror_msg2: Interrupted system call"
return 0;
}
#include <stdio.h>
#include <errno.h> // EINTR
#include <string.h> // strerror()
int main(int argc, char *argv[])
{
printf("%s\n", argv[0]);
// print out "./a.out"
printf("%s\n", program_invocation_name);
// print out "./a.out"
printf("%s\n", program_invocation_short_name);
// print out "a.out"
return 0;
}
#include <stdio.h>
#include <errno.h> // EINTR
#include <string.h> // strerror()
int main(int argc, char *argv[])
{
error(0, 0, "%s", "msg");
error(0, EINTR, "%s", "msg");
// print out "./a.out: msg: Interrupted system call"
error(1, EINTR, "%s", "msg");
// print out "./a.out: msg: Interrupted system call" and exit(1)
return 0;
}
#include <stdio.h>
#include <errno.h> // EINTR
#include <string.h> // strerror()
int main(int argc, char *argv[])
{
error_at_line(0, 0, __FILE__, __LINE__, "%s", "msg");
// print out "./a.out:error_at_line.c:7: msg"
error_at_line(0, EINTR, __FILE__, __LINE__, "%s", "msg");
// print out "./a.out:error_at_line.c:8: msg: Interrupted system call"
error_at_line(1, EINTR, __FILE__, __LINE__, "%s", "msg");
// print out "./a.out:error_at_line.c:11: msg: Interrupted system call"
return 0;
}
header("Content-Type: application/octetstream; name=$FILEname"); //for IE & Opera
header("Content-Type: application/octet-stream; name=$FILEname"); //for the rest
header("Content-Disposition: attachment; filename=$FILEname;");
header("Content-Transfer-Encoding: binary");
header("Cache-Control: cache, must-revalidate");
header("Pragma: public");
header("Expires: 0");
Luci不過就是改呼叫luci.http.header()。luci.http.header("Content-Type", "application/octetstream; name=" .. fname); //for IE & Opera
luci.http.header("Content-Type", "application/octet-stream; name=" .. fname); //for the rest
luci.http.header("Content-Disposition", "attachment; filename=" .. fname);
luci.http.header("Content-Transfer-Encoding", "binary");
luci.http.header("Cache-Control", "cache, must-revalidate");
luci.http.header("Pragma", "public");
luci.http.header("Expires", "0");
brook@vista:~/src$ git clone https://github.com/json-c/json-c.git json-c Cloning into json-c... remote: Counting objects: 448, done. remote: Compressing objects: 100% (169/169), done. remote: Total 448 (delta 315), reused 405 (delta 274) Receiving objects: 100% (448/448), 125.68 KiB | 76 KiB/s, done. Resolving deltas: 100% (315/315), done. brook@vista:~/src$ cd json-c/ brook@vista:~/src/json-c$ ./autogen.sh autoreconf: Entering directory `.' autoreconf: configure.in: not using Gettext autoreconf: running: aclocal autoreconf: configure.in: tracing autoreconf: running: libtoolize --install --copy libtoolize: Consider adding `AC_CONFIG_MACRO_DIR([m4])' to configure.in and libtoolize: rerunning libtoolize, to keep the correct libtool macros in-tree. libtoolize: Consider adding `-I m4' to ACLOCAL_AMFLAGS in Makefile.am. autoreconf: running: /usr/bin/autoconf autoreconf: running: /usr/bin/autoheader autoreconf: running: automake --add-missing --copy --no-force autoreconf: Leaving directory `.' brook@vista:~/src/json-c$ ./configure checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p... /bin/mkdir -p ... brook@vista:~/src/json-c$ make make all-am make[1]: Entering directory `/home/brook/src/json-c' /bin/bash ./libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -Wall -Wwrite-strings -Werror -std=gnu99 -D_GNU_SOURCE -D_REENTRANT -g -O2 -MT arraylist.lo -MD -MP -MF .deps/arraylist.Tpo -c -o arraylist.lo arraylist.c ... brook@vista:~/src/json-c$ make check make test1 test2 test4 test_parse_int64 test_null test_cast make[1]: Entering directory `/home/brook/src/json-c' gcc -DHAVE_CONFIG_H -I. -Wall -Wwrite-strings -Werror -std=gnu99 -D_GNU_SOURCE -D_REENTRANT -g -O2 -MT test1.o -MD -MP -MF .deps/test1.Tpo -c -o test1.o test1.c test1.c: In function ‘sort_fn’: test1.c:14:8: error: assignment discards ‘const’ qualifier from pointer target type [-Werror] test1.c:15:8: error: assignment discards ‘const’ qualifier from pointer target type [-Werror] cc1: all warnings being treated as errors make[1]: *** [test1.o] Error 1 make[1]: Leaving directory `/home/brook/src/json-c' make: *** [check-am] Error 2 brook@vista:~/src/json-c$ sed -i 's/-Werror //' Makefile brook@vista:~/src/json-c$ make check make test1 test2 test4 test_parse_int64 test_null test_cast make[1]: Entering directory `/home/brook/src/json-c' ... brook@vista:~/src/json-c$ ./test1 my_string= my_string.to_string()="\t" my_string=\ my_string.to_string()="\\" my_string=foo my_string.to_string()="foo" my_int=9 my_int.to_string()=9 my_array= [0]=1 [1]=2 [2]=3 [3]=null [4]=5 ...
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include "json.h"
int main(int argc, char **argv)
{
json_object *new_obj;
MC_SET_DEBUG(1);
new_obj = json_tokener_parse("/* more difficult test case */ { \"glossary\": { \"title\": \"example glossary\", \"GlossDiv\": { \"title\": \"S\", \"GlossList\": [ { \"ID\": \"SGML\", \"SortAs\": \"SGML\", \"GlossTerm\": \"Standard Generalized Markup Language\", \"Acronym\": \"SGML\", \"Abbrev\": \"ISO 8879:1986\", \"GlossDef\": \"A meta-markup language, used to create markup languages such as DocBook.\", \"GlossSeeAlso\": [\"GML\", \"XML\", \"markup\"] } ] } } }");
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
json_object_put(new_obj);
return 0;
}
ssid=test hw_mode=g channel=1 interface=wlan1 #bridge=br1 driver=nl80211 ignore_broadcast_ssid=0 macaddr_acl=0 wmm_enabled=0
#include <linux/module.h>
#include <linux/init.h>
#include <linux/moduleparam.h>
#include <linux/sched.h>
#include <linux/kernel.h> /* printk() */
// #include <linux/slab.h> /* kmalloc() */
#include <linux/errno.h> /* error codes */
#include <linux/types.h> /* size_t */
#include <linux/signal.h>
#include <linux/proc_fs.h>
#include <linux/uaccess.h>
#define PROC_NAME "sig2pid"
/**
* 送signal 到pid去
*/
static int send_sig_to_pid(int sig, pid_t pid)
{
struct siginfo info;
info.si_signo = sig;
info.si_errno = 0;
info.si_code = SI_USER; // sent by kill, sigsend, raise
info.si_pid = get_current()->pid; // sender's pid
info.si_uid = current_uid(); // sender's uid
return kill_proc_info(sig, &info, pid);
}
/**
* /proc/sig2pid的write ops
*/
static int
sig2pid_proc_write(struct file *file, const char __user * buffer,
unsigned long count, void *data)
{
int sig, pid, ret;
char line[count];
ret = copy_from_user(line, buffer, count);
if (ret) {
return -EFAULT;
}
sscanf(line, "%d %d", &pid, &sig);
printk("%s(#%d): pid(%d), sig(%d)\n",
__func__, __LINE__, pid, sig);
send_sig_to_pid(sig, (pid_t) pid);
return count;
}
/**
* 建立/proc/sig2pid
*/
static int create_proc_file(void)
{
struct proc_dir_entry *p;
p = create_proc_entry(PROC_NAME, S_IFREG | S_IWUGO, NULL);
if (!p) {
printk("%s(#%d): create proc entry failed\n", __func__, __LINE__);
return -EFAULT;
}
p->write_proc = sig2pid_proc_write;
return 0;
}
int sig2pid_init_module(void)
{
return create_proc_file();
}
void sig2pid_exit_module(void)
{
remove_proc_entry(PROC_NAME, NULL);
}
module_init(sig2pid_init_module);
module_exit(sig2pid_exit_module);
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <stdlib.h>
#define handle_error(msg) \
do { perror(msg); exit(EXIT_FAILURE); } while (0)
int main(int argc, char *argv[])
{
int srv_fd, cli_fd;
socklen_t cli_len;
struct sockaddr_un srv_addr, cli_addr;
char buf[128] = "Brook: ";
ssize_t len;
unlink("server_socket");
if ((srv_fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
handle_error("socket");
}
srv_addr.sun_family = AF_UNIX;
strcpy(srv_addr.sun_path, "/tmp/unix_sock");
if (bind(srv_fd, (struct sockaddr *)&srv_addr, sizeof(srv_addr)) < 0) {
handle_error("bind");
}
if (listen(srv_fd, 1) < 0) {
handle_error("listen");
}
while (1) {
cli_fd = accept(srv_fd, (struct sockaddr *)&cli_addr, &cli_len);
len = read(cli_fd, buf + 6, sizeof(buf) - 6);
buf[6 + len] = 0;
write(cli_fd, buf, strlen(buf));
close(cli_fd);
}
return 0;
}
/dev/tcp/host/port
If host is a valid hostname or Internet address, and port is an integer
port number or service name, bash attempts to open a TCP connection to
the corresponding socket.
/dev/udp/host/port
If host is a valid hostname or Internet address, and port is an integer
port number or service name, bash attempts to open a UDP connection to
the corresponding socket.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Canvas/Simple shapes (rectangles)</title>
</head>
<body>
<canvas id="myCanvas" width="300" height="150">
Fallback content, in case the browser does not support Canvas.
</canvas>
<script type="application/x-javascript">
// Get a reference to the element.
var elem = document.getElementById('myCanvas');
// 判斷是否能取得context
if (elem && elem.getContext) {
// 你只能對每一個canvas做initialize一次(getContext).
// context = canvas . getContext(contextId [, ... ])
var context = elem.getContext('2d');
if (context) {
// context.fillRect(x, y, w, h)
// 畫方形
context.fillRect(0, 0, 150, 100);
// context.clearRect(x, y, w, h)
// 清方形
context.clearRect(100,50, 50, 50);
// context.strokeRect(x, y, w, h)
// 畫框
context.strokeRect(150,100, 50, 50);
}
}
</script>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Canvas/FillRect attribute</title>
</head>
<body>
<canvas id="myCanvas" width="300" height="150">
Fallback content, in case the browser does not support Canvas.
</canvas>
<script type="application/x-javascript">
// Get a reference to the element.
var elem = document.getElementById('myCanvas');
// 判斷是否能取得context
if (elem && elem.getContext) {
// 你只能對每一個canvas做initialize一次(getContext).
// context = canvas . getContext(contextId [, ... ])
var context = elem.getContext('2d');
if (context) {
context.fillStyle = 'pink';
context.fillRect(0, 0, 50, 50);
context.fillStyle = '#f00'; // red
context.fillRect(50, 50, 50, 50);
context.fillStyle = '#0f0'; // green
context.fillRect(100, 100, 50, 50);
context.fillStyle = '#00f'; // blue
context.fillRect(150, 150, 50, 50);
// RGBA(red, green, blue, alpha)
// Alpha1是透明度
context.fillStyle = 'RGBA(100, 100, 255, 0.2)';
context.fillRect(50, 50, 150, 150);
}
}
</script>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Canvas/Line styles</title>
</head>
<body>
<canvas id="myCanvas" width="300" height="150">
Fallback content, in case the browser does not support Canvas.
</canvas>
<script type="application/x-javascript">
// Get a reference to the element.
var elem = document.getElementById('myCanvas');
// 判斷是否能取得context
if (elem && elem.getContext) {
// 你只能對每一個canvas做initialize一次(getContext).
// context = canvas . getContext(contextId [, ... ])
var context = elem.getContext('2d');
if (context) {
// The beginPath() starts a new path
context.beginPath();
// reset the path to (0, 0)
context.moveTo(0,0);
context.strokeStyle = '#f00';
// lineWidth是線的大小
context.lineWidth = 1;
context.strokeRect(0, 0, 20, 20);
context.lineWidth = 10;
context.strokeRect(30, 30, 20, 20);
// LineJoin是連接處(轉角)的樣式
context.lineJoin = 'bevel';
context.strokeRect(60, 60, 20, 20);
context.lineJoin = 'round';
context.strokeRect(90, 90, 20, 20);
context.lineJoin = 'miter';
context.strokeRect(120, 120, 20, 20);
}
}
</script>
</body>
</html>