~ubuntu-branches/ubuntu/dapper/cpufreqd/dapper

« back to all changes in this revision

Viewing changes to libsys_apm.c

  • Committer: Bazaar Package Importer
  • Author(s): Mattia Dongili
  • Date: 2005-11-27 18:47:42 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051127184742-9h26euwetr6kh1e6
Tags: 2.0.0-1

* New upstream release.
* cpufreqd.init: exit succesfully in case a stop is issued and
  cpufreqd is found running as requested by LSB thus making it
  possible to remove cpufreqd when cpufreqd itsef is stopped
  (closes: #340133)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  Copyright (C) 2002,2003,2004  Mattia Dongili<dongili@supereva.it>
3
 
 *                                George Staikos <staikos@0wned.org>
4
 
 *
5
 
 *  This program is free software; you can redistribute it and/or modify
6
 
 *  it under the terms of the GNU General Public License as published by
7
 
 *  the Free Software Foundation; either version 2 of the License, or
8
 
 *  (at your option) any later version.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 
 */
19
 
 
20
 
#include "libsys.h"
21
 
 
22
 
int libsys_init(void) {
23
 
  struct stat sb;
24
 
  int rc;
25
 
  
26
 
  rc = stat(APM_PROC_FILE, &sb);
27
 
  if (rc < 0) {
28
 
    cp_log(LOG_ERR, "libsys_init(): %s: %s\n", APM_PROC_FILE, strerror(errno));
29
 
    return -1;
30
 
  }
31
 
  return 0;
32
 
}
33
 
 
34
 
void libsys_fini (void) {}
35
 
 
36
 
/* int scan_system_info(sys_info *s) 
37
 
 *
38
 
 * Reads APM info and fills the input sys_info struct.
39
 
 * Implements the prototype needed by cpufreqd to get
40
 
 * info from the PM layer.
41
 
 *
42
 
 * Returns 0 on success, -1 otherwise
43
 
 *
44
 
 */
45
 
int scan_system_info(sys_info *s) {
46
 
  
47
 
  FILE *fp;
48
 
  char buf[101];
49
 
  
50
 
  /***** APM SCAN *****/
51
 
  char ignore3[101];
52
 
  int ignore;
53
 
  unsigned int ignore2;
54
 
  unsigned int batt_flag;
55
 
    
56
 
  fp = fopen(APM_PROC_FILE , "r");
57
 
  if (!fp) {
58
 
    cp_log(LOG_ERR, "scan_system_info(): %s: %s\n", APM_PROC_FILE, strerror(errno));
59
 
    return -1;
60
 
  }
61
 
    
62
 
  if (!fgets(buf, 100, fp)) {
63
 
    fclose(fp);
64
 
    cp_log(LOG_ERR, "scan_system_info(): %s: %s\n", APM_PROC_FILE, strerror(errno));
65
 
    return -1;
66
 
  }
67
 
    
68
 
  sscanf(buf, "%s %d.%d %x %x %x %x %d%% %d %s\n",
69
 
                    s->version, &ignore, &ignore, &s->flags, &s->ac, &ignore2,
70
 
                    &batt_flag, &s->battery_percent, &s->battery_time, ignore3);
71
 
 
72
 
  if (!strncmp(ignore3, "sec", 3)) {
73
 
    s->battery_time /= 60;
74
 
  }
75
 
    
76
 
  if (s->battery_percent > 100) {
77
 
    s->battery_percent = -1;
78
 
  }
79
 
 
80
 
  s->has_battery = batt_flag < 128;
81
 
    
82
 
  fclose(fp);
83
 
  
84
 
  cp_log(LOG_INFO, "scan_system_info(): battery %s - %d - %s cpu %d\n",
85
 
                    s->has_battery?"present":"absent", 
86
 
                    s->battery_percent, 
87
 
                    s->ac?"on-line":"off-line",
88
 
                    s->cpu_percent );
89
 
  return 0;
90
 
}
91
 
 
92