WiP
[oweals/gnunet.git] / src / util / os_priority.c
index 3993f572c3fd190d5a66f75a43d04863e95ddf02..4e868a3ccd5add614d5636256d09f23d8897d3ce 100644 (file)
@@ -320,11 +320,32 @@ GNUNET_OS_set_process_priority (struct GNUNET_OS_Process *proc,
     SetPriorityClass (h, rprio);
   }
 #elif LINUX 
-  if (0 != setpriority (PRIO_PROCESS, proc->pid, rprio))
+  pid_t pid;
+
+  pid = proc->pid;
+  if ( (0 == pid) ||
+       (pid == getpid () ) )
     {
-      GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING |
-                          GNUNET_ERROR_TYPE_BULK, "setpriority");
-      return GNUNET_SYSERR;
+      int have = nice (0);
+      int delta = rprio - have;
+      errno = 0;
+      if ( (delta != 0) &&
+          (rprio == nice (delta)) && 
+          (errno != 0) )
+        {
+          GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING |
+                               GNUNET_ERROR_TYPE_BULK, "nice");
+          return GNUNET_SYSERR;
+        }
+    }
+  else
+    {
+      if (0 != setpriority (PRIO_PROCESS, pid, rprio))
+        {
+          GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING |
+                               GNUNET_ERROR_TYPE_BULK, "setpriority");
+          return GNUNET_SYSERR;
+        }
     }
 #else
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
@@ -439,7 +460,9 @@ CreateCustomEnvTable (char **vars)
  * @param pipe_stdout pipe to use to get output from child process (or NULL)
  * @param filename name of the binary
  * @param ... NULL-terminated list of arguments to the process
+ *
  * @return pointer to process structure of the new process, NULL on error
+ *
  */
 struct GNUNET_OS_Process *
 GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin,