~ubuntu-branches/ubuntu/vivid/thermald/vivid

« back to all changes in this revision

Viewing changes to src/main.cpp

  • Committer: Package Import Robot
  • Author(s): Colin King
  • Date: 2014-07-28 09:39:34 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20140728093934-xvrqjaw68x6q48ji
Tags: 1.3-1
Sync up with version 1.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
71
71
                gchar **pref_out, GError **error);
72
72
gboolean thd_dbus_interface_set_user_max_temperature(PrefObject *obj,
73
73
                gchar *zone_name, gchar *temperature, GError **error);
 
74
gboolean thd_dbus_interface_set_user_passive_temperature(PrefObject *obj,
 
75
                gchar *zone_name, gchar *temperature, GError **error);
74
76
// This is a generated file, which expects the above prototypes
75
77
#include "thd-dbus-interface.h"
76
78
 
176
178
        return TRUE;
177
179
}
178
180
 
 
181
gboolean thd_dbus_interface_set_user_passive_temperature(PrefObject *obj,
 
182
                gchar *zone_name, gchar *temperature, GError **error) {
 
183
        thd_log_debug("thd_dbus_interface_set_user_passive_temperature %s:%s\n", zone_name,
 
184
                        temperature);
 
185
        g_assert(obj != NULL);
 
186
        cthd_preference thd_pref;
 
187
        if (thd_engine->thd_engine_set_user_psv_temp(zone_name,
 
188
                        (char*) temperature) == THD_SUCCESS)
 
189
                thd_engine->send_message(PREF_CHANGED, 0, NULL);
 
190
 
 
191
        return TRUE;
 
192
}
 
193
 
179
194
// g_log handler. All logs will be directed here
180
195
void thd_logger(const gchar *log_domain, GLogLevelFlags log_level,
181
196
                const gchar *message, gpointer user_data) {
209
224
                g_print("%s", message);
210
225
}
211
226
 
 
227
bool check_thermald_running() {
 
228
        const char *lock_file = TDRUNDIR"/thermald.pid";
 
229
        int pid_file_handle;
 
230
 
 
231
        pid_file_handle = open(lock_file, O_RDWR | O_CREAT, 0600);
 
232
        if (pid_file_handle == -1) {
 
233
                /* Couldn't open lock file */
 
234
                thd_log_error("Could not open PID lock file %s, exiting\n", lock_file);
 
235
                return false;
 
236
        }
 
237
        /* Try to lock file */
 
238
        if (lockf(pid_file_handle, F_TLOCK, 0) == -1) {
 
239
                /* Couldn't get lock on lock file */
 
240
                thd_log_error("Couldn't get lock file %d\n", getpid());
 
241
                return true;
 
242
        }
 
243
 
 
244
        return false;
 
245
}
 
246
 
212
247
static GMainLoop *g_main_loop;
213
248
 
214
249
// Setup dbus server
282
317
                }
283
318
        }
284
319
 
 
320
        if (check_thermald_running()) {
 
321
                thd_log_fatal(
 
322
                                "An instance of thermald is already running, exiting ...\n");
 
323
                exit(EXIT_FAILURE);
 
324
        }
 
325
 
285
326
        thd_engine = new cthd_engine_default();
286
327
        if (exclusive_control)
287
328
                thd_engine->set_control_mode(EXCLUSIVE);