简体   繁体   English

c包装到perl脚本,该脚本接受包装器中硬编码的参数

[英]c wrapper to a perl script that accepts arguments hard coded in the wrapper

My question might be described as the reverse of "Passing cmd line arguments through a C setuid wrapper...". 我的问题可能被描述为“通过C setuid包装器传递cmd行参数......”的反向。 That question asks how to run this ./cwrapper perl.pl --option1 --option2 那个问题询问如何运行这个./cwrapper perl.pl --option1 --option2

In my case, the Perl script is embedded in the wrapper. 在我的例子中,Perl脚本嵌入在包装器中。 This wrapper comes from page 570 "Programming Perl". 这个包装器来自第570页“Programming Perl”。 And it works---until I add an argument following the script in the wrapper. 它的工作原理---直到我在包装器中的脚本后添加一个参数。

THIS WORKS -- perl_script.pl outputs expected results: 这个工作 - perl_script.pl输出预期结果:

#define REAL_SCRIPT "/path/to/script/perl_script.pl"
main (ac, av)
    char **av;
{
    execv(REAL_SCRIPT, av);
}

THIS DOES NOT WORK--eg perl_script outputs nothing to stdin or stderr. 这不起作用 - 例如perl_script不向stdin或stderr输出任何内容。 Note the "arg=12345": 注意“arg = 12345”:

#define REAL_SCRIPT "/path/to/script/perl_script.pl arg=12345"
main (ac, av)
    char **av;
{
    execv(REAL_SCRIPT, av);
}

Thanks for any clues. 谢谢你的任何线索。 John 约翰

The first argument of execv() is the path to the executable to execute. execv()的第一个参数是要执行的可执行文件的路径。 It works when you pass the args as the second parameter to execv() , but when you pass the extra param in as part of the executable's name, execv() fails. 当你将args作为第二个参数传递给execv() ,它可以工作,但当你将额外的参数作为可执行文件名称的一部分传递时, execv()失败。

I notice a lack of error handling in your example. 我注意到你的例子中缺少错误处理。 I infer from the lack of an error message reported above that you're not checking for and handling errors from execv(). 我推断,由于缺少上面报告的错误消息,您没有检查并处理来自execv()的错误。 It is probably telling you why it won't run your program. 它可能告诉你为什么它不会运行你的程序。 It returns and integer, and if non-zero, you should look up the error using perror() . 它返回并返回整数,如果非零,则应使用perror()查找错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM