Server IP : 158.178.228.73 / Your IP : 80.80.80.153 Web Server : Apache/2.4.37 (Oracle Linux Server) OpenSSL/1.1.1k System : Linux ust-wp1-prod 5.15.0-308.179.6.el8uek.x86_64 #2 SMP Wed Apr 23 10:46:57 PDT 2025 x86_64 User : tomasFtp ( 1007) PHP Version : 8.4.8 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /proc/thread-self/root/proc/self/root/proc/thread-self/root/bin/ |
Upload File : |
#!/usr/libexec/platform-python -s # See included LICENSE file for additional license and copyright information. from __future__ import print_function import sys import os # This script might invoke itself if the user moves it to /bin/uname. # When this happens, exit with a special code so that the invoking # process can fail with the correct error message. RECURSIVE_USE_EXIT_CODE = 17 if 'KSPLICE_INVOKED_BY_UPTRACK_UNAME' in os.environ: sys.exit(RECURSIVE_USE_EXIT_CODE) os.environ['KSPLICE_INVOKED_BY_UPTRACK_UNAME'] = 'True' BUG_EMAIL = 'Oracle support' RECURSIVE_USE_MESSAGE = """\ It seems that /bin/uname is a copy or symlink of uptrack-uname. This is not a supported configuration. Please reinstall the version of /bin/uname that came with your Linux distribution's packages. Please contact %s for assistance if you are unable to resolve this error.""" % (BUG_EMAIL,) def exception_hook(ty, val, tb): # If something unexpected happens, fall back to /bin/uname. print("uptrack-uname: unexpected error", file=sys.stderr) try: # Log to /tmp because we might not have write privs elsewhere. import tempfile import traceback (logfile_fd, logfile_name) = tempfile.mkstemp(prefix='uptrack-uname.log.') logfile = os.fdopen(logfile_fd, 'w') print("uptrack-uname invoked as", sys.argv, "\n", file=logfile) traceback.print_exception(ty, val, tb, file=logfile) logfile.close() print("Please send the file %s\nto %s for assistance.\n" % (logfile_name, BUG_EMAIL), file=sys.stderr) except Exception: print("Could not write error message to log file.", file=sys.stderr) print("Please contact %s for assistance.\n" % (BUG_EMAIL,), file=sys.stderr) print("Falling back to original kernel version.\n", file=sys.stderr) os.execv('/bin/uname', ['/bin/uname'] + sys.argv[1:]) # Disable Launchpad's apport traceback hooks, and install our own hook sys.excepthook = exception_hook # We don't want to get KeyboardInterrupt. Just kill the program. import signal signal.signal(signal.SIGINT, signal.SIG_DFL) from uptrack import version import optparse import errno import subprocess import yaml try: from yaml import CSafeLoader as yaml_loader except ImportError: from yaml import SafeLoader as yaml_loader EFFECTIVE_FILE = '/var/lib/uptrack/effective_kernel' class UptrackUname(object): def getInstalledIDs(self): # This is like Uptrack.LocalStatus.getInstalledIDs, but less precise # and doesn't require root, because we don't check the 'stage' file. ids = set() # Don't rely on lsmod being in $PATH. new_env = {'PATH': '/sbin:/bin:' + os.environ.get('PATH', '/bin')} proc = subprocess.Popen('lsmod', shell=True, env=new_env, stdout=subprocess.PIPE, stderr=open('/dev/null', 'w')) out, _ = proc.communicate() if proc.returncode: return set() for ln in out.decode('utf-8').splitlines(): parts = ln.split() if parts: # We'd like to check for new-code modules only, but that will miss # cold-applied updates. if parts[0].startswith('ksplice_'): if len(parts[0].split('_')) > 1: ids.add(parts[0].split('_')[1]) return ids def getEffective(self): # This is like Uptrack.LocalStatus.getEffective. try: f = open(EFFECTIVE_FILE, 'r') data = yaml.load(f, Loader=yaml_loader) f.close() except IOError as e: if e.errno == errno.EACCES: self.permission_denied = True return None except Exception: return None try: orig = data['OriginalKernel'] if False in [orig[k] == self.os_uname[k] for k in ('Sysname', 'Release', 'Version', 'UserArchitecture')]: return None # If uptrack-upgrade was interrupted, it could leave an update that looks # installed to us but isn't really. We'll still consider the effective # kernel data valid in that case. if not self.installed >= set(data['Installed']): return None return data['EffectiveKernel'] except (KeyError, TypeError): return None def __init__(self): self.permission_denied = False # Get some information directly from the uname(2) syscall. keys = ['Sysname', 'Hostname', 'Release', 'Version', 'UserArchitecture'] self.os_uname = dict(zip(keys, os.uname())) # Get the installed KIDs. self.installed = self.getInstalledIDs() self.no_updates = len(self.installed) == 0 # Load effective kernel data, or None if it can't be determined. self.effective = self.getEffective() # Have we warned about missing effective kernel data? self.warned = False self.parser = optparse.OptionParser("""\ usage: %prog [options] Print the effective kernel version according to Ksplice Uptrack. Accepts uname(1) command-line options and produces compatible output.""", version=version.version, add_help_option=False) # Add this manually so that we don't get -h too. self.parser.add_option('--help', action='help', help='show this help message and exit') uname_group = optparse.OptionGroup(self.parser, "uname(1) options") uname_group.add_option('-a', '--all', action='store_true', dest='all', default=False, help='print all information, in the following order, except omit -p and -i if unknown') # The names of methods which contribute traditional uname(1) components. self.methods = [] def flag(short, long, help): ident = long.replace('-', '_') uname_group.add_option('-' + short, '--' + long, action='store_true', dest=ident, default=False, help=help) self.methods.append(ident) # The order here sets the output order. flag('s', 'kernel-name', 'print the kernel name') flag('n', 'nodename', 'print the network node hostname') flag('r', 'kernel-release', 'print the kernel release') flag('v', 'kernel-version', 'print the kernel version') flag('m', 'machine', 'print the machine hardware name') flag('p', 'processor', 'print the processor type or "unknown"') flag('i', 'hardware-platform', 'print the hardware platform or "unknown"') flag('o', 'operating-system', 'print the operating system') self.parser.add_option_group(uname_group) uptrack_group = optparse.OptionGroup(self.parser, "Uptrack-specific options") uptrack_group.add_option('--package-version', action='store_true', dest='package_version', default=False, help="print the effective version of the distribution's kernel " "package, on a separate line") uptrack_group.add_option('--no-fallback', action='store_false', dest='fallback', default=True, help="exit with failure when effective kernel data is unavailable, " "rather than falling back to the original kernel version") self.parser.add_option_group(uptrack_group) def main(self, args): self.opts, args = self.parser.parse_args(args) # With no flags, act like uname -s if not self.opts.all and not self.opts.package_version and (True not in [getattr(self.opts, m) for m in self.methods]): self.opts.kernel_name = True # --package-version implies --no-fallback if self.opts.package_version: self.opts.fallback = False if self.effective is None: self.warnMissingEffective() # will exit out = [] for m in self.methods: if self.opts.all or getattr(self.opts, m): out.append(getattr(self, m)()) if len(out) > 0: print(' '.join([x for x in out if x is not None])) if self.opts.package_version: print("Package version:", self.effective['PackageVersion']) def warnMissingEffective(self): if self.warned: return if self.permission_denied: print("""\ Uptrack does not have permission to read your effective kernel version from %s . Check the file and directory permissions, or re-run uptrack-uname as root.""" % (EFFECTIVE_FILE,), file=sys.stderr) else: print("""\ Uptrack is unable to determine your effective kernel version. Please run '/usr/sbin/uptrack-upgrade -n' to update the effective kernel data.""", file=sys.stderr) print(""" Please contact %s for assistance if you are unable to resolve this error. """ % (BUG_EMAIL,), file=sys.stderr) if not self.opts.fallback: sys.exit(1) print("Falling back to original kernel version.\n", file=sys.stderr) self.warned = True def kernel_name(self): return self.os_uname['Sysname'] def nodename(self): return self.os_uname['Hostname'] def machine(self): return self.os_uname['UserArchitecture'] def bin_uname(self, arg, dfl): try: proc = subprocess.Popen(['/bin/uname', arg], stdout=subprocess.PIPE, stderr=open('/dev/null', 'w')) out, _ = proc.communicate() if proc.returncode == RECURSIVE_USE_EXIT_CODE: print(RECURSIVE_USE_MESSAGE, file=sys.stderr) sys.exit(1) elif proc.returncode: return dfl return out.decode('utf-8') except SystemExit: raise except Exception: return dfl def plat(self, arg): # x86 Linux doesn't really provide these. /bin/uname # might return 'unknown' or the architecture or something. # If it returns 'unknown' we hide it from -a. x = self.bin_uname(arg, 'unknown').strip() if x == 'unknown' and self.opts.all: return None return x def processor(self): return self.plat('-p') def hardware_platform(self): return self.plat('-i') def operating_system(self): return self.bin_uname('-o', 'GNU/Linux').strip() def effectiveField(self, field): # If no updates are installed and we have no effective kernel data, # follow uname(2). This is particularly likely after booting into a # new kernel. if self.no_updates and not self.effective: return self.os_uname[field] if not self.effective: self.warnMissingEffective() return self.os_uname[field] return self.effective[field] def kernel_release(self): return self.effectiveField('Release') def kernel_version(self): return self.effectiveField('Version') if __name__ == '__main__': UptrackUname().main(sys.argv[1:]) """ =head1 NAME uptrack-uname - print the Ksplice Uptrack effective kernel version. =head1 SYNOPSIS B<uptrack-uname> [I<OPTION>] =head1 DESCRIPTION B<uptrack-uname> prints the effective kernel version according to Ksplice Uptrack. It accepts B<uname(1)> command-line options and produces compatible output. =head1 OPTIONS =over 4 =item B<--version> Show program's version number and exit. =item B<--help> Show a help message and exit. =back =head2 UNAME(1) OPTIONS =over 4 =item B<-a>, B<--all> Print all information, in the following order, except omit B<-p> and B<-i> if unknown. =item B<-s>, B<--kernel-name> Print the kernel name. =item B<-n>, B<--nodename> Print the network node hostname. =item B<-r>, B<--kernel-release> Print the kernel release. =item B<-v>, B<--kernel-version> Print the kernel version. =item B<-m>, B<--machine> Print the machine hardware name. =item B<-p>, B<--processor> Print the processor type or "unknown". =item B<-i>, B<--hardware-platform> Print the hardware platform or "unknown". =item B<-o>, B<--operating-system> Print the operating system. =back =head2 UPTRACK-SPECIFIC OPTIONS =over 4 =item B<--package-version> Print the effective version of the distribution's kernel package, on a separate line. =item B<--no-fallback> Exit with failure when effective kernel data is unavailable, rather than falling back to the original kernel version. =back =head1 SEE ALSO L<uptrack-upgrade(8)>, L<uptrack-install(8)>, L<uptrack-remove(8)>, L<uptrack-show(8)> =head1 BUGS Please report bugs to <ksplice-support_ww@oracle.com>. =head1 AUTHORS Keegan McAllister et al. =head1 COPYRIGHT See included LICENSE file for additional license and copyright information. =cut """