Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a way to test the configuration #301

Open
jvoisin opened this issue Jul 25, 2019 · 2 comments
Open

Provide a way to test the configuration #301

jvoisin opened this issue Jul 25, 2019 · 2 comments

Comments

@jvoisin
Copy link
Owner

jvoisin commented Jul 25, 2019

Currently, the only way to verify that a configuration file is valid is to restart PHP: this is inconvenient.

We should provide a standalone binary to perform configuration validation. Since we're doing manual parsing instead of using shlex/yacc/bison/… as the rest of the zoo, we should re-use the code, instead of writing a linter in an other language, since it'll be tedious to keep them in since.

@jvoisin
Copy link
Owner Author

jvoisin commented Aug 1, 2019

The obvious solution would be something like this I guess:

#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>

int main(int argc, char** argv) {
	char* error;
	int (*sp_parse_config)(const char*);

	if (argc <= 2) {
		printf("Usage: %s file ...", argv[0]);
		return -1;
	}

	void* handle = dlopen("./.libs/snuffleupagus.so", RTLD_LAZY | RTLD_DEEPBIND);
	if (!handle) {
		fprintf(stderr, "%s\n", dlerror());
		return -1;
	}
	dlerror(); 

	sp_parse_config = (int (*)(const char*)) dlsym(handle, "sp_parse_config");
	error = dlerror();
	if (error != NULL) {
		fprintf(stderr, "%s\n", error);
		return -1;
	}

	for(int i=0; i != argc; i++) {
		int ret = sp_parse_config(argv[i]);
		if (ret != 0) {
			return -1;
		}
	}
	dlclose(handle);
	return 0;
}

But PHP's modules are a bit weird, with a lot of moving pieces between the .so and the main PHP binary, so it's not working well™

@jvoisin jvoisin added this to the 1.0.0 - Elephant Gambit milestone May 3, 2022
@bef
Copy link
Collaborator

bef commented May 11, 2022

My current work-in-progress solution is to export the configuration in PHP serialized format for use with separate tools. The export part is already implemented. As for the tools, I think about adding unit tests for ini-checks and disabled_functions that can be embedded into the config file as comments and parsed separately by the external config checker tool.

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

No branches or pull requests

2 participants