- static const str::regex rx( "[0-9]+:name=systemd:/system.slice/(.*/)?(.*).service$" );
- str::smatch what;
- std::string ret;
- iostr::simpleParseFile( InputStream( Pathname("/proc")/pid/"cgroup" ),
- [&]( int num_r, std::string line_r )->bool
- {
- if ( str::regex_match( line_r, what, rx ) )
- {
- ret = what[2];
- return false; // stop after match
- }
- return true;
- } );
- return ret;
+ if ( command.empty() )
+ return std::string();
+ // TODO: This needs to be implemented smarter... be carefull
+ // as we don't know whether the target is up.
+
+ static const Pathname initD( "/etc/init.d" );
+ { // init.d script with same name
+ PathInfo pi( initD/command );
+ if ( pi.isFile() && pi.isX() )
+ return command;
+ }
+ { // init.d script with name + 'd'
+ std::string alt( command+"d" );
+ PathInfo pi( initD/alt );
+ if ( pi.isFile() && pi.isX() )
+ return alt;
+ }
+ if ( *command.rbegin() == 'd' )
+ { // init.d script with name - trailing'd'
+ std::string alt( command );
+ alt.erase( alt.size()-1 );
+ PathInfo pi( initD/alt );
+ WAR <<pi << endl;
+ if ( pi.isFile() && pi.isX() )
+ return alt;
+ }
+ return std::string();