Fix wrong output when nesting $combine-s
[monky] / src / openbsd.c
index 4d5f240..2cd3f0c 100644 (file)
@@ -10,7 +10,7 @@
  * Please see COPYING for details
  *
  * Copyright (c) 2007 Toni Spets
- * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
+ * Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al.
  *     (see AUTHORS)
  * All rights reserved.
  *
@@ -440,6 +440,14 @@ void update_load_average()
        info.loadavg[2] = (float) v[2];
 }
 
+#define OBSD_MAX_SENSORS 256
+static struct obsd_sensors_struct {
+       int device;
+       float temp[MAXSENSORDEVICES][OBSD_MAX_SENSORS];
+       unsigned int fan[MAXSENSORDEVICES][OBSD_MAX_SENSORS];
+       float volt[MAXSENSORDEVICES][OBSD_MAX_SENSORS];
+} obsd_sensors;
+
 /* read sensors from sysctl */
 void update_obsd_sensors()
 {
@@ -503,6 +511,41 @@ void update_obsd_sensors()
        init_sensors = 1;
 }
 
+void parse_obsd_sensor(struct text_object *obj, const char *arg)
+{
+       if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
+                       || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
+               obj->data.l = 0;
+               NORM_ERR("Invalid sensor number!");
+       } else
+               obj->data.l = atoi(&arg[0]);
+}
+
+void print_obsd_sensors_temp(struct text_object *obj, char *p, int p_max_size)
+{
+       obsd_sensors.device = sensor_device;
+       update_obsd_sensors();
+       temp_print(p, p_max_size,
+                       obsd_sensors.temp[obsd_sensors.device][obj->data.l],
+                       TEMP_CELSIUS);
+}
+
+void print_obsd_sensors_fan(struct text_object *obj, char *p, int p_max_size)
+{
+       obsd_sensors.device = sensor_device;
+       update_obsd_sensors();
+       snprintf(p, p_max_size, "%d",
+                       obsd_sensors.fan[obsd_sensors.device][obj->data.l]);
+}
+
+void print_obsd_sensors_volt(struct text_object *obj, char *p, int p_max_size)
+{
+       obsd_sensors.device = sensor_device;
+       update_obsd_sensors();
+       snprintf(p, p_max_size, "%.2f",
+                       obsd_sensors.volt[obsd_sensors.device][obj->data.l]);
+}
+
 /* chipset vendor */
 void get_obsd_vendor(char *buf, size_t client_buffer_size)
 {
@@ -539,49 +582,6 @@ void get_obsd_product(char *buf, size_t client_buffer_size)
        }
 }
 
-/* rdtsc() and get_freq_dynamic() copied from linux.c */
-
-#if  defined(__i386) || defined(__x86_64)
-__inline__ unsigned long long int rdtsc()
-{
-       unsigned long long int x;
-
-       __asm__ volatile(".byte 0x0f, 0x31":"=A" (x));
-       return x;
-}
-#endif
-
-/* return system frequency in MHz (use divisor=1) or GHz (use divisor=1000) */
-void get_freq_dynamic(char *p_client_buffer, size_t client_buffer_size,
-               const char *p_format, int divisor)
-{
-#if  defined(__i386) || defined(__x86_64)
-       struct timezone tz;
-       struct timeval tvstart, tvstop;
-       unsigned long long cycles[2];   /* gotta be 64 bit */
-       unsigned int microseconds;      /* total time taken */
-
-       memset(&tz, 0, sizeof(tz));
-
-       /* get this function in cached memory */
-       gettimeofday(&tvstart, &tz);
-       cycles[0] = rdtsc();
-       gettimeofday(&tvstart, &tz);
-
-       /* we don't trust that this is any specific length of time */
-       usleep(100);
-       cycles[1] = rdtsc();
-       gettimeofday(&tvstop, &tz);
-       microseconds = ((tvstop.tv_sec - tvstart.tv_sec) * 1000000) +
-               (tvstop.tv_usec - tvstart.tv_usec);
-
-       snprintf(p_client_buffer, client_buffer_size, p_format,
-               (float) ((cycles[1] - cycles[0]) / microseconds) / divisor);
-#else
-       get_freq(p_client_buffer, client_buffer_size, p_format, divisor, 1);
-#endif
-}
-
 /* void */
 char get_freq(char *p_client_buffer, size_t client_buffer_size,
                const char *p_format, int divisor, unsigned int cpu)
@@ -695,11 +695,11 @@ int comparecpu(const void *a, const void *b)
 
 int comparemem(const void *a, const void *b)
 {
-       if (((struct process *) a)->totalmem > ((struct process *) b)->totalmem) {
+       if (((struct process *) a)->rss > ((struct process *) b)->rss) {
                return -1;
        }
 
-       if (((struct process *) a)->totalmem < ((struct process *) b)->totalmem) {
+       if (((struct process *) a)->rss < ((struct process *) b)->rss) {
                return 1;
        }
 
@@ -740,8 +740,6 @@ inline void proc_find_top(struct process **cpu, struct process **mem)
                        processes[j].pid = p[i].p_pid;
                        processes[j].name = strndup(p[i].p_comm, text_buffer_size);
                        processes[j].amount = 100.0 * p[i].p_pctcpu / FSCALE;
-                       processes[j].totalmem = (float) (p[i].p_vm_rssize /
-                                       (float) total_pages) * 100.0;
                        j++;
                }
        }
@@ -753,7 +751,6 @@ inline void proc_find_top(struct process **cpu, struct process **mem)
                tmp = malloc(sizeof(struct process));
                tmp->pid = processes[i].pid;
                tmp->amount = processes[i].amount;
-               tmp->totalmem = processes[i].totalmem;
                tmp->name = strndup(processes[i].name, text_buffer_size);
 
                ttmp = mem[i];
@@ -771,7 +768,6 @@ inline void proc_find_top(struct process **cpu, struct process **mem)
                tmp = malloc(sizeof(struct process));
                tmp->pid = processes[i].pid;
                tmp->amount = processes[i].amount;
-               tmp->totalmem = processes[i].totalmem;
                tmp->name = strndup(processes[i].name, text_buffer_size);
 
                ttmp = cpu[i];
@@ -919,8 +915,14 @@ void prepare_update()
 {
 }
 
-void update_entropy(void)
+int get_entropy_avail(unsigned int *val)
+{
+       return 1;
+}
+
+int get_entropy_poolsize(unsigned int *val)
 {
+       return 1;
 }
 
 void free_all_processes(void)