stat not returning properly on centos 7? - c++

So I am running a C++ app, built with CMake (not by me). It works fine on other people testing with it, but not found anyone to test on centos7 yet.
The issue seems to arrise at this snippet of code:
struct stat fileStat;
if ( stat( pszFilePath, &fileStat) == -1 )
{
DEBUG_ERR(( "Can't open input dir [%s]\n", pszFilePath ));
return( false );
}
Which is the first part of the ReadFileInfo call here:
time_t dateChange;
DWORD dwSize;
if ( ! CFileList::ReadFileInfo( GetFilePath(), dateChange, dwSize ))
{
DEBUG_ERR(( "Can't get stats info for file '%s'\n", static_cast<LPCTSTR>(GetFilePath()) ));
return false;
}
Now, pszFilePath is many value, a few examples are:
'scripts/sphere_template_vend.scp'
'scripts/sphere_serv_triggers.scp'
The application is owned by root, the whole folder it all sits in is owned by root. The scripts folder is there and has read/write permissions as do all files (all also owned by root)
Running the application triggers both errors in the above code, there is nothing before them that influences anything.
Im not a C++ developer and do not have the tools to compile with debugs for checking the current path and so on, but I see no reason why it throws these errors. The files exist, the files are accessible, no one else seems to have this problem.
I do have cPanel on the server, but it shouldn't be causing any issues as I am using root user and also keeping out of the /home/ directory
Anyone know of any issue this could be because of? I tried with a '/sphere/' prepending the paths but it still has the same issue, it seems the application does not have access to the files (the application oddly reports line errors within the files it says it cannot read, but they do not match, so assuming its not correct).
Issue reported on the Github for the project here: https://github.com/Sphereserver/Source/issues/64
But no one seems to know whats going on

Related

boost::filesystem How to handle directories with no permissions

I am running into an error while trying to enumerate a directory using boost::filesystem.
The error appears when I try to enumerate a directory for which I have no permissions on an SMB shared directory - ie, I have RW on the share but a subdirectory on the share is access denied.
Platform etc:
Windows 10.
C++ 17 code.
Visual Studio 2019.
Unicode VS project (thus the use of std::wstring).
Shared folders from a Samba server running on Linux.
Sample code below, then details of the fail.
int enumerate(const std::wstring dir_to_enumerate) {
if (directory.size() == 0)
return -1;
boost::filesystem::path dir_to_enumerate(dir_to_enumerate);
boost::system::error_code ec;
if ( ! boost::filesystem::exists(dir_to_enumerate, ec))
return -2;
if (ec.value())
return -4;
if ( ! boost::filesystem::is_directory(dir_to_enumerate))
return -3;
boost::filesystem::directory_iterator it{ dir_to_enumerate };
while (it != boost::filesystem::directory_iterator{}) {
// ... do stuff
}
return 0;
}
Consider a folder C:\temp2 with permissions removed for my account. The test
if ( ! boost::filesystem::exists(dir_to_enumerate, ec))
return -2;
reliably detects C:\temp2 is not accessible.
Consider a folder "temp2" located on a Samba share T:. This folder on the Linux box is /data/temp2. So the directory passed into the function is L"T:\temp2", and that corresponds to location /data/temp2 on the Linux filesystem.
Samba itself shares the location R/W.
If on the Linux server the EXT4 permissions of the directory /data/temp2 are R/W (mode 700, or 750, or 755 you get the idea) for my account then everything works as expected, I can enumerate the contents of T:\temp2
The problem shows up detecting the following case reliably:
If I set the EXT4 permissions on the directory /data/temp2 to denied (mode 000) then the above code behaves unpredictably...
Sometimes, most of the time, the test
if ( ! boost::filesystem::exists(dir_to_enumerate, ec))
return -2;
detects T:\temp2 is not accessible.
But occasionally exists() returns true, and we fall thru to testing the boost::filesystem::error_code value.
However the error_code never indicates an error.
In this case the line
boost::filesystem::directory_iterator it{ dir_to_enumerate };
always throws. I can't figure out exactly what it is throwing.
I'm pulling my hair out. Can anyone tell me what I am missing, or even just what the directory_iterator initializer is throwing?
(And... if I may be so forward: please do not tell me to just use std::filesystem. On Visual Studio 2019, and AFAIK C++17 itself, std::filesystem is incomplete. Boost::filesystem works better.)

fopen() working with windows but giving issues in linux

I am trying to use fopen() in a program in which I am creating a new file and then using that file into another function. The function is created as follows:-
FILE* check=NULL;
check =fopen(convert_wchartoString(file_Name.c_str()).c_str(), "rb");
if(check==NULL)
{
cout<<"Unable to open";
}
Now, the issue is that fopen is returning NULL in linux but, in windows it is working. I am not sure why this issue is coming. I have debugged the value of file_name and it is coming fine on both the platforms. Please advice something which could be potentially wrong in this?
UPDATE:-
Seems like it is a path issue. Currently, the file_name has path to C:\files but when i try to run the same code in wsl, it doesn't work. The path in wsl is /mnt/c/files. But when trying to give this path to file_name. It is also not working. Is there any permission issues for the same or should I need to modify the path?

How to initialise a git repository with libgit2

