{"id":7156,"date":"2022-12-20T19:35:40","date_gmt":"2022-12-20T22:35:40","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/mdkcommonsystem-man3\/"},"modified":"2022-12-20T19:35:40","modified_gmt":"2022-12-20T22:35:40","slug":"mdkcommonsystem-man3","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/mdkcommonsystem-man3\/","title":{"rendered":"MDK::Common::System (man3)"},"content":{"rendered":"<h1 align=\"center\">MDK::Common::System<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#EXPORTS\">EXPORTS<\/a><br \/> <a href=\"#OTHER\">OTHER<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">MDK::Common::System \u2212 system\u2212related useful functions<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">use MDK::Common::System qw(:all);<\/p>\n<h2>EXPORTS <a name=\"EXPORTS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">%compat_arch<\/p>\n<p style=\"margin-left:17%;\">architecture compatibility mapping (eg: k6 => i586, k7 => k6 &#8230;)<\/p>\n<p style=\"margin-left:11%;\">%printable_chars<\/p>\n<p style=\"margin-left:17%;\">7 bit ascii characters<\/p>\n<p style=\"margin-left:11%;\">$sizeof_int<\/p>\n<p style=\"margin-left:17%;\">sizeof(int)<\/p>\n<p style=\"margin-left:11%;\">$bitof_int<\/p>\n<p style=\"margin-left:17%;\">$sizeof_int bodies manpages.csv script_extrae_body.sh script.sh usr 8<\/p>\n<p style=\"margin-left:11%;\"><b>arch()<\/b><\/p>\n<p style=\"margin-left:17%;\">return the architecture (eg: i686, ppc, ia64, k7&#8230;)<\/p>\n<p style=\"margin-left:11%;\">typeFromMagic( <small>FILENAME, LIST<\/small> )<\/p>\n<p style=\"margin-left:17%;\">find the first corresponding magic in <small>FILENAME.<\/small> eg of <small>LIST:<\/small><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">[ &#8216;empty&#8217;, 0, &#8220;\u0000\u0000\u0000\u0000&#8221; ], <br \/> [ &#8216;grub&#8217;, 0, &#8220;xEBG&#8221;, 0x17d, &#8220;stage1 \u0000&#8221; ], <br \/> [ &#8216;lilo&#8217;, 0x2, &#8220;LILO&#8221; ], <br \/> sub { my ($F) = @_; <br \/> #\u2212 standard grub has no good magic (Mageia&#8217;s grub is patched to have &#8220;GRUB&#8221; at offset 6) <br \/> #\u2212 so scanning a range of possible places where grub can have its string <br \/> my ($min, $max, $magic) = (0x176, 0x181, &#8220;GRUB \u0000&#8221;); <br \/> my $tmp; <br \/> sysseek($F, 0, 0) &#038;&#038; sysread($F, $tmp, $max + length($magic)) or return; <br \/> substr($tmp, 0, 2) eq &#8220;xEBH&#8221; or return; <br \/> index($tmp, $magic, $min) >= 0 &#038;&#038; &#8220;grub&#8221;; <br \/> },<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">where each entry is [ magic_name, offset, string, offset, string, &#8230; ].<\/p>\n<p style=\"margin-left:11%;\"><b>list_passwd()<\/b><\/p>\n<p style=\"margin-left:17%;\">return the list of users as given by &#8220;getpwent&#8221; (see perlfunc)<\/p>\n<p style=\"margin-left:11%;\"><b>is_real_user()<\/b><\/p>\n<p style=\"margin-left:17%;\">checks whether or not the user is a system user or a real user<\/p>\n<p style=\"margin-left:11%;\"><b>is_real_group()<\/b><\/p>\n<p style=\"margin-left:17%;\">checks whether or not the group is a system group or a real group<\/p>\n<p style=\"margin-left:11%;\"><b>list_home()<\/b><\/p>\n<p style=\"margin-left:17%;\">return the list of home (eg: \/home\/foo, \/home\/pixel, &#8230;)<\/p>\n<p style=\"margin-left:11%;\"><b>list_skels()<\/b><\/p>\n<p style=\"margin-left:17%;\">return the directories where we can find dot files: homes, \/root and \/etc\/skel<\/p>\n<p style=\"margin-left:11%;\"><b>list_users()<\/b><\/p>\n<p style=\"margin-left:17%;\">return the list of unprivilegied users (uses the is_real_user function to filter out system users from the full list)<\/p>\n<p style=\"margin-left:11%;\">syscall_( <small>NAME, PARA<\/small> )<\/p>\n<p style=\"margin-left:17%;\">calls the syscall <small>NAME<\/small><\/p>\n<p style=\"margin-left:11%;\">psizeof( <small>STRING<\/small> )<\/p>\n<p style=\"margin-left:17%;\">useful to know the length of a &#8220;pack&#8221; format string.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">psizeof(&#8220;I I I C C S&#8221;) = 4 + 4 + 4 + 1 + 1 + 2 = 16<\/p>\n<p style=\"margin-left:11%;\"><b>availableMemory()<\/b><\/p>\n<p style=\"margin-left:17%;\">size of swap + memory<\/p>\n<p style=\"margin-left:11%;\"><b>availableRamMB()<\/b><\/p>\n<p style=\"margin-left:17%;\">size of <small>RAM<\/small> as reported by the <small>BIOS<\/small> (it is a round number that can be displayed or given as &#8220;mem=128M&#8221; to the kernel)<\/p>\n<p style=\"margin-left:11%;\"><b>gettimeofday()<\/b><\/p>\n<p style=\"margin-left:17%;\">returns the epoch in microseconds<\/p>\n<p style=\"margin-left:11%;\">unix2dos( <small>STRING<\/small> )<\/p>\n<p style=\"margin-left:17%;\">takes care of <small>CR\/LF<\/small> translation<\/p>\n<p style=\"margin-left:11%;\">whereis_binary( <small>STRING<\/small> )<\/p>\n<p style=\"margin-left:17%;\">return the first absolute file in $PATH (similar to <b>which<\/b>(1) and <b>whereis<\/b>(1))<\/p>\n<p style=\"margin-left:11%;\">getVarsFromSh( <small>FILENAME<\/small> )<\/p>\n<p style=\"margin-left:17%;\">returns a hash associating shell variables to their value. useful for config files such as \/etc\/sysconfig files<\/p>\n<p style=\"margin-left:11%;\">setVarsInSh( <small>FILENAME, HASH REF<\/small> )<\/p>\n<p style=\"margin-left:17%;\">write file in shell format association a shell variable + value for each key\/value<\/p>\n<p style=\"margin-left:11%;\">setVarsInSh( <small>FILENAME, HASH REF, LIST<\/small> )<\/p>\n<p style=\"margin-left:17%;\">restrict the fields that will be printed to <small>LIST<\/small><\/p>\n<p style=\"margin-left:11%;\">setVarsInShMode( <small>FILENAME, INT, HASH REF, LIST<\/small> )<\/p>\n<p style=\"margin-left:17%;\">like setVarsInSh with <small>INT<\/small> being the chmod value for the config file<\/p>\n<p style=\"margin-left:11%;\">addVarsInSh( <small>FILENAME, HASH REF<\/small> )<\/p>\n<p style=\"margin-left:17%;\">like setVarsInSh but keeping the entries in the file<\/p>\n<p style=\"margin-left:11%;\">addVarsInSh( <small>FILENAME, HASH REF, LIST<\/small> )<\/p>\n<p style=\"margin-left:17%;\">like setVarsInSh but keeping the entries in the file<\/p>\n<p style=\"margin-left:11%;\">addVarsInShMode( <small>FILENAME, INT, HASH REF, LIST<\/small> )<\/p>\n<p style=\"margin-left:17%;\">like addVarsInShMode but keeping the entries in the file<\/p>\n<p style=\"margin-left:11%;\">setExportedVarsInCsh( <small>FILENAME, HASH REF, LIST<\/small> )<\/p>\n<p style=\"margin-left:17%;\">same as &#8220;setExportedVarsInSh&#8221; for csh format<\/p>\n<p style=\"margin-left:11%;\">template2file( <small>FILENAME_IN, FILENAME_OUT, HASH<\/small> )<\/p>\n<p style=\"margin-left:17%;\">read in a template file, replace keys @@@key@@@ with value, save it in out file<\/p>\n<p style=\"margin-left:11%;\">template2userfile( <small>PREFIX, FILENAME_IN, FILENAME_OUT, BOOL, HASH<\/small> )<\/p>\n<p style=\"margin-left:17%;\">read in a template file, replace keys @@@key@@@ with value, save it in every homes. If <small>BOOL<\/small> is true, overwrite existing files. <small>FILENAME_OUT<\/small> must be a relative filename<\/p>\n<p style=\"margin-left:11%;\">read_gnomekderc( <small>FILENAME, STRING<\/small> )<\/p>\n<p style=\"margin-left:17%;\">reads GNOME-like and KDE-like config files (aka windows-like). You must give a category. eg:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">read_gnomekderc(&#8220;\/etc\/skels\/.kderc&#8221;, &#8216;KDE&#8217;)<\/p>\n<p style=\"margin-left:11%;\">update_gnomekderc( <small>FILENAME, STRING, HASH<\/small> )<\/p>\n<p style=\"margin-left:17%;\">modifies GNOME-like and KDE-like config files (aka windows-like). If the category doesn\u2019t exist, it creates it. eg:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">update_gnomekderc(&#8220;\/etc\/skels\/.kderc&#8221;, &#8216;KDE&#8217;, <br \/> kfmIconStyle => &#8220;Large&#8221;)<\/p>\n<p style=\"margin-left:11%;\">fuzzy_pidofs( <small>REGEXP<\/small> )<\/p>\n<p style=\"margin-left:17%;\">return the list of process ids matching the regexp<\/p>\n<h2>OTHER <a name=\"OTHER\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">better_arch( <small>ARCH1, ARCH2<\/small> )<\/p>\n<p style=\"margin-left:17%;\">is <small>ARCH1<\/small> compatible with <small>ARCH2<\/small> ?<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">better_arch(\u2019i386\u2019, \u2019ia64\u2019) and better_arch(\u2019ia64\u2019, \u2019i386\u2019) are false<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">better_arch(\u2019k7\u2019, \u2019k6\u2019) is true and better_arch(\u2019k6\u2019, \u2019k7\u2019) is false<\/p>\n<p style=\"margin-left:11%;\">compat_arch( <small>STRING<\/small> )<\/p>\n<p style=\"margin-left:17%;\">test the architecture compatibility. eg:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">compat_arch(\u2019i386\u2019) is false on a ia64<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">compat_arch(\u2019k6\u2019) is true on a k6 and k7 but false on a i386 and i686<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">MDK::Common<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  MDK::Common::System \u2212 system\u2212related useful functions <\/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,3491],"class_list":["post-7156","post","type-post","status-publish","format-standard","hentry","category-sin-categoria","tag-man3","tag-mdkcommonsystem"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/7156","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=7156"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/7156\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=7156"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=7156"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=7156"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}