On 03/21/2012 04:10 PM, Vratislav Podzimek wrote:
---
  src/daemon/abrt-server.c |   31 ++++++++++++++++++++++++++++---
  1 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/src/daemon/abrt-server.c b/src/daemon/abrt-server.c
index 7ef9ce7..720692e 100644
--- a/src/daemon/abrt-server.c
+++ b/src/daemon/abrt-server.c
@@ -76,13 +76,12 @@ static unsigned total_bytes_read = 0;

  static uid_t client_uid = (uid_t)-1L;

-static int   pid;

  /* Create a new debug dump from client session.
   * Caller must ensure that all fields in struct client
   * are properly filled.
   */
-static int create_debug_dump(GHashTable *problem_info)
+static int create_debug_dump(GHashTable *problem_info, unsigned pid)
  {
      /* Create temp directory with the debug dump.
         This directory is renamed to final directory name after
@@ -311,6 +310,31 @@ static void die_if_data_is_missing(GHashTable 
*problem_info)
          error_msg_and_die("Some data is missing. Aborting.");
  }

+/*
+ * Takes hash table, looks for key FILENAME_PID and tries to convert its value
+ * to int.
+ */
+unsigned convert_pid(GHashTable *problem_info)
+{
+    long ret;
+    gchar *pid_str = (gchar *) g_hash_table_lookup(problem_info, FILENAME_PID);
+    char *err_pos;
+    int old_errno;
+
+    if (!pid_str)
+        error_msg_and_die("PID data is missing. Aborting!");
+
+    old_errno = errno;
+    errno = 0;
+    ret = strtol(pid_str,&err_pos, 10);
+    if (errno || pid_str == err_pos || *err_pos != '\0'
+        || ret>  UINT_MAX || ret<  1)
+        error_msg_and_die("Malformed or out-of-range PID number: '%s'", 
pid_str);
+    errno = old_errno;

I don't see why you bother to save/restore errno.

Why can't you use xatou() as current code does?
It's much more compact:

        pid = xatou(pid_str);
        if (pid < 1)
            /* pid == 0 is error, the lowest PID is 1. */
            error_msg_and_die("Malformed or out-of-range number: '%s'", 
pid_str);

--
vda

Reply via email to