[Uludag-commits] r16416 - in branches/comar-dbus/comar: . include src

uludag-commits at pardus.org.tr uludag-commits at pardus.org.tr
24 Ara 2007 Pzt 11:08:35 EET


Author: bahadir.kandemir
Date: Mon Dec 24 11:08:34 2007
New Revision: 16416

Modified:
   branches/comar-dbus/comar/CMakeLists.txt
   branches/comar-dbus/comar/include/cfg.h
   branches/comar-dbus/comar/include/process.h
   branches/comar-dbus/comar/src/cfg.c
   branches/comar-dbus/comar/src/main.c
   branches/comar-dbus/comar/src/process.c
Log:
Create pidfile

Modified: branches/comar-dbus/comar/CMakeLists.txt
=================================================================
--- branches/comar-dbus/comar/CMakeLists.txt	(original)
+++ branches/comar-dbus/comar/CMakeLists.txt	Mon Dec 24 11:08:34 2007
@@ -27,6 +27,7 @@
 ADD_DEFINITIONS (-D'VERSION="${VERSION}"'
                  -D'CONFIG_DIR="/etc/${APP_NAME}"'
                  -D'DATA_DIR="/var/db/${APP_NAME}"'
+                 -D'PID_FILE="/var/run/${APP_NAME}.pid"'
                  -D'LOG_FILE="/var/log/${APP_NAME}.log"')
 
 # Set standard sources

Modified: branches/comar-dbus/comar/include/cfg.h
=================================================================
--- branches/comar-dbus/comar/include/cfg.h	(original)
+++ branches/comar-dbus/comar/include/cfg.h	Mon Dec 24 11:08:34 2007
@@ -15,6 +15,7 @@
 extern int cfg_log_console;
 extern int cfg_log_file;
 extern char *cfg_log_file_name;
+extern char *cfg_pid_name;
 extern int cfg_log_flags;
 
 void cfg_init(int argc, char *argv[]);

Modified: branches/comar-dbus/comar/include/process.h
=================================================================
--- branches/comar-dbus/comar/include/process.h	(original)
+++ branches/comar-dbus/comar/include/process.h	Mon Dec 24 11:08:34 2007
@@ -32,7 +32,7 @@
 extern struct Proc my_proc;
 extern int shutdown_activated;
 
-void proc_init(int argc, char *argv[], const char *name);
+int proc_init(int argc, char *argv[], const char *name);
 int proc_listen(struct ProcChild **senderp, size_t *sizep, int timeout_sec, int timeout_usec);
 void proc_check_shutdown(void);
 struct ProcChild *proc_fork(void (*child_func)(void), const char *desc, DBusConnection *bus_conn, DBusMessage *bus_msg);

Modified: branches/comar-dbus/comar/src/cfg.c
=================================================================
--- branches/comar-dbus/comar/src/cfg.c	(original)
+++ branches/comar-dbus/comar/src/cfg.c	Mon Dec 24 11:08:34 2007
@@ -42,6 +42,9 @@
 //! Log file
 char *cfg_log_file_name = LOG_FILE;
 
+//! PID file
+char *cfg_pid_name = PID_FILE;
+
 //! Log debug flags
 int cfg_log_flags = 0;
 

Modified: branches/comar-dbus/comar/src/main.c
=================================================================
--- branches/comar-dbus/comar/src/main.c	(original)
+++ branches/comar-dbus/comar/src/main.c	Mon Dec 24 11:08:34 2007
@@ -43,7 +43,9 @@
     }
 
     // Initialize main process
-    proc_init(argc, argv, "Comar");
+    if (proc_init(argc, argv, "Comar") != 0) {
+        exit(1);
+    }
 
     // Start logging
     if (log_start() != 0) {

Modified: branches/comar-dbus/comar/src/process.c
=================================================================
--- branches/comar-dbus/comar/src/process.c	(original)
+++ branches/comar-dbus/comar/src/process.c	Mon Dec 24 11:08:34 2007
@@ -100,12 +100,13 @@
 }
 
 //! Initializes main process
-void
+int
 proc_init(int argc, char *argv[], const char *name)
 {
     /*!
      * Initializes main process. Gets name address, size, and
-     * initializes signal handler.
+     * initializes signal handler. Creates pidfile if bus type
+     * is system.
      *
      * @argc Number of arguments
      * @argv Array of arguments
@@ -129,6 +130,20 @@
     handle_signals();
     set_my_name(my_proc.desc);
     time_lastaction = time(0);
+
+    if (cfg_bus_type == DBUS_BUS_SYSTEM) {
+        FILE *f = fopen(cfg_pid_name, "w");
+        if (f) {
+            fprintf(f, "%d", getpid());
+            fclose(f);
+        }
+        else {
+            printf("Can't create pid file '%s'\n", cfg_pid_name);
+            return 1;
+        }
+    }
+
+    return 0;
 }
 
 //! Appends child process' information to parent's info table


Uludag-commits mesaj listesiyle ilgili daha fazla bilgi