On a Windows XP, 32-bit machine I've cloned the libgit2 repository using
git clone git://github.com/libgit2/libgit2.git trunk
Then I configured from trunk_build_debug for mingw using:
cmake ../trunk -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_FLAGS=-g
and build-ed it with
make
With this newly build library I'm trying to create a new repository. So I'm using
error_code = git_repository_init( &repo, path, 0 );
if ( error_code != 0 )
{
const git_error * error = giterr_last();
/* the text representation:
( error == NULL || error->message == NULL ?
"(no description)" :
error->message )
*/
}
On first attempt this fails with the error message:
Git error -1: The global file '.config/git/config' doesn't exist: The
system cannot find the file specified.
The .git directory is created and I can use git status to query it. Also, I have git installed in Program Files/git and it works just fine. The file that is mentioned does not exist in user directory, that is true. I'm not happy because I can't check the returned error code (the error may be "real").
So I've created an empty file in D:\Documents and Settings\User Name.config\git\config
The .git directory is again created but I get the same -1 error code. This time giterr_last() returns NULL.
Tracing the code in debugger seems to indicate that the library is not happy with my empty file.
However, I think this indicates that I'm doing something wrong. Is there an initialization method? Do I need to create the file and use the git_config_ functions to point the library to it?
BTW, is this the wrong place to ask this? Is there a dedicated forum where I should ask this question?
Thanks
Here is the back trace where the call fails: pastebin
It seems that the configure file inside .git directory can't be parsed (not shown in in trace is the 'config_parse()' that fails).
I've opened an issue in libgit2.
To create a new repository, one should rather rely on git_repository_init(). For more information, you can peek at the header and the tests.
git_repository_open() should rather be used when the repository already exists.
Is there a dedicated forum where I should ask this question?
It's ok to ask programming related question on StackOverflow. Beside this, some libgit2 developers hang out in the #libgit2 channel on irc.freenode.net. However, when you encounter bugs, it's recommended to submit them to the issue tracker.
Update
There had been some issues in the past with the way the configuration files are being probbed on Windows. Along with some attempts to fix them. See this issue for some background about this.
Beside the complexity of the probbing, some users may want to explictly provide alternate locations for their files. This pull request works this angle.
Considering what you discovered while debugging the libgit2, maybe now would be a good time to open a bug in the issue tracker. Beware that two issues may be at play: the probbing one and and the empty config issue.

system() c++ wont run in VirtualBox

I'm trying to compile and run the app, which was created 4 years ago. It was developed for Windows in Embarcadero RAD Studio C++ builder. Now I try to compile and run it in Windows in VirtualBox using the latest version of RAD Studio. I have a system call to another app in my app:
system("dot.exe -Tjpg -o nfa.jpg NFA_graph.txt");
It keeps returning 1 and the file is not created. I also tried
system("Echo %CD% >> z:\log.txt");
and the file is not created. I also tried like this:
FILE *fpipe;
char *command = "Echo %CD% >> z:\log.txt";
char line[256];
if (0 == (fpipe = (FILE*)_popen(command, "r")))
{
perror("popen() failed.");
exit(1);
}
while (fread(line, sizeof line, 1, fpipe))
{
ShowMessage(line);
}
_pclose(fpipe);
And nothing I get. I wonder if the reason of such strange behaviour is that I'm running this all in VirtualBox?
You're not escaping your \ characters. You should use / in file paths, or \\ if you must. In addition, Windows 7 won't let you write to the root directory of a hard drive w/o administrator access.
To determine if a command environment is available, first do this:
if (!system(NULL)) {
// Can't make any system() calls
}
If your command environment is available, then you need to fully specify the path, making sure to escape the \'s like I mentioned above, and don't write anything to a drive's root directory. Also make note that opening files does not default create directories.
No, it's very unlikely. I see few issues with your code: you did not check errno if system() returns 1. It can help you to spot a real problem. Also, all backslashes must be Esc'ed.
I'm suggesting that dot.exe is not in PATH environment variable, that's the reason of the system() failure.

Eclipse SDL build error: "The program specified in the launch configuration does not exist"

I've tried working some SDL on my set-up eclipse, and as I tried running it it gave me the following error:
'Launching SDL.exe' has encountered a problem.
The program specified in the launch configuration does not exist
I instantly went to another project to see if it builds, and it did. I also tried re-building, debugging the SDL project. I don't know if it's an error in code but just in case, this is the code:
#include "SDL/SDL.h"
#include <string>
#include <SDL/SDL_image.h>
SDL_Surface *load_image( std::string filename ) {
SDL_Surface* loadedImage = NULL;
SDL_Surface* optimizedImage = NULL;
loadedImage = IMG_Load(filename.c_str());
if(loadedImage != NULL) {
optimizedImage = SDL_DisplayFormat(loadedImage);
SDL_FreeSurface(loadedImage);
}
return optimizedImage;
}
I've googled it, and there's a duplicate question on stackOverFlow here, however it has 0 answers, not even a comment. There are no answers on google regarding this problem, so if you'd answer it, you'd probably solve hours of headaches for more people.
I encountered the same problem with eclipse in Ubuntu. Spent 30 minutes and finally got it fixed as below:
Click Project -> Properties;
Select run/debug settings, and then the current configuration on the right pane, click edit;
In the c/c++ application textbox, select search project, and then click the binary you want to execute for the current project.
On my system, the previous problem is due to incorrect default file name --- the linker generates abinary.exe but in run configuration it is "abinary".
Such tiny (but time consuming) problems should have been fixed by Eclipse developers, if they got well paid as MS or apple developers. Alas, free software?
Right click on your project in the Project Explorer and select Debug As -> Local C/C++ Application.
Check to make sure you didn't accidentally hit a space first, when typing in the project name. Also, if on windows use CMD or Linux ls -al your workspace and look carefully at the columns of names. Try executing your .exe from the command line. If it's not there, well, look at your build output more closely! :-)
I'm using Eclipse Neon.
In my case I was copy pasting a code to understand enumerator, but the code was faulty. As I built the project, the binaries disappeared and it said:
the program file in launch configuration does not exist
Then I tried a simple hello world program and it still gave an error. The actual problem was that the src folder had both the files (I don't know how). When I deleted the other one it built and ran successfully. Hope this helped.