Changeset 4119

Show
Ignore:
Timestamp:
08/28/06 23:19:59 (7 years ago)
Author:
khali
Message:

sensors-detect: Exit immediately if user isn't root. It makes very little
sense to try and continue as a non-root user, as we won't be able to load
modules, nor to probe i2c busses, nor to access the ISA ports. It's way
less confusing for the user to clearly state he/she needs to be root,
and stop.

Location:
lm-sensors/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/trunk/CHANGES

    r4118 r4119  
    7575                          Add Analog Devices ADM1033, ADM1034, ADT7462, 
    7676                           ADT7466, ADT7470, ADT7473 and ADT7475 detection 
     77                          Check for root user at startup 
    7778 
    7879 
  • lm-sensors/trunk/prog/detect/sensors-detect

    r4117 r4119  
    52485248  my (@adapters,$res,$did_adapter_detection,$adapter); 
    52495249 
     5250  # We won't go very far if not root 
     5251  unless ($> == 0) { 
     5252    print "You need to be root to run this script.\n"; 
     5253    exit -1; 
     5254  } 
     5255 
    52505256  initialize_conf; 
    52515257  initialize_proc_pci; 
     
    52585264        "load to use lm_sensors most effectively. You need to have i2c and\n", 
    52595265        "lm_sensors installed before running this program.\n"; 
    5260   print "Also, you need to be `root', or at least have access to the $dev_i2c*\n", 
    5261         "files, for most things.\n"; 
    52625266  print "If you have patched your kernel and have some drivers built in, you can\n", 
    52635267        "safely answer NO if asked to load some modules. In this case, things may\n", 
     
    52675271 
    52685272  print " We can start with probing for (PCI) I2C or SMBus adapters.\n"; 
    5269   print " You do not need any special privileges for this.\n"; 
    52705273  print " Do you want to probe now? (YES/no): "; 
    52715274  @adapters = adapter_pci_detection  
     
    52775280    print "As you skipped adapter detection, we will only scan already loaded\n". 
    52785281          "adapter modules.\n"; 
    5279   } elsif ($> != 0) { 
    5280     print "As you are not root, we can't load adapter modules. We will only scan\n". 
    5281           "already loaded adapters.\n"; 
    52825282  } else { 
    52835283    print "We will now try to load each adapter module in turn.\n"; 
     
    53115311    print "i2c-dev is already loaded.\n"; 
    53125312  } else { 
    5313     if ($> != 0) { 
    5314       print " i2c-dev is not loaded. As you are not root, we will just hope ", 
    5315             "you edited\n", 
    5316             " `$modules_conf' for automatic loading of\n", 
    5317             " this module. If not, you won't be able to open any $dev_i2c* file.\n"; 
     5313    print "i2c-dev is not loaded. Do you want to load it now? (YES/no): "; 
     5314    if (<STDIN> =~ /^\s*n/i) { 
     5315      print "Well, you will know best.\n"; 
     5316    } elsif (system "modprobe", "i2c-dev") { 
     5317      print "Loading failed, expect problems later on.\n"; 
    53185318    } else { 
    5319       print " i2c-dev is not loaded. Do you want to load it now? (YES/no): "; 
    5320       if (<STDIN> =~ /^\s*[Nn]/) { 
    5321         print " Well, you will know best. We will just hope you edited ", 
    5322               "`$modules_conf'\n", 
    5323               " for automatic loading of this module. If not,\n", 
    5324               " you won't be able to open any $dev_i2c* file (unless you", 
    5325               "have it built-in\n", 
    5326               " into your kernel)\n"; 
    5327       } elsif (system "modprobe","i2c-dev") { 
    5328         print " Loading failed, expect problems later on.\n"; 
    5329       } else { 
    5330         print " Module loaded successfully.\n"; 
    5331       } 
     5319      print "Module loaded successfully.\n"; 
    53325320    } 
    53335321  } 
     
    53795367        "this. This is usually safe though.\n". 
    53805368        "Yes, you do have ISA I/O ports even if you do not have any ISA slots!\n\n"; 
    5381   if ($> != 0) { 
    5382     print "As you are not root, we shall skip this step.\n"; 
    5383   } else { 
    5384     print "Do you want to scan the ISA I/O ports? (YES/no): "; 
    5385     unless (<STDIN> =~ /^\s*n/i) { 
    5386       initialize_ioports(); 
    5387       scan_isa_bus(); 
    5388       close_ioports(); 
    5389     } 
     5369  print "Do you want to scan the ISA I/O ports? (YES/no): "; 
     5370  unless (<STDIN> =~ /^\s*n/i) { 
     5371    initialize_ioports(); 
     5372    scan_isa_bus(); 
     5373    close_ioports(); 
    53905374  } 
    53915375 
     
    53935377        "typically a bit more dangerous, as we have to write to I/O ports to do\n". 
    53945378        "this. This is usually safe though.\n\n"; 
    5395   if ($> != 0) { 
    5396     print "As you are not root, we shall skip this step.\n"; 
    5397   } else { 
    5398     print "Do you want to scan for Super I/O sensors? (YES/no): "; 
     5379  print "Do you want to scan for Super I/O sensors? (YES/no): "; 
     5380  unless (<STDIN> =~ /^\s*n/i) { 
     5381    initialize_ioports(); 
     5382    scan_superio(0x2e, 0x2f); 
     5383    print "\nDo you want to scan for secondary Super I/O sensors? (YES/no): "; 
    53995384    unless (<STDIN> =~ /^\s*n/i) { 
    5400       initialize_ioports(); 
    5401       scan_superio(0x2e, 0x2f); 
    5402       print "\nDo you want to scan for secondary Super I/O sensors? (YES/no): "; 
    5403       unless (<STDIN> =~ /^\s*n/i) { 
    5404         scan_superio(0x4e, 0x4f); 
    5405       } 
    5406       close_ioports(); 
     5385      scan_superio(0x4e, 0x4f); 
    54075386    } 
     5387    close_ioports(); 
    54085388  } 
    54095389 
     
    54815461  print "\nDo you want to generate /etc/sysconfig/lm_sensors? (". 
    54825462    ($have_sysconfig?"YES/no":"yes/NO")."): "; 
    5483   if ($> != 0) { 
    5484     print "\nAs you are not root, we shall skip this step.\n"; 
    5485   } else { 
    5486     $_ = <STDIN>; 
    5487     if (($have_sysconfig and not m/^\s*[Nn]/) or m/^\s*[Yy]/) { 
    5488       unless ($have_sysconfig) { 
    5489         mkdir '/etc/sysconfig', 0777 
    5490           or die "Sorry, can't create /etc/sysconfig ($!)?!?"; 
    5491       } 
    5492       open(local *SYSCONFIG, ">/etc/sysconfig/lm_sensors") 
    5493         or die "Sorry, can't create /etc/sysconfig/lm_sensors ($!)?!?"; 
    5494       print SYSCONFIG <<'EOT'; 
     5463  $_ = <STDIN>; 
     5464  if (($have_sysconfig and not m/^\s*n/i) or m/^\s*y/i) { 
     5465    unless ($have_sysconfig) { 
     5466      mkdir '/etc/sysconfig', 0777 
     5467        or die "Sorry, can't create /etc/sysconfig ($!)"; 
     5468    } 
     5469    open(local *SYSCONFIG, ">/etc/sysconfig/lm_sensors") 
     5470      or die "Sorry, can't create /etc/sysconfig/lm_sensors ($!)"; 
     5471    print SYSCONFIG <<'EOT'; 
    54955472#    /etc/sysconfig/sensors - Defines modules loaded by /etc/rc.d/init.d/lm_sensors 
    54965473#    Copyright (c) 1998 - 2001  Frodo Looijaard <frodol@dds.nl> 
     
    55245501# 
    55255502EOT 
    5526       print SYSCONFIG 
    5527        "# Generated by sensors-detect on " . scalar localtime() . "\n"; 
    5528       my @modules = grep /^modprobe /, split "\n", $modprobes; 
    5529       my $i = 0; 
    5530       my $sysconfig = ""; 
    5531       foreach (@modules) { 
    5532         s/^modprobe //; 
    5533         $sysconfig .= "MODULE_$i=$_\n"; 
    5534         $i++; 
    5535       } 
    5536       print SYSCONFIG $sysconfig; 
    5537       print "Copy prog/init/lm_sensors.init to /etc/rc.d/init.d/lm_sensors\n"; 
    5538       print "for initialization at boot time.\n"; 
     5503    print SYSCONFIG 
     5504      "# Generated by sensors-detect on " . scalar localtime() . "\n"; 
     5505    my @modules = grep /^modprobe /, split "\n", $modprobes; 
     5506    my $i = 0; 
     5507    my $sysconfig = ""; 
     5508    foreach (@modules) { 
     5509      s/^modprobe //; 
     5510      $sysconfig .= "MODULE_$i=$_\n"; 
     5511      $i++; 
    55395512    } 
     5513    print SYSCONFIG $sysconfig; 
     5514    print "Copy prog/init/lm_sensors.init to /etc/rc.d/init.d/lm_sensors\n"; 
     5515    print "for initialization at boot time.\n"; 
    55405516  } 
    55415517}