Skip to content

support DB_PROGRAM to be absolute, relative or in PATH#4013

Open
TurBoss wants to merge 4 commits intoLinuxCNC:masterfrom
TurBoss:tool_db_path
Open

support DB_PROGRAM to be absolute, relative or in PATH#4013
TurBoss wants to merge 4 commits intoLinuxCNC:masterfrom
TurBoss:tool_db_path

Conversation

@TurBoss
Copy link
Copy Markdown
Contributor

@TurBoss TurBoss commented May 9, 2026

Hello

This commit allows DB_PROGRAM to handle absolute, relative path or binaries in env PATH

closes #3982

Thanks

Edit: also check if path/file exists

Comment thread src/emc/tooldata/tooldata_db.cc Outdated
char* saveptr;
char* token = strtok_r(progname_plus_args, " ", &saveptr);
int n;
char* fork_argv[PATH_MAX] = {0};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you allocating PATH_MAX pointers to char? I think that PATH_MAX is normally about 4096 and you are allocating that many pointers. Should use std::vector.

See also other comment about this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reduced that to 10, was a mistake thanks!

Comment on lines +267 to +272
if (db_childname[0] != '/') { // prog path not absolute
if(strchr(db_childname, '/') != NULL){ // prog path is relative
strncpy(prog_path, db_childname, PATH_MAX);
}
else { // just prog name, search in the actual directory or PATH
envpath = getenv( (char*)"PATH");
Copy link
Copy Markdown
Contributor

@BsAtHome BsAtHome May 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...and the rest...
I think this needs to be redesigned using std::string and std::vector<std::string>. There is no point nowadays to use C style (more error prone) string handling in a C++ source file. It was already outdated in 2021 when written and added. Now, when you try to fix it, it should be modernized to remove the standard pitfalls.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry I'm not much familiar with c++

@BsAtHome
Copy link
Copy Markdown
Contributor

BsAtHome commented May 9, 2026

Some more observations while reading this code...
The code is wrong how it splits arguments. It uses a simple ' ' (space) tokenizer and neglects both IFS and quoting. I can understand IFS ignorance, but when you split arguments from a value you got from the INI-file and want to execute the program, how then can you supply it properly with arguments if such an argument includes a space?

When you change the code to use a path search, why then not make it easier for yourself and run it via a shell -c exec (not a call to system)? Then the shell can deal with all the intricacies of argument splitting and path searches?

The code will crash and burn when the maximum number of arguments are parsed because the call to execv() must terminate the arg list with a NULL. In effect, this is a off-by-one error.

The code also spits out stuff using fprintf() and not the usual rcs_print stuff. This happens a lot of places (not only in the tooldata stuff).

Other things in the code:
When the pipe creating or forking fails, it simply calls exit() killing the whole parent process and not gracefully returning an error that can be handled up the call-tree.

The code gets debug variables from the environment, where it should be reading those from the INI-file as the central place for configuration.

The SIGCHLD handler waits for all processes that may be a zombi (that is good), however, it then only checks the last of the zombi's status. What about the others?

Probably a lot more if I start looking deeper. Enough for now.

@BsAtHome
Copy link
Copy Markdown
Contributor

BsAtHome commented May 9, 2026

BTW, using a shell -c is also a very tricky suggestion requiring a lot of escaping.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

unable to run binaries on PATH in DB_PROGRAM

2 participants