Use setpriority() instead of nice() on UNIX-like systems.
[oweals/tinc.git] / src / tincd.c
index 89e0c93405b697273edf84866fc14e9adb2f3fd1..775815118b6486cc5ec70f56ad4c065c81f49f62 100644 (file)
@@ -5,6 +5,7 @@
                   2008      Max Rijevski <maksuf@gmail.com>
                   2009      Michael Tokarev <mjt@tls.msk.ru>
                   2010      Julien Muchembled <jm@jmuchemb.eu>
+                  2010      Timothy Redaelli <timothy@redaelli.eu>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -220,7 +221,9 @@ static bool parse_options(int argc, char **argv) {
                                break;
 
                        case 'n':                               /* net name given */
-                               netname = xstrdup(optarg);
+                               /* netname "." is special: a "top-level name" */
+                               netname = strcmp(optarg, ".") != 0 ?
+                                               xstrdup(optarg) : NULL;
                                break;
 
                        case 'o':                               /* option */
@@ -364,6 +367,7 @@ static bool keygen(int bits) {
        fchmod(fileno(f), 0600);
 #endif
                
+       fputc('\n', f);
        PEM_write_RSAPrivateKey(f, rsa_key, NULL, NULL, 0, NULL, NULL);
        fclose(f);
        free(filename);
@@ -381,6 +385,7 @@ static bool keygen(int bits) {
        if(disable_old_keys(f))
                fprintf(stderr, "Warning: old key(s) found and disabled.\n");
 
+       fputc('\n', f);
        PEM_write_RSAPublicKey(f, rsa_key);
        fclose(f);
        free(filename);
@@ -497,12 +502,12 @@ static bool drop_privs() {
 }
 
 #ifdef HAVE_MINGW
-# define setpriority(level) SetPriorityClass(GetCurrentProcess(), level)
+# define setpriority(level) SetPriorityClass(GetCurrentProcess(), (level))
 #else
 # define NORMAL_PRIORITY_CLASS 0
 # define BELOW_NORMAL_PRIORITY_CLASS 10
 # define HIGH_PRIORITY_CLASS -10
-# define setpriority(level) nice(level)
+# define setpriority(level) (setpriority(PRIO_PROCESS, 0, (level)))
 #endif
 
 int main(int argc, char **argv) {