esp-idf esp32 spiffs suddenly failed - esp32

what can cause spiffs suddenly failed in esp-idf? It was ok during start up. Until certain time it failed. After reboot again it become ok again.
Failed mean when I try to open the file for read it return null.
FILE* f = fopen(filePath, "r");
if (f == NULL)
{
ESP_LOGE(TAG, "Failed to open file for reading");
return;
}
Thanks

Related

Unable to update Console Cursor Info (PCONSOLE_CURSOR_INFO) due to security

In console application, I want to write the output at a specific location and there should be no cursor at the console (Windows CMD). To do so, I got following way:
HANDLE hdl = GetStdHandle(STD_OUTPUT_HANDLE);
if (hdl == INVALID_HANDLE_VALUE)
{
printf("Error : Unable to get console handle.\n");
return 0;
}
PCONSOLE_CURSOR_INFO lpConsoleCursorInfo = { NULL };
if (!GetConsoleCursorInfo(hdl, &lpConsoleCursorInfo))
{
printf("Error : Unable to get console cursor information.\n");
return 0;
}
lpConsoleCursorInfo->dwSize = 1; //App exit at this point with error code 0xC0000005h
I got runtime error 0xC0000005h. By searching, I have reach at the conclusion that it is a security level issue, and to setup access level SECURITY_DESCRIPTOR is used.
I am unable to find the way how to set the access level to STD_OUTPUT_HANDLE that already created and associated with my console application by visual studio console application.
Can someone point me in the right direction?
There is no security issue, you simply don't understand how Windows pointer types work. PCONSOLE_CURSOR_INFO is just a pointer, remove the P.
CONSOLE_CURSOR_INFO ConsoleCursorInfo = { NULL };
if (!GetConsoleCursorInfo(hdl, &ConsoleCursorInfo)) ...
else ConsoleCursorInfo.dwSize = ...

ssh "packet_write_wait: Connection to x.x.x.x port 22: Broken pipe" -- where is the source code?

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.

Get permission denied message when creating a file to /var/log on os x

I want to write qt application log to /var/log/message_app.log on OS X. I am getting
"Cannot open file for writing: "Permission denied""
message on console.
This is the my test code parts:
logfile = fopen(logFilePath, "a");
if (!logfile) {
fprintf(stderr, "ERROR: Unable to access keystroke log file. Please make sure you have the correct permissions.\n");
}
and
QString filename = "/var/log/data.txt";
QFile file(filename);
file.setPermissions(QFile::ExeGroup);
file.setPermissions(QFile::ExeOther);
file.setPermissions(QFile::ExeOwner);
file.setPermissions(QFile::ExeUser);
if (!file.open(QIODevice::ReadWrite)) {
qDebug() << "Cannot open file for writing: " << file.errorString();
return 0;
}
else {
QTextStream stream(&file);
stream << "something" << endl;
}
Both of them return same error.
When I start QtCreator from console using sudo command, it works. But when I deployed my app and change some permissions (with chown, chmod, etc.) it doesn't work.
I googled and found out some privileged issues like that.
So, is there any other effective solution?
Thanks!

OSX: shm_open returns ENAMETOOLONG

I am trying atm to create a shared memory file for my process. The filename constists of several parts to identify the process the SHM belongs to and whats its content. An example would be:
shm_pl_dev_system_25077
I create all the files in a directory I created in /tmp where I have full write and read permissions.
So the complete Path would be:
/tmp/pl_dev/shm_pl_dev_system_25077
I create several files there, some fifo pipes and other stuff and also the shm. The only Problem I get is that shm_open will always return the errno 63 (ENAMETOOLONG).
Can you tell me what the issue here is?
Here is the code:
handle_ = ::shm_open(shm_name.get(), O_RDWR, 0755);
if (handle_ == -1 && errno == ENOENT)
{
// SHM does not yet exists, so create it!
handle_ = ::shm_open(shm_name.get(), O_CREAT | O_RDWR, 0755);
if (handle_ != -1) {
created_ = true;
}
else
{
if (!silent_)
{
log.error("Couldn't create the SHM (%d).", errno);
}
return false;
}
}
Okay. As it seems OSX is very limited in the filename of SHMs... The maximum length for a filename currently is 31 chars per section (see PSHMNAMELENGTH in /usr/include/sys/posix_shm.h)

setuid(0) gives EPERM on Mac OS X 10.9

when executing this:
err = setuid(0);
if (err < 0) {
fprintf(stderr, "return value: %d \n", err);
fprintf(stderr, "error code: %d \n", errno);
}
I am getting this output:
return value: -1
error code: 1
Error code 1 implies an EPERM error. Any ideas as to how should I fix it?
You cannot setuid() to root from a non-root user.
If you want to run your application as root, use Authorization Services, or sudo if it's a command-line tool.
SETUID(2) Man Pages
If the user is not the super user, or the uid specified is not the
real, effective ID, or saved ID,these functions return -1.
setuid(0); will work only from root(SU) user.
error code: 1
#define EPERM 1 /* Operation not permitted */

Resources