All posts by hua

Linux System Errors

Linux errors list

/* Copy from CentOS 6.5 */
 
/* /usr/include/asm-generic/errno-base.h */
#define EPERM        1  /* Operation not permitted */
#define ENOENT       2  /* No such file or directory */
#define ESRCH        3  /* No such process */
#define EINTR        4  /* Interrupted system call */
#define EIO          5  /* I/O error */
#define ENXIO        6  /* No such device or address */
#define E2BIG        7  /* Argument list too long */
#define ENOEXEC      8  /* Exec format error */
#define EBADF        9  /* Bad file number */
#define ECHILD      10  /* No child processes */
#define EAGAIN      11  /* Try again */
#define ENOMEM      12  /* Out of memory */
#define EACCES      13  /* Permission denied */
#define EFAULT      14  /* Bad address */
#define ENOTBLK     15  /* Block device required */
#define EBUSY       16  /* Device or resource busy */
#define EEXIST      17  /* File exists */
#define EXDEV       18  /* Cross-device link */
#define ENODEV      19  /* No such device */
#define ENOTDIR     20  /* Not a directory */
#define EISDIR      21  /* Is a directory */
#define EINVAL      22  /* Invalid argument */
#define ENFILE      23  /* File table overflow */
#define EMFILE      24  /* Too many open files */
#define ENOTTY      25  /* Not a typewriter */
#define ETXTBSY     26  /* Text file busy */
#define EFBIG       27  /* File too large */
#define ENOSPC      28  /* No space left on device */
#define ESPIPE      29  /* Illegal seek */
#define EROFS       30  /* Read-only file system */
#define EMLINK      31  /* Too many links */
#define EPIPE       32  /* Broken pipe */
#define EDOM        33  /* Math argument out of domain of func */
#define ERANGE      34  /* Math result not representable */
 
/* /usr/include/asm-generic/errno.h */
#define EDEADLK     35  /* Resource deadlock would occur */
#define ENAMETOOLONG    36  /* File name too long */
#define ENOLCK      37  /* No record locks available */
#define ENOSYS      38  /* Function not implemented */
#define ENOTEMPTY   39  /* Directory not empty */
#define ELOOP       40  /* Too many symbolic links encountered */
#define EWOULDBLOCK EAGAIN  /* Operation would block */
#define ENOMSG      42  /* No message of desired type */
#define EIDRM       43  /* Identifier removed */
#define ECHRNG      44  /* Channel number out of range */
#define EL2NSYNC    45  /* Level 2 not synchronized */
#define EL3HLT      46  /* Level 3 halted */
#define EL3RST      47  /* Level 3 reset */
#define ELNRNG      48  /* Link number out of range */
#define EUNATCH     49  /* Protocol driver not attached */
#define ENOCSI      50  /* No CSI structure available */
#define EL2HLT      51  /* Level 2 halted */
#define EBADE       52  /* Invalid exchange */
#define EBADR       53  /* Invalid request descriptor */
#define EXFULL      54  /* Exchange full */
#define ENOANO      55  /* No anode */
#define EBADRQC     56  /* Invalid request code */
#define EBADSLT     57  /* Invalid slot */
 
#define EDEADLOCK   EDEADLK
 
#define EBFONT      59  /* Bad font file format */
#define ENOSTR      60  /* Device not a stream */
#define ENODATA     61  /* No data available */
#define ETIME       62  /* Timer expired */
#define ENOSR       63  /* Out of streams resources */
#define ENONET      64  /* Machine is not on the network */
#define ENOPKG      65  /* Package not installed */
#define EREMOTE     66  /* Object is remote */
#define ENOLINK     67  /* Link has been severed */
#define EADV        68  /* Advertise error */
#define ESRMNT      69  /* Srmount error */
#define ECOMM       70  /* Communication error on send */
#define EPROTO      71  /* Protocol error */
#define EMULTIHOP   72  /* Multihop attempted */
#define EDOTDOT     73  /* RFS specific error */
#define EBADMSG     74  /* Not a data message */
#define EOVERFLOW   75  /* Value too large for defined data type */
#define ENOTUNIQ    76  /* Name not unique on network */
#define EBADFD      77  /* File descriptor in bad state */
#define EREMCHG     78  /* Remote address changed */
#define ELIBACC     79  /* Can not access a needed shared library */
#define ELIBBAD     80  /* Accessing a corrupted shared library */
#define ELIBSCN     81  /* .lib section in a.out corrupted */
#define ELIBMAX     82  /* Attempting to link in too many shared libraries */
#define ELIBEXEC    83  /* Cannot exec a shared library directly */
#define EILSEQ      84  /* Illegal byte sequence */
#define ERESTART    85  /* Interrupted system call should be restarted */
#define ESTRPIPE    86  /* Streams pipe error */
#define EUSERS      87  /* Too many users */
#define ENOTSOCK    88  /* Socket operation on non-socket */
#define EDESTADDRREQ    89  /* Destination address required */
#define EMSGSIZE    90  /* Message too long */
#define EPROTOTYPE  91  /* Protocol wrong type for socket */
#define ENOPROTOOPT 92  /* Protocol not available */
#define EPROTONOSUPPORT 93  /* Protocol not supported */
#define ESOCKTNOSUPPORT 94  /* Socket type not supported */
#define EOPNOTSUPP  95  /* Operation not supported on transport endpoint */
#define EPFNOSUPPORT    96  /* Protocol family not supported */
#define EAFNOSUPPORT    97  /* Address family not supported by protocol */
#define EADDRINUSE  98  /* Address already in use */
#define EADDRNOTAVAIL   99  /* Cannot assign requested address */
#define ENETDOWN    100 /* Network is down */
#define ENETUNREACH 101 /* Network is unreachable */
#define ENETRESET   102 /* Network dropped connection because of reset */
#define ECONNABORTED    103 /* Software caused connection abort */
#define ECONNRESET  104 /* Connection reset by peer */
#define ENOBUFS     105 /* No buffer space available */
#define EISCONN     106 /* Transport endpoint is already connected */
#define ENOTCONN    107 /* Transport endpoint is not connected */
#define ESHUTDOWN   108 /* Cannot send after transport endpoint shutdown */
#define ETOOMANYREFS    109 /* Too many references: cannot splice */
#define ETIMEDOUT   110 /* Connection timed out */
#define ECONNREFUSED    111 /* Connection refused */
#define EHOSTDOWN   112 /* Host is down */
#define EHOSTUNREACH    113 /* No route to host */
#define EALREADY    114 /* Operation already in progress */
#define EINPROGRESS 115 /* Operation now in progress */
#define ESTALE      116 /* Stale NFS file handle */
#define EUCLEAN     117 /* Structure needs cleaning */
#define ENOTNAM     118 /* Not a XENIX named type file */
#define ENAVAIL     119 /* No XENIX semaphores available */
#define EISNAM      120 /* Is a named type file */
#define EREMOTEIO   121 /* Remote I/O error */
#define EDQUOT      122 /* Quota exceeded */
 
#define ENOMEDIUM   123 /* No medium found */
#define EMEDIUMTYPE 124 /* Wrong medium type */
#define ECANCELED   125 /* Operation Canceled */
#define ENOKEY      126 /* Required key not available */
#define EKEYEXPIRED 127 /* Key has expired */
#define EKEYREVOKED 128 /* Key has been revoked */
#define EKEYREJECTED    129 /* Key was rejected by service */
 
/* for robust mutexes */
#define EOWNERDEAD  130 /* Owner died */
#define ENOTRECOVERABLE 131 /* State not recoverable */
 
#define ERFKILL     132 /* Operation not possible due to RF-kill */
source: http://liudonghua.net/wiki/Linux_System_Errors


找回Windows 10的“Windows照片查看器”

Windows 10里的“Windows照片查看器”不见了。个人不喜欢“Photos”应用,就谷歌了下,特此记录。新建一个TXT文本文档,把以下代码复制粘贴到其中,接着命名以.reg结尾,然后双击执行。

Windows Registry Editor Version 5.00

; Change Extension's File Type

[HKEY_CURRENT_USER\Software\Classes\.jpg]

@="PhotoViewer.FileAssoc.Tiff"

; Change Extension's File Type

[HKEY_CURRENT_USER\Software\Classes\.jpeg]

@="PhotoViewer.FileAssoc.Tiff"

; Change Extension's File Type

[HKEY_CURRENT_USER\Software\Classes\.gif]

@="PhotoViewer.FileAssoc.Tiff"

; Change Extension's File Type

[HKEY_CURRENT_USER\Software\Classes\.png]

@="PhotoViewer.FileAssoc.Tiff"

; Change Extension's File Type

[HKEY_CURRENT_USER\Software\Classes\.bmp]

@="PhotoViewer.FileAssoc.Tiff"

; Change Extension's File Type

[HKEY_CURRENT_USER\Software\Classes\.pcx]

@="PhotoViewer.FileAssoc.Tiff"

; Change Extension's File Type

[HKEY_CURRENT_USER\Software\Classes\.tiff]

@="PhotoViewer.FileAssoc.Tiff"

; Change Extension's File Type

[HKEY_CURRENT_USER\Software\Classes\.ico]

@="PhotoViewer.FileAssoc.Tiff"



Windows自带端口转发软件netsh的小用处

Windows下还是有些有意思的小工具,端口转发软件netsh就是其一。拿它能用来干嘛呢?懂的人不用多说了,不懂的人估计也没兴趣。再在ios上设置个代理就方便很多了。

Vista及以上版本才有,当然需要管理员权限啦。

1.添加端口转发的命令
netsh interface portproxy add v4tov4 listenport=新开的监听端口 listenaddress=新开端口的绑定地址 connectaddress=要转发的地址 connectport=要转发的端口 protocol=tcp

如:
netsh interface portproxy add v4tov4 listenport=12345 listenaddress=0.0.0.0 connectaddress=127.0.0.1 connectport=1080 protocol=tcp

2.删除端口转发的命令
netsh interface portproxy delete v4tov4 listenport=新开的监听端口 listenaddress=新开端口的绑定地址

如:
netsh interface portproxy delete v4tov4 listenport=12345 listenaddress=0.0.0.0



shell脚本中的单双引号经验分享

遇到的问题

在python脚本中使用zip软件打包数据,方法是用os.system(”)来执行shell命令,并设置密码,如PREFIX987rst@@)!%%ZIP(脚本中显示的内容)。因为脚本是同事写的,没想那么多就把字符串直接复制,然后用来解压。故事就开始了——密码错误,不管是linux下,还是windows下,都提示密码错误。各种尝试还是错误,就自己用这个密码压缩解压看看,做法如下:

zip -r -P ‘PREFIX987rst@@)!%%ZIP’ abc.zip *

unzip -P “PREFIX987rst@@)!%%ZIP” abc.zip -d abc

密码错误!没有任何惊喜。只能求助了。

分析原因

在飞哥的帮助下,原来是单双引号使用不当导致的。对shell没有系统的学习过的我,单双引号在我眼里一直是一样的,在平时的工作中好像也没遇到过什么问题,直到现在。

赶紧查下单双引号的区别:

单引号:当shell碰到第一个单引号时,它忽略掉其后直到右引号的任何字符。

双引号:与单引号类似,但它只忽略大多数字符,一些特殊字符不被忽略,如:$,\,`,! ,特殊字符依然按照shell来执行。

解决方法

知道原因,解决方法就好说了,统一用单引号或者双引号就行了。根据单双引号的差异,强烈建议用单引号。

后续

我自己测试的没问题了,但我按照这个方法去解压以前的压缩文档还是不行。再仔细一看,python中 ‘%’ 字符是需要转义的。

好吧,这个经验适合小白、适合小白、适合小白!



背景图片高斯模糊

javascript 参考代码:

blur(document.getElementById(‘list_album_image’),’image-url’,5);
function blur(element, src, strength){
var image = new Image();
image.onload = function(e){
var canvas = document.getElementById(‘bk-canvas’);
var context = canvas.getContext(‘2d’);

canvas.width = $(element).width();
canvas.height = $(element).height();

context.drawImage(this, 0, 0, canvas.width, canvas.height);

context.globalAlpha = 0.2; // Higher alpha made it more smooth
// Add blur layers by strength to x and y
// 2 made it a bit faster without noticeable quality loss
for (var y = -strength; y <= strength; y += 2) {
for (var x = -strength; x <= strength; x += 2) {
context.drawImage(canvas, x, y);
}
}
context.globalAlpha = 1;
element.style.backgroundImage = ‘url(‘+canvas.toDataURL()+’)';
}
image.src = src;
}



跨域上传文件

有上传的请求头里加如下:

Access-Control-Allow-Headers: Cache-Control, X-Requested-With
Access-Control-Allow-Methods: POST
Access-Control-Allow-Origin: http://some.example.com



Linux /proc/[pid]/maps说明

address   perms  offset  dev  inode  pathname

08048000-08056000  r-xp   00000000  03:0c  64593  /usr/sbin/gpm

•address – This is the starting and ending address of the region in the process’s address space

•permissions – This describes how pages in the region can be accessed. There are four different permissions: read, write, execute, and shared. If read/write/execute are disabled, a ‘-‘ will appear instead of the ‘r’/’w’/’x’. If a region is not shared, it is private, so a ‘p’ will appear instead of an ‘s’. If the process attempts to access memory in a way that is not permitted, a segmentation fault is generated. Permissions can be changed using the mprotect system call.

•offset – If the region was mapped from a file (using mmap), this is the offset in the file where the mapping begins. If the memory was not mapped from a file, it’s just 0.

•device – If the region was mapped from a file, this is the major and minor device number (in hex) where the file lives.

•inode – If the region was mapped from a file, this is the file number.

•pathname – If the region was mapped from a file, this is the name of the file. This field is blank for anonymous mapped regions. There are also special regions with names like [heap], [stack], or [vdso]. [vdso] stands for virtual dynamic shared object. It’s used by system calls to switch to kernel mode. Here’s a good article about it.

 



linux下swap的用法

创建

mkdir /test/swap_dir

dd if=/dev/zero of=/test/swap_dir/swap  bs=1k count=10240

mkswap /test/swap_dir/swap

swapon /test/swap_dir/swap #临时开启这个交换空间

/test/swap_dir/swap  swap  swap    defaults  0 0 #开机启用,在/etc/fstab文件里配置

swapon -s # 查看

配置

系统在什么情况下才会使用SWAP?

cat /proc/sys/vm/swappiness

swappiness=0的时候表示最大限度使用物理内存,然后才是 swap空间,

swappiness=100的时候表示积极的使用swap分区,并且把内存上的数据及时的搬运到swap空间里面。

如果内存充足,这个参数值设置的低一些,让操作系统尽可能的使用物理内存,降低系统对swap的使用,从而提高系统的性能。

 如何修改swappiness参数?

临时性修改:
sysctl vm.swappiness=10
永久修改,在/etc/sysctl.conf 文件里添加如下参数:
vm.swappiness=10

打赏点吧(微信扫码)
dashang