{"id":7039,"date":"2022-12-20T19:34:43","date_gmt":"2022-12-20T22:34:43","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/manatoolssharedrunprogram-man3\/"},"modified":"2022-12-20T19:34:43","modified_gmt":"2022-12-20T22:34:43","slug":"manatoolssharedrunprogram-man3","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/manatoolssharedrunprogram-man3\/","title":{"rendered":"ManaTools::Shared::RunProgram (man3)"},"content":{"rendered":"<h1 align=\"center\">ManaTools::Shared::RunProgram<\/h1>\n<p> <a href=\"#SYNOPSYS\">SYNOPSYS<\/a><br \/> <a href=\"#Functions\">Functions<\/a><br \/> <a href=\"#POD ERRORS\">POD ERRORS<\/a> <\/p>\n<hr>\n<h2>SYNOPSYS <a name=\"SYNOPSYS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>rManaTools::Shared::RunProgram<\/b> enables to:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"68%\">\n<p>run programs in foreground or in background,<\/p>\n<\/td>\n<td width=\"15%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"68%\">\n<p>to retrieve their stdout or stderr<\/p>\n<\/td>\n<td width=\"15%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"68%\">\n<p>&#8230;<\/p>\n<\/td>\n<td width=\"15%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%; margin-top: 1em\">Most functions exits in a normal form &#038; a rooted one. e.g.:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p style=\"margin-top: 1em\">\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"58%\">\n<p style=\"margin-top: 1em\">&#8220;run()&#8221; &#038; &#8220;rooted()&#8221;<\/p>\n<\/td>\n<td width=\"25%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"58%\">\n<p>&#8220;get_stdout()&#8221; &#038; &#8220;rooted_get_stdout()&#8221;<\/p>\n<\/td>\n<td width=\"25%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%; margin-top: 1em\">Most functions exits in a normal form &#038; one that die. e.g.:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p style=\"margin-top: 1em\">\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"46%\">\n<p style=\"margin-top: 1em\">&#8220;run()&#8221; &#038; &#8220;run_or_die()&#8221;<\/p>\n<\/td>\n<td width=\"37%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"46%\">\n<p>&#8220;rooted()&#8221; &#038; &#8220;rooted_or_die()&#8221;<\/p>\n<\/td>\n<td width=\"37%\"> <\/td>\n<\/tr>\n<\/table>\n<h2>Functions <a name=\"Functions\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">set_default_timeout($seconds)<\/p>\n<p style=\"margin-left:17%;\">Alters defaults timeout (eg for harddrake service)<\/p>\n<p style=\"margin-left:11%;\">run_or_die($name, @args)<\/p>\n<p style=\"margin-left:17%;\">Runs $name with @args parameterXs. Dies if it exit code is not 0.<\/p>\n<p style=\"margin-left:11%;\">rooted_or_die($root, $name, @args)<\/p>\n<p style=\"margin-left:17%;\">Similar to <b>run_or_die()<\/b> but runs in chroot in $root<\/p>\n<p style=\"margin-left:11%;\">get_stdout($name, @args)<\/p>\n<p style=\"margin-left:17%;\">Similar to <b>run_or_die()<\/b> but return stdout of program:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"17%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"74%\">\n<p>a list of lines in list context<\/p>\n<\/td>\n<td width=\"3%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"17%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"74%\">\n<p>a string of concatenated lines in scalar context<\/p>\n<\/td>\n<td width=\"3%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\">get_stdout_raw($options, $name, @args)<\/p>\n<p style=\"margin-left:17%;\">Similar to <b>get_stdout()<\/b> but allow to pass options to <b>raw()<\/b><\/p>\n<p style=\"margin-left:11%;\">rooted_get_stdout($root, $name, @args)<\/p>\n<p style=\"margin-left:17%;\">Similar to <b>get_stdout()<\/b> but runs in chroot in $root<\/p>\n<p style=\"margin-left:11%;\">run($name, @args)<\/p>\n<p style=\"margin-left:17%;\">Runs $name with @args parameters.<\/p>\n<p style=\"margin-left:11%;\">rooted($root, $name, @args)<\/p>\n<p style=\"margin-left:17%;\">Similar to <b>run()<\/b> but runs in chroot in $root<\/p>\n<p style=\"margin-left:11%;\">raw($options, $name, @args)<\/p>\n<p style=\"margin-left:17%;\">The function used by all the other, making every combination possible. Runs $name with @args parameters. $options is a hash ref that can contains:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"17%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"77%\">\n<p><b>root<\/b>: $name will be chrooted in $root prior to run<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"17%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"77%\">\n<p><b>as_user<\/b>: $name will be run as $ENV{ <small>PKEXEC_UID<\/small> } or with the <small>UID<\/small> of parent process. Implies <i>setuid<\/i><\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"17%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"77%\">\n<p><b>sensitive_arguments<\/b>: parameters will be hidden in logs (b\/c eg there\u2019s a password)<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"17%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"77%\">\n<p><b>detach<\/b>: $name will be run in the background. Default is foreground<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"17%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"77%\">\n<p><b>chdir<\/b>: $name will be run in a different default directory<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"17%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"77%\">\n<p><b>setuid<\/b>: contains a <b>getpwnam<\/b>(3) struct ; $name will be with droped privileges ; make sure environment is set right and keep a copy of the X11 cookie<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"17%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"77%\">\n<p><b>timeout<\/b>: execution of $name will be aborted after &#8220;timeout&#8221; seconds<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"17%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"77%\">\n<p><b>exitcode<\/b>: function will return the exit code of the process<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:17%; margin-top: 1em\">eg:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"17%\"><\/td>\n<td width=\"1%\">\n<p style=\"margin-top: 1em\">\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"77%\">\n<p style=\"margin-top: 1em\">&#8220;ManaTools::Shared::RunProgram::raw({ root => $::prefix, sensitive_arguments => 1 }, &#8220;echo \u2212e $user\u2212>{password} | cryptsetup luksFormat $device&#8221;);&#8221;<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"17%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"77%\">\n<p>&#8220;ManaTools::Shared::RunProgram::raw({ detach => 1 }, &#8216;\/etc\/rc.d\/init.d\/dm&#8217;, &#8216;>&#8217;, &#8216;\/dev\/null&#8217;, &#8216;2>&#8217;, &#8216;\/dev\/null&#8217;, &#8216;restart&#8217;);&#8221;<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\"><b>get_parent_uid()<\/b><\/p>\n<p style=\"margin-left:17%;\">Returns <small>UID<\/small> of the parent process.<\/p>\n<h2>POD ERRORS <a name=\"POD ERRORS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Hey! <b>The above document had some coding errors, which are explained below:<\/b> <br \/> Around line 58:<\/p>\n<p style=\"margin-left:17%;\">=over without closing =back<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>ManaTools::Shared::RunProgram SYNOPSYS Functions POD ERRORS SYNOPSYS rManaTools::Shared::RunProgram enables to: \u2022 run programs in foreground or in background, \u2022 to retrieve their stdout or stderr \u2022 &#8230; Most functions exits in a normal form &#038; a rooted one. e.g.: \u2022 &#8220;run()&#8221; &#038; &#8220;rooted()&#8221; \u2022 &#8220;get_stdout()&#8221; &#038; &#8220;rooted_get_stdout()&#8221; Most functions exits in a normal form &#038; one [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3007,3386],"class_list":["post-7039","post","type-post","status-publish","format-standard","hentry","category-sin-categoria","tag-man3","tag-manatoolssharedrunprogram"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/7039","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=7039"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/7039\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=7039"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=7039"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=7039"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}