^@与控制字符

在应用服务日志中看到了服务器日志记录错误NumberFormatExeception input string ^@^@^@^@,对于 ^@ 这个控制字符没有什么映像了于是vi打开一个临时文件 ctrl + V, ctrl + @ 输入到文件中然后hexdump 看了一下二进制内容发现是 0000000 0a00 0000002 本来输入一个字符变成两个了, (不过当时错误判断这个值就是0xa了换行符) 。vi编辑的时候会自动向文件中插入LF。可以输入其他字符比如a,结果是下面这样。 0000000 0a61 0000002 下面程序打印了ascii码, 1-31,127是控制字符 #include <stdio.h> void print_control_char(char c) { // 打印控制字符的可见形式 if (c >= 0 && c <= 31) { printf("^%c", c + 64); // 显示为 ^@, ^A, ..., ^Z 等 } else if (c == 127) { printf("^?"); // DEL字符显示为 ^? } else { printf(" "); // 非控制字符为空 } } int main() { printf("+-----+--------+--------+--------------+\n"); printf("| Dec | Hex | Char | Visible Form |\n"); printf("+-----+--------+--------+--------------+\n"); // 打印所有控制字符 (0-31, 127) for (int i = 0; i <= 127; i++) { if (i <= 31 || i == 127) { // 构造可见形式的字符串 char visibleForm[4] = " "; // 初始化为空字符串 if (i <= 31) { visibleForm[0] = '^'; visibleForm[1] = i + 64; // 转换为可见形式(如 ^A) } else if (i == 127) { visibleForm[0] = '^'; visibleForm[1] = '?'; // DEL字符的可见形式为 ^? } // 打印表格行 printf("| %3d | 0x%02X | %c | %-12s |\n", i, i, (i == 127 ? '?' : ' '), visibleForm); printf("+-----+--------+--------+--------------+\n"); } } return 0; } ...

2024-10-27 · 3 min · 503 words

C语言宏参数转换为字符串

用宏定义来定义一个SQL语句, 用来指定字段的长度。那就拼接一下 #include <stdio.h> // 定义字段长度 #define NAME_LENGTH 50 // 定义创建表的SQL语句,使用宏来指定字段长度 #define CREATE_TABLE_SQL "CREATE TABLE Users (ID INT, Name VARCHAR(" NAME_LENGTH "))" int main() { // 输出创建表的SQL语句 printf("SQL Statement: %s\n", CREATE_TABLE_SQL); return 0; } # gcc test2.c -o test2 test2.c: In function ‘main’: test2.c:4:21: error: expected ‘)’ before numeric constant 4 | #define NAME_LENGTH 50 | ^~ test2.c:7:70: note: in expansion of macro ‘NAME_LENGTH’ 7 | #define CREATE_TABLE_SQL "CREATE TABLE Users (ID INT, Name VARCHAR(" NAME_LENGTH "))" | ^~~~~~~~~~~ c的预处理器没有将数字转化为字符串。 ...

2024-04-25 · 1 min · 201 words

conflicts with file from package kernel-debuginfo

安全更新 dnf upgrade-minimal –security 报错信息: install of kernel-debuginfo-5.10.134-16.3.al8.x86_64 conflicts with file from package kernel-debuginfo-5.10.134-16.2.al8.x86_64 Linux 系统上两个版本的 kernel-debuginfo 包之间存在文件冲突。 环境: # cat /etc/redhat-release Alibaba Cloud Linux release 3 (Soaring Falcon) 处理步骤: the older version (5.10.134-16.2.al8.x86_64) the newer verion (5.10.134-16.3.al8.x86_64) ## Remove the older version of the debuginfo package sudo dnf remove kernel-debuginfo-5.10.134-16.2.al8.x86_64 ##Clean the package manager cache sudo dnf clean all ##Reinstall the newer version: sudo dnf install kernel-debuginfo-5.10.134-16.3.al8.x86_64 ##Check for remaining conflicts: sudo dnf check ...

2024-04-13 · 1 min · 77 words

curl support TLCP using TASSL

TLCP 传输层密码协议TLCP 对应 TLS协议, 在GB/T 38636-2020规范中定义。支持国密sm2, sm3, sm4密钥套件。增加加密证书, 6.4.5.3章节中提到 选择ECC, ECDHE算法,密钥交换算法使用用加密证书公钥。 https://blog.csdn.net/shenshaojun/article/details/114576162 这里对密钥体系进行了说明, 目前没看到标准里介绍,加密证书CA生成,并拥有私钥。这样的涉及对于信息保密性要依赖CA机构? CURL curl工具目前还不支持TLCP,一般需要进行简单修改。 目前支持国密库: GMSSL Tongsuo 铜锁 江南天安TASSL TencentKonaSMSuite curl支持TLCP: GMSSL 开源版本 : https://github.com/pengtianabc/curl-gm Tongsuo : https://github.com/Tongsuo-Project/curl CURL compile using TASSL 具体实现:https://github.com/weida/Curl-with-TASSL-support-for-TLCP 需要注意新版本curl的参数使用二分查找,参数需要自己排序 "src/tool_getparam.c" /* this array MUST be alphasorted based on the 'lname' */ static const struct LongShort aliases[]= { ... 目前测试环境仅有linux版本,只提了个linux patch。 参考及引用: https://zhuanlan.zhihu.com/p/564452283 https://www.cnblogs.com/anding/p/17627553.html 图片from陳丁光

2024-02-16 · 1 min · 61 words

http3 - nginx with quictls

nginx 从1.25开始支持QUIC和http3 # quictls 编译安装 ./Configure --prefix=$HOME/quictls --openssldir=$HOME/openssl-quic -fPIC no-shared make && make install # nginx 编译安装 auto/configure --with-debug --with-http_v3_module --with-http_v2_module --with-cc-opt="-I $HOME/quictls/include" --with-ld-opt="-L $HOME/quictls/lib64" --prefix=$HOME/nginx-quic --with-cc-opt="-DNGX_QUIC_DEBUG_PACKETS -DNGX_QUIC_DEBUG_CRYPTO" --with-openssl=$HOME/install/openssl make && make install nginx.conf user root; worker_processes 1; error_log logs/error.log debug; #pid logs/nginx.pid; events { worker_connections 1024; } http { log_format quic '$remote_addr - $remote_user [$time_local] ' '"$request" $status $body_bytes_sent ' '"$http_referer" "$http_user_agent" "$http3"'; access_log logs/access.log quic; server { # for better compatibility it's recommended # to use the same port for quic and https listen 443 quic reuseport; listen 443 ssl ; http3 on; http2 on; quic_retry on; ssl_early_data on; #server_name server_name; ssl_certificate certs/cert.pem; ssl_certificate_key certs/priv.key; ssl_protocols TLSv1.3; add_header Alt-Svc 'h3=":443"; ma=86400'; location / { index index.html index.htm; } } } ...

2024-02-16 · 2 min · 215 words

systemctl 启动服务缓慢

服务启动缓慢 使用systemd配置服务启动慢 strace -s 1024 systemctl start AAA 有 -1 : EAGAIN (Resource temporarily unavailable) 报错及卡顿, 查看了服务配置依赖项 /etc/systemd/system/multi-user.target.wants 目录下找到服务配置文件, 查看对应配置文件 Unit配置项里的Requires值, 查找对应依赖服务发现有一个服务异常, 这个服务启动脚本中启动network服务, 由于配置网卡错误导致无法启动。 systemd systemd 是 Linux 操作系统的系统和服务管理器系统。 当作为启动时的第一个进程(作为 PID 1)运行时,它充当 启动和维护用户空间服务的 init 系统。为登录用户启动单独的实例来启动他们的服务。 garlic@garlic:~$ ls -l /sbin/init lrwxrwxrwx 1 root root 20 Mar 20 2023 /sbin/init -> /lib/systemd/systemd garlic@garlic:~$ uname -a Linux garlic 6.2.0-35-generic #35-Ubuntu SMP PREEMPT_DYNAMIC Tue Oct 3 13:14:56 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux 创建一个服务 之前写的应用软件自己写daemon进程,然后通过数据库完成配置管理,然后通过一个工具实现服务器启动关闭。简单的应用也是够用的。 ...

2023-10-21 · 2 min · 286 words

linux 生成指定大小文件

linux生成指定大小文件常用的几个命令: fallocate truncate dd head tail fallocate...

2023-08-19 · 1 min · 180 words

linux sudoers

linux安装完有些系统会默认禁用root登录, 所以我习惯创建一个普通用户然后配置sudoers登录。 %garlic ALL=(ALL:ALL) NOPASSWD: ALL 安装虚拟机由于网卡的一个错误配置发现 ,使用garlic su 执行 命令很慢使用strace跟踪了一下发现, 出现dns相关操作。 13:19:22.212222 connect(6, {sa_family=AF_UNIX, sun_path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory) 13:19:22.212654 close(6) = 0 13:19:22.212838 socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 6 13:19:22.213041 connect(6, {sa_family=AF_UNIX, sun_path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory) 13:19:22.213454 close(6) = 0 13:19:22.213698 newfstatat(AT_FDCWD, "/etc/nsswitch.conf", {st_mode=S_IFREG|0644, st_size=510, ...}, 0) = 0 13:19:22.214040 newfstatat(AT_FDCWD, "/etc/resolv.conf", {st_mode=S_IFREG|0644, st_size=930, ...}, 0) = 0 13:19:22.214630 openat(AT_FDCWD, "/etc/host.conf", O_RDONLY|O_CLOEXEC) = 6 13:19:22.214796 newfstatat(6, "", {st_mode=S_IFREG|0644, st_size=92, ...}, AT_EMPTY_PATH) = 0 13:19:22.215223 read(6, "# The \"order\" line is only used "..., 4096) = 92 13:19:22.215438 read(6, "", 4096) = 0 13:19:22.215787 close(6) = 0 13:19:22.215939 futex(0x7fdd6262232c, FUTEX_WAKE_PRIVATE, 2147483647) = 0 13:19:22.216160 openat(AT_FDCWD, "/etc/resolv.conf", O_RDONLY|O_CLOEXEC) = 6 13:19:22.216340 newfstatat(6, "", {st_mode=S_IFREG|0644, st_size=930, ...}, AT_EMPTY_PATH) = 0 13:19:22.216621 read(6, "# This is /run/systemd/resolve/s"..., 4096) = 930 13:19:22.216916 read(6, "", 4096) = 0 13:19:22.217355 newfstatat(6, "", {st_mode=S_IFREG|0644, st_size=930, ...}, AT_EMPTY_PATH) = 0 13:19:22.217887 close(6) = 0 13:19:22.218025 openat(AT_FDCWD, "/etc/hosts", O_RDONLY|O_CLOEXEC) = 6 13:19:22.218411 newfstatat(6, "", {st_mode=S_IFREG|0644, st_size=240, ...}, AT_EMPTY_PATH) = 0 13:19:22.218707 lseek(6, 0, SEEK_SET) = 0 13:19:22.218967 read(6, "127.0.0.1 localhost\n127.0.1.1 ga"..., 4096) = 240 13:19:22.219197 read(6, "", 4096) = 0 13:19:22.219337 close(6) = 0 13:19:22.219607 socket(AF_INET, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, IPPROTO_IP) = 6 13:19:22.219903 setsockopt(6, SOL_IP, IP_RECVERR, [1], 4) = 0 13:19:22.220180 connect(6, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("127.0.0.53")}, 16) = 0 13:19:22.220518 poll([{fd=6, events=POLLOUT}], 1, 0) = 1 ([{fd=6, revents=POLLOUT}]) 13:19:22.220985 sendmmsg(6, [{msg_hdr={msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="!H\1 \0\1\0\0\0\0\0\1\6node-1\vlocaldomain\0"..., iov_len=47}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, msg_len=47}, {msg_hdr={msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="eT\1 \0\1\0\0\0\0\0\1\6node-1\vlocaldomain\0"..., iov_len=47}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, msg_len=47}], 2, MSG_NOSIGNAL) = 2 13:19:22.224149 poll([{fd=6, events=POLLIN}], 1, 5000) = 0 (Timeout) 13:19:27.227039 poll([{fd=6, events=POLLOUT}], 1, 0) = 1 ([{fd=6, revents=POLLOUT}]) 13:19:27.227693 sendmmsg(6, [{msg_hdr={msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="!H\1 \0\1\0\0\0\0\0\1\6node-1\vlocaldomain\0"..., iov_len=47}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, msg_len=47}, {msg_hdr={msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="eT\1 \0\1\0\0\0\0\0\1\6node-1\vlocaldomain\0"..., iov_len=47}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, msg_len=47}], 2, MSG_NOSIGNAL) = 2 13:19:27.233376 poll([{fd=6, events=POLLIN}], 1, 5000 ...

2023-05-16 · 2 min · 322 words

Linux sed 中的&

 一次使用sed 替换操作,替换后的字符串包含 **&,**替换文本如下 $ cat test.txt key=hello & 替换命令 $ sed 's/^key=.*$/key=world & /' test.txt 结果 key=world key=hello & sed 中 s 指令语法: ‘s/regexp/replacement/flags & 符号是代表 regexp 匹配的全部。所以又将原有匹配内容打印了一遍, 可以通过增加 \,将&按照普通字符处理 $ sed 's/^key=.*$/key=world \& /' test.txt key=world & 也可以使用 c 命令, 他之后的所有字符都被认为文本处理 $ sed '/^key=.*$/ckey=world & ' test.txt key=world & 参考及引用 更加详细使用 https://www.gnu.org/software/sed/manual/sed.html#Programming-Commands https://www.grymoire.com/Unix/Sed.html https://likegeeks.com/sed-linux/ 图片from 机滄泳

2022-12-03 · 1 min · 57 words

ubuntu 忘记密码

...

2022-12-03 · 1 min · 37 words