Is there any strerror-like functionality currently in the kernel? I haven't been able to find one so my thought is no, but more importantly, has their been any discussion about this? I would think it could reduce troubleshooting time, since you wont have to look up error codes (which not everybody has memorized) and possibly make things a bit easier for system administrators and normal ever-day users (via dmesg).
I wanted to ask here before mailing the LKML. My thoughts were for a dual mechanism, one for the error name (e.g., EINVAL) and another for the description. Further, the %m glibc extension could be added to printk, except that it would have to read a error code since the glibc extension reads errno. Perhaps %m could print the error name while %M could print the error description?
Anyway, if it is added, it should be a .config option since it will bloat the text size. The size can be shrunk by just storing the error names (1 through 133 currently) in a single string with a null terminator between each string and just a slow strerror (forced to iterate through the string and count null-terminators), since the speed of this shouldn't matter. Internal errors 512-529 would have to be in a separate string. Then, a direct pointer to the null-terminated string could be returned with no need to copy anything. By my calculations, this would take roughly 1322 bytes for the error names and 3540 bytes for the descriptions (based upon what are now in comments after each error's #define and adding "no description" for those that are currently missing one).
Then, when config-disabled, the printk %m could just be interpreted as %d and %M could just print nothing (or some such).
No, there isn't. But you can see the list of the error codes in include/asm-generic/errno.h and in include/asm-generic/errno-base.h. There isn't too many (fewer than 200), so it is not too hard to learn them during the development.
char *get_error(int error){
int er = abs(error);
switch(er){
case EPERM:
return "Operation not permitted";
case ENOENT:
return "No such file or directory";
case ESRCH:
return "No such process";
case EINTR:
return "Interrupted system call";
case EIO:
return "I/O error";
case ENXIO:
return "No such device or address";
case E2BIG:
return "Argument list too long";
case ENOEXEC:
return "Exec format error";
case EBADF:
return "Bad file number";
case ECHILD:
return "No child processes";
case EAGAIN:
return "Try again Or Operation would block";
case ENOMEM:
return "Out of memory";
case EACCES:
return "Permission denied";
case EFAULT:
return "Bad address";
case ENOTBLK:
return "Block device required";
case EBUSY:
return "Device or resource busy";
case EEXIST:
return "File exists";
case EXDEV:
return "Cross-device link";
case ENODEV:
return "No such device";
case ENOTDIR:
return "Not a directory";
case EISDIR:
return "Is a directory";
case EINVAL:
return "Invalid argument";
case ENFILE:
return "File table overflow";
case EMFILE:
return "Too many open files";
case ENOTTY:
return "Not a typewriter";
case ETXTBSY:
return "Text file busy";
case EFBIG:
return "File too large";
case ENOSPC:
return "No space left on device";
case ESPIPE:
return "Illegal seek";
case EROFS:
return "Read-only file system";
case EMLINK:
return "Too many links";
case EPIPE:
return "Broken pipe";
case EDOM:
return "Math argument out of domain of func";
case ERANGE:
return "Math result not representable";
case EDEADLK:
return "Resource deadlock would occur";
case ENAMETOOLONG:
return "File name too long";
case ENOLCK:
return "No record locks available";
case ENOSYS:
return "Invalid system call number";
case ENOTEMPTY:
return "Directory not empty";
case ELOOP:
return "Too many symbolic links encountered";
case ENOMSG:
return "No message of desired type";
case EIDRM:
return "Identifier removed";
case ECHRNG:
return "Channel number out of range";
case EL2NSYNC:
return "Level 2 not synchronized";
case EL3HLT:
return "Level 3 halted";
case EL3RST:
return "Level 3 reset";
case ELNRNG:
return "Link number out of range";
case EUNATCH:
return "Protocol driver not attached";
case ENOCSI:
return "No CSI structure available";
case EL2HLT:
return "Level 2 halted";
case EBADE:
return "Invalid exchange";
case EBADR:
return "Invalid request descriptor";
case EXFULL:
return "Exchange full";
case ENOANO:
return "No anode";
case EBADRQC:
return "Invalid request code";
case EBADSLT:
return "Invalid slot";
case EBFONT:
return "Bad font file format";
case ENOSTR:
return "Device not a stream";
case ENODATA:
return "No data available";
case ETIME:
return "Timer expired";
case ENOSR:
return "Out of streams resources";
case ENONET:
return "Machine is not on the network";
case ENOPKG:
return "Package not installed";
case EREMOTE:
return "Object is remote";
case ENOLINK:
return "Link has been severed";
case EADV:
return "Advertise error";
case ESRMNT:
return "Srmount error";
case ECOMM:
return "Communication error on send";
case EPROTO:
return "Protocol error";
case EMULTIHOP:
return "Multihop attempted";
case EDOTDOT:
return "RFS specific error";
case EBADMSG:
return "Not a data message";
case EOVERFLOW:
return "Value too large for defined data type";
case ENOTUNIQ:
return "Name not unique on network";
case EBADFD:
return "File descriptor in bad state";
case EREMCHG:
return "Remote address changed";
case ELIBACC:
return "Can not access a needed shared library";
case ELIBBAD:
return "Accessing a corrupted shared library";
case ELIBSCN:
return ".lib section in a.out corrupted";
case ELIBMAX:
return "Attempting to link in too many shared libraries";
case ELIBEXEC:
return "Cannot exec a shared library directly";
case EILSEQ:
return "Illegal byte sequence";
case ERESTART:
return "Interrupted system call should be restarted";
case ESTRPIPE:
return "Streams pipe error";
case EUSERS:
return "Too many users";
case ENOTSOCK:
return "Socket operation on non-socket";
case EDESTADDRREQ:
return "Destination address required";
case EMSGSIZE:
return "Message too long";
case EPROTOTYPE:
return "Protocol wrong type for socket";
case ENOPROTOOPT:
return "Protocol not available";
case EPROTONOSUPPORT:
return "Protocol not supported";
case ESOCKTNOSUPPORT:
return "Socket type not supported";
case EOPNOTSUPP:
return "Operation not supported on transport endpoint";
case EPFNOSUPPORT:
return "Protocol family not supported";
case EAFNOSUPPORT:
return "Address family not supported by protocol";
case EADDRINUSE:
return "Address already in use";
case EADDRNOTAVAIL:
return "Cannot assign requested address";
case ENETDOWN:
return "Network is down";
case ENETUNREACH:
return "Network is unreachable";
case ENETRESET:
return "Network dropped connection because of reset";
case ECONNABORTED:
return "Software caused connection abort";
case ECONNRESET:
return "Connection reset by peer";
case ENOBUFS:
return "No buffer space available";
case EISCONN:
return "Transport endpoint is already connected";
case ENOTCONN:
return "Transport endpoint is not connected";
case ESHUTDOWN:
return "Cannot send after transport endpoint shutdown";
case ETOOMANYREFS:
return "Too many references: cannot splice";
case ETIMEDOUT:
return "Connection timed out";
case ECONNREFUSED:
return "Connection refused";
case EHOSTDOWN:
return "Host is down";
case EHOSTUNREACH:
return "No route to host";
case EALREADY:
return "Operation already in progress";
case EINPROGRESS:
return "Operation now in progress";
case ESTALE:
return "Stale file handle";
case EUCLEAN:
return "Structure needs cleaning";
case ENOTNAM:
return "Not a XENIX named type file";
case ENAVAIL:
return "No XENIX semaphores available";
case EISNAM:
return "Is a named type file";
case EREMOTEIO:
return "Remote I/O error";
case EDQUOT:
return "Quota exceeded";
case ENOMEDIUM:
return "No medium found";
case EMEDIUMTYPE:
return "Wrong medium type";
case ECANCELED:
return "Operation Canceled";
case ENOKEY:
return "Required key not available";
case EKEYREVOKED:
return "Key has been revoked";
case EKEYREJECTED:
return "Key was rejected by service";
case EOWNERDEAD:
return "Owner died";
case ENOTRECOVERABLE:
return "State not recoverable";
case ERFKILL:
return "Operation not possible due to RF-kill";
case EHWPOISON:
return "Memory page has hardware error";
}
return "Unknown Error Dash!";
}
EXPORT_SYMBOL(get_error);
Related
Reference:
websocket_client_sync_ssl.cpp
// Read a message into our buffer
ws.read(buffer);
// Close the WebSocket connection
ws.close(websocket::close_code::normal);
Based on my test, the ws.close will spit out a warning below:
ERROR message: short read (SSL routines, SSL routines), value:
335544539
Based on this post short read, this error can be safely ignored in the end of the session. I have tried the following method to suppress the warning:
try
{
boost::system::error_code close_ec;
ws.close(websocket::close_code::normal, close_ec);
if (close_ec)
{
std::cerr << "ERROR message: " << close_ec.message() << ", value: " << close_ec.value() << std::endl;
}
}
catch(...)
{
}
However, the ws.close still prints out the warning message.
Question> Is there a way that I can suppress this message?
However, the ws.close still prints out the warning message.
Are you sure? It looks like that's simply coming from the line:
std::cerr << "ERROR message: " << close_ec.message() << ", value: " << close_ec.value() << std::endl;
So, you would check the value of close_ec and conditionally handle it: Short read error-Boost asio synchoronous https call
Also, note that some kinds of "short reads" can constitute security errors. Some of the samples have very insightful comments about this:
// `net::ssl::error::stream_truncated`, also known as an SSL "short read",
// indicates the peer closed the connection without performing the
// required closing handshake (for example, Google does this to
// improve performance). Generally this can be a security issue,
// but if your communication protocol is self-terminated (as
// it is with both HTTP and WebSocket) then you may simply
// ignore the lack of close_notify:
//
// https://github.com/boostorg/beast/issues/38
//
// https://security.stackexchange.com/questions/91435/how-to-handle-a-malicious-ssl-tls-shutdown
//
// When a short read would cut off the end of an HTTP message,
// Beast returns the error beast::http::error::partial_message.
// Therefore, if we see a short read here, it has occurred
// after the message has been completed, so it is safe to ignore it.
if(ec == net::ssl::error::stream_truncated)
ec = {};
else if(ec)
return;
We got a client ssh to a remote server showing this error. It has always been running fine, no firewall rules change either. When an ssh session is idled over the weekend, it is still connected. Just some times when we 'less' and shift-F on a file for couple of hours, it shows this error.
I'm not trying to solve this problem in this post. We want to look at the ssh source code to figure out what is going on. On Centos 7, I downloaded openssh-7.4p1-21.el7.src.rpm, and extracted openssh-7.4p1.tar.gz. 'grep' through source code and found 'packet_write_wait' function. But curiously, "Broken pipe" (or -i on each word separately) is not found in all the .h and .c files. Where is that error text coming from?
You can find a copy of the OpenSSH source code in github. The packet_write_wait function is in opacket.c:
void
packet_write_wait(void)
{
int r;
if ((r = ssh_packet_write_wait(active_state)) != 0)
sshpkt_fatal(active_state, __func__, r);
}
It calls another function to write the packet. If that fails, it calls sshpkt_fatal. sshpkt_fatal is in packet.c, and its job is to print an error message and then exit.
/*
* Pretty-print connection-terminating errors and exit.
*/
void
sshpkt_fatal(struct ssh *ssh, const char *tag, int r)
{
switch (r) {
case SSH_ERR_CONN_CLOSED:
logdie("Connection closed by %.200s port %d",
ssh_remote_ipaddr(ssh), ssh_remote_port(ssh));
[...code removed...]
/* FALLTHROUGH */
default:
logdie("%s%sConnection %s %.200s port %d: %s",
tag != NULL ? tag : "", tag != NULL ? ": " : "",
ssh->state->server_side ? "from" : "to",
ssh_remote_ipaddr(ssh), ssh_remote_port(ssh), ssh_err(r));
}
}
The message that you're asking about is handled by the default case. The last argument, which provides the text after the colon, is provided by calling ssh_err:
const char *
ssh_err(int n)
{
switch (n) {
case SSH_ERR_SUCCESS:
return "success";
case SSH_ERR_INTERNAL_ERROR:
return "unexpected internal error";
[...etc...]
The ssh_err case that you're interested in is this one:
case SSH_ERR_SYSTEM_ERROR:
return strerror(errno);
In short, the "Broken pipe" message comes from the standard library function strerror, which converts error numbers to standard error messages.
The list of standard error codes indicates that "Broken pipe" is associated with the EPIPE error.
My app runs as Standard User. Occasionally I need to create a Registry Key that requires Admin access. I would like to prompt the user for Admin permission.
If I do something along these lines:
GetNamedSecurityInfo
AllocateAndInitializeSid
SetEntriesInAcl
SetNamedSecurityInfo (or RegSetKeySecurity)
should this cause Windows to automatically pop up a dialog prompting the user for authorization?
Do I instead have to launch a process just to get access to the Registry? In which case, how do I prompt the user to obtain Admin rights for the process?
I prefer not to use CredUIPromptForCredentials because I don't want to see the user's password.
I've read through the Access Control documentation, can't seem to see the forest for the trees.
Windows will not display the UAC dialog just because you called some API that requires elevation to perform its task, the API will simply fail with ERROR_ACCESS_DENIED.
You basically have three options:
Implement a elevated COM object.
ShellExecute yourself with the RunAs verb and a command line parameter so you can detect that you are in this mode.
Create a NT service that you can start on demand and communicate with over a named pipe. I don't recommend this approach.
Here's what I have come up with, thanks to #Anders' excellent advice:
// launch separate process for elevation to Admin
void launchAsAdmin(void)
{ SHELLEXECUTEINFO shelinfo;
char *err = NULL;
DWORD exitCode;
memset(&shelinfo, 0, sizeof(shelinfo));
shelinfo.cbSize = sizeof(shelinfo);
shelinfo.hwnd = NULL;
shelinfo.fMask = SEE_MASK_NOCLOSEPROCESS;
shelinfo.lpVerb = "RunAs";
shelinfo.lpFile = "notepad.exe";
shelinfo.lpParameters = "C:\\Windows\\System32\\drivers\\etc\\hosts";
shelinfo.nShow = SW_SHOW;
ShellExecuteEx(&shelinfo);
switch((int)shelinfo.hInstApp)
{ case SE_ERR_FNF:
err = "File not found"; break;
case SE_ERR_PNF:
err = "Path not found"; break;
case SE_ERR_ACCESSDENIED:
err = "Access denied"; break;
case SE_ERR_OOM:
err = "Out of memory"; break;
case SE_ERR_DLLNOTFOUND:
err = "Dynamic-link library not found"; break;
case SE_ERR_SHARE:
err = "Cannot share an open file"; break;
case SE_ERR_ASSOCINCOMPLETE:
err = "File association information not complete"; break;
case SE_ERR_DDETIMEOUT:
err = "DDE operation timed out"; break;
case SE_ERR_DDEFAIL:
err = "DDE operation failed"; break;
case SE_ERR_DDEBUSY:
err = "DDE operation is busy"; break;
case SE_ERR_NOASSOC:
err = "File association not available"; break;
}
if((int)shelinfo.hInstApp <= 32)
return; // failed
if(shelinfo.hProcess == 0)
return; // nothing to monitor
// wait until the process has finished
time_t st = clock();
do
{ if(!GetExitCodeProcess(shelinfo.hProcess, &exitCode))
break;
if(clock() - st > CLOCKS_PER_SEC * 5) // max 5 seconds - give up
break;
} while(exitCode != STATUS_WAIT_0); // STILL_ACTIVE
CloseHandle(shelinfo.hProcess);
}
This works. If I am Standard User and I run a program that calls this function, I am prompted for Admin login ID & password, and allowed to change and save the "HOSTS" system file. (Normally this file is off-limits to a Standard User).
I have the below shell script (expect) where I am trying to send SMS. I have referred many stack overflow references and found out that ctrl-z maps to \x1a. However, even after appending it to the message and sending to the port or sending ctrl z separately to the port didn't help me. It timeouts later.
The script is written to send sms in pdu format. Irrespective of that, I believe, this is a generic issue to send ctrl-z to port. If you feel the script has some other errors, please share the solution for the same.
Also the length (34) mentioned below is the length of the (PDU_LENGTH -2)/2 as per the specification. This length doesn't include ctrl-z character.
at_command = "AT+CMGS=34\r"
message_content = "0011000C810056890......"
Script:
set PROMPT "0"
set timeout "$COMMAND_TIMEOUT"
send "$at_command"
expect {
"OK" { puts "Command Accepted\n"; }
"ERROR" { puts "Command Failed\n"; }
timeout { puts "Unable to connect to $HOSTIP at $HOSTPORT"; exit 1 }
"*>*" { set PROMPT "1"; }
}
if { "$PROMPT" == "1" } {
send "$message_content"
send "\x1a"
expect {
"OK" { puts "\nCommand accepted"; }
"ERROR" { puts "\nCommand failed"; }
"*>*" { puts "CTRL-Z dint reach UT. Error..."; }
"*" { puts "Unexpected return value received"; }
}
}
Am very sure the script sends $message_content" to port but exits immediately after sending "$message_content".
OUTPUT:
AT+CMGS=34
>
I did something like this in c# with an SMS-Gateway-Modul.
I had to switch to PDU-Mode first!
After that i had to transmit the expected PDU-Length and finally the PDU itself.
Every command has to be committed with can carriage return ASC[13] and the PDU had to be committed with an ASC[26] finally.
Here you can see a schematic(!) flow, how i did it in c#:
1) Create PDU and get length
int len;
var pdu = PDUGenerator.GetPdu(destination, message, "", out len);
2) Switch to PDUMode
SendToCom("AT+CMGF=0" + System.Convert.ToChar(13));
3) Announce message length
SendToCom("AT+CMGS=" + len + System.Convert.ToChar(13));
4) Send PDU and commit
SendToCom(pdu + System.Convert.ToChar(26));
I get a warning with the following code using ruby 1.9.3-p194
if (x = true)
puts 'it worked'
end
# => warning: found = in conditional, should be ==
However, if I assign an array, no warning
if (x = [true])
puts 'it worked'
end
# => 'it worked', then returns nil since return of 'puts' is nil
Why does using a string cause a warning? Or maybe a better question, why is it that using an array does NOT cause a warning?
Ruby reports warning when assigning (Literals: Fixnum, Symbol, String), nil and true/false
ruby-1.9.3-p194
parse.c:15026
static int
assign_in_cond(struct parser_params *parser, NODE *node)
{
switch (nd_type(node)) {
case NODE_MASGN:
yyerror("multiple assignment in conditional");
return 1;
case NODE_LASGN:
case NODE_DASGN:
case NODE_DASGN_CURR:
case NODE_GASGN:
case NODE_IASGN:
break;
default:
return 0;
}
if (!node->nd_value) return 1;
switch (nd_type(node->nd_value)) {
case NODE_LIT:
case NODE_STR:
case NODE_NIL:
case NODE_TRUE:
case NODE_FALSE:
/* reports always */
parser_warn(node->nd_value, "found = in conditional, should be ==");
return 1;
case NODE_DSTR:
case NODE_XSTR:
case NODE_DXSTR:
case NODE_EVSTR:
case NODE_DREGX:
default:
break;
}
return 1;
}
Both of your programs have the same output "it worked".
Both of your programs use the value of an assignment statement
The first uses a pattern which the compiler believes usually indicates an mistake (hence the warning)
The second uses an expression which is (evidently) too complex to trigger the warning